blob: a15e6fe926b11efd116ce1cafe317fabbfc6d2a9 [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]c8865482009-07-23 20:40:1039#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1740#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2441#include "chrome/browser/platform_util.h"
[email protected]67c052e2011-01-31 16:33:5842#include "chrome/browser/plugin_observer.h"
[email protected]36fb2c7c2011-04-04 15:49:0843#include "chrome/browser/prefs/pref_service.h"
[email protected]8ecad5e2010-12-02 21:18:3344#include "chrome/browser/profiles/profile.h"
[email protected]96d185d2009-04-24 03:28:5445#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3246#include "chrome/browser/renderer_preferences_util.h"
[email protected]fa685ff2011-02-17 19:47:1347#include "chrome/browser/safe_browsing/client_side_detection_host.h"
[email protected]c37e3b62010-01-22 00:15:1748#include "chrome/browser/sessions/session_types.h"
[email protected]a40f6e92011-03-04 23:30:2949#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4950#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]d54169e92011-01-21 09:19:5251#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1652#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3553#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]7ec6bef2011-02-26 02:22:2954#include "chrome/browser/ui/browser_dialogs.h"
[email protected]54ec6472010-04-09 19:39:5855#include "chrome/common/bindings_policy.h"
[email protected]1698f612011-03-11 11:28:1556#include "chrome/common/chrome_constants.h"
[email protected]35f7d212009-04-29 21:19:2757#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2158#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4959#include "chrome/common/extensions/extension.h"
[email protected]44c49c92011-03-28 16:17:2360#include "chrome/common/extensions/extension_messages.h"
[email protected]12802702010-07-09 19:43:0961#include "chrome/common/extensions/url_pattern.h"
initial.commit09911bf2008-07-26 23:55:2962#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3263#include "chrome/common/render_messages.h"
[email protected]96d185d2009-04-24 03:28:5464#include "chrome/common/url_constants.h"
[email protected]567812d2011-02-24 17:40:5065#include "content/browser/child_process_security_policy.h"
[email protected]1fd1a502011-03-30 16:55:5666#include "content/browser/content_browser_client.h"
[email protected]567812d2011-02-24 17:40:5067#include "content/browser/host_zoom_map.h"
68#include "content/browser/in_process_webkit/session_storage_namespace.h"
69#include "content/browser/renderer_host/render_process_host.h"
70#include "content/browser/renderer_host/render_view_host.h"
71#include "content/browser/renderer_host/render_widget_host_view.h"
72#include "content/browser/renderer_host/resource_request_details.h"
73#include "content/browser/site_instance.h"
[email protected]0dd3a0ab2011-02-18 08:17:4474#include "content/browser/tab_contents/interstitial_page.h"
75#include "content/browser/tab_contents/navigation_entry.h"
76#include "content/browser/tab_contents/provisional_load_details.h"
77#include "content/browser/tab_contents/tab_contents_delegate.h"
78#include "content/browser/tab_contents/tab_contents_observer.h"
79#include "content/browser/tab_contents/tab_contents_view.h"
[email protected]1fd1a502011-03-30 16:55:5680#include "content/browser/webui/web_ui_factory.h"
81#include "content/common/content_client.h"
[email protected]4dd57932011-03-17 06:06:1282#include "content/common/navigation_types.h"
[email protected]7f070d42011-03-09 20:25:3283#include "content/common/notification_service.h"
[email protected]2c5569662011-03-22 20:45:0284#include "content/common/view_messages.h"
[email protected]d686e812009-06-03 19:10:2985#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3286#include "net/base/registry_controlled_domain.h"
[email protected]abe2c032011-03-31 18:49:3487#include "net/url_request/url_request_context_getter.h"
[email protected]8bd0fe62011-01-17 06:44:3788#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]42ce29d2011-01-20 23:19:4689#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:3890#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:0391#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:3192#include "webkit/glue/webpreferences.h"
93
94#if defined(OS_MACOSX)
[email protected]b9b751f22011-03-25 14:04:1295#include "ui/gfx/surface/io_surface_support_mac.h"
[email protected]3c733bde2010-12-21 19:56:3196#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:0097
[email protected]420ae012009-04-24 05:16:3298// Cross-Site Navigations
99//
100// If a TabContents is told to navigate to a different web site (as determined
101// by SiteInstance), it will replace its current RenderViewHost with a new
102// RenderViewHost dedicated to the new SiteInstance. This works as follows:
103//
104// - Navigate determines whether the destination is cross-site, and if so,
105// it creates a pending_render_view_host_ and moves into the PENDING
106// RendererState.
107// - The pending RVH is "suspended," so that no navigation messages are sent to
108// its renderer until the onbeforeunload JavaScript handler has a chance to
109// run in the current RVH.
110// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
111// that it has a pending cross-site request. ResourceDispatcherHost will
112// check for this when the response arrives.
113// - The current RVH runs its onbeforeunload handler. If it returns false, we
114// cancel all the pending logic and go back to NORMAL. Otherwise we allow
115// the pending RVH to send the navigation request to its renderer.
116// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
117// checks CrossSiteRequestManager to see that the RVH responsible has a
118// pending cross-site request, and then installs a CrossSiteEventHandler.
119// - When RDH receives a response, the BufferedEventHandler determines whether
120// it is a download. If so, it sends a message to the new renderer causing
121// it to cancel the request, and the download proceeds in the download
122// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34123// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32124// doesn't affect any functionality.
125// - After RDH receives a response and determines that it is safe and not a
126// download, it pauses the response to first run the old page's onunload
127// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34128// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32129// to the current RVH.
130// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
131// the ResourceDispatcherHost, who unpauses the response. Data is then sent
132// to the pending RVH.
133// - The pending renderer sends a FrameNavigate message that invokes the
134// DidNavigate method. This replaces the current RVH with the
135// pending RVH and goes back to the NORMAL RendererState.
136
137namespace {
138
139// Amount of time we wait between when a key event is received and the renderer
140// is queried for its state and pushed to the NavigationEntry.
141const int kQueryStateDelay = 5000;
142
[email protected]6ebdc9b2010-09-27 16:55:57143const int kSyncWaitDelay = 40;
144
[email protected]420ae012009-04-24 05:16:32145// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51146const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32147 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17148 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32149 prefs::kWebKitJavaEnabled,
150 prefs::kWebKitJavascriptEnabled,
151 prefs::kWebKitLoadsImagesAutomatically,
152 prefs::kWebKitPluginsEnabled,
153 prefs::kWebKitUsesUniversalDetector,
[email protected]16480f62011-03-01 23:39:10154 prefs::kWebKitStandardFontFamily,
[email protected]420ae012009-04-24 05:16:32155 prefs::kWebKitSerifFontFamily,
156 prefs::kWebKitSansSerifFontFamily,
157 prefs::kWebKitFixedFontFamily,
158 prefs::kWebKitDefaultFontSize,
159 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13160 prefs::kWebKitMinimumFontSize,
161 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36162 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32163 prefs::kDefaultCharset
[email protected]420ae012009-04-24 05:16:32164};
165
166const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
167
[email protected]420ae012009-04-24 05:16:32168#if defined(OS_WIN)
169
170BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
171 // Note: erase is required to properly paint some widgets borders. This can
172 // be seen with textfields.
173 InvalidateRect(hwnd, NULL, TRUE);
174 return TRUE;
175}
176#endif
177
[email protected]2c5569662011-03-22 20:45:02178ViewMsg_Navigate_Type::Value GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16179 Profile* profile, const NavigationEntry& entry,
180 NavigationController::ReloadType reload_type) {
181 switch (reload_type) {
182 case NavigationController::RELOAD:
[email protected]2c5569662011-03-22 20:45:02183 return ViewMsg_Navigate_Type::RELOAD;
[email protected]1ccb3568d2010-02-19 10:51:16184 case NavigationController::RELOAD_IGNORING_CACHE:
[email protected]2c5569662011-03-22 20:45:02185 return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE;
[email protected]1ccb3568d2010-02-19 10:51:16186 case NavigationController::NO_RELOAD:
187 break; // Fall through to rest of function.
188 }
[email protected]5e369672009-11-03 23:48:30189
190 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
191 profile->DidLastSessionExitCleanly())
[email protected]2c5569662011-03-22 20:45:02192 return ViewMsg_Navigate_Type::RESTORE;
[email protected]5e369672009-11-03 23:48:30193
[email protected]2c5569662011-03-22 20:45:02194 return ViewMsg_Navigate_Type::NORMAL;
[email protected]5e369672009-11-03 23:48:30195}
196
[email protected]876bc832010-09-07 16:29:54197void MakeNavigateParams(const NavigationEntry& entry,
198 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16199 NavigationController::ReloadType reload_type,
200 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34201 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54202 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00203 params->current_history_list_offset = controller.last_committed_entry_index();
204 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34205 params->url = entry.url();
206 params->referrer = entry.referrer();
207 params->transition = entry.transition_type();
208 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00209 params->navigation_type =
210 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34211 params->request_time = base::Time::Now();
212}
213
[email protected]420ae012009-04-24 05:16:32214} // namespace
215
[email protected]f4f50ef2011-01-21 19:01:19216
217// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32218
[email protected]420ae012009-04-24 05:16:32219TabContents::TabContents(Profile* profile,
220 SiteInstance* site_instance,
221 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07222 const TabContents* base_tab_contents,
223 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42224 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07225 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
226 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13227 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22228 TabContentsView::Create(this))),
229 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06230 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34231 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23232 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
233 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34234 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34235 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57236 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56237 upload_size_(0),
238 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57239 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40240 blocked_contents_(NULL),
241 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49242 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47243 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57244 capturing_contents_(false),
245 is_being_destroyed_(false),
246 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57247#if defined(OS_WIN)
248 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
249#endif
[email protected]c2e74fe82009-09-03 17:57:44250 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01251 is_showing_before_unload_dialog_(false),
[email protected]1fd1a502011-03-30 16:55:56252 opener_web_ui_type_(WebUI::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16253 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38254 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25255 minimum_zoom_percent_(
256 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
257 maximum_zoom_percent_(
258 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00259 temporary_zoom_settings_(false),
[email protected]4850a7f2011-03-08 23:36:59260 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54261 renderer_preferences_util::UpdateFromSystemSettings(
262 &renderer_preferences_, profile);
263
[email protected]9fb83e82010-07-02 18:24:55264 content_settings_delegate_.reset(
265 new TabSpecificContentSettings(this, profile));
266
[email protected]12636df2009-09-28 22:32:21267 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32268
[email protected]34ac70502009-09-25 17:07:23269 // We have the initial size of the view be based on the size of the passed in
270 // tab contents (normally a tab from the same window).
271 view_->CreateView(base_tab_contents ?
272 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32273
274 // Register for notifications about all interested prefs change.
275 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28276 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32277 if (prefs) {
278 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28279 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32280 }
281
[email protected]420ae012009-04-24 05:16:32282 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
283 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09284#if defined(OS_LINUX)
285 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
286 NotificationService::AllSources());
287#endif
[email protected]420ae012009-04-24 05:16:32288
[email protected]6c32ce72010-03-08 05:18:06289 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
290 NotificationService::AllSources());
291
[email protected]79580c62010-02-02 02:36:25292 // Register for notifications about content setting changes.
293 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
294 NotificationService::AllSources());
295
[email protected]969182a2011-03-03 14:53:23296 // Listen for Google URL changes.
[email protected]88152052010-10-01 04:05:18297 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
298 NotificationService::AllSources());
299
[email protected]c8865482009-07-23 20:40:10300 // Set-up the showing of the omnibox search infobar if applicable.
301 if (OmniboxSearchHint::IsEnabled(profile))
302 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53303
[email protected]b5a1d11c2011-02-17 03:09:42304 // Can only add observers after render_manager_.Init() is called, since that's
305 // what sets up the render_view_host which TabContentObserver's constructor
306 // uses to get the routing_id.
307 AddObservers();
[email protected]332af7732009-03-11 13:21:35308}
initial.commit09911bf2008-07-26 23:55:29309
310TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32311 is_being_destroyed_ = true;
312
[email protected]bfe4c1582009-10-02 18:11:09313 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32314 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28315 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32316
[email protected]420ae012009-04-24 05:16:32317 NotifyDisconnected();
[email protected]7ec6bef2011-02-26 02:22:29318 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:32319
[email protected]420ae012009-04-24 05:16:32320 // First cleanly close all child windows.
321 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
322 // some of these to close. CloseWindows is async, so it might get called
323 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49324 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32325
[email protected]c65e2f152010-10-14 15:30:40326 // Close all blocked contents.
327 if (blocked_contents_)
328 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13329
[email protected]420ae012009-04-24 05:16:32330 // Notify any observer that have a reference on this tab contents.
331 NotificationService::current()->Notify(
332 NotificationType::TAB_CONTENTS_DESTROYED,
333 Source<TabContents>(this),
334 NotificationService::NoDetails());
335
[email protected]1e5e74f2009-05-27 20:55:12336 // Notify any lasting InfobarDelegates that have not yet been removed that
337 // whatever infobar they were handling in this TabContents has closed,
338 // because the TabContents is going away entirely.
339 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
340 // notification may trigger infobars calls that access their delegate. (and
341 // some implementations of InfoBarDelegate do delete themselves on
342 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40343 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12344 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
345 delegate->InfoBarClosed();
346 }
347 infobar_delegates_.clear();
348
[email protected]420ae012009-04-24 05:16:32349 // TODO(brettw) this should be moved to the view.
350#if defined(OS_WIN)
351 // If we still have a window handle, destroy it. GetNativeView can return
352 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42353 if (GetNativeView()) {
354 RenderViewHost* host = render_view_host();
355 if (host && host->view()) {
356 host->view()->WillWmDestroy();
357 }
[email protected]420ae012009-04-24 05:16:32358 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42359 }
[email protected]420ae012009-04-24 05:16:32360#endif
[email protected]7ab1e7d62009-10-14 23:32:01361
362 // OnCloseStarted isn't called in unit tests.
363 if (!tab_close_start_time_.is_null()) {
364 UMA_HISTOGRAM_TIMES("Tab.Close",
365 base::TimeTicks::Now() - tab_close_start_time_);
366 }
[email protected]b5a1d11c2011-02-17 03:09:42367
[email protected]07d490bc2011-03-07 17:05:26368 FOR_EACH_OBSERVER(TabContentsObserver, observers_, TabContentsDestroyed());
[email protected]232a5812011-03-04 22:42:08369
370 net::NetworkChangeNotifier::RemoveOnlineStateObserver(this);
[email protected]b5a1d11c2011-02-17 03:09:42371}
372
373void TabContents::AddObservers() {
[email protected]0150cfc2011-04-07 22:51:41374 favicon_helper_.reset(new FaviconHelper(this));
[email protected]b5a1d11c2011-02-17 03:09:42375 plugin_observer_.reset(new PluginObserver(this));
[email protected]fa685ff2011-02-17 19:47:13376 safebrowsing_detection_host_.reset(new safe_browsing::ClientSideDetectionHost(
377 this));
[email protected]232a5812011-03-04 22:42:08378 net::NetworkChangeNotifier::AddOnlineStateObserver(this);
initial.commit09911bf2008-07-26 23:55:29379}
380
[email protected]724159a2010-12-30 01:11:18381bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17382 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
383 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10384 while ((observer = it.GetNext()) != NULL)
385 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53386 return true;
[email protected]403415a2011-01-10 18:57:53387
[email protected]724159a2010-12-30 01:11:18388 bool handled = true;
389 bool message_is_ok = true;
390 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
391 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
392 OnDidStartProvisionalLoadForFrame)
393 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
394 OnDidRedirectProvisionalLoad)
395 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
396 OnDidFailProvisionalLoadWithError)
397 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
398 OnDidLoadResourceFromMemoryCache)
399 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
400 OnDidDisplayInsecureContent)
401 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
402 OnDidRunInsecureContent)
403 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
404 OnDocumentLoadedInFrame)
405 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17406 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
407 OnUpdateContentRestrictions)
408 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
409 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25410 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]7d472472011-01-22 01:30:25411 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
412 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
[email protected]724159a2010-12-30 01:11:18413 IPC_MESSAGE_UNHANDLED(handled = false)
414 IPC_END_MESSAGE_MAP_EX()
415
416 if (!message_is_ok) {
417 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
418 GetRenderProcessHost()->ReceivedBadMessage();
419 }
420
421 return handled;
422}
423
[email protected]13367f72009-07-08 16:39:02424// Returns true if contains content rendered by an extension.
425bool TabContents::HostsExtension() const {
426 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34427}
428
[email protected]1f18184a2010-07-21 19:34:49429TabContentsSSLHelper* TabContents::GetSSLHelper() {
430 if (ssl_helper_.get() == NULL)
431 ssl_helper_.reset(new TabContentsSSLHelper(this));
432 return ssl_helper_.get();
433}
434
[email protected]8cb5d5b2010-02-09 11:36:16435RenderProcessHost* TabContents::GetRenderProcessHost() const {
436 return render_manager_.current_host()->process();
437}
438
[email protected]d5f942ba2008-09-26 19:30:34439const GURL& TabContents::GetURL() const {
440 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57441 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54442 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34443}
444
[email protected]96d185d2009-04-24 03:28:54445const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55446 // Transient entries take precedence. They are used for interstitial pages
447 // that are shown on top of existing pages.
448 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23449 if (entry) {
450 return entry->GetTitleForDisplay(profile()->GetPrefs()->
451 GetString(prefs::kAcceptLanguages));
452 }
[email protected]7ade2732011-02-10 00:13:58453 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
454 render_manager_.pending_web_ui() : render_manager_.web_ui();
455 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54456 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55457 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54458 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35459 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58460 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54461 if (!title.empty())
462 return title;
463 }
464 }
465
466 // We use the title for the last committed entry rather than a pending
467 // navigation entry. For example, when the user types in a URL, we want to
468 // keep the old page's title until the new load has committed and we get a new
469 // title.
[email protected]96d185d2009-04-24 03:28:54470 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23471 if (entry) {
472 return entry->GetTitleForDisplay(profile()->GetPrefs()->
473 GetString(prefs::kAcceptLanguages));
474 }
[email protected]96d185d2009-04-24 03:28:54475 return EmptyString16();
476}
477
[email protected]d5f942ba2008-09-26 19:30:34478int32 TabContents::GetMaxPageID() {
479 if (GetSiteInstance())
480 return GetSiteInstance()->max_page_id();
481 else
482 return max_page_id_;
483}
484
485void TabContents::UpdateMaxPageID(int32 page_id) {
486 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34487 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34488 // testing.
489 if (GetSiteInstance())
490 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16491 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34492}
493
[email protected]96d185d2009-04-24 03:28:54494SiteInstance* TabContents::GetSiteInstance() const {
495 return render_manager_.current_host()->site_instance();
496}
497
[email protected]96d185d2009-04-24 03:28:54498bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15499 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54500 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15501 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01502 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54503 return true;
[email protected]8ab24cc2009-11-13 20:56:15504 }
[email protected]83e3895b2009-06-11 00:07:16505
[email protected]2b9a06402011-02-16 04:57:10506 // We always display the URL for non-WebUI URLs to prevent spoofing.
[email protected]1fd1a502011-03-30 16:55:56507 if (entry && !content::WebUIFactory::Get()->HasWebUIScheme(entry->url()))
[email protected]2b9a06402011-02-16 04:57:10508 return true;
509
[email protected]d0980792011-02-13 19:41:40510 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58511 if (web_ui)
512 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54513 return true;
514}
515
[email protected]0150cfc2011-04-07 22:51:41516SkBitmap TabContents::GetFavicon() const {
517 // Like GetTitle(), we also want to use the favicon for the last committed
518 // entry rather than a pending navigation entry.
519 NavigationEntry* entry = controller_.GetTransientEntry();
520 if (entry)
521 return entry->favicon().bitmap();
522
523 entry = controller_.GetLastCommittedEntry();
524 if (entry)
525 return entry->favicon().bitmap();
526 return SkBitmap();
527}
528
529bool TabContents::FaviconIsValid() const {
530 NavigationEntry* entry = controller_.GetTransientEntry();
531 if (entry)
532 return entry->favicon().is_valid();
533
534 entry = controller_.GetLastCommittedEntry();
535 if (entry)
536 return entry->favicon().is_valid();
537
538 return false;
539}
540
541bool TabContents::ShouldDisplayFavicon() {
542 // Always display a throbber during pending loads.
543 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
544 return true;
545
546 WebUI* web_ui = GetWebUIForCurrentState();
547 if (web_ui)
548 return !web_ui->hide_favicon();
549 return true;
550}
551
[email protected]585b30362011-01-28 02:30:17552void TabContents::AddObserver(TabContentsObserver* observer) {
553 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49554}
555
[email protected]585b30362011-01-28 02:30:17556void TabContents::RemoveObserver(TabContentsObserver* observer) {
557 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49558}
559
[email protected]443b80e2010-12-14 00:42:23560void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
561 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34562 return;
563
[email protected]443b80e2010-12-14 00:42:23564 crashed_status_ = status;
565 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50566 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34567}
568
569void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
570 if (delegate_)
571 delegate_->NavigationStateChanged(this, changed_flags);
572}
573
[email protected]96d185d2009-04-24 03:28:54574void TabContents::DidBecomeSelected() {
575 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16576 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
577 if (rwhv) {
578 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43579#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16580 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43581#endif
582 }
[email protected]96d185d2009-04-24 03:28:54583
[email protected]8cb5d5b2010-02-09 11:36:16584 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11585 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54586}
587
588void TabContents::WasHidden() {
589 if (!capturing_contents()) {
590 // |render_view_host()| can be NULL if the user middle clicks a link to open
591 // a tab in then background, then closes the tab before selecting it. This
592 // is because closing the tab calls TabContents::Destroy(), which removes
593 // the |render_view_host()|; then when we actually destroy the window,
594 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16595 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
596 if (rwhv)
597 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54598 }
599
600 NotificationService::current()->Notify(
601 NotificationType::TAB_CONTENTS_HIDDEN,
602 Source<TabContents>(this),
603 NotificationService::NoDetails());
604}
605
[email protected]d5f942ba2008-09-26 19:30:34606void TabContents::Activate() {
607 if (delegate_)
608 delegate_->ActivateContents(this);
609}
610
[email protected]ea42e7782010-08-23 23:58:12611void TabContents::Deactivate() {
612 if (delegate_)
613 delegate_->DeactivateContents(this);
614}
615
[email protected]96d185d2009-04-24 03:28:54616void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16617 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
618 if (rwhv)
619 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54620}
621
622void TabContents::HideContents() {
623 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
624 // our superclass HideContents(), because some callers want to be very picky
625 // about the order in which these get called. In addition to making the code
626 // here practically impossible to understand, this also means we end up
627 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34628 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54629 WasHidden();
630}
631
[email protected]5aab5e22010-12-08 22:13:29632bool TabContents::NeedToFireBeforeUnload() {
633 // TODO(creis): Should we fire even for interstitial pages?
634 return notify_disconnection() &&
635 !showing_interstitial_page() &&
636 !render_view_host()->SuddenTerminationAllowed();
637}
638
[email protected]c0588052008-10-27 23:01:50639void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34640 WindowOpenDisposition disposition,
641 PageTransition::Type transition) {
642 if (delegate_)
[email protected]c0588052008-10-27 23:01:50643 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34644}
645
[email protected]1ccb3568d2010-02-19 10:51:16646bool TabContents::NavigateToPendingEntry(
647 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54648 return NavigateToEntry(*controller_.pending_entry(), reload_type);
649}
[email protected]96d185d2009-04-24 03:28:54650
[email protected]876bc832010-09-07 16:29:54651bool TabContents::NavigateToEntry(
652 const NavigationEntry& entry,
653 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54654 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
655 if (!dest_render_view_host)
656 return false; // Unable to create the desired render view host.
657
[email protected]770dd8b2010-05-24 18:11:39658 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
659 dest_render_view_host->EnablePreferredSizeChangedMode(
660 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
661 }
[email protected]9fb325e2010-05-06 18:23:24662
[email protected]80a8fad2011-01-29 04:02:38663 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07664 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58665 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]1fd1a502011-03-30 16:55:56666 bool is_allowed_in_web_ui_renderer = content::GetContentClient()->
667 browser()->GetWebUIFactory()->IsURLAcceptableForWebUI(profile(),
668 entry.url());
[email protected]c09163a2011-02-15 00:05:55669 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
670 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58671
[email protected]96d185d2009-04-24 03:28:54672 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12673 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32674 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00675 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
676 dest_render_view_host,
677 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32678 }
[email protected]96d185d2009-04-24 03:28:54679
680 // Used for page load time metrics.
681 current_load_start_ = base::TimeTicks::Now();
682
683 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34684 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54685 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04686 if (delegate_) {
687 navigate_params.extra_headers =
688 delegate_->GetNavigationHeaders(navigate_params.url);
689 }
[email protected]056de2d2009-06-26 16:41:34690 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54691
692 if (entry.page_id() == -1) {
693 // HACK!! This code suppresses javascript: URLs from being added to
694 // session history, which is what we want to do for javascript: URLs that
695 // do not generate content. What we really need is a message from the
696 // renderer telling us that a new page was not created. The same message
697 // could be used for mailto: URLs and the like.
698 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
699 return false;
700 }
701
[email protected]3c9e1872010-11-18 16:17:49702 // Notify observers about navigation.
[email protected]0150cfc2011-04-07 22:51:41703 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
704
705 if (reload_type != NavigationController::NO_RELOAD &&
706 !profile()->IsOffTheRecord()) {
707 FaviconService* favicon_service =
708 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
709 if (favicon_service)
710 favicon_service->SetFaviconOutOfDateForPage(entry.url());
711 }
[email protected]96d185d2009-04-24 03:28:54712
[email protected]d5f942ba2008-09-26 19:30:34713 return true;
714}
715
[email protected]96d185d2009-04-24 03:28:54716void TabContents::Stop() {
717 render_manager_.Stop();
[email protected]2e3f4572011-03-25 19:24:47718 FOR_EACH_OBSERVER(TabContentsObserver, observers_, StopNavigation());
[email protected]96d185d2009-04-24 03:28:54719}
720
[email protected]96d185d2009-04-24 03:28:54721void TabContents::DisassociateFromPopupCount() {
722 render_view_host()->DisassociateFromPopupCount();
723}
724
725TabContents* TabContents::Clone() {
726 // We create a new SiteInstance so that the new tab won't share processes
727 // with the old one. This can be changed in the future if we need it to share
728 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32729 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54730 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07731 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54732 tc->controller().CopyStateFrom(controller_);
733 return tc;
734}
735
[email protected]4d677202009-07-19 07:37:12736void TabContents::ShowPageInfo(const GURL& url,
737 const NavigationEntry::SSLStatus& ssl,
738 bool show_history) {
739 if (!delegate_)
740 return;
741
[email protected]bb678332009-07-21 00:15:50742 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12743}
744
[email protected]0150cfc2011-04-07 22:51:41745void TabContents::SaveFavicon() {
746 NavigationEntry* entry = controller_.GetActiveEntry();
747 if (!entry || entry->url().is_empty())
748 return;
749
750 // Make sure the page is in history, otherwise adding the favicon does
751 // nothing.
752 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
753 Profile::IMPLICIT_ACCESS);
754 if (!history)
755 return;
756 history->AddPageNoVisitForBookmark(entry->url());
757
758 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
759 Profile::IMPLICIT_ACCESS);
760 if (!service)
761 return;
762 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
763 if (!favicon.is_valid() || favicon.url().is_empty() ||
764 favicon.bitmap().empty()) {
765 return;
766 }
767 std::vector<unsigned char> image_data;
768 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
769 service->SetFavicon(
770 entry->url(), favicon.url(), image_data, history::FAVICON);
771}
772
initial.commit09911bf2008-07-26 23:55:29773ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28774 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29775 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28776 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
[email protected]aed59602011-02-28 22:57:33777 AddConstrainedDialog(window);
778 return window;
779}
780
781void TabContents::AddConstrainedDialog(ConstrainedWindow* window) {
initial.commit09911bf2008-07-26 23:55:29782 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44783
784 if (child_windows_.size() == 1) {
785 window->ShowConstrainedWindow();
786 BlockTabContent(true);
787 }
initial.commit09911bf2008-07-26 23:55:29788}
789
[email protected]fa1cf0b82010-01-15 21:49:44790void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55791 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45792 // 70% opaque grey.
793 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55794 if (rwhv)
[email protected]1b072562010-12-13 19:37:45795 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44796 render_view_host()->set_ignore_input_events(blocked);
797 if (delegate_)
798 delegate_->SetTabContentBlocked(this, blocked);
799}
800
initial.commit09911bf2008-07-26 23:55:29801void TabContents::AddNewContents(TabContents* new_contents,
802 WindowOpenDisposition disposition,
803 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29804 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40805 if (all_contents_blocked_) {
806 if (!blocked_contents_)
807 blocked_contents_ = new BlockedContentContainer(this);
808 blocked_contents_->AddTabContents(
809 new_contents, disposition, initial_pos, user_gesture);
810 return;
811 }
812
initial.commit09911bf2008-07-26 23:55:29813 if (!delegate_)
814 return;
815
[email protected]35f7d212009-04-29 21:19:27816 if ((disposition == NEW_POPUP) && !user_gesture &&
817 !CommandLine::ForCurrentProcess()->HasSwitch(
818 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22819 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31820 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29821 delegate_->GetConstrainingContents(this)->AddPopup(
822 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31823 } else {
[email protected]0aa55312008-10-17 21:53:08824 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29825 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
826 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49827 NotificationService::current()->Notify(
828 NotificationType::TAB_ADDED,
829 Source<TabContentsDelegate>(delegate_),
830 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29831 }
initial.commit09911bf2008-07-26 23:55:29832
[email protected]8cc8d492010-02-02 10:40:49833 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:40834 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:29835}
836
[email protected]96d185d2009-04-24 03:28:54837void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49838 if (is_being_destroyed_)
839 return;
[email protected]9fb83e82010-07-02 18:24:55840 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49841 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40842 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:54843}
844
[email protected]5c9e97a2009-09-09 23:48:30845gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54846 return view_->GetContentNativeView();
847}
848
849gfx::NativeView TabContents::GetNativeView() const {
850 return view_->GetNativeView();
851}
852
853void TabContents::GetContainerBounds(gfx::Rect *out) const {
854 view_->GetContainerBounds(out);
855}
856
857void TabContents::Focus() {
858 view_->Focus();
859}
860
[email protected]90daadb42009-06-08 21:27:28861void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54862 if (showing_interstitial_page()) {
863 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
864 return;
865 }
[email protected]96d185d2009-04-24 03:28:54866 render_view_host()->SetInitialFocus(reverse);
867}
868
869bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:40870 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58871 if (web_ui)
872 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43873 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25874 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43875 return true;
[email protected]96d185d2009-04-24 03:28:54876 return false;
877}
878
[email protected]a26dc362010-04-23 01:48:58879void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38880 if (delegate())
[email protected]a26dc362010-04-23 01:48:58881 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38882}
883
[email protected]616ed5a2008-11-21 22:27:24884void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32885 if (delegate_ && !delegate_->infobars_enabled()) {
886 delegate->InfoBarClosed();
887 return;
888 }
889
[email protected]616ed5a2008-11-21 22:27:24890 // Look through the existing InfoBarDelegates we have for a match. If we've
891 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:40892 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:45893 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
894 // Tell the new infobar to close so that it can clean itself up.
895 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:24896 return;
[email protected]6d27a7b2009-12-18 23:25:45897 }
[email protected]616ed5a2008-11-21 22:27:24898 }
899
900 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56901 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:19902 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:56903 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24904
905 // Add ourselves as an observer for navigations the first time a delegate is
906 // added. We use this notification to expire InfoBars that need to expire on
907 // page transitions.
908 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56909 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57910 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24911 }
912}
913
914void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32915 if (delegate_ && !delegate_->infobars_enabled()) {
916 return;
917 }
918
[email protected]616ed5a2008-11-21 22:27:24919 std::vector<InfoBarDelegate*>::iterator it =
920 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
921 if (it != infobar_delegates_.end()) {
922 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56923 NotificationService::current()->Notify(
924 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
925 Source<TabContents>(this),
926 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24927
[email protected]f4f50ef2011-01-21 19:01:19928 infobar_delegates_.erase(it);
929 // Remove ourselves as an observer if we are tracking no more InfoBars.
930 if (infobar_delegates_.empty()) {
931 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
932 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03933 }
[email protected]616ed5a2008-11-21 22:27:24934 }
935}
[email protected]3edd9522009-03-04 22:19:41936
[email protected]f81821c2009-08-07 01:29:47937void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
938 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:32939 if (delegate_ && !delegate_->infobars_enabled()) {
940 new_delegate->InfoBarClosed();
941 return;
942 }
943
[email protected]f81821c2009-08-07 01:29:47944 std::vector<InfoBarDelegate*>::iterator it =
945 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
946 DCHECK(it != infobar_delegates_.end());
947
948 // Notify the container about the change of plans.
949 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
950 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
951 old_delegate, new_delegate));
952 NotificationService::current()->Notify(
953 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
954 Source<TabContents>(this),
955 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
956
[email protected]f4f50ef2011-01-21 19:01:19957 // Remove the old one.
958 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:47959
960 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:08961 DCHECK(find(infobar_delegates_.begin(),
962 infobar_delegates_.end(), new_delegate) ==
963 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:47964 infobar_delegates_.push_back(new_delegate);
965}
966
[email protected]20ede072009-10-06 00:28:35967bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:27968 if (showing_interstitial_page())
969 return false;
970
[email protected]c8f74942010-09-03 10:04:14971 // Do not show bookmarks bar if bookmarks aren't enabled.
972 if (!browser_defaults::bookmarks_enabled)
973 return false;
974
[email protected]d0980792011-02-13 19:41:40975 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:54976 // similar, but for non-first loads, we want to use the committed entry. This
977 // is so the bookmarks bar disappears at the same time the page does.
978 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:35979 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:58980 return (render_manager_.web_ui() == NULL) ?
981 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:54982 }
983
984 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:40985 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:54986 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:58987 if (render_manager_.pending_web_ui())
988 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
989 return (render_manager_.web_ui() == NULL) ?
990 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:54991}
992
[email protected]3edd9522009-03-04 22:19:41993void TabContents::ToolbarSizeChanged(bool is_animating) {
994 TabContentsDelegate* d = delegate();
995 if (d)
996 d->ToolbarSizeChanged(this, is_animating);
997}
[email protected]616ed5a2008-11-21 22:27:24998
[email protected]fc6fb7fb2009-11-07 02:35:04999bool TabContents::CanDownload(int request_id) {
1000 TabContentsDelegate* d = delegate();
1001 if (d)
1002 return d->CanDownload(request_id);
1003 return true;
1004}
1005
[email protected]d5f942ba2008-09-26 19:30:341006void TabContents::OnStartDownload(DownloadItem* download) {
1007 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341008
1009 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311010 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341011
[email protected]5b928b62010-08-03 11:46:511012 if (tab_contents && tab_contents->delegate())
1013 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411014}
[email protected]3edd9522009-03-04 22:19:411015
[email protected]d5f942ba2008-09-26 19:30:341016void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371017 ConstrainedWindowList::iterator i(
1018 std::find(child_windows_.begin(), child_windows_.end(), window));
1019 bool removed_topmost_window = i == child_windows_.begin();
1020 if (i != child_windows_.end())
1021 child_windows_.erase(i);
1022 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441023 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371024 } else {
1025 if (removed_topmost_window)
1026 child_windows_[0]->ShowConstrainedWindow();
1027 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441028 }
[email protected]66ba4932009-06-04 19:22:131029}
[email protected]d5f942ba2008-09-26 19:30:341030
[email protected]c65e2f152010-10-14 15:30:401031void TabContents::WillCloseBlockedContentContainer(
1032 BlockedContentContainer* container) {
1033 DCHECK(blocked_contents_ == container);
1034 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491035 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341036}
1037
[email protected]89d6e6e2009-12-03 23:06:511038void TabContents::EmailPageLocation() {
1039 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1040 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1041 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1042 title + "&body=%0A%0A" + page_url;
1043 platform_util::OpenExternal(GURL(mailto));
1044}
1045
[email protected]420ae012009-04-24 05:16:321046bool TabContents::PrintNow() {
1047 // We can't print interstitial page for now.
1048 if (showing_interstitial_page())
1049 return false;
1050
1051 return render_view_host()->PrintPages();
1052}
1053
1054bool TabContents::IsActiveEntry(int32 page_id) {
1055 NavigationEntry* active_entry = controller_.GetActiveEntry();
1056 return (active_entry != NULL &&
1057 active_entry->site_instance() == GetSiteInstance() &&
1058 active_entry->page_id() == page_id);
1059}
1060
[email protected]b2fe07d12010-02-09 14:38:081061void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161062 set_encoding(encoding);
1063 render_view_host()->SetPageEncoding(encoding);
1064}
1065
[email protected]b2fe07d12010-02-09 14:38:081066void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161067 reset_encoding();
1068 render_view_host()->ResetPageEncodingToDefault();
1069}
1070
1071void TabContents::WindowMoveOrResizeStarted() {
1072 render_view_host()->WindowMoveOrResizeStarted();
1073}
1074
[email protected]c65e2f152010-10-14 15:30:401075void TabContents::SetAllContentsBlocked(bool value) {
1076 if (all_contents_blocked_ == value)
1077 return;
1078
1079 all_contents_blocked_ = value;
1080 if (!all_contents_blocked_ && blocked_contents_) {
1081 std::vector<TabContents*> blocked;
1082 blocked_contents_->GetBlockedContents(&blocked);
1083 for (size_t i = 0; i < blocked.size(); ++i)
1084 blocked_contents_->LaunchForContents(blocked[i]);
1085 }
1086}
1087
[email protected]3f8eb7f2009-10-02 23:58:051088void TabContents::LogNewTabTime(const std::string& event_name) {
1089 // Not all new tab pages get timed. In those cases, we don't have a
1090 // new_tab_start_time_.
1091 if (new_tab_start_time_.is_null())
1092 return;
1093
1094 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441095 MetricEventDurationDetails details(event_name,
1096 static_cast<int>(duration.InMilliseconds()));
1097
[email protected]7ab1e7d62009-10-14 23:32:011098 if (event_name == "Tab.NewTabScriptStart") {
1099 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1100 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1101 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1102 } else if (event_name == "Tab.NewTabOnload") {
1103 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051104 // The new tab page has finished loading; reset it.
1105 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441106 } else {
1107 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051108 }
[email protected]84abba62009-10-07 17:01:441109 NotificationService::current()->Notify(
1110 NotificationType::METRIC_EVENT_DURATION,
1111 Source<TabContents>(this),
1112 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051113}
1114
[email protected]7ab1e7d62009-10-14 23:32:011115void TabContents::OnCloseStarted() {
1116 if (tab_close_start_time_.is_null())
1117 tab_close_start_time_ = base::TimeTicks::Now();
1118}
1119
[email protected]46624bf2010-06-09 16:04:191120bool TabContents::ShouldAcceptDragAndDrop() const {
1121#if defined(OS_CHROMEOS)
1122 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1123 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201124 if (delegate() && delegate()->IsPopup(this))
1125 return false;
1126 return true;
[email protected]46624bf2010-06-09 16:04:191127#else
1128 return true;
1129#endif
1130}
1131
[email protected]7813bd72011-02-05 02:19:341132void TabContents::SystemDragEnded() {
1133 if (render_view_host())
1134 render_view_host()->DragSourceSystemDragEnded();
1135 if (delegate())
1136 delegate()->DragEnded();
1137}
1138
[email protected]ec0b6c42010-08-26 03:16:581139void TabContents::UpdateHistoryForNavigation(
1140 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1141 if (profile()->IsOffTheRecord())
1142 return;
1143
1144 // Add to history service.
1145 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1146 if (hs)
1147 hs->AddPage(*add_page_args);
1148}
1149
1150void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1151 if (profile()->IsOffTheRecord())
1152 return;
1153
1154 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1155 if (hs)
1156 hs->SetPageTitle(entry.virtual_url(), entry.title());
1157}
1158
[email protected]d0b8d092010-10-25 04:05:171159double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251160 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1161 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171162 return 0;
[email protected]b75b8292010-10-01 07:28:251163
1164 double zoom_level;
1165 if (temporary_zoom_settings_) {
1166 zoom_level = zoom_map->GetTemporaryZoomLevel(
1167 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1168 } else {
1169 zoom_level = zoom_map->GetZoomLevel(GetURL());
1170 }
[email protected]d0b8d092010-10-25 04:05:171171 return zoom_level;
1172}
[email protected]b75b8292010-10-01 07:28:251173
[email protected]d0b8d092010-10-25 04:05:171174int TabContents::GetZoomPercent(bool* enable_increment,
1175 bool* enable_decrement) {
1176 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251177 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171178 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251179 *enable_decrement = percent > minimum_zoom_percent_;
1180 *enable_increment = percent < maximum_zoom_percent_;
1181 return percent;
1182}
1183
[email protected]3c733bde2010-12-21 19:56:311184void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501185 if (!delegate_)
1186 return;
1187
1188 NavigationEntry* active_entry = controller().GetActiveEntry();
1189 if (!active_entry)
1190 return;
1191
1192 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121193}
1194
[email protected]932b7a12011-03-09 12:50:271195void TabContents::ViewFrameSource(const GURL& url,
1196 const std::string& content_state) {
1197 if (!delegate_)
1198 return;
1199
1200 delegate_->ViewSourceForFrame(this, url, content_state);
1201}
1202
[email protected]c40d6232011-03-25 00:16:211203void TabContents::SetContentRestrictions(int restrictions) {
1204 content_restrictions_ = restrictions;
1205 delegate()->ContentRestrictionsChanged(this);
1206}
1207
[email protected]724159a2010-12-30 01:11:181208void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1209 bool is_main_frame,
1210 const GURL& url) {
1211 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1212 GURL validated_url(url);
1213 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1214 GetRenderProcessHost()->id(), &validated_url);
1215
1216 ProvisionalLoadDetails details(
1217 is_main_frame,
1218 controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091219 validated_url, std::string(), is_error_page, frame_id);
[email protected]724159a2010-12-30 01:11:181220 NotificationService::current()->Notify(
1221 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1222 Source<NavigationController>(&controller_),
1223 Details<ProvisionalLoadDetails>(&details));
1224 if (is_main_frame) {
1225 // If we're displaying a network error page do not reset the content
1226 // settings delegate's cookies so the user has a chance to modify cookie
1227 // settings.
1228 if (!is_error_page)
1229 content_settings_delegate_->ClearCookieSpecificContentSettings();
1230 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381231
[email protected]4850a7f2011-03-08 23:36:591232 // Notify observers about the provisional change in the main frame URL.
1233 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1234 OnProvisionalChangeToMainFrameUrl(url));
[email protected]724159a2010-12-30 01:11:181235 }
1236}
1237
1238void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1239 const GURL& source_url,
1240 const GURL& target_url) {
[email protected]18ba2b12011-04-06 16:35:491241 // TODO(creis): Remove this method and have the pre-rendering code listen to
1242 // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification
1243 // instead. See http://crbug.com/78512.
[email protected]724159a2010-12-30 01:11:181244 NavigationEntry* entry;
1245 if (page_id == -1)
1246 entry = controller_.pending_entry();
1247 else
1248 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1249 if (!entry || entry->url() != source_url)
1250 return;
[email protected]e7d50892011-01-19 21:47:381251
[email protected]4850a7f2011-03-08 23:36:591252 // Notify observers about the provisional change in the main frame URL.
1253 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
1254 OnProvisionalChangeToMainFrameUrl(target_url));
[email protected]724159a2010-12-30 01:11:181255}
1256
1257void TabContents::OnDidFailProvisionalLoadWithError(
1258 int64 frame_id,
1259 bool is_main_frame,
1260 int error_code,
1261 const GURL& url,
1262 bool showing_repost_interstitial) {
1263 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1264 << ", error_code: " << error_code
1265 << " is_main_frame: " << is_main_frame
1266 << " showing_repost_interstitial: " << showing_repost_interstitial
1267 << " frame_id: " << frame_id;
1268 GURL validated_url(url);
1269 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1270 GetRenderProcessHost()->id(), &validated_url);
1271
1272 if (net::ERR_ABORTED == error_code) {
1273 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1274 // This means that the interstitial won't be torn down properly, which is
1275 // bad. But if we have an interstitial, go back to another tab type, and
1276 // then load the same interstitial again, we could end up getting the first
1277 // interstitial's "failed" message (as a result of the cancel) when we're on
1278 // the second one.
1279 //
1280 // We can't tell this apart, so we think we're tearing down the current page
1281 // which will cause a crash later one. There is also some code in
1282 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1283 // out because of this problem.
1284 //
1285 // http://code.google.com/p/chromium/issues/detail?id=2855
1286 // Because this will not tear down the interstitial properly, if "back" is
1287 // back to another tab type, the interstitial will still be somewhat alive
1288 // in the previous tab type. If you navigate somewhere that activates the
1289 // tab with the interstitial again, you'll see a flash before the new load
1290 // commits of the interstitial page.
1291 if (showing_interstitial_page()) {
1292 LOG(WARNING) << "Discarding message during interstitial.";
1293 return;
1294 }
1295
1296 // This will discard our pending entry if we cancelled the load (e.g., if we
1297 // decided to download the file instead of load it). Only discard the
1298 // pending entry if the URLs match, otherwise the user initiated a navigate
1299 // before the page loaded so that the discard would discard the wrong entry.
1300 NavigationEntry* pending_entry = controller_.pending_entry();
1301 if (pending_entry && pending_entry->url() == validated_url) {
1302 controller_.DiscardNonCommittedEntries();
1303 // Update the URL display.
1304 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1305 }
1306
1307 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1308 }
1309
1310 // Send out a notification that we failed a provisional load with an error.
1311 ProvisionalLoadDetails details(
1312 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
[email protected]b9e8ea62011-03-04 06:29:091313 validated_url, std::string(), false, frame_id);
[email protected]724159a2010-12-30 01:11:181314 details.set_error_code(error_code);
1315
1316 NotificationService::current()->Notify(
1317 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1318 Source<NavigationController>(&controller_),
1319 Details<ProvisionalLoadDetails>(&details));
1320}
1321
1322void TabContents::OnDidLoadResourceFromMemoryCache(
1323 const GURL& url,
[email protected]724159a2010-12-30 01:11:181324 const std::string& security_info) {
[email protected]28620862011-03-22 23:07:191325 base::StatsCounter cache("WebKit.CacheHit");
[email protected]724159a2010-12-30 01:11:181326 cache.Increment();
1327
1328 // Send out a notification that we loaded a resource from our memory cache.
1329 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1330 SSLManager::DeserializeSecurityInfo(security_info,
1331 &cert_id, &cert_status,
1332 &security_bits,
1333 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161334 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1335 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181336
1337 NotificationService::current()->Notify(
1338 NotificationType::LOAD_FROM_MEMORY_CACHE,
1339 Source<NavigationController>(&controller_),
1340 Details<LoadFromMemoryCacheDetails>(&details));
1341}
1342
1343void TabContents::OnDidDisplayInsecureContent() {
1344 displayed_insecure_content_ = true;
1345 SSLManager::NotifySSLInternalStateChanged();
1346}
1347
1348void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021349 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231350 LOG(INFO) << security_origin << " ran insecure content from "
1351 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181352 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1353}
1354
1355void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1356 controller_.DocumentLoadedInFrame();
1357 NotificationService::current()->Notify(
1358 NotificationType::FRAME_DOM_CONTENT_LOADED,
1359 Source<NavigationController>(&controller_),
1360 Details<int64>(&frame_id));
1361}
1362
1363void TabContents::OnDidFinishLoad(int64 frame_id) {
1364 NotificationService::current()->Notify(
1365 NotificationType::FRAME_DID_FINISH_LOAD,
1366 Source<NavigationController>(&controller_),
1367 Details<int64>(&frame_id));
1368}
1369
[email protected]c8f73ab2011-01-22 00:05:171370void TabContents::OnUpdateContentRestrictions(int restrictions) {
[email protected]c40d6232011-03-25 00:16:211371 SetContentRestrictions(restrictions);
[email protected]c8f73ab2011-01-22 00:05:171372}
1373
1374void TabContents::OnPDFHasUnsupportedFeature() {
1375 PDFHasUnsupportedFeature(this);
1376}
1377
[email protected]96d185d2009-04-24 03:28:541378// Notifies the RenderWidgetHost instance about the fact that the page is
1379// loading, or done loading and calls the base implementation.
1380void TabContents::SetIsLoading(bool is_loading,
1381 LoadNotificationDetails* details) {
1382 if (is_loading == is_loading_)
1383 return;
1384
1385 if (!is_loading) {
1386 load_state_ = net::LOAD_STATE_IDLE;
1387 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561388 upload_size_ = 0;
1389 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541390 }
1391
1392 render_manager_.SetIsLoading(is_loading);
1393
1394 is_loading_ = is_loading;
1395 waiting_for_response_ = is_loading;
1396
[email protected]6ebdc9b2010-09-27 16:55:571397 if (delegate_)
1398 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351399 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541400
1401 NotificationType type = is_loading ? NotificationType::LOAD_START :
1402 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111403 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541404 if (details)
1405 det = Details<LoadNotificationDetails>(details);
1406 NotificationService::current()->Notify(type,
1407 Source<NavigationController>(&controller_),
1408 det);
1409}
1410
[email protected]b6c874582009-05-08 19:38:311411void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291412 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061413 // A page can't spawn popups (or do anything else, either) until its load
1414 // commits, so when we reach here, the popup was spawned by the
1415 // NavigationController's last committed entry, not the active entry. For
1416 // example, if a page opens a popup in an onunload() handler, then the active
1417 // entry is the page to be loaded as we navigate away from the unloading
1418 // page. For this reason, we can't use GetURL() to get the opener URL,
1419 // because it returns the active entry.
1420 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1421 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1422
1423 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491424 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091425 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491426 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1427 } else {
[email protected]c65e2f152010-10-14 15:30:401428 if (!blocked_contents_)
1429 blocked_contents_ = new BlockedContentContainer(this);
1430 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1431 true);
[email protected]55126132010-08-19 14:53:281432 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1433 std::string());
[email protected]8cc8d492010-02-02 10:40:491434 }
[email protected]b9681312008-11-07 00:08:261435}
[email protected]616ed5a2008-11-21 22:27:241436
[email protected]616ed5a2008-11-21 22:27:241437void TabContents::ExpireInfoBars(
1438 const NavigationController::LoadCommittedDetails& details) {
1439 // Only hide InfoBars when the user has done something that makes the main
1440 // frame load. We don't want various automatic or subframe navigations making
1441 // it disappear.
1442 if (!details.is_user_initiated_main_frame_load())
1443 return;
1444
[email protected]ec8f51162011-02-08 04:20:401445 // NOTE: It is not safe to change the following code to count upwards or use
1446 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1447 // list.
1448 for (size_t i = infobar_count(); i > 0; --i) {
1449 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051450 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241451 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241452 }
1453}
[email protected]fdd61c62009-04-22 19:22:571454
[email protected]d0980792011-02-13 19:41:401455WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581456 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541457 // that goes along with it to control the basic flags. For example, we want to
1458 // show the pending URL in the URL bar, so we want the display_url flag to
1459 // be from the pending entry.
1460 //
1461 // The confusion comes because there are multiple possibilities for the
1462 // initial load in a tab as a side effect of the way the RenderViewHostManager
1463 // works.
1464 //
[email protected]e0112912011-02-02 22:54:351465 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541466 // the pending one, and we want it to apply here.
1467 //
1468 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1469 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581470 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351471 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541472 //
1473 // This condition handles all of these cases:
1474 //
1475 // - First load in first tab: no committed nav entry + pending nav entry +
1476 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351477 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541478 //
1479 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351480 // no pending Web UI:
1481 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541482 //
1483 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351484 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541485 //
1486 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351487 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541488 if (controller_.pending_entry() &&
1489 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581490 render_manager_.pending_web_ui()))
1491 return render_manager_.pending_web_ui();
1492 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541493}
[email protected]420ae012009-04-24 05:16:321494
[email protected]1fd1a502011-03-30 16:55:561495WebUI::TypeID TabContents::GetWebUITypeForCurrentState() {
1496 return content::WebUIFactory::Get()->GetWebUIType(profile(), GetURL());
1497}
1498
[email protected]420ae012009-04-24 05:16:321499void TabContents::DidNavigateMainFramePostCommit(
1500 const NavigationController::LoadCommittedDetails& details,
1501 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]1fd1a502011-03-30 16:55:561502 if (opener_web_ui_type_ != WebUI::kNoWebUI) {
[email protected]80a8fad2011-01-29 04:02:381503 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441504 // that opened the window, as long as both renderers have the same
1505 // privileges.
[email protected]1fd1a502011-03-30 16:55:561506 if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) {
1507 WebUI* web_ui = content::GetContentClient()->browser()->
1508 GetWebUIFactory()->CreateWebUIForURL(this, GetURL());
[email protected]7ade2732011-02-10 00:13:581509 // web_ui might be NULL if the URL refers to a non-existent extension.
1510 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401511 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581512 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441513 }
1514 }
[email protected]1fd1a502011-03-30 16:55:561515 opener_web_ui_type_ = WebUI::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441516 }
1517
[email protected]420ae012009-04-24 05:16:321518 if (details.is_user_initiated_main_frame_load()) {
1519 // Clear the status bubble. This is a workaround for a bug where WebKit
1520 // doesn't let us know that the cursor left an element during a
1521 // transition (this is also why the mouse cursor remains as a hand after
1522 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1523 // clear the bubble when a user navigates to a named anchor in the same
1524 // page.
1525 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321526 }
1527
[email protected]420ae012009-04-24 05:16:321528 // Allow the new page to set the title again.
1529 received_page_title_ = false;
1530
[email protected]0150cfc2011-04-07 22:51:411531 // Get the favicon, either from history or request it from the net.
1532 favicon_helper_->FetchFavicon(details.entry->url());
1533
[email protected]0de80162010-02-03 04:52:351534 // Clear all page actions, blocked content notifications and browser actions
1535 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141536 if (!details.is_in_page) {
[email protected]0de80162010-02-03 04:52:351537 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401538 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341539 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401540 blocked_contents_->Destroy();
1541 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351542 }
1543
1544 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411545 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551546 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471547
1548 // Once the main frame is navigated, we're no longer considered to have
1549 // displayed insecure content.
1550 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171551 }
[email protected]ce5c4502009-05-06 16:46:111552
[email protected]8cc8d492010-02-02 10:40:491553 // Close constrained windows if necessary.
1554 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1555 details.previous_url, details.entry->url()))
1556 CloseConstrainedWindows();
1557
[email protected]3c9e1872010-11-18 16:17:491558 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171559 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491560 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321561}
1562
1563void TabContents::DidNavigateAnyFramePostCommit(
1564 RenderViewHost* render_view_host,
1565 const NavigationController::LoadCommittedDetails& details,
1566 const ViewHostMsg_FrameNavigate_Params& params) {
1567 // If we navigate, start showing messages again. This does nothing to prevent
1568 // a malicious script from spamming messages, since the script could just
1569 // reload the page to stop blocking.
1570 suppress_javascript_messages_ = false;
1571
[email protected]3c9e1872010-11-18 16:17:491572 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171573 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491574 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551575
1576 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581577 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321578}
1579
[email protected]8cc8d492010-02-02 10:40:491580void TabContents::CloseConstrainedWindows() {
1581 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]aed59602011-02-28 22:57:331582 // To ensure that we iterate over every element in child_windows_ we
1583 // need to use a copy of child_windows_. Otherwise if
1584 // window->CloseConstrainedWindow() modifies child_windows_ we could end up
1585 // skipping some elements.
1586 ConstrainedWindowList child_windows_copy(child_windows_);
1587 for (ConstrainedWindowList::iterator it = child_windows_copy.begin();
1588 it != child_windows_copy.end(); ++it) {
1589 ConstrainedWindow* window = *it;
[email protected]fa1cf0b82010-01-15 21:49:441590 if (window) {
[email protected]420ae012009-04-24 05:16:321591 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441592 BlockTabContent(false);
1593 }
[email protected]420ae012009-04-24 05:16:321594 }
1595}
1596
[email protected]420ae012009-04-24 05:16:321597void TabContents::UpdateAlternateErrorPageURL() {
1598 GURL url = GetAlternateErrorPageURL();
1599 render_view_host()->SetAlternateErrorPageURL(url);
1600}
1601
1602void TabContents::UpdateWebPreferences() {
1603 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1604}
1605
[email protected]d0b8d092010-10-25 04:05:171606void TabContents::UpdateZoomLevel() {
1607 render_view_host()->SetZoomLevel(GetZoomLevel());
1608}
1609
[email protected]420ae012009-04-24 05:16:321610void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1611 RenderViewHost* rvh) {
1612 // If we are creating a RVH for a restored controller, then we might
1613 // have more page IDs than the SiteInstance's current max page ID. We must
1614 // make sure that the max page ID is larger than any restored page ID.
1615 // Note that it is ok for conflicting page IDs to exist in another tab
1616 // (i.e., NavigationController), but if any page ID is larger than the max,
1617 // the back/forward list will get confused.
1618 int max_restored_page_id = controller_.max_restored_page_id();
1619 if (max_restored_page_id > 0) {
1620 int curr_max_page_id = site_instance->max_page_id();
1621 if (max_restored_page_id > curr_max_page_id) {
1622 // Need to update the site instance immediately.
1623 site_instance->UpdateMaxPageID(max_restored_page_id);
1624
1625 // Also tell the renderer to update its internal representation. We
1626 // need to reserve enough IDs to make all restored page IDs less than
1627 // the max.
1628 if (curr_max_page_id < 0)
1629 curr_max_page_id = 0;
1630 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1631 }
1632 }
1633}
1634
[email protected]ec0b6c42010-08-26 03:16:581635scoped_refptr<history::HistoryAddPageArgs>
1636TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541637 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471638 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321639 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581640 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1641 new history::HistoryAddPageArgs(
1642 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1643 params.redirects, params.transition, history::SOURCE_BROWSED,
1644 details.did_replace_entry));
1645 if (PageTransition::IsMainFrame(params.transition) &&
1646 virtual_url != params.url) {
1647 // Hack on the "virtual" URL so that it will appear in history. For some
1648 // types of URLs, we will display a magic URL that is different from where
1649 // the page is actually navigated. We want the user to see in history what
1650 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1651 // only applies to the main frame, as the virtual URL doesn't apply to
1652 // sub-frames.
1653 add_page_args->url = virtual_url;
1654 if (!add_page_args->redirects.empty())
1655 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321656 }
[email protected]ec0b6c42010-08-26 03:16:581657 return add_page_args;
[email protected]420ae012009-04-24 05:16:321658}
1659
1660bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1661 const std::wstring& title) {
1662 // For file URLs without a title, use the pathname instead. In the case of a
1663 // synthesized title, we don't want the update to count toward the "one set
1664 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251665 string16 final_title;
[email protected]420ae012009-04-24 05:16:321666 bool explicit_set;
1667 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251668 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321669 explicit_set = false; // Don't count synthetic titles toward the set limit.
1670 } else {
[email protected]e53668962010-06-23 15:35:251671 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321672 explicit_set = true;
1673 }
1674
[email protected]e53668962010-06-23 15:35:251675 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321676 return false; // Nothing changed, don't bother.
1677
[email protected]e53668962010-06-23 15:35:251678 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321679
[email protected]ec0b6c42010-08-26 03:16:581680 if (!received_page_title_) {
1681 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321682 received_page_title_ = explicit_set;
1683 }
1684
1685 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251686 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321687
[email protected]cbc0e1b2010-04-12 18:33:041688 NotificationService::current()->Notify(
1689 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1690 Source<TabContents>(this),
1691 NotificationService::NoDetails());
1692
[email protected]420ae012009-04-24 05:16:321693 return true;
1694}
1695
1696void TabContents::NotifySwapped() {
1697 // After sending out a swap notification, we need to send a disconnect
1698 // notification so that clients that pick up a pointer to |this| can NULL the
1699 // pointer. See Bug 1230284.
1700 notify_disconnection_ = true;
1701 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341702 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221703 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321704 NotificationService::NoDetails());
1705}
1706
1707void TabContents::NotifyConnected() {
1708 notify_disconnection_ = true;
1709 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341710 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221711 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321712 NotificationService::NoDetails());
1713}
1714
1715void TabContents::NotifyDisconnected() {
1716 if (!notify_disconnection_)
1717 return;
1718
1719 notify_disconnection_ = false;
1720 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341721 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221722 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321723 NotificationService::NoDetails());
1724}
1725
[email protected]7d472472011-01-22 01:30:251726void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541727 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1728 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1729 if (!entry)
1730 return;
1731 // Note that we don't call NavigationController::GotToOffset() as we don't
1732 // want to create a pending navigation entry (it might end up lingering
1733 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521734 entry->set_transition_type(entry->transition_type() |
1735 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:541736 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
1737 }
[email protected]bf5c2ff392009-07-08 16:24:331738}
1739
[email protected]a2cf65eb2010-01-18 08:20:381740void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:381741 int32 page_id,
[email protected]e5106202010-06-11 21:12:361742 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101743 const std::string& language,
1744 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381745 // Don't index any https pages. People generally don't want their bank
1746 // accounts, etc. indexed on their computer, especially since some of these
1747 // things are not marked cachable.
1748 // TODO(brettw) we may want to consider more elaborate heuristics such as
1749 // the cachability of the page. We may also want to consider subframes (this
1750 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271751 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1752 // content indexing for chromeos in some future releases.
1753#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381754 if (!url.SchemeIsSecure()) {
1755 Profile* p = profile();
1756 if (p && !p->IsOffTheRecord()) {
1757 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1758 if (hs)
1759 hs->SetPageContents(url, contents);
1760 }
1761 }
[email protected]ccd40a52010-05-11 16:15:271762#endif
[email protected]a8a81292010-01-21 00:32:451763
[email protected]1c57b7b2010-07-12 17:38:101764 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451765
1766 std::string lang = language;
1767 NotificationService::current()->Notify(
1768 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151769 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451770 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:521771
1772 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
1773 if (CommandLine::ForCurrentProcess()->HasSwitch(
1774 switches::kEnableInBrowserThumbnailing)) {
1775 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
1776 }
[email protected]a2cf65eb2010-01-18 08:20:381777}
1778
[email protected]7e0831b2010-02-01 08:45:151779void TabContents::OnPageTranslated(int32 page_id,
1780 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:161781 const std::string& translated_lang,
1782 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:551783 language_state_.set_current_language(translated_lang);
1784 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:161785 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:151786 NotificationService::current()->Notify(
1787 NotificationType::PAGE_TRANSLATED,
1788 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:161789 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:151790}
1791
[email protected]dcd5b332010-08-11 08:55:181792void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:561793 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241794 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:561795}
1796
[email protected]8d3347f2009-07-09 22:00:211797RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321798 return view_.get();
1799}
1800
[email protected]8d3347f2009-07-09 22:00:211801RenderViewHostDelegate::RendererManagement*
1802TabContents::GetRendererManagementDelegate() {
1803 return &render_manager_;
1804}
1805
[email protected]46ba9082010-06-22 10:00:581806RenderViewHostDelegate::ContentSettings*
1807TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:551808 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:581809}
1810
[email protected]1f18184a2010-07-21 19:34:491811RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
1812 return GetSSLHelper();
1813}
1814
[email protected]fd571bb2010-03-19 01:23:541815AutomationResourceRoutingDelegate*
1816TabContents::GetAutomationResourceRoutingDelegate() {
1817 return delegate();
1818}
1819
[email protected]ced90ae12010-02-20 02:06:161820RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
1821 return bookmark_drag_;
1822}
1823
1824void TabContents::SetBookmarkDragDelegate(
1825 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
1826 bookmark_drag_ = bookmark_drag;
1827}
1828
[email protected]9fb83e82010-07-02 18:24:551829TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
1830 return content_settings_delegate_.get();
1831}
1832
[email protected]93623c5d2009-12-10 21:40:321833RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:461834 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511835}
1836
[email protected]57c6a652009-05-04 07:58:341837TabContents* TabContents::GetAsTabContents() {
1838 return this;
1839}
1840
[email protected]7b291f92009-08-14 05:43:531841ViewType::Type TabContents::GetRenderViewType() const {
1842 return ViewType::TAB_CONTENTS;
1843}
1844
1845int TabContents::GetBrowserWindowID() const {
1846 return controller().window_id().id();
1847}
1848
[email protected]420ae012009-04-24 05:16:321849void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061850 NotificationService::current()->Notify(
1851 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1852 Source<TabContents>(this),
1853 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321854 NavigationEntry* entry = controller_.GetActiveEntry();
1855 if (!entry)
1856 return;
1857
1858 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:351859 // use the pending Web UI rather than any possibly existing committed one.
[email protected]1fd1a502011-03-30 16:55:561860 if (render_manager_.pending_web_ui())
[email protected]7ade2732011-02-10 00:13:581861 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321862
1863 if (entry->IsViewSourceMode()) {
1864 // Put the renderer in view source mode.
1865 render_view_host->Send(
1866 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1867 }
[email protected]0666aef2009-05-13 19:48:081868
1869 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321870}
1871
1872void TabContents::RenderViewReady(RenderViewHost* rvh) {
1873 if (rvh != render_view_host()) {
1874 // Don't notify the world, since this came from a renderer in the
1875 // background.
1876 return;
1877 }
1878
1879 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301880 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:231881 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:301882
1883 // Restore the focus to the tab (otherwise the focus will be on the top
1884 // window).
[email protected]484ae5912010-09-29 19:16:141885 if (was_crashed && !FocusLocationBarByDefault() &&
1886 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:301887 Focus();
[email protected]484ae5912010-09-29 19:16:141888 }
[email protected]420ae012009-04-24 05:16:321889}
1890
[email protected]443b80e2010-12-14 00:42:231891void TabContents::RenderViewGone(RenderViewHost* rvh,
1892 base::TerminationStatus status,
1893 int error_code) {
[email protected]420ae012009-04-24 05:16:321894 if (rvh != render_view_host()) {
1895 // The pending page's RenderViewHost is gone.
1896 return;
1897 }
1898
[email protected]2e3f4572011-03-25 19:24:471899 // Let observers know first and give them a chance to act.
1900 FOR_EACH_OBSERVER(TabContentsObserver, observers_, RenderViewGone());
1901
[email protected]420ae012009-04-24 05:16:321902 SetIsLoading(false, NULL);
1903 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:231904 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321905
[email protected]ff9efc62010-02-18 22:10:541906 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:401907 while (!infobar_delegates_.empty())
1908 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:541909
[email protected]8e537302009-06-10 21:19:581910 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:551911 // Only do this if we're not in browser shutdown, so that TabContents
1912 // objects that are not in a browser (e.g., HTML dialogs) and thus are
1913 // visible do not flash a sad tab page.
1914 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:161915 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:321916
1917 // Hide any visible hung renderer warning for this web contents' process.
[email protected]7ec6bef2011-02-26 02:22:291918 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:321919}
1920
[email protected]2e4633c2009-07-09 16:58:061921void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
[email protected]fb7b79f72009-11-06 18:00:481922 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:061923}
1924
[email protected]420ae012009-04-24 05:16:321925void TabContents::DidNavigate(RenderViewHost* rvh,
1926 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:371927 int extra_invalidate_flags = 0;
1928
1929 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:351930 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:371931
[email protected]420ae012009-04-24 05:16:321932 render_manager_.DidNavigateMainFrame(rvh);
1933
[email protected]20ede072009-10-06 00:28:351934 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:371935 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:371936 }
1937
[email protected]420ae012009-04-24 05:16:321938 // Update the site of the SiteInstance if it doesn't have one yet.
1939 if (!GetSiteInstance()->has_site())
1940 GetSiteInstance()->SetSite(params.url);
1941
1942 // Need to update MIME type here because it's referred to in
1943 // UpdateNavigationCommands() called by RendererDidNavigate() to
1944 // determine whether or not to enable the encoding menu.
1945 // It's updated only for the main frame. For a subframe,
1946 // RenderView::UpdateURL does not set params.contents_mime_type.
1947 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1948 // TODO(jungshik): Add a test for the encoding menu to avoid
1949 // regressing it again.
1950 if (PageTransition::IsMainFrame(params.transition))
1951 contents_mime_type_ = params.contents_mime_type;
1952
1953 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:371954 bool did_navigate = controller_.RendererDidNavigate(
1955 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:391956
[email protected]a9c0bfe2010-09-17 08:35:221957 // Send notification about committed provisional loads. This notification is
1958 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
1959 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
1960 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:071961 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
1962 // that is not recorded in the navigation history. For the purpose of
1963 // tracking navigation events, we treat this event as a sub frame navigation
1964 // event.
1965 bool is_main_frame = did_navigate ? details.is_main_frame : false;
1966 ProvisionalLoadDetails load_details(
[email protected]b9e8ea62011-03-04 06:29:091967 is_main_frame, details.is_in_page, params.url, std::string(),
[email protected]dd0aafd2010-12-02 13:13:411968 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:221969 load_details.set_transition_type(params.transition);
1970 // Whether or not a page transition was triggered by going backward or
1971 // forward in the history is only stored in the navigation controller's
1972 // entry list.
1973 if (did_navigate &&
1974 (controller_.GetActiveEntry()->transition_type() &
1975 PageTransition::FORWARD_BACK)) {
1976 load_details.set_transition_type(
1977 params.transition | PageTransition::FORWARD_BACK);
1978 }
1979 NotificationService::current()->Notify(
1980 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
1981 Source<NavigationController>(&controller_),
1982 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:221983 }
1984
[email protected]3e90d4a2009-07-03 17:38:391985 // Update history. Note that this needs to happen after the entry is complete,
1986 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:581987 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:391988 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:581989 // URLs, we use a data: URL as the real value. We actually want to save the
1990 // about: URL to the history db and keep the data: URL hidden. This is what
1991 // the TabContents' URL getter does.
1992 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1993 CreateHistoryAddPageArgs(GetURL(), details, params));
1994 if (!delegate() ||
1995 delegate()->ShouldAddNavigationToHistory(*add_page_args,
1996 details.type)) {
1997 UpdateHistoryForNavigation(add_page_args);
1998 }
[email protected]3e90d4a2009-07-03 17:38:391999 }
2000
[email protected]76543b92009-08-31 17:27:452001 if (!did_navigate)
2002 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322003
2004 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2005 // for the appropriate notification (best) or you can add it to
2006 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2007 // necessary, please).
2008
2009 // Run post-commit tasks.
2010 if (details.is_main_frame)
2011 DidNavigateMainFramePostCommit(details, params);
2012 DidNavigateAnyFramePostCommit(rvh, details, params);
2013}
2014
2015void TabContents::UpdateState(RenderViewHost* rvh,
2016 int32 page_id,
2017 const std::string& state) {
2018 DCHECK(rvh == render_view_host());
2019
2020 // We must be prepared to handle state updates for any page, these occur
2021 // when the user is scrolling and entering form data, as well as when we're
2022 // leaving a page, in which case our state may have already been moved to
2023 // the next page. The navigation controller will look up the appropriate
2024 // NavigationEntry and update it when it is notified via the delegate.
2025
2026 int entry_index = controller_.GetEntryIndexWithPageID(
2027 GetSiteInstance(), page_id);
2028 if (entry_index < 0)
2029 return;
2030 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2031
2032 if (state == entry->content_state())
2033 return; // Nothing to update.
2034 entry->set_content_state(state);
2035 controller_.NotifyEntryChanged(entry, entry_index);
2036}
2037
2038void TabContents::UpdateTitle(RenderViewHost* rvh,
2039 int32 page_id, const std::wstring& title) {
2040 // If we have a title, that's a pretty good indication that we've started
2041 // getting useful data.
2042 SetNotWaitingForResponse();
2043
2044 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482045 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582046 page_id);
[email protected]420ae012009-04-24 05:16:322047 if (!entry || !UpdateTitleForEntry(entry, title))
2048 return;
2049
2050 // Broadcast notifications when the UI should be updated.
2051 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032052 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322053}
2054
[email protected]420ae012009-04-24 05:16:322055void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402056 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322057 set_encoding(encoding);
2058}
2059
2060void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2061 if (delegate())
2062 delegate()->UpdateTargetURL(this, url);
2063}
2064
[email protected]c4e98902010-06-01 10:20:142065void TabContents::UpdateInspectorSetting(const std::string& key,
2066 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052067 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082068}
2069
[email protected]45aafc92010-06-07 14:18:532070void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052071 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532072}
2073
[email protected]420ae012009-04-24 05:16:322074void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292075 // The UI may be in an event-tracking loop, such as between the
2076 // mouse-down and mouse-up in text selection or a button click.
2077 // Defer the close until after tracking is complete, so that we
2078 // don't free objects out from under the UI.
2079 // TODO(shess): This could probably be integrated with the
2080 // IsDoingDrag() test below. Punting for now because I need more
2081 // research to understand how this impacts platforms other than Mac.
2082 // TODO(shess): This could get more fine-grained. For instance,
2083 // closing a tab in another window while selecting text in the
2084 // current window's Omnibox should be just fine.
2085 if (view()->IsEventTracking()) {
2086 view()->CloseTabAfterEventTracking();
2087 return;
2088 }
2089
[email protected]24a4d1062009-07-10 23:10:422090 // If we close the tab while we're in the middle of a drag, we'll crash.
2091 // Instead, cancel the drag and close it as soon as the drag ends.
2092 if (view()->IsDoingDrag()) {
2093 view()->CancelDragAndCloseTab();
2094 return;
2095 }
2096
[email protected]420ae012009-04-24 05:16:322097 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2098 if (delegate() && rvh == render_view_host())
2099 delegate()->CloseContents(this);
2100}
2101
2102void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2103 if (delegate() && delegate()->IsPopup(this))
2104 delegate()->MoveContents(this, new_bounds);
2105}
2106
[email protected]7ab1e7d62009-10-14 23:32:012107void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322108 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492109
[email protected]c40d6232011-03-25 00:16:212110 if (delegate() && content_restrictions_) {
2111 content_restrictions_ = 0;
[email protected]de4761b2010-12-07 21:05:212112 delegate()->ContentRestrictionsChanged(this);
[email protected]9e823662010-10-13 23:36:002113 }
[email protected]3c9e1872010-11-18 16:17:492114
2115 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172116 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322117}
2118
[email protected]7ab1e7d62009-10-14 23:32:012119void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322120 scoped_ptr<LoadNotificationDetails> details;
2121
2122 NavigationEntry* entry = controller_.GetActiveEntry();
2123 // An entry may not exist for a stop when loading an initial blank page or
2124 // if an iframe injected by script into a blank page finishes loading.
2125 if (entry) {
[email protected]420ae012009-04-24 05:16:322126 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2127
2128 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542129 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322130 entry->transition_type(),
2131 elapsed,
2132 &controller_,
2133 controller_.GetCurrentEntryIndex()));
2134 }
2135
[email protected]420ae012009-04-24 05:16:322136 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492137
2138 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172139 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322140}
2141
[email protected]1a3c3cb2010-12-16 21:03:402142void TabContents::DidChangeLoadProgress(double progress) {
2143 if (delegate())
2144 delegate()->LoadProgressChanged(progress);
2145}
2146
[email protected]25497492010-09-11 15:15:082147void TabContents::DocumentOnLoadCompletedInMainFrame(
2148 RenderViewHost* render_view_host,
2149 int32 page_id) {
2150 NotificationService::current()->Notify(
2151 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2152 Source<TabContents>(this),
2153 Details<int>(&page_id));
2154}
2155
[email protected]420ae012009-04-24 05:16:322156void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2157 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582158 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352159 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322160 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2161 // generated suggestions).
2162 //
[email protected]e0112912011-02-02 22:54:352163 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162164 // want web sites to see a referrer of "chrome://blah" (and some
2165 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322166 // send to the site), so we send no referrer.
2167 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582168 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322169 } else {
2170 OpenURL(url, referrer, disposition, PageTransition::LINK);
2171 }
2172}
2173
[email protected]1ee614862009-07-06 20:29:182174void TabContents::DomOperationResponse(const std::string& json_string,
2175 int automation_id) {
2176}
2177
[email protected]badcca352011-02-12 01:08:082178void TabContents::ProcessWebUIMessage(
[email protected]44c49c92011-03-28 16:17:232179 const ExtensionHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582180 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442181 // This can happen if someone uses window.open() to open an extension URL
2182 // from a non-extension context.
[email protected]553602e12011-04-05 17:01:182183 render_view_host()->Send(new ExtensionMsg_Response(
2184 render_view_host()->routing_id(), params.request_id, false, "",
2185 "Access to extension API denied."));
[email protected]420ae012009-04-24 05:16:322186 return;
2187 }
[email protected]badcca352011-02-12 01:08:082188 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322189}
2190
2191void TabContents::ProcessExternalHostMessage(const std::string& message,
2192 const std::string& origin,
2193 const std::string& target) {
2194 if (delegate())
2195 delegate()->ForwardMessageToExternalHost(message, origin, target);
2196}
2197
[email protected]420ae012009-04-24 05:16:322198void TabContents::RunJavaScriptMessage(
2199 const std::wstring& message,
2200 const std::wstring& default_prompt,
2201 const GURL& frame_url,
2202 const int flags,
2203 IPC::Message* reply_msg,
2204 bool* did_suppress_message) {
2205 // Suppress javascript messages when requested and when inside a constrained
2206 // popup window (because that activates them and breaks them out of the
2207 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552208 // Also suppress messages when showing an interstitial. The interstitial is
2209 // shown over the previous page, we don't want the hidden page dialogs to
2210 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502211 bool suppress_this_message =
2212 suppress_javascript_messages_ ||
2213 showing_interstitial_page() ||
2214 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322215 if (delegate())
2216 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312217 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322218
2219 *did_suppress_message = suppress_this_message;
2220
2221 if (!suppress_this_message) {
2222 base::TimeDelta time_since_last_message(
2223 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2224 bool show_suppress_checkbox = false;
2225 // Show a checkbox offering to suppress further messages if this message is
2226 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2227 if (time_since_last_message <
[email protected]1698f612011-03-11 11:28:152228 base::TimeDelta::FromMilliseconds(
2229 chrome::kJavascriptMessageExpectedDelay))
[email protected]420ae012009-04-24 05:16:322230 show_suppress_checkbox = true;
2231
[email protected]d6ad7442010-09-05 19:06:522232 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2233 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322234 } else {
2235 // If we are suppressing messages, just reply as is if the user immediately
2236 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542237 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322238 }
2239}
2240
2241void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2242 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292243 if (delegate())
2244 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502245 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2246 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2247 std::wstring());
2248 return;
2249 }
[email protected]7ab1e7d62009-10-14 23:32:012250 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222251 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322252}
2253
[email protected]420ae012009-04-24 05:16:322254GURL TabContents::GetAlternateErrorPageURL() const {
2255 GURL url;
2256 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2257 if (profile()->IsOffTheRecord())
2258 return url;
2259
2260 PrefService* prefs = profile()->GetPrefs();
2261 DCHECK(prefs);
2262 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152263 url = google_util::AppendGoogleLocaleParam(
2264 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322265 url = google_util::AppendGoogleTLDParam(url);
2266 }
2267 return url;
2268}
2269
2270WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062271 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582272 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082273 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582274 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082275
[email protected]9beff752010-09-22 19:35:432276 // Force accelerated compositing and 2d canvas off for chrome: and
2277 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432278 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2279 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082280 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432281 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082282 }
2283
[email protected]39553442010-09-09 00:01:552284#if defined(OS_MACOSX)
2285 // Disable accelerated compositing if IOSurface's are not supported,
2286 // as is the case in 10.5.
2287 if (!IOSurfaceSupport::Initialize())
2288 web_prefs.accelerated_compositing_enabled = false;
2289#endif
2290
[email protected]447021c2010-09-08 21:29:082291 return web_prefs;
[email protected]420ae012009-04-24 05:16:322292}
2293
[email protected]7d472472011-01-22 01:30:252294void TabContents::OnUserGesture() {
2295 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2296 DownloadRequestLimiter* limiter =
2297 g_browser_process->download_request_limiter();
2298 if (limiter)
2299 limiter->OnUserGesture(this);
2300 ExternalProtocolHandler::PermitLaunchUrl();
2301}
2302
[email protected]fa1cf0b82010-01-15 21:49:442303void TabContents::OnIgnoredUIEvent() {
2304 if (constrained_window_count()) {
2305 ConstrainedWindow* window = *constrained_window_begin();
2306 window->FocusConstrainedWindow();
2307 }
2308}
2309
[email protected]420ae012009-04-24 05:16:322310void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2311 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342312 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322313 // delivered to a pending RenderViewHost. We must first run the onunload
2314 // handler of the old RenderViewHost before we can allow it to proceed.
2315 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2316 new_request_id);
2317}
2318
[email protected]420ae012009-04-24 05:16:322319void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2320 bool is_during_unload) {
2321 if (is_during_unload) {
2322 // Hang occurred while firing the beforeunload/unload handler.
2323 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112324 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322325
2326 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2327 return;
2328
2329 // If the tab hangs in the beforeunload/unload handler there's really
2330 // nothing we can do to recover. Pretend the unload listeners have
2331 // all fired and close the tab. If the hang is in the beforeunload handler
2332 // then the user will not have the option of cancelling the close.
2333 Close(rvh);
2334 return;
2335 }
2336
[email protected]61b50092011-02-03 18:02:192337 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2338 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]7ec6bef2011-02-26 02:22:292339 browser::ShowHungRendererDialog(this);
[email protected]61b50092011-02-03 18:02:192340 }
[email protected]420ae012009-04-24 05:16:322341}
2342
2343void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]7ec6bef2011-02-26 02:22:292344 browser::HideHungRendererDialog(this);
[email protected]420ae012009-04-24 05:16:322345}
2346
2347void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562348 net::LoadState load_state,
2349 uint64 upload_position,
2350 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322351 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562352 upload_position_ = upload_position;
2353 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292354 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192355 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292356 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422357 load_state_host_ = WideToUTF16Hack(
2358 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322359 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2360 SetNotWaitingForResponse();
2361 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502362 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322363}
2364
[email protected]1ee614862009-07-06 20:29:182365bool TabContents::IsExternalTabContainer() const {
2366 if (!delegate())
2367 return false;
2368
2369 return delegate()->IsExternalTabContainer();
2370}
2371
[email protected]1ee614862009-07-06 20:29:182372void TabContents::DidInsertCSS() {
2373 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322374}
2375
[email protected]546ae4e02010-12-08 14:57:192376void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352377 NotificationService::current()->Notify(
2378 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212379 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192380 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352381}
2382
[email protected]b75b8292010-10-01 07:28:252383void TabContents::UpdateZoomLimits(int minimum_percent,
2384 int maximum_percent,
2385 bool remember) {
2386 minimum_zoom_percent_ = minimum_percent;
2387 maximum_zoom_percent_ = maximum_percent;
2388 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382389}
2390
[email protected]7d472472011-01-22 01:30:252391void TabContents::WorkerCrashed() {
[email protected]0dd3a0ab2011-02-18 08:17:442392 if (delegate())
2393 delegate()->WorkerCrashed();
[email protected]7d472472011-01-22 01:30:252394}
2395
[email protected]f364d1392011-04-08 21:03:102396void TabContents::RequestDesktopNotificationPermission(
2397 const GURL& source_origin, int callback_context) {
2398 DesktopNotificationService* service =
2399 profile()->GetDesktopNotificationService();
2400 service->RequestPermission(
2401 source_origin, GetRenderProcessHost()->id(),
2402 render_view_host()->routing_id(), callback_context, this);
2403}
2404
[email protected]420ae012009-04-24 05:16:322405void TabContents::BeforeUnloadFiredFromRenderManager(
2406 bool proceed,
2407 bool* proceed_to_fire_unload) {
2408 if (delegate())
2409 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2410}
2411
[email protected]3a3d47472010-07-15 21:03:542412void TabContents::DidStartLoadingFromRenderManager(
2413 RenderViewHost* render_view_host) {
2414 DidStartLoading();
2415}
2416
2417void TabContents::RenderViewGoneFromRenderManager(
2418 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232419 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2420 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542421}
2422
[email protected]420ae012009-04-24 05:16:322423void TabContents::UpdateRenderViewSizeForRenderManager() {
2424 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262425 gfx::Size size = view_->GetContainerSize();
2426 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2427 // here during container initialization and normal window size will be set
2428 // later. In case of tab duplication this resizing to 0x0 prevents setting
2429 // normal size later so just ignore it.
2430 if (!size.IsEmpty())
2431 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322432}
2433
[email protected]3a3d47472010-07-15 21:03:542434void TabContents::NotifySwappedFromRenderManager() {
2435 NotifySwapped();
2436}
2437
2438NavigationController& TabContents::GetControllerForRenderManager() {
2439 return controller();
2440}
2441
[email protected]d0980792011-02-13 19:41:402442WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]1fd1a502011-03-30 16:55:562443 return content::WebUIFactory::Get()->CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322444}
2445
2446NavigationEntry*
2447TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2448 return controller_.GetLastCommittedEntry();
2449}
2450
2451bool TabContents::CreateRenderViewForRenderManager(
2452 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322453 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522454
[email protected]674b3822010-08-04 04:02:512455 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322456 return false;
2457
2458 // Now that the RenderView has been created, we need to tell it its size.
2459 rwh_view->SetSize(view_->GetContainerSize());
2460
2461 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2462 render_view_host);
2463 return true;
2464}
2465
2466void TabContents::Observe(NotificationType type,
2467 const NotificationSource& source,
2468 const NotificationDetails& details) {
2469 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322470 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512471 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322472 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2473 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2474 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532475 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2476 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322477 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172478 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2479 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322480 } else {
2481 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2482 }
2483 break;
2484 }
2485 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2486 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2487 break;
2488
2489 case NotificationType::NAV_ENTRY_COMMITTED: {
2490 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2491
2492 NavigationController::LoadCommittedDetails& committed_details =
2493 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2494 ExpireInfoBars(committed_details);
2495 break;
2496 }
2497
[email protected]d3ba77272009-09-03 00:06:092498#if defined(OS_LINUX)
2499 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542500 renderer_preferences_util::UpdateFromSystemSettings(
2501 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092502 render_view_host()->SyncRendererPrefs();
2503 break;
2504 }
2505#endif
2506
[email protected]6c32ce72010-03-08 05:18:062507 case NotificationType::USER_STYLE_SHEET_UPDATED:
2508 UpdateWebPreferences();
2509 break;
2510
[email protected]79580c62010-02-02 02:36:252511 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452512 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252513 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492514 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292515 if (entry)
[email protected]da0c8e92010-02-09 23:25:492516 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292517 if (settings_details.ptr()->update_all() ||
2518 settings_details.ptr()->pattern().Matches(entry_url)) {
2519 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232520 profile()->GetHostContentSettingsMap()->
2521 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252522 }
2523 break;
2524 }
2525
[email protected]88152052010-10-01 04:05:182526 case NotificationType::GOOGLE_URL_UPDATED:
2527 UpdateAlternateErrorPageURL();
2528 break;
2529
[email protected]420ae012009-04-24 05:16:322530 default:
2531 NOTREACHED();
2532 }
2533}
[email protected]aacd7cc2009-09-02 14:51:102534
[email protected]beb440c2009-11-06 04:08:542535gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2536 return view_->GetTopLevelNativeWindow();
2537}
2538
2539void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2540 bool success,
2541 const std::wstring& prompt) {
2542 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2543 if (is_showing_before_unload_dialog_ && !success) {
2544 // If a beforeunload dialog is canceled, we need to stop the throbber from
2545 // spinning, since we forced it to start spinning in Navigate.
2546 DidStopLoading();
2547
2548 tab_close_start_time_ = base::TimeTicks();
2549 }
2550 is_showing_before_unload_dialog_ = false;
2551 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2552}
2553
2554void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2555 set_suppress_javascript_messages(suppress_message_boxes);
2556}
2557
[email protected]3a3d47472010-07-15 21:03:542558TabContents* TabContents::AsTabContents() {
2559 return this;
2560}
2561
2562ExtensionHost* TabContents::AsExtensionHost() {
2563 return NULL;
2564}
2565
[email protected]41fc0322009-09-04 22:23:402566void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102567 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2568}
[email protected]f45d2a72010-03-08 23:28:352569
[email protected]33f74972010-12-08 16:40:362570void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2571 render_manager_.SwapInRenderViewHost(rvh);
2572}
2573
2574void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2575 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2576 rwh_view->SetSize(view()->GetContainerSize());
2577}
[email protected]e7d50892011-01-19 21:47:382578
[email protected]232a5812011-03-04 22:42:082579void TabContents::OnOnlineStateChanged(bool online) {
2580 render_view_host()->Send(new ViewMsg_NetworkStateChanged(
2581 render_view_host()->routing_id(), online));
2582}