blob: 5ca1e0f400412a68b26331895a2070e44e258d8c [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]420ae012009-04-24 05:16:3225#include "chrome/browser/dom_operation_notification_details.h"
[email protected]bcef0dc02009-02-28 00:35:0226#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0128#include "chrome/browser/download/download_request_limiter.h"
[email protected]3c733bde2010-12-21 19:56:3129#include "chrome/browser/external_protocol_handler.h"
[email protected]0150cfc2011-04-07 22:51:4130#include "chrome/browser/favicon_service.h"
[email protected]3c733bde2010-12-21 19:56:3131#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2132#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5833#include "chrome/browser/history/history_types.h"
[email protected]420ae012009-04-24 05:16:3234#include "chrome/browser/load_from_memory_cache_details.h"
35#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4436#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]724159a2010-12-30 01:11:1837#include "chrome/browser/metrics/user_metrics.h"
[email protected]f364d1392011-04-08 21:03:1038#include "chrome/browser/notifications/desktop_notification_service.h"
[email protected]dcb72d52011-04-13 12:36:5339#include "chrome/browser/notifications/desktop_notification_service_factory.h"
[email protected]c8865482009-07-23 20:40:1040#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1741#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2442#include "chrome/browser/platform_util.h"
[email protected]67c052e2011-01-31 16:33:5843#include "chrome/browser/plugin_observer.h"
[email protected]36fb2c7c2011-04-04 15:49:0844#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3345#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5446#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3247#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1348#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1749#include "chrome/browser/sessions/session_types.h"
[email protected]a40f6e92011-03-04 23:30:2950#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4951#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5252#include "chrome/browser/tab_contents/thumbnail_generator.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]0a8db0d2011-04-13 15:15:40163 prefs::kDefaultCharset,
164 prefs::kEnableReferrers
[email protected]420ae012009-04-24 05:16:32165};
166
167const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
168
[email protected]420ae012009-04-24 05:16:32169#if defined(OS_WIN)
170
171BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
172 // Note: erase is required to properly paint some widgets borders. This can
173 // be seen with textfields.
174 InvalidateRect(hwnd, NULL, TRUE);
175 return TRUE;
176}
177#endif
178
[email protected]2c5569662011-03-22 20:45:02179ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16180 Profile* profile, const NavigationEntry& entry,
181 NavigationController::ReloadType reload_type) {
182 switch (reload_type) {
183 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02184 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16185 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02186 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16187 case NavigationController::NO_RELOAD:
188 break; // Fall through to rest of function.
189 }
[email protected]5e369672009-11-03 23:48:30190
191 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
192 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02193 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30194
[email protected]2c5569662011-03-22 20:45:02195 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30196}
197
[email protected]876bc832010-09-07 16:29:54198void MakeNavigateParams(const NavigationEntry& entry,
199 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16200 NavigationController::ReloadType reload_type,
201 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34202 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54203 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00204 params->current_history_list_offset = controller.last_committed_entry_index();
205 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34206 params->url = entry.url();
207 params->referrer = entry.referrer();
208 params->transition = entry.transition_type();
209 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00210 params->navigation_type =
211 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34212 params->request_time = base::Time::Now();
213}
214
[email protected]420ae012009-04-24 05:16:32215} // namespace
216
[email protected]f4f50ef2011-01-21 19:01:19217
218// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32219
[email protected]420ae012009-04-24 05:16:32220TabContents::TabContents(Profile* profile,
221 SiteInstance* site_instance,
222 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07223 const TabContents* base_tab_contents,
224 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42225 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07226 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
227 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13228 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22229 TabContentsView::Create(this))),
230 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06231 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34232 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23233 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
234 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34235 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34236 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57237 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56238 upload_size_(0),
239 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57240 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40241 blocked_contents_(NULL),
242 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49243 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47244 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57245 capturing_contents_(false),
246 is_being_destroyed_(false),
247 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57248#if defined(OS_WIN)
249 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
250#endif
[email protected]c2e74fe82009-09-03 17:57:44251 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01252 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56253 opener_web_ui_type_(WebUI::kNoWebUI),
[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]1718509f2011-04-12 07:04:34267 // Start the in-browser thumbnailing if the feature is enabled.
268 if (CommandLine::ForCurrentProcess()->HasSwitch(
269 switches::kEnableInBrowserThumbnailing)) {
270 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
271 if (generator)
272 generator->StartThumbnailing();
273 }
274
[email protected]12636df2009-09-28 22:32:21275 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32276
[email protected]34ac70502009-09-25 17:07:23277 // We have the initial size of the view be based on the size of the passed in
278 // tab contents (normally a tab from the same window).
279 view_->CreateView(base_tab_contents ?
280 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32281
282 // Register for notifications about all interested prefs change.
283 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28284 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32285 if (prefs) {
286 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28287 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32288 }
289
[email protected]420ae012009-04-24 05:16:32290 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
291 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09292#if defined(OS_LINUX)
293 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
294 NotificationService::AllSources());
295#endif
[email protected]420ae012009-04-24 05:16:32296
[email protected]6c32ce72010-03-08 05:18:06297 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
298 NotificationService::AllSources());
299
[email protected]79580c62010-02-02 02:36:25300 // Register for notifications about content setting changes.
301 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
302 NotificationService::AllSources());
303
[email protected]969182a2011-03-03 14:53:23304 // Listen for Google URL changes.
[email protected]88152052010-10-01 04:05:18305 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
306 NotificationService::AllSources());
307
[email protected]c8865482009-07-23 20:40:10308 // Set-up the showing of the omnibox search infobar if applicable.
309 if (OmniboxSearchHint::IsEnabled(profile))
310 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53311
[email protected]b5a1d11c2011-02-17 03:09:42312 // Can only add observers after render_manager_.Init() is called, since that's
313 // what sets up the render_view_host which TabContentObserver's constructor
314 // uses to get the routing_id.
315 AddObservers();
[email protected]332af7732009-03-11 13:21:35316}
initial.commit09911bf2008-07-26 23:55:29317
318TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32319 is_being_destroyed_ = true;
320
[email protected]bfe4c1582009-10-02 18:11:09321 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32322 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28323 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32324
[email protected]420ae012009-04-24 05:16:32325 NotifyDisconnected();
[email protected]7ec6bef2011-02-26 02:22:29326 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:32327
[email protected]420ae012009-04-24 05:16:32328 // First cleanly close all child windows.
329 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
330 // some of these to close. CloseWindows is async, so it might get called
331 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49332 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32333
[email protected]c65e2f152010-10-14 15:30:40334 // Close all blocked contents.
335 if (blocked_contents_)
336 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13337
[email protected]420ae012009-04-24 05:16:32338 // Notify any observer that have a reference on this tab contents.
339 NotificationService::current()->Notify(
340 NotificationType::TAB_CONTENTS_DESTROYED,
341 Source<TabContents>(this),
342 NotificationService::NoDetails());
343
[email protected]1e5e74f2009-05-27 20:55:12344 // Notify any lasting InfobarDelegates that have not yet been removed that
345 // whatever infobar they were handling in this TabContents has closed,
346 // because the TabContents is going away entirely.
347 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
348 // notification may trigger infobars calls that access their delegate. (and
349 // some implementations of InfoBarDelegate do delete themselves on
350 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40351 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12352 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
353 delegate->InfoBarClosed();
354 }
355 infobar_delegates_.clear();
356
[email protected]420ae012009-04-24 05:16:32357 // TODO(brettw) this should be moved to the view.
358#if defined(OS_WIN)
359 // If we still have a window handle, destroy it. GetNativeView can return
360 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42361 if (GetNativeView()) {
362 RenderViewHost* host = render_view_host();
[email protected]b9a1fb42011-04-12 23:16:44363 if (host && host->view())
[email protected]50bd6452010-11-27 19:39:42364 host->view()->WillWmDestroy();
[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]60f36f92011-04-12 16:18:31380 favicon_helper_.reset(new FaviconHelper(this, FaviconHelper::FAVICON));
381 if (browser_defaults::kEnableTouchIcon)
382 touch_icon_helper_.reset(new FaviconHelper(this, FaviconHelper::TOUCH));
[email protected]b5a1d11c2011-02-17 03:09:42383 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]60f36f92011-04-12 16:18:31419 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL)
[email protected]724159a2010-12-30 01:11:18420 IPC_MESSAGE_UNHANDLED(handled = false)
421 IPC_END_MESSAGE_MAP_EX()
422
423 if (!message_is_ok) {
424 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
425 GetRenderProcessHost()->ReceivedBadMessage();
426 }
427
428 return handled;
429}
430
[email protected]13367f72009-07-08 16:39:02431// Returns true if contains content rendered by an extension.
432bool TabContents::HostsExtension() const {
433 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34434}
435
[email protected]1f18184a2010-07-21 19:34:49436TabContentsSSLHelper* TabContents::GetSSLHelper() {
437 if (ssl_helper_.get() == NULL)
438 ssl_helper_.reset(new TabContentsSSLHelper(this));
439 return ssl_helper_.get();
440}
441
[email protected]8cb5d5b2010-02-09 11:36:16442RenderProcessHost* TabContents::GetRenderProcessHost() const {
443 return render_manager_.current_host()->process();
444}
445
[email protected]d5f942ba2008-09-26 19:30:34446const GURL& TabContents::GetURL() const {
447 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57448 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54449 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34450}
451
[email protected]96d185d2009-04-24 03:28:54452const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55453 // Transient entries take precedence. They are used for interstitial pages
454 // that are shown on top of existing pages.
455 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23456 if (entry) {
457 return entry->GetTitleForDisplay(profile()->GetPrefs()->
458 GetString(prefs::kAcceptLanguages));
459 }
[email protected]7ade2732011-02-10 00:13:58460 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
461 render_manager_.pending_web_ui() : render_manager_.web_ui();
462 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54463 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55464 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54465 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35466 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58467 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54468 if (!title.empty())
469 return title;
470 }
471 }
472
473 // We use the title for the last committed entry rather than a pending
474 // navigation entry. For example, when the user types in a URL, we want to
475 // keep the old page's title until the new load has committed and we get a new
476 // title.
[email protected]96d185d2009-04-24 03:28:54477 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23478 if (entry) {
479 return entry->GetTitleForDisplay(profile()->GetPrefs()->
480 GetString(prefs::kAcceptLanguages));
481 }
[email protected]96d185d2009-04-24 03:28:54482 return EmptyString16();
483}
484
[email protected]d5f942ba2008-09-26 19:30:34485int32 TabContents::GetMaxPageID() {
486 if (GetSiteInstance())
487 return GetSiteInstance()->max_page_id();
488 else
489 return max_page_id_;
490}
491
492void TabContents::UpdateMaxPageID(int32 page_id) {
493 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34494 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34495 // testing.
496 if (GetSiteInstance())
497 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16498 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34499}
500
[email protected]96d185d2009-04-24 03:28:54501SiteInstance* TabContents::GetSiteInstance() const {
502 return render_manager_.current_host()->site_instance();
503}
504
[email protected]96d185d2009-04-24 03:28:54505bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15506 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54507 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15508 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01509 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54510 return true;
[email protected]8ab24cc2009-11-13 20:56:15511 }
[email protected]83e3895b2009-06-11 00:07:16512
[email protected]2b9a06402011-02-16 04:57:10513 // We always display the URL for non-WebUI URLs to prevent spoofing.
[email protected]1fd1a502011-03-30 16:55:56514 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url()))
[email protected]2b9a06402011-02-16 04:57:10515 return true;
516
[email protected]d0980792011-02-13 19:41:40517 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58518 if (web_ui)
519 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54520 return true;
521}
522
[email protected]0150cfc2011-04-07 22:51:41523SkBitmap TabContents::GetFavicon() const {
524 // Like GetTitle(), we also want to use the favicon for the last committed
525 // entry rather than a pending navigation entry.
526 NavigationEntry* entry = controller_.GetTransientEntry();
527 if (entry)
528 return entry->favicon().bitmap();
529
530 entry = controller_.GetLastCommittedEntry();
531 if (entry)
532 return entry->favicon().bitmap();
533 return SkBitmap();
534}
535
536bool TabContents::FaviconIsValid() const {
537 NavigationEntry* entry = controller_.GetTransientEntry();
538 if (entry)
539 return entry->favicon().is_valid();
540
541 entry = controller_.GetLastCommittedEntry();
542 if (entry)
543 return entry->favicon().is_valid();
544
545 return false;
546}
547
548bool TabContents::ShouldDisplayFavicon() {
549 // Always display a throbber during pending loads.
550 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
551 return true;
552
553 WebUI* web_ui = GetWebUIForCurrentState();
554 if (web_ui)
555 return !web_ui->hide_favicon();
556 return true;
557}
558
[email protected]585b30362011-01-28 02:30:17559void TabContents::AddObserver(TabContentsObserver* observer) {
560 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49561}
562
[email protected]585b30362011-01-28 02:30:17563void TabContents::RemoveObserver(TabContentsObserver* observer) {
564 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49565}
566
[email protected]443b80e2010-12-14 00:42:23567void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
568 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34569 return;
570
[email protected]443b80e2010-12-14 00:42:23571 crashed_status_ = status;
572 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50573 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34574}
575
576void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
577 if (delegate_)
578 delegate_->NavigationStateChanged(this, changed_flags);
579}
580
[email protected]96d185d2009-04-24 03:28:54581void TabContents::DidBecomeSelected() {
582 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16583 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
584 if (rwhv) {
585 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43586#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16587 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43588#endif
589 }
[email protected]96d185d2009-04-24 03:28:54590
[email protected]8cb5d5b2010-02-09 11:36:16591 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11592 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54593}
594
595void TabContents::WasHidden() {
596 if (!capturing_contents()) {
597 // |render_view_host()| can be NULL if the user middle clicks a link to open
598 // a tab in then background, then closes the tab before selecting it. This
599 // is because closing the tab calls TabContents::Destroy(), which removes
600 // the |render_view_host()|; then when we actually destroy the window,
601 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16602 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
603 if (rwhv)
604 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54605 }
606
607 NotificationService::current()->Notify(
608 NotificationType::TAB_CONTENTS_HIDDEN,
609 Source<TabContents>(this),
610 NotificationService::NoDetails());
611}
612
[email protected]d5f942ba2008-09-26 19:30:34613void TabContents::Activate() {
614 if (delegate_)
615 delegate_->ActivateContents(this);
616}
617
[email protected]ea42e7782010-08-23 23:58:12618void TabContents::Deactivate() {
619 if (delegate_)
620 delegate_->DeactivateContents(this);
621}
622
[email protected]96d185d2009-04-24 03:28:54623void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16624 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
625 if (rwhv)
626 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54627}
628
629void TabContents::HideContents() {
630 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
631 // our superclass HideContents(), because some callers want to be very picky
632 // about the order in which these get called. In addition to making the code
633 // here practically impossible to understand, this also means we end up
634 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34635 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54636 WasHidden();
637}
638
[email protected]5aab5e22010-12-08 22:13:29639bool TabContents::NeedToFireBeforeUnload() {
640 // TODO(creis): Should we fire even for interstitial pages?
641 return notify_disconnection() &&
642 !showing_interstitial_page() &&
643 !render_view_host()->SuddenTerminationAllowed();
644}
645
[email protected]c0588052008-10-27 23:01:50646void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34647 WindowOpenDisposition disposition,
648 PageTransition::Type transition) {
[email protected]1c642b52011-04-15 09:05:49649 if (delegate_) {
[email protected]c0588052008-10-27 23:01:50650 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]1c642b52011-04-15 09:05:49651 // Notify observers.
652 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
653 DidOpenURL(url, referrer, disposition, transition));
654 }
[email protected]d5f942ba2008-09-26 19:30:34655}
656
[email protected]1ccb3568d2010-02-19 10:51:16657bool TabContents::NavigateToPendingEntry(
658 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54659 return NavigateToEntry(*controller_.pending_entry(), reload_type);
660}
[email protected]96d185d2009-04-24 03:28:54661
[email protected]876bc832010-09-07 16:29:54662bool TabContents::NavigateToEntry(
663 const NavigationEntry& entry,
664 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54665 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
666 if (!dest_render_view_host)
667 return false; // Unable to create the desired render view host.
668
[email protected]770dd8b2010-05-24 18:11:39669 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
670 dest_render_view_host->EnablePreferredSizeChangedMode(
671 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
672 }
[email protected]9fb325e2010-05-06 18:23:24673
[email protected]80a8fad2011-01-29 04:02:38674 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07675 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58676 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56677 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
678 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(),
679 entry.url());
[email protected]c09163a2011-02-15 00:05:55680 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
681 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58682
[email protected]96d185d2009-04-24 03:28:54683 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12684 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32685 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00686 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
687 dest_render_view_host,
688 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32689 }
[email protected]96d185d2009-04-24 03:28:54690
691 // Used for page load time metrics.
692 current_load_start_ = base::TimeTicks::Now();
693
694 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34695 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54696 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04697 if (delegate_) {
698 navigate_params.extra_headers =
699 delegate_->GetNavigationHeaders(navigate_params.url);
700 }
[email protected]056de2d2009-06-26 16:41:34701 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54702
703 if (entry.page_id() == -1) {
704 // HACK!! This code suppresses javascript: URLs from being added to
705 // session history, which is what we want to do for javascript: URLs that
706 // do not generate content. What we really need is a message from the
707 // renderer telling us that a new page was not created. The same message
708 // could be used for mailto: URLs and the like.
709 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
710 return false;
711 }
712
[email protected]3c9e1872010-11-18 16:17:49713 // Notify observers about navigation.
[email protected]0150cfc2011-04-07 22:51:41714 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
715
716 if (reload_type != NavigationController::NO_RELOAD &&
717 !profile()->IsOffTheRecord()) {
718 FaviconService* favicon_service =
719 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
720 if (favicon_service)
721 favicon_service->SetFaviconOutOfDateForPage(entry.url());
722 }
[email protected]96d185d2009-04-24 03:28:54723
[email protected]d5f942ba2008-09-26 19:30:34724 return true;
725}
726
[email protected]96d185d2009-04-24 03:28:54727void TabContents::Stop() {
728 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47729 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54730}
731
[email protected]96d185d2009-04-24 03:28:54732void TabContents::DisassociateFromPopupCount() {
733 render_view_host()->DisassociateFromPopupCount();
734}
735
736TabContents* TabContents::Clone() {
737 // We create a new SiteInstance so that the new tab won't share processes
738 // with the old one. This can be changed in the future if we need it to share
739 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32740 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54741 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07742 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54743 tc->controller().CopyStateFrom(controller_);
744 return tc;
745}
746
[email protected]4d677202009-07-19 07:37:12747void TabContents::ShowPageInfo(const GURL& url,
748 const NavigationEntry::SSLStatus& ssl,
749 bool show_history) {
750 if (!delegate_)
751 return;
752
[email protected]bb678332009-07-21 00:15:50753 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12754}
755
[email protected]0150cfc2011-04-07 22:51:41756void TabContents::SaveFavicon() {
757 NavigationEntry* entry = controller_.GetActiveEntry();
758 if (!entry || entry->url().is_empty())
759 return;
760
761 // Make sure the page is in history, otherwise adding the favicon does
762 // nothing.
763 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
764 Profile::IMPLICIT_ACCESS);
765 if (!history)
766 return;
767 history->AddPageNoVisitForBookmark(entry->url());
768
769 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
770 Profile::IMPLICIT_ACCESS);
771 if (!service)
772 return;
773 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
774 if (!favicon.is_valid() || favicon.url().is_empty() ||
775 favicon.bitmap().empty()) {
776 return;
777 }
778 std::vector<unsigned char> image_data;
779 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
780 service->SetFavicon(
781 entry->url(), favicon.url(), image_data, history::FAVICON);
782}
783
initial.commit09911bf2008-07-26 23:55:29784ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28785 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29786 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28787 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33788 AddConstrainedDialog(window);
789 return window;
790}
791
792void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29793 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44794
795 if (child_windows_.size() == 1) {
796 window->ShowConstrainedWindow();
797 BlockTabContent(true);
798 }
initial.commit09911bf2008-07-26 23:55:29799}
800
[email protected]fa1cf0b82010-01-15 21:49:44801void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55802 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45803 // 70% opaque grey.
804 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55805 if (rwhv)
[email protected]1b072562010-12-13 19:37:45806 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]a7eccac2011-04-15 03:05:19807 // RenderViewHost may be NULL during shutdown.
808 if (render_view_host())
809 render_view_host()->set_ignore_input_events(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44810 if (delegate_)
811 delegate_->SetTabContentBlocked(this, blocked);
812}
813
initial.commit09911bf2008-07-26 23:55:29814void TabContents::AddNewContents(TabContents* new_contents,
815 WindowOpenDisposition disposition,
816 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29817 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40818 if (all_contents_blocked_) {
819 if (!blocked_contents_)
820 blocked_contents_ = new BlockedContentContainer(this);
821 blocked_contents_->AddTabContents(
822 new_contents, disposition, initial_pos, user_gesture);
823 return;
824 }
825
initial.commit09911bf2008-07-26 23:55:29826 if (!delegate_)
827 return;
828
[email protected]35f7d212009-04-29 21:19:27829 if ((disposition == NEW_POPUP) && !user_gesture &&
830 !CommandLine::ForCurrentProcess()->HasSwitch(
831 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22832 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31833 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29834 delegate_->GetConstrainingContents(this)->AddPopup(
835 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31836 } else {
[email protected]0aa55312008-10-17 21:53:08837 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29838 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
839 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49840 NotificationService::current()->Notify(
841 NotificationType::TAB_ADDED,
842 Source<TabContentsDelegate>(delegate_),
843 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29844 }
initial.commit09911bf2008-07-26 23:55:29845
[email protected]8cc8d492010-02-02 10:40:49846 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40847 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29848}
849
[email protected]96d185d2009-04-24 03:28:54850void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49851 if (is_being_destroyed_)
852 return;
[email protected]9fb83e82010-07-02 18:24:55853 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49854 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40855 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54856}
857
[email protected]5c9e97a2009-09-09 23:48:30858gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54859 return view_->GetContentNativeView();
860}
861
862gfx::NativeView TabContents::GetNativeView() const {
863 return view_->GetNativeView();
864}
865
866void TabContents::GetContainerBounds(gfx::Rect *out) const {
867 view_->GetContainerBounds(out);
868}
869
870void TabContents::Focus() {
871 view_->Focus();
872}
873
[email protected]90daadb42009-06-08 21:27:28874void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54875 if (showing_interstitial_page()) {
876 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
877 return;
878 }
[email protected]96d185d2009-04-24 03:28:54879 render_view_host()->SetInitialFocus(reverse);
880}
881
882bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40883 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58884 if (web_ui)
885 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43886 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25887 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43888 return true;
[email protected]96d185d2009-04-24 03:28:54889 return false;
890}
891
[email protected]a26dc362010-04-23 01:48:58892void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38893 if (delegate())
[email protected]a26dc362010-04-23 01:48:58894 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38895}
896
[email protected]616ed5a2008-11-21 22:27:24897void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32898 if (delegate_ && !delegate_->infobars_enabled()) {
899 delegate->InfoBarClosed();
900 return;
901 }
902
[email protected]616ed5a2008-11-21 22:27:24903 // Look through the existing InfoBarDelegates we have for a match. If we've
904 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40905 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45906 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
907 // Tell the new infobar to close so that it can clean itself up.
908 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24909 return;
[email protected]6d27a7b2009-12-18 23:25:45910 }
[email protected]616ed5a2008-11-21 22:27:24911 }
912
913 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56914 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:19915 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:56916 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24917
918 // Add ourselves as an observer for navigations the first time a delegate is
919 // added. We use this notification to expire InfoBars that need to expire on
920 // page transitions.
921 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56922 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57923 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24924 }
925}
926
927void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32928 if (delegate_ && !delegate_->infobars_enabled()) {
929 return;
930 }
931
[email protected]616ed5a2008-11-21 22:27:24932 std::vector<InfoBarDelegate*>::iterator it =
933 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
934 if (it != infobar_delegates_.end()) {
935 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56936 NotificationService::current()->Notify(
937 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
938 Source<TabContents>(this),
939 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24940
[email protected]f4f50ef2011-01-21 19:01:19941 infobar_delegates_.erase(it);
942 // Remove ourselves as an observer if we are tracking no more InfoBars.
943 if (infobar_delegates_.empty()) {
944 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
945 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03946 }
[email protected]616ed5a2008-11-21 22:27:24947 }
948}
[email protected]3edd9522009-03-04 22:19:41949
[email protected]f81821c2009-08-07 01:29:47950void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
951 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:32952 if (delegate_ && !delegate_->infobars_enabled()) {
953 new_delegate->InfoBarClosed();
954 return;
955 }
956
[email protected]f81821c2009-08-07 01:29:47957 std::vector<InfoBarDelegate*>::iterator it =
958 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
959 DCHECK(it != infobar_delegates_.end());
960
961 // Notify the container about the change of plans.
962 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
963 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
964 old_delegate, new_delegate));
965 NotificationService::current()->Notify(
966 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
967 Source<TabContents>(this),
968 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
969
[email protected]f4f50ef2011-01-21 19:01:19970 // Remove the old one.
971 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:47972
973 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:08974 DCHECK(find(infobar_delegates_.begin(),
975 infobar_delegates_.end(), new_delegate) ==
976 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:47977 infobar_delegates_.push_back(new_delegate);
978}
979
[email protected]20ede072009-10-06 00:28:35980bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:27981 if (showing_interstitial_page())
982 return false;
983
[email protected]c8f74942010-09-03 10:04:14984 // Do not show bookmarks bar if bookmarks aren't enabled.
985 if (!browser_defaults::bookmarks_enabled)
986 return false;
987
[email protected]b3be10fa2011-04-11 15:43:15988 if (!profile()->GetPrefs()->GetBoolean(prefs::kEnableBookmarkBar))
989 return false;
990
[email protected]d0980792011-02-13 19:41:40991 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:54992 // similar, but for non-first loads, we want to use the committed entry. This
993 // is so the bookmarks bar disappears at the same time the page does.
994 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:35995 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:58996 return (render_manager_.web_ui() == NULL) ?
997 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:54998 }
999
1000 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:401001 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:541002 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:581003 if (render_manager_.pending_web_ui())
1004 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
1005 return (render_manager_.web_ui() == NULL) ?
1006 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541007}
1008
[email protected]3edd9522009-03-04 22:19:411009void TabContents::ToolbarSizeChanged(bool is_animating) {
1010 TabContentsDelegate* d = delegate();
1011 if (d)
1012 d->ToolbarSizeChanged(this, is_animating);
1013}
[email protected]616ed5a2008-11-21 22:27:241014
[email protected]fc6fb7fb2009-11-07 02:35:041015bool TabContents::CanDownload(int request_id) {
1016 TabContentsDelegate* d = delegate();
1017 if (d)
1018 return d->CanDownload(request_id);
1019 return true;
1020}
1021
[email protected]d5f942ba2008-09-26 19:30:341022void TabContents::OnStartDownload(DownloadItem* download) {
1023 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341024
1025 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311026 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341027
[email protected]5b928b62010-08-03 11:46:511028 if (tab_contents && tab_contents->delegate())
1029 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411030}
[email protected]3edd9522009-03-04 22:19:411031
[email protected]d5f942ba2008-09-26 19:30:341032void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371033 ConstrainedWindowList::iterator i(
1034 std::find(child_windows_.begin(), child_windows_.end(), window));
1035 bool removed_topmost_window = i == child_windows_.begin();
1036 if (i != child_windows_.end())
1037 child_windows_.erase(i);
1038 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441039 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371040 } else {
1041 if (removed_topmost_window)
1042 child_windows_[0]->ShowConstrainedWindow();
1043 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441044 }
[email protected]66ba4932009-06-04 19:22:131045}
[email protected]d5f942ba2008-09-26 19:30:341046
[email protected]c65e2f152010-10-14 15:30:401047void TabContents::WillCloseBlockedContentContainer(
1048 BlockedContentContainer* container) {
1049 DCHECK(blocked_contents_ == container);
1050 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491051 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341052}
1053
[email protected]89d6e6e2009-12-03 23:06:511054void TabContents::EmailPageLocation() {
1055 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1056 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1057 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1058 title + "&body=%0A%0A" + page_url;
1059 platform_util::OpenExternal(GURL(mailto));
1060}
1061
[email protected]420ae012009-04-24 05:16:321062bool TabContents::PrintNow() {
1063 // We can't print interstitial page for now.
1064 if (showing_interstitial_page())
1065 return false;
1066
1067 return render_view_host()->PrintPages();
1068}
1069
1070bool TabContents::IsActiveEntry(int32 page_id) {
1071 NavigationEntry* active_entry = controller_.GetActiveEntry();
1072 return (active_entry != NULL &&
1073 active_entry->site_instance() == GetSiteInstance() &&
1074 active_entry->page_id() == page_id);
1075}
1076
[email protected]b2fe07d12010-02-09 14:38:081077void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161078 set_encoding(encoding);
1079 render_view_host()->SetPageEncoding(encoding);
1080}
1081
[email protected]b2fe07d12010-02-09 14:38:081082void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161083 reset_encoding();
1084 render_view_host()->ResetPageEncodingToDefault();
1085}
1086
1087void TabContents::WindowMoveOrResizeStarted() {
1088 render_view_host()->WindowMoveOrResizeStarted();
1089}
1090
[email protected]c65e2f152010-10-14 15:30:401091void TabContents::SetAllContentsBlocked(bool value) {
1092 if (all_contents_blocked_ == value)
1093 return;
1094
1095 all_contents_blocked_ = value;
1096 if (!all_contents_blocked_ && blocked_contents_) {
1097 std::vector<TabContents*> blocked;
1098 blocked_contents_->GetBlockedContents(&blocked);
1099 for (size_t i = 0; i < blocked.size(); ++i)
1100 blocked_contents_->LaunchForContents(blocked[i]);
1101 }
1102}
1103
[email protected]3f8eb7f2009-10-02 23:58:051104void TabContents::LogNewTabTime(const std::string& event_name) {
1105 // Not all new tab pages get timed. In those cases, we don't have a
1106 // new_tab_start_time_.
1107 if (new_tab_start_time_.is_null())
1108 return;
1109
1110 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441111 MetricEventDurationDetails details(event_name,
1112 static_cast<int>(duration.InMilliseconds()));
1113
[email protected]7ab1e7d62009-10-14 23:32:011114 if (event_name == "Tab.NewTabScriptStart") {
1115 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1116 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1117 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1118 } else if (event_name == "Tab.NewTabOnload") {
1119 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051120 // The new tab page has finished loading; reset it.
1121 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441122 } else {
1123 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051124 }
[email protected]84abba62009-10-07 17:01:441125 NotificationService::current()->Notify(
1126 NotificationType::METRIC_EVENT_DURATION,
1127 Source<TabContents>(this),
1128 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051129}
1130
[email protected]7ab1e7d62009-10-14 23:32:011131void TabContents::OnCloseStarted() {
1132 if (tab_close_start_time_.is_null())
1133 tab_close_start_time_ = base::TimeTicks::Now();
1134}
1135
[email protected]46624bf2010-06-09 16:04:191136bool TabContents::ShouldAcceptDragAndDrop() const {
1137#if defined(OS_CHROMEOS)
1138 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1139 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201140 if (delegate() && delegate()->IsPopup(this))
1141 return false;
1142 return true;
[email protected]46624bf2010-06-09 16:04:191143#else
1144 return true;
1145#endif
1146}
1147
[email protected]7813bd72011-02-05 02:19:341148void TabContents::SystemDragEnded() {
1149 if (render_view_host())
1150 render_view_host()->DragSourceSystemDragEnded();
1151 if (delegate())
1152 delegate()->DragEnded();
1153}
1154
[email protected]ec0b6c42010-08-26 03:16:581155void TabContents::UpdateHistoryForNavigation(
1156 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1157 if (profile()->IsOffTheRecord())
1158 return;
1159
1160 // Add to history service.
1161 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1162 if (hs)
1163 hs->AddPage(*add_page_args);
1164}
1165
1166void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1167 if (profile()->IsOffTheRecord())
1168 return;
1169
1170 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1171 if (hs)
1172 hs->SetPageTitle(entry.virtual_url(), entry.title());
1173}
1174
[email protected]d0b8d092010-10-25 04:05:171175double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251176 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1177 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171178 return 0;
[email protected]b75b8292010-10-01 07:28:251179
1180 double zoom_level;
1181 if (temporary_zoom_settings_) {
1182 zoom_level = zoom_map->GetTemporaryZoomLevel(
1183 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1184 } else {
1185 zoom_level = zoom_map->GetZoomLevel(GetURL());
1186 }
[email protected]d0b8d092010-10-25 04:05:171187 return zoom_level;
1188}
[email protected]b75b8292010-10-01 07:28:251189
[email protected]d0b8d092010-10-25 04:05:171190int TabContents::GetZoomPercent(bool* enable_increment,
1191 bool* enable_decrement) {
1192 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251193 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171194 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251195 *enable_decrement = percent > minimum_zoom_percent_;
1196 *enable_increment = percent < maximum_zoom_percent_;
1197 return percent;
1198}
1199
[email protected]3c733bde2010-12-21 19:56:311200void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501201 if (!delegate_)
1202 return;
1203
1204 NavigationEntry* active_entry = controller().GetActiveEntry();
1205 if (!active_entry)
1206 return;
1207
1208 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121209}
1210
[email protected]932b7a12011-03-09 12:50:271211void TabContents::ViewFrameSource(const GURL& url,
1212 const std::string& content_state) {
1213 if (!delegate_)
1214 return;
1215
1216 delegate_->ViewSourceForFrame(this, url, content_state);
1217}
1218
[email protected]c40d6232011-03-25 00:16:211219void TabContents::SetContentRestrictions(int restrictions) {
1220 content_restrictions_ = restrictions;
1221 delegate()->ContentRestrictionsChanged(this);
1222}
1223
[email protected]724159a2010-12-30 01:11:181224void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1225 bool is_main_frame,
1226 const GURL& url) {
1227 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1228 GURL validated_url(url);
1229 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1230 GetRenderProcessHost()->id(), &validated_url);
1231
[email protected]0d60f0192011-04-14 12:40:101232 // Notify observers about the start of the provisional load.
1233 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1234 DidStartProvisionalLoadForFrame(frame_id, is_main_frame,
1235 validated_url, is_error_page));
1236
[email protected]724159a2010-12-30 01:11:181237 if (is_main_frame) {
1238 // If we're displaying a network error page do not reset the content
1239 // settings delegate's cookies so the user has a chance to modify cookie
1240 // settings.
1241 if (!is_error_page)
1242 content_settings_delegate_->ClearCookieSpecificContentSettings();
1243 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381244
[email protected]4850a7f2011-03-08 23:36:591245 // Notify observers about the provisional change in the main frame URL.
1246 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101247 ProvisionalChangeToMainFrameUrl(url));
[email protected]724159a2010-12-30 01:11:181248 }
1249}
1250
1251void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1252 const GURL& source_url,
1253 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491254 // TODO(creis): Remove this method and have the pre-rendering code listen to
1255 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1256 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:181257 NavigationEntry* entry;
1258 if (page_id == -1)
1259 entry = controller_.pending_entry();
1260 else
1261 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1262 if (!entry || entry->url() != source_url)
1263 return;
[email protected]e7d50892011-01-19 21:47:381264
[email protected]4850a7f2011-03-08 23:36:591265 // Notify observers about the provisional change in the main frame URL.
1266 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]0d60f0192011-04-14 12:40:101267 ProvisionalChangeToMainFrameUrl(target_url));
[email protected]724159a2010-12-30 01:11:181268}
1269
1270void TabContents::OnDidFailProvisionalLoadWithError(
1271 int64 frame_id,
1272 bool is_main_frame,
1273 int error_code,
1274 const GURL& url,
1275 bool showing_repost_interstitial) {
1276 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1277 << ", error_code: " << error_code
1278 << " is_main_frame: " << is_main_frame
1279 << " showing_repost_interstitial: " << showing_repost_interstitial
1280 << " frame_id: " << frame_id;
1281 GURL validated_url(url);
1282 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1283 GetRenderProcessHost()->id(), &validated_url);
1284
1285 if (net::ERR_ABORTED == error_code) {
1286 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1287 // This means that the interstitial won't be torn down properly, which is
1288 // bad. But if we have an interstitial, go back to another tab type, and
1289 // then load the same interstitial again, we could end up getting the first
1290 // interstitial's "failed" message (as a result of the cancel) when we're on
1291 // the second one.
1292 //
1293 // We can't tell this apart, so we think we're tearing down the current page
1294 // which will cause a crash later one. There is also some code in
1295 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1296 // out because of this problem.
1297 //
1298 // http://code.google.com/p/chromium/issues/detail?id=2855
1299 // Because this will not tear down the interstitial properly, if "back" is
1300 // back to another tab type, the interstitial will still be somewhat alive
1301 // in the previous tab type. If you navigate somewhere that activates the
1302 // tab with the interstitial again, you'll see a flash before the new load
1303 // commits of the interstitial page.
1304 if (showing_interstitial_page()) {
1305 LOG(WARNING) << "Discarding message during interstitial.";
1306 return;
1307 }
1308
1309 // This will discard our pending entry if we cancelled the load (e.g., if we
1310 // decided to download the file instead of load it). Only discard the
1311 // pending entry if the URLs match, otherwise the user initiated a navigate
1312 // before the page loaded so that the discard would discard the wrong entry.
1313 NavigationEntry* pending_entry = controller_.pending_entry();
1314 if (pending_entry && pending_entry->url() == validated_url) {
1315 controller_.DiscardNonCommittedEntries();
1316 // Update the URL display.
1317 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1318 }
1319
1320 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1321 }
1322
1323 // Send out a notification that we failed a provisional load with an error.
1324 ProvisionalLoadDetails details(
1325 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091326 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:181327 details.set_error_code(error_code);
1328
1329 NotificationService::current()->Notify(
1330 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1331 Source<NavigationController>(&controller_),
1332 Details<ProvisionalLoadDetails>(&details));
[email protected]0d60f0192011-04-14 12:40:101333
1334 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1335 DidFailProvisionalLoad(frame_id, is_main_frame,
1336 validated_url, error_code));
[email protected]724159a2010-12-30 01:11:181337}
1338
1339void TabContents::OnDidLoadResourceFromMemoryCache(
1340 const GURL& url,
[email protected]724159a2010-12-30 01:11:181341 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:191342 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181343 cache.Increment();
1344
1345 // Send out a notification that we loaded a resource from our memory cache.
1346 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1347 SSLManager::DeserializeSecurityInfo(security_info,
1348 &cert_id, &cert_status,
1349 &security_bits,
1350 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161351 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1352 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181353
1354 NotificationService::current()->Notify(
1355 NotificationType::LOAD_FROM_MEMORY_CACHE,
1356 Source<NavigationController>(&controller_),
1357 Details<LoadFromMemoryCacheDetails>(&details));
1358}
1359
1360void TabContents::OnDidDisplayInsecureContent() {
1361 displayed_insecure_content_ = true;
1362 SSLManager::NotifySSLInternalStateChanged();
1363}
1364
1365void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021366 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231367 LOG(INFO) << security_origin << " ran insecure content from "
1368 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181369 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1370}
1371
1372void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1373 controller_.DocumentLoadedInFrame();
[email protected]0d60f0192011-04-14 12:40:101374 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1375 DocumentLoadedInFrame(frame_id));
[email protected]724159a2010-12-30 01:11:181376}
1377
1378void TabContents::OnDidFinishLoad(int64 frame_id) {
[email protected]0d60f0192011-04-14 12:40:101379 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1380 DidFinishLoad(frame_id));
[email protected]724159a2010-12-30 01:11:181381}
1382
[email protected]c8f73ab2011-01-22 00:05:171383void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211384 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171385}
1386
1387void TabContents::OnPDFHasUnsupportedFeature() {
1388 PDFHasUnsupportedFeature(this);
1389}
1390
[email protected]96d185d2009-04-24 03:28:541391// Notifies the RenderWidgetHost instance about the fact that the page is
1392// loading, or done loading and calls the base implementation.
1393void TabContents::SetIsLoading(bool is_loading,
1394 LoadNotificationDetails* details) {
1395 if (is_loading == is_loading_)
1396 return;
1397
1398 if (!is_loading) {
1399 load_state_ = net::LOAD_STATE_IDLE;
1400 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561401 upload_size_ = 0;
1402 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541403 }
1404
1405 render_manager_.SetIsLoading(is_loading);
1406
1407 is_loading_ = is_loading;
1408 waiting_for_response_ = is_loading;
1409
[email protected]6ebdc9b2010-09-27 16:55:571410 if (delegate_)
1411 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351412 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541413
1414 NotificationType type = is_loading ? NotificationType::LOAD_START :
1415 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111416 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541417 if (details)
1418 det = Details<LoadNotificationDetails>(details);
1419 NotificationService::current()->Notify(type,
1420 Source<NavigationController>(&controller_),
1421 det);
1422}
1423
[email protected]b6c874582009-05-08 19:38:311424void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291425 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061426 // A page can't spawn popups (or do anything else, either) until its load
1427 // commits, so when we reach here, the popup was spawned by the
1428 // NavigationController's last committed entry, not the active entry. For
1429 // example, if a page opens a popup in an onunload() handler, then the active
1430 // entry is the page to be loaded as we navigate away from the unloading
1431 // page. For this reason, we can't use GetURL() to get the opener URL,
1432 // because it returns the active entry.
1433 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1434 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1435
1436 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491437 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091438 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491439 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1440 } else {
[email protected]c65e2f152010-10-14 15:30:401441 if (!blocked_contents_)
1442 blocked_contents_ = new BlockedContentContainer(this);
1443 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1444 true);
[email protected]55126132010-08-19 14:53:281445 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1446 std::string());
[email protected]8cc8d492010-02-02 10:40:491447 }
[email protected]b9681312008-11-07 00:08:261448}
[email protected]616ed5a2008-11-21 22:27:241449
[email protected]616ed5a2008-11-21 22:27:241450void TabContents::ExpireInfoBars(
1451 const NavigationController::LoadCommittedDetails& details) {
1452 // Only hide InfoBars when the user has done something that makes the main
1453 // frame load. We don't want various automatic or subframe navigations making
1454 // it disappear.
1455 if (!details.is_user_initiated_main_frame_load())
1456 return;
1457
[email protected]ec8f51162011-02-08 04:20:401458 // NOTE: It is not safe to change the following code to count upwards or use
1459 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1460 // list.
1461 for (size_t i = infobar_count(); i > 0; --i) {
1462 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051463 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241464 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241465 }
1466}
[email protected]fdd61c62009-04-22 19:22:571467
[email protected]d0980792011-02-13 19:41:401468WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581469 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541470 // that goes along with it to control the basic flags. For example, we want to
1471 // show the pending URL in the URL bar, so we want the display_url flag to
1472 // be from the pending entry.
1473 //
1474 // The confusion comes because there are multiple possibilities for the
1475 // initial load in a tab as a side effect of the way the RenderViewHostManager
1476 // works.
1477 //
[email protected]e0112912011-02-02 22:54:351478 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541479 // the pending one, and we want it to apply here.
1480 //
1481 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1482 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581483 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351484 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541485 //
1486 // This condition handles all of these cases:
1487 //
1488 // - First load in first tab: no committed nav entry + pending nav entry +
1489 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351490 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541491 //
1492 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351493 // no pending Web UI:
1494 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541495 //
1496 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351497 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541498 //
1499 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351500 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541501 if (controller_.pending_entry() &&
1502 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581503 render_manager_.pending_web_ui()))
1504 return render_manager_.pending_web_ui();
1505 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541506}
[email protected]420ae012009-04-24 05:16:321507
[email protected]1fd1a502011-03-30 16:55:561508WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1509 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL());
1510}
1511
[email protected]420ae012009-04-24 05:16:321512void TabContents::DidNavigateMainFramePostCommit(
1513 const NavigationController::LoadCommittedDetails& details,
1514 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561515 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381516 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441517 // that opened the window, as long as both renderers have the same
1518 // privileges.
[email protected]1fd1a502011-03-30 16:55:561519 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1520 WebUI* web_ui = content::GetContentClient()->browser()->
1521 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581522 // web_ui might be NULL if the URL refers to a non-existent extension.
1523 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401524 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581525 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441526 }
1527 }
[email protected]1fd1a502011-03-30 16:55:561528 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441529 }
1530
[email protected]420ae012009-04-24 05:16:321531 if (details.is_user_initiated_main_frame_load()) {
1532 // Clear the status bubble. This is a workaround for a bug where WebKit
1533 // doesn't let us know that the cursor left an element during a
1534 // transition (this is also why the mouse cursor remains as a hand after
1535 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1536 // clear the bubble when a user navigates to a named anchor in the same
1537 // page.
1538 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321539 }
1540
[email protected]420ae012009-04-24 05:16:321541 // Allow the new page to set the title again.
1542 received_page_title_ = false;
1543
[email protected]0150cfc2011-04-07 22:51:411544 // Get the favicon, either from history or request it from the net.
1545 favicon_helper_->FetchFavicon(details.entry->url());
1546
[email protected]60f36f92011-04-12 16:18:311547 if (touch_icon_helper_.get())
1548 touch_icon_helper_->FetchFavicon(details.entry->url());
1549
[email protected]0de80162010-02-03 04:52:351550 // Clear all page actions, blocked content notifications and browser actions
1551 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141552 if (!details.is_in_page) {
[email protected]0de80162010-02-03 04:52:351553 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401554 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341555 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401556 blocked_contents_->Destroy();
1557 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351558 }
1559
1560 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411561 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551562 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471563
1564 // Once the main frame is navigated, we're no longer considered to have
1565 // displayed insecure content.
1566 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171567 }
[email protected]ce5c4502009-05-06 16:46:111568
[email protected]8cc8d492010-02-02 10:40:491569 // Close constrained windows if necessary.
1570 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1571 details.previous_url, details.entry->url()))
1572 CloseConstrainedWindows();
1573
[email protected]3c9e1872010-11-18 16:17:491574 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171575 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491576 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321577}
1578
1579void TabContents::DidNavigateAnyFramePostCommit(
1580 RenderViewHost* render_view_host,
1581 const NavigationController::LoadCommittedDetails& details,
1582 const ViewHostMsg_FrameNavigate_Params& params) {
1583 // If we navigate, start showing messages again. This does nothing to prevent
1584 // a malicious script from spamming messages, since the script could just
1585 // reload the page to stop blocking.
1586 suppress_javascript_messages_ = false;
1587
[email protected]3c9e1872010-11-18 16:17:491588 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171589 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491590 DidNavigateAnyFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321591}
1592
[email protected]8cc8d492010-02-02 10:40:491593void TabContents::CloseConstrainedWindows() {
1594 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331595 // To ensure that we iterate over every element in child_windows_ we
1596 // need to use a copy of child_windows_. Otherwise if
1597 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1598 // skipping some elements.
1599 ConstrainedWindowList child_windows_copy(child_windows_);
1600 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1601 it != child_windows_copy.end(); ++it) {
1602 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441603 if (window) {
[email protected]420ae012009-04-24 05:16:321604 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441605 BlockTabContent(false);
1606 }
[email protected]420ae012009-04-24 05:16:321607 }
1608}
1609
[email protected]420ae012009-04-24 05:16:321610void TabContents::UpdateAlternateErrorPageURL() {
1611 GURL url = GetAlternateErrorPageURL();
1612 render_view_host()->SetAlternateErrorPageURL(url);
1613}
1614
1615void TabContents::UpdateWebPreferences() {
1616 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1617}
1618
[email protected]d0b8d092010-10-25 04:05:171619void TabContents::UpdateZoomLevel() {
1620 render_view_host()->SetZoomLevel(GetZoomLevel());
1621}
1622
[email protected]420ae012009-04-24 05:16:321623void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1624 RenderViewHost* rvh) {
1625 // If we are creating a RVH for a restored controller, then we might
1626 // have more page IDs than the SiteInstance's current max page ID. We must
1627 // make sure that the max page ID is larger than any restored page ID.
1628 // Note that it is ok for conflicting page IDs to exist in another tab
1629 // (i.e., NavigationController), but if any page ID is larger than the max,
1630 // the back/forward list will get confused.
1631 int max_restored_page_id = controller_.max_restored_page_id();
1632 if (max_restored_page_id > 0) {
1633 int curr_max_page_id = site_instance->max_page_id();
1634 if (max_restored_page_id > curr_max_page_id) {
1635 // Need to update the site instance immediately.
1636 site_instance->UpdateMaxPageID(max_restored_page_id);
1637
1638 // Also tell the renderer to update its internal representation. We
1639 // need to reserve enough IDs to make all restored page IDs less than
1640 // the max.
1641 if (curr_max_page_id < 0)
1642 curr_max_page_id = 0;
1643 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1644 }
1645 }
1646}
1647
[email protected]ec0b6c42010-08-26 03:16:581648scoped_refptr<history::HistoryAddPageArgs>
1649TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541650 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471651 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321652 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581653 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1654 new history::HistoryAddPageArgs(
1655 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1656 params.redirects, params.transition, history::SOURCE_BROWSED,
1657 details.did_replace_entry));
1658 if (PageTransition::IsMainFrame(params.transition) &&
1659 virtual_url != params.url) {
1660 // Hack on the "virtual" URL so that it will appear in history. For some
1661 // types of URLs, we will display a magic URL that is different from where
1662 // the page is actually navigated. We want the user to see in history what
1663 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1664 // only applies to the main frame, as the virtual URL doesn't apply to
1665 // sub-frames.
1666 add_page_args->url = virtual_url;
1667 if (!add_page_args->redirects.empty())
1668 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321669 }
[email protected]ec0b6c42010-08-26 03:16:581670 return add_page_args;
[email protected]420ae012009-04-24 05:16:321671}
1672
1673bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1674 const std::wstring& title) {
1675 // For file URLs without a title, use the pathname instead. In the case of a
1676 // synthesized title, we don't want the update to count toward the "one set
1677 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251678 string16 final_title;
[email protected]420ae012009-04-24 05:16:321679 bool explicit_set;
1680 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251681 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321682 explicit_set = false; // Don't count synthetic titles toward the set limit.
1683 } else {
[email protected]e53668962010-06-23 15:35:251684 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321685 explicit_set = true;
1686 }
1687
[email protected]e53668962010-06-23 15:35:251688 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321689 return false; // Nothing changed, don't bother.
1690
[email protected]e53668962010-06-23 15:35:251691 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321692
[email protected]ec0b6c42010-08-26 03:16:581693 if (!received_page_title_) {
1694 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321695 received_page_title_ = explicit_set;
1696 }
1697
1698 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251699 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321700
[email protected]cbc0e1b2010-04-12 18:33:041701 NotificationService::current()->Notify(
1702 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1703 Source<TabContents>(this),
1704 NotificationService::NoDetails());
1705
[email protected]420ae012009-04-24 05:16:321706 return true;
1707}
1708
1709void TabContents::NotifySwapped() {
1710 // After sending out a swap notification, we need to send a disconnect
1711 // notification so that clients that pick up a pointer to |this| can NULL the
1712 // pointer. See Bug 1230284.
1713 notify_disconnection_ = true;
1714 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341715 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221716 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321717 NotificationService::NoDetails());
1718}
1719
1720void TabContents::NotifyConnected() {
1721 notify_disconnection_ = true;
1722 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341723 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221724 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321725 NotificationService::NoDetails());
1726}
1727
1728void TabContents::NotifyDisconnected() {
1729 if (!notify_disconnection_)
1730 return;
1731
1732 notify_disconnection_ = false;
1733 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341734 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221735 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321736 NotificationService::NoDetails());
1737}
1738
[email protected]7d472472011-01-22 01:30:251739void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541740 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1741 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1742 if (!entry)
1743 return;
1744 // Note that we don't call NavigationController::GotToOffset() as we don't
1745 // want to create a pending navigation entry (it might end up lingering
1746 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521747 entry->set_transition_type(entry->transition_type() |
1748 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541749 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1750 }
[email protected]bf5c2ff392009-07-08 16:24:331751}
1752
[email protected]dcd5b332010-08-11 08:55:181753void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:561754 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241755 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:561756}
1757
[email protected]8d3347f2009-07-09 22:00:211758RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321759 return view_.get();
1760}
1761
[email protected]8d3347f2009-07-09 22:00:211762RenderViewHostDelegate::RendererManagement*
1763TabContents::GetRendererManagementDelegate() {
1764 return &render_manager_;
1765}
1766
[email protected]46ba9082010-06-22 10:00:581767RenderViewHostDelegate::ContentSettings*
1768TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:551769 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:581770}
1771
[email protected]1f18184a2010-07-21 19:34:491772RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
1773 return GetSSLHelper();
1774}
1775
[email protected]fd571bb2010-03-19 01:23:541776AutomationResourceRoutingDelegate*
1777TabContents::GetAutomationResourceRoutingDelegate() {
1778 return delegate();
1779}
1780
[email protected]ced90ae12010-02-20 02:06:161781RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
1782 return bookmark_drag_;
1783}
1784
1785void TabContents::SetBookmarkDragDelegate(
1786 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
1787 bookmark_drag_ = bookmark_drag;
1788}
1789
[email protected]9fb83e82010-07-02 18:24:551790TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
1791 return content_settings_delegate_.get();
1792}
1793
[email protected]93623c5d2009-12-10 21:40:321794RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:461795 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511796}
1797
[email protected]57c6a652009-05-04 07:58:341798TabContents* TabContents::GetAsTabContents() {
1799 return this;
1800}
1801
[email protected]7b291f92009-08-14 05:43:531802ViewType::Type TabContents::GetRenderViewType() const {
1803 return ViewType::TAB_CONTENTS;
1804}
1805
1806int TabContents::GetBrowserWindowID() const {
1807 return controller().window_id().id();
1808}
1809
[email protected]420ae012009-04-24 05:16:321810void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061811 NotificationService::current()->Notify(
1812 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1813 Source<TabContents>(this),
1814 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321815 NavigationEntry* entry = controller_.GetActiveEntry();
1816 if (!entry)
1817 return;
1818
1819 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351820 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561821 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581822 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321823
1824 if (entry->IsViewSourceMode()) {
1825 // Put the renderer in view source mode.
1826 render_view_host->Send(
1827 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1828 }
[email protected]0666aef2009-05-13 19:48:081829
1830 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321831}
1832
1833void TabContents::RenderViewReady(RenderViewHost* rvh) {
1834 if (rvh != render_view_host()) {
1835 // Don't notify the world, since this came from a renderer in the
1836 // background.
1837 return;
1838 }
1839
1840 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301841 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231842 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301843
1844 // Restore the focus to the tab (otherwise the focus will be on the top
1845 // window).
[email protected]484ae5912010-09-29 19:16:141846 if (was_crashed && !FocusLocationBarByDefault() &&
1847 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301848 Focus();
[email protected]484ae5912010-09-29 19:16:141849 }
[email protected]420ae012009-04-24 05:16:321850}
1851
[email protected]443b80e2010-12-14 00:42:231852void TabContents::RenderViewGone(RenderViewHost* rvh,
1853 base::TerminationStatus status,
1854 int error_code) {
[email protected]420ae012009-04-24 05:16:321855 if (rvh != render_view_host()) {
1856 // The pending page's RenderViewHost is gone.
1857 return;
1858 }
1859
[email protected]2e3f4572011-03-25 19:24:471860 // Let observers know first and give them a chance to act.
1861 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
1862
[email protected]420ae012009-04-24 05:16:321863 SetIsLoading(false, NULL);
1864 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231865 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321866
[email protected]ff9efc62010-02-18 22:10:541867 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:401868 while (!infobar_delegates_.empty())
1869 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:541870
[email protected]8e537302009-06-10 21:19:581871 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:551872 // Only do this if we're not in browser shutdown, so that TabContents
1873 // objects that are not in a browser (e.g., HTML dialogs) and thus are
1874 // visible do not flash a sad tab page.
1875 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:161876 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321877
1878 // Hide any visible hung renderer warning for this web contents' process.
[email protected]7ec6bef2011-02-26 02:22:291879 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:321880}
1881
[email protected]2e4633c2009-07-09 16:58:061882void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481883 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:061884}
1885
[email protected]420ae012009-04-24 05:16:321886void TabContents::DidNavigate(RenderViewHost* rvh,
1887 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:371888 int extra_invalidate_flags = 0;
1889
1890 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:351891 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:371892
[email protected]420ae012009-04-24 05:16:321893 render_manager_.DidNavigateMainFrame(rvh);
1894
[email protected]20ede072009-10-06 00:28:351895 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:371896 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:371897 }
1898
[email protected]420ae012009-04-24 05:16:321899 // Update the site of the SiteInstance if it doesn't have one yet.
1900 if (!GetSiteInstance()->has_site())
1901 GetSiteInstance()->SetSite(params.url);
1902
1903 // Need to update MIME type here because it's referred to in
1904 // UpdateNavigationCommands() called by RendererDidNavigate() to
1905 // determine whether or not to enable the encoding menu.
1906 // It's updated only for the main frame. For a subframe,
1907 // RenderView::UpdateURL does not set params.contents_mime_type.
1908 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1909 // TODO(jungshik): Add a test for the encoding menu to avoid
1910 // regressing it again.
1911 if (PageTransition::IsMainFrame(params.transition))
1912 contents_mime_type_ = params.contents_mime_type;
1913
1914 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:371915 bool did_navigate = controller_.RendererDidNavigate(
1916 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:391917
[email protected]a9c0bfe2010-09-17 08:35:221918 // Send notification about committed provisional loads. This notification is
1919 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1920 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
1921 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071922 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1923 // that is not recorded in the navigation history. For the purpose of
1924 // tracking navigation events, we treat this event as a sub frame navigation
1925 // event.
1926 bool is_main_frame = did_navigate ? details.is_main_frame : false;
[email protected]0d60f0192011-04-14 12:40:101927 PageTransition::Type transition_type = params.transition;
[email protected]a9c0bfe2010-09-17 08:35:221928 // Whether or not a page transition was triggered by going backward or
1929 // forward in the history is only stored in the navigation controller's
1930 // entry list.
1931 if (did_navigate &&
1932 (controller_.GetActiveEntry()->transition_type() &
1933 PageTransition::FORWARD_BACK)) {
[email protected]0d60f0192011-04-14 12:40:101934 transition_type = params.transition | PageTransition::FORWARD_BACK;
[email protected]a9c0bfe2010-09-17 08:35:221935 }
[email protected]0d60f0192011-04-14 12:40:101936 // Notify observers about the commit of the provisional load.
1937 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1938 DidCommitProvisionalLoadForFrame(params.frame_id,
1939 is_main_frame, params.url, transition_type));
[email protected]a9c0bfe2010-09-17 08:35:221940 }
1941
[email protected]3e90d4a2009-07-03 17:38:391942 // Update history. Note that this needs to happen after the entry is complete,
1943 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:581944 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:391945 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:581946 // URLs, we use a data: URL as the real value. We actually want to save the
1947 // about: URL to the history db and keep the data: URL hidden. This is what
1948 // the TabContents' URL getter does.
1949 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1950 CreateHistoryAddPageArgs(GetURL(), details, params));
1951 if (!delegate() ||
1952 delegate()->ShouldAddNavigationToHistory(*add_page_args,
1953 details.type)) {
1954 UpdateHistoryForNavigation(add_page_args);
1955 }
[email protected]3e90d4a2009-07-03 17:38:391956 }
1957
[email protected]76543b92009-08-31 17:27:451958 if (!did_navigate)
1959 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321960
1961 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1962 // for the appropriate notification (best) or you can add it to
1963 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1964 // necessary, please).
1965
1966 // Run post-commit tasks.
1967 if (details.is_main_frame)
1968 DidNavigateMainFramePostCommit(details, params);
1969 DidNavigateAnyFramePostCommit(rvh, details, params);
1970}
1971
1972void TabContents::UpdateState(RenderViewHost* rvh,
1973 int32 page_id,
1974 const std::string& state) {
1975 DCHECK(rvh == render_view_host());
1976
1977 // We must be prepared to handle state updates for any page, these occur
1978 // when the user is scrolling and entering form data, as well as when we're
1979 // leaving a page, in which case our state may have already been moved to
1980 // the next page. The navigation controller will look up the appropriate
1981 // NavigationEntry and update it when it is notified via the delegate.
1982
1983 int entry_index = controller_.GetEntryIndexWithPageID(
1984 GetSiteInstance(), page_id);
1985 if (entry_index < 0)
1986 return;
1987 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1988
1989 if (state == entry->content_state())
1990 return; // Nothing to update.
1991 entry->set_content_state(state);
1992 controller_.NotifyEntryChanged(entry, entry_index);
1993}
1994
1995void TabContents::UpdateTitle(RenderViewHost* rvh,
1996 int32 page_id, const std::wstring& title) {
1997 // If we have a title, that's a pretty good indication that we've started
1998 // getting useful data.
1999 SetNotWaitingForResponse();
2000
2001 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482002 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582003 page_id);
[email protected]420ae012009-04-24 05:16:322004 if (!entry || !UpdateTitleForEntry(entry, title))
2005 return;
2006
2007 // Broadcast notifications when the UI should be updated.
2008 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032009 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322010}
2011
[email protected]420ae012009-04-24 05:16:322012void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402013 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322014 set_encoding(encoding);
2015}
2016
2017void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2018 if (delegate())
2019 delegate()->UpdateTargetURL(this, url);
2020}
2021
[email protected]c4e98902010-06-01 10:20:142022void TabContents::UpdateInspectorSetting(const std::string& key,
2023 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052024 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082025}
2026
[email protected]45aafc92010-06-07 14:18:532027void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052028 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532029}
2030
[email protected]420ae012009-04-24 05:16:322031void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292032 // The UI may be in an event-tracking loop, such as between the
2033 // mouse-down and mouse-up in text selection or a button click.
2034 // Defer the close until after tracking is complete, so that we
2035 // don't free objects out from under the UI.
2036 // TODO(shess): This could probably be integrated with the
2037 // IsDoingDrag() test below. Punting for now because I need more
2038 // research to understand how this impacts platforms other than Mac.
2039 // TODO(shess): This could get more fine-grained. For instance,
2040 // closing a tab in another window while selecting text in the
2041 // current window's Omnibox should be just fine.
2042 if (view()->IsEventTracking()) {
2043 view()->CloseTabAfterEventTracking();
2044 return;
2045 }
2046
[email protected]24a4d1062009-07-10 23:10:422047 // If we close the tab while we're in the middle of a drag, we'll crash.
2048 // Instead, cancel the drag and close it as soon as the drag ends.
2049 if (view()->IsDoingDrag()) {
2050 view()->CancelDragAndCloseTab();
2051 return;
2052 }
2053
[email protected]420ae012009-04-24 05:16:322054 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2055 if (delegate() && rvh == render_view_host())
2056 delegate()->CloseContents(this);
2057}
2058
2059void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2060 if (delegate() && delegate()->IsPopup(this))
2061 delegate()->MoveContents(this, new_bounds);
2062}
2063
[email protected]7ab1e7d62009-10-14 23:32:012064void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322065 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492066
[email protected]c40d6232011-03-25 00:16:212067 if (delegate() && content_restrictions_) {
2068 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:212069 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002070 }
[email protected]3c9e1872010-11-18 16:17:492071
2072 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172073 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322074}
2075
[email protected]7ab1e7d62009-10-14 23:32:012076void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322077 scoped_ptr<LoadNotificationDetails> details;
2078
2079 NavigationEntry* entry = controller_.GetActiveEntry();
2080 // An entry may not exist for a stop when loading an initial blank page or
2081 // if an iframe injected by script into a blank page finishes loading.
2082 if (entry) {
[email protected]420ae012009-04-24 05:16:322083 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2084
2085 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542086 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322087 entry->transition_type(),
2088 elapsed,
2089 &controller_,
2090 controller_.GetCurrentEntryIndex()));
2091 }
2092
[email protected]420ae012009-04-24 05:16:322093 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492094
2095 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172096 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322097}
2098
[email protected]1a3c3cb2010-12-16 21:03:402099void TabContents::DidChangeLoadProgress(double progress) {
2100 if (delegate())
2101 delegate()->LoadProgressChanged(progress);
2102}
2103
[email protected]25497492010-09-11 15:15:082104void TabContents::DocumentOnLoadCompletedInMainFrame(
2105 RenderViewHost* render_view_host,
2106 int32 page_id) {
2107 NotificationService::current()->Notify(
2108 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2109 Source<TabContents>(this),
2110 Details<int>(&page_id));
2111}
2112
[email protected]420ae012009-04-24 05:16:322113void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2114 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582115 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352116 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322117 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2118 // generated suggestions).
2119 //
[email protected]e0112912011-02-02 22:54:352120 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162121 // want web sites to see a referrer of "chrome://blah" (and some
2122 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322123 // send to the site), so we send no referrer.
2124 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582125 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322126 } else {
2127 OpenURL(url, referrer, disposition, PageTransition::LINK);
2128 }
2129}
2130
[email protected]1ee614862009-07-06 20:29:182131void TabContents::DomOperationResponse(const std::string& json_string,
2132 int automation_id) {
2133}
2134
[email protected]badcca352011-02-12 01:08:082135void TabContents::ProcessWebUIMessage(
[email protected]44c49c92011-03-28 16:17:232136 const ExtensionHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582137 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442138 // This can happen if someone uses window.open() to open an extension URL
2139 // from a non-extension context.
[email protected]553602e12011-04-05 17:01:182140 render_view_host()->Send(new ExtensionMsg_Response(
2141 render_view_host()->routing_id(), params.request_id, false, "",
2142 "Access to extension API denied."));
[email protected]420ae012009-04-24 05:16:322143 return;
2144 }
[email protected]badcca352011-02-12 01:08:082145 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322146}
2147
2148void TabContents::ProcessExternalHostMessage(const std::string& message,
2149 const std::string& origin,
2150 const std::string& target) {
2151 if (delegate())
2152 delegate()->ForwardMessageToExternalHost(message, origin, target);
2153}
2154
[email protected]420ae012009-04-24 05:16:322155void TabContents::RunJavaScriptMessage(
2156 const std::wstring& message,
2157 const std::wstring& default_prompt,
2158 const GURL& frame_url,
2159 const int flags,
2160 IPC::Message* reply_msg,
2161 bool* did_suppress_message) {
2162 // Suppress javascript messages when requested and when inside a constrained
2163 // popup window (because that activates them and breaks them out of the
2164 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552165 // Also suppress messages when showing an interstitial. The interstitial is
2166 // shown over the previous page, we don't want the hidden page dialogs to
2167 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502168 bool suppress_this_message =
2169 suppress_javascript_messages_ ||
2170 showing_interstitial_page() ||
2171 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322172 if (delegate())
2173 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312174 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322175
2176 *did_suppress_message = suppress_this_message;
2177
2178 if (!suppress_this_message) {
2179 base::TimeDelta time_since_last_message(
2180 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2181 bool show_suppress_checkbox = false;
2182 // Show a checkbox offering to suppress further messages if this message is
2183 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2184 if (time_since_last_message <
[email protected]1698f612011-03-11 11:28:152185 base::TimeDelta::FromMilliseconds(
2186 chrome::kJavascriptMessageExpectedDelay))
[email protected]420ae012009-04-24 05:16:322187 show_suppress_checkbox = true;
2188
[email protected]d6ad7442010-09-05 19:06:522189 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2190 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322191 } else {
2192 // If we are suppressing messages, just reply as is if the user immediately
2193 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542194 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322195 }
2196}
2197
2198void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2199 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292200 if (delegate())
2201 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502202 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2203 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2204 std::wstring());
2205 return;
2206 }
[email protected]7ab1e7d62009-10-14 23:32:012207 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222208 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322209}
2210
[email protected]420ae012009-04-24 05:16:322211GURL TabContents::GetAlternateErrorPageURL() const {
2212 GURL url;
2213 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2214 if (profile()->IsOffTheRecord())
2215 return url;
2216
2217 PrefService* prefs = profile()->GetPrefs();
2218 DCHECK(prefs);
2219 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152220 url = google_util::AppendGoogleLocaleParam(
2221 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322222 url = google_util::AppendGoogleTLDParam(url);
2223 }
2224 return url;
2225}
2226
2227WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062228 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582229 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082230 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582231 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082232
[email protected]9beff752010-09-22 19:35:432233 // Force accelerated compositing and 2d canvas off for chrome: and
2234 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432235 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2236 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082237 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432238 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082239 }
2240
[email protected]39553442010-09-09 00:01:552241#if defined(OS_MACOSX)
2242 // Disable accelerated compositing if IOSurface's are not supported,
2243 // as is the case in 10.5.
2244 if (!IOSurfaceSupport::Initialize())
2245 web_prefs.accelerated_compositing_enabled = false;
2246#endif
2247
[email protected]447021c2010-09-08 21:29:082248 return web_prefs;
[email protected]420ae012009-04-24 05:16:322249}
2250
[email protected]7d472472011-01-22 01:30:252251void TabContents::OnUserGesture() {
2252 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2253 DownloadRequestLimiter* limiter =
2254 g_browser_process->download_request_limiter();
2255 if (limiter)
2256 limiter->OnUserGesture(this);
2257 ExternalProtocolHandler::PermitLaunchUrl();
2258}
2259
[email protected]fa1cf0b82010-01-15 21:49:442260void TabContents::OnIgnoredUIEvent() {
2261 if (constrained_window_count()) {
2262 ConstrainedWindow* window = *constrained_window_begin();
2263 window->FocusConstrainedWindow();
2264 }
2265}
2266
[email protected]420ae012009-04-24 05:16:322267void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2268 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342269 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322270 // delivered to a pending RenderViewHost. We must first run the onunload
2271 // handler of the old RenderViewHost before we can allow it to proceed.
2272 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2273 new_request_id);
2274}
2275
[email protected]420ae012009-04-24 05:16:322276void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2277 bool is_during_unload) {
2278 if (is_during_unload) {
2279 // Hang occurred while firing the beforeunload/unload handler.
2280 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112281 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322282
2283 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2284 return;
2285
2286 // If the tab hangs in the beforeunload/unload handler there's really
2287 // nothing we can do to recover. Pretend the unload listeners have
2288 // all fired and close the tab. If the hang is in the beforeunload handler
2289 // then the user will not have the option of cancelling the close.
2290 Close(rvh);
2291 return;
2292 }
2293
[email protected]61b50092011-02-03 18:02:192294 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2295 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]7ec6bef2011-02-26 02:22:292296 browser::ShowHungRendererDialog(this);
[email protected]61b50092011-02-03 18:02:192297 }
[email protected]420ae012009-04-24 05:16:322298}
2299
2300void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]7ec6bef2011-02-26 02:22:292301 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322302}
2303
2304void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562305 net::LoadState load_state,
2306 uint64 upload_position,
2307 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322308 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562309 upload_position_ = upload_position;
2310 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292311 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192312 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292313 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422314 load_state_host_ = WideToUTF16Hack(
2315 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322316 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2317 SetNotWaitingForResponse();
2318 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502319 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322320}
2321
[email protected]1ee614862009-07-06 20:29:182322bool TabContents::IsExternalTabContainer() const {
2323 if (!delegate())
2324 return false;
2325
2326 return delegate()->IsExternalTabContainer();
2327}
2328
[email protected]1ee614862009-07-06 20:29:182329void TabContents::DidInsertCSS() {
2330 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322331}
2332
[email protected]546ae4e02010-12-08 14:57:192333void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352334 NotificationService::current()->Notify(
2335 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212336 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192337 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352338}
2339
[email protected]b75b8292010-10-01 07:28:252340void TabContents::UpdateZoomLimits(int minimum_percent,
2341 int maximum_percent,
2342 bool remember) {
2343 minimum_zoom_percent_ = minimum_percent;
2344 maximum_zoom_percent_ = maximum_percent;
2345 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382346}
2347
[email protected]7d472472011-01-22 01:30:252348void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442349 if (delegate())
2350 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252351}
2352
[email protected]f364d1392011-04-08 21:03:102353void TabContents::RequestDesktopNotificationPermission(
2354 const GURL& source_origin, int callback_context) {
2355 DesktopNotificationService* service =
[email protected]dcb72d52011-04-13 12:36:532356 DesktopNotificationServiceFactory::GetForProfile(profile());
[email protected]f364d1392011-04-08 21:03:102357 service->RequestPermission(
2358 source_origin, GetRenderProcessHost()->id(),
2359 render_view_host()->routing_id(), callback_context, this);
2360}
2361
[email protected]60f36f92011-04-12 16:18:312362void TabContents::OnUpdateFaviconURL(
2363 int32 page_id,
2364 const std::vector<FaviconURL>& candidates) {
2365 favicon_helper().OnUpdateFaviconURL(page_id, candidates);
2366 if (touch_icon_helper_.get())
2367 touch_icon_helper_->OnUpdateFaviconURL(page_id, candidates);
2368}
2369
[email protected]420ae012009-04-24 05:16:322370void TabContents::BeforeUnloadFiredFromRenderManager(
2371 bool proceed,
2372 bool* proceed_to_fire_unload) {
2373 if (delegate())
2374 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2375}
2376
[email protected]3a3d47472010-07-15 21:03:542377void TabContents::DidStartLoadingFromRenderManager(
2378 RenderViewHost* render_view_host) {
2379 DidStartLoading();
2380}
2381
2382void TabContents::RenderViewGoneFromRenderManager(
2383 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232384 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2385 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542386}
2387
[email protected]420ae012009-04-24 05:16:322388void TabContents::UpdateRenderViewSizeForRenderManager() {
2389 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262390 gfx::Size size = view_->GetContainerSize();
2391 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2392 // here during container initialization and normal window size will be set
2393 // later. In case of tab duplication this resizing to 0x0 prevents setting
2394 // normal size later so just ignore it.
2395 if (!size.IsEmpty())
2396 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322397}
2398
[email protected]3a3d47472010-07-15 21:03:542399void TabContents::NotifySwappedFromRenderManager() {
2400 NotifySwapped();
2401}
2402
2403NavigationController& TabContents::GetControllerForRenderManager() {
2404 return controller();
2405}
2406
[email protected]d0980792011-02-13 19:41:402407WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562408 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322409}
2410
2411NavigationEntry*
2412TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2413 return controller_.GetLastCommittedEntry();
2414}
2415
2416bool TabContents::CreateRenderViewForRenderManager(
2417 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322418 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522419
[email protected]674b3822010-08-04 04:02:512420 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322421 return false;
2422
2423 // Now that the RenderView has been created, we need to tell it its size.
2424 rwh_view->SetSize(view_->GetContainerSize());
2425
2426 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2427 render_view_host);
2428 return true;
2429}
2430
2431void TabContents::Observe(NotificationType type,
2432 const NotificationSource& source,
2433 const NotificationDetails& details) {
2434 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322435 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512436 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322437 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2438 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2439 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532440 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2441 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322442 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172443 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2444 UpdateZoomLevel();
[email protected]0a8db0d2011-04-13 15:15:402445 } else if (*pref_name_in == prefs::kEnableReferrers) {
2446 renderer_preferences_util::UpdateFromSystemSettings(
2447 &renderer_preferences_, profile());
2448 render_view_host()->SyncRendererPrefs();
[email protected]420ae012009-04-24 05:16:322449 } else {
2450 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2451 }
2452 break;
2453 }
2454 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2455 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2456 break;
2457
2458 case NotificationType::NAV_ENTRY_COMMITTED: {
2459 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2460
2461 NavigationController::LoadCommittedDetails& committed_details =
2462 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2463 ExpireInfoBars(committed_details);
2464 break;
2465 }
2466
[email protected]d3ba77272009-09-03 00:06:092467#if defined(OS_LINUX)
2468 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542469 renderer_preferences_util::UpdateFromSystemSettings(
2470 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092471 render_view_host()->SyncRendererPrefs();
2472 break;
2473 }
2474#endif
2475
[email protected]6c32ce72010-03-08 05:18:062476 case NotificationType::USER_STYLE_SHEET_UPDATED:
2477 UpdateWebPreferences();
2478 break;
2479
[email protected]79580c62010-02-02 02:36:252480 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452481 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252482 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492483 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292484 if (entry)
[email protected]da0c8e92010-02-09 23:25:492485 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292486 if (settings_details.ptr()->update_all() ||
2487 settings_details.ptr()->pattern().Matches(entry_url)) {
2488 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232489 profile()->GetHostContentSettingsMap()->
2490 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252491 }
2492 break;
2493 }
2494
[email protected]88152052010-10-01 04:05:182495 case NotificationType::GOOGLE_URL_UPDATED:
2496 UpdateAlternateErrorPageURL();
2497 break;
2498
[email protected]420ae012009-04-24 05:16:322499 default:
2500 NOTREACHED();
2501 }
2502}
[email protected]aacd7cc2009-09-02 14:51:102503
[email protected]beb440c2009-11-06 04:08:542504gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2505 return view_->GetTopLevelNativeWindow();
2506}
2507
2508void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2509 bool success,
2510 const std::wstring& prompt) {
2511 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2512 if (is_showing_before_unload_dialog_ && !success) {
2513 // If a beforeunload dialog is canceled, we need to stop the throbber from
2514 // spinning, since we forced it to start spinning in Navigate.
2515 DidStopLoading();
2516
2517 tab_close_start_time_ = base::TimeTicks();
2518 }
2519 is_showing_before_unload_dialog_ = false;
2520 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2521}
2522
2523void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2524 set_suppress_javascript_messages(suppress_message_boxes);
2525}
2526
[email protected]3a3d47472010-07-15 21:03:542527TabContents* TabContents::AsTabContents() {
2528 return this;
2529}
2530
2531ExtensionHost* TabContents::AsExtensionHost() {
2532 return NULL;
2533}
2534
[email protected]41fc0322009-09-04 22:23:402535void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102536 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2537}
[email protected]f45d2a72010-03-08 23:28:352538
[email protected]33f74972010-12-08 16:40:362539void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2540 render_manager_.SwapInRenderViewHost(rvh);
2541}
2542
2543void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2544 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2545 rwh_view->SetSize(view()->GetContainerSize());
2546}
[email protected]e7d50892011-01-19 21:47:382547
[email protected]232a5812011-03-04 22:42:082548void TabContents::OnOnlineStateChanged(bool online) {
2549 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2550 render_view_host()->routing_id(), online));
2551}