blob: 166c59bbc7bf92086b70777aa72e2f52f2395772 [file] [log] [blame]
[email protected]ce5c4502009-05-06 16:46:111// Copyright (c) 2009 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]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]a92b8642009-05-05 23:38:567#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:118#include "app/resource_bundle.h"
[email protected]420ae012009-04-24 05:16:329#include "base/file_version_info.h"
10#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5411#include "base/string16.h"
12#include "base/time.h"
[email protected]fdd61c62009-04-22 19:22:5713#include "chrome/browser/autofill_manager.h"
[email protected]66ba4932009-06-04 19:22:1314#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3215#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5416#include "chrome/browser/browser_process.h"
initial.commit09911bf2008-07-26 23:55:2917#include "chrome/browser/cert_store.h"
[email protected]96d185d2009-04-24 03:28:5418#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3219#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5420#include "chrome/browser/dom_ui/dom_ui.h"
21#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0222#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3223#include "chrome/browser/download/download_manager.h"
24#include "chrome/browser/download/download_request_manager.h"
[email protected]0189bc722009-08-28 21:56:4825#include "chrome/browser/favicon_service.h"
[email protected]420ae012009-04-24 05:16:3226#include "chrome/browser/gears_integration.h"
27#include "chrome/browser/google_util.h"
[email protected]8897c382009-05-06 17:53:2628#include "chrome/browser/hung_renderer_dialog.h"
[email protected]420ae012009-04-24 05:16:3229#include "chrome/browser/jsmessage_box_handler.h"
30#include "chrome/browser/load_from_memory_cache_details.h"
31#include "chrome/browser/load_notification_details.h"
[email protected]ea0e80892009-08-22 00:36:0532#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1033#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5734#include "chrome/browser/password_manager/password_manager.h"
35#include "chrome/browser/plugin_installer.h"
[email protected]ce560f82009-06-03 09:39:4436#include "chrome/browser/profile.h"
[email protected]96d185d2009-04-24 03:28:5437#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3738#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]96d185d2009-04-24 03:28:5439#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]bd1ad682009-05-15 22:19:1740#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5441#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1642#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4343#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1644#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]fdd61c62009-04-22 19:22:5745#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0246#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]449478302009-06-09 20:04:2847#include "chrome/browser/thumbnail_store.h"
[email protected]420ae012009-04-24 05:16:3248#include "chrome/browser/search_engines/template_url_fetcher.h"
49#include "chrome/browser/search_engines/template_url_model.h"
[email protected]35f7d212009-04-29 21:19:2750#include "chrome/common/chrome_switches.h"
[email protected]bfd04a62009-02-01 18:16:5651#include "chrome/common/notification_service.h"
[email protected]ce5c4502009-05-06 16:46:1152#include "chrome/common/page_action.h"
initial.commit09911bf2008-07-26 23:55:2953#include "chrome/common/pref_names.h"
[email protected]1eb89e82008-08-15 12:27:0354#include "chrome/common/pref_service.h"
[email protected]420ae012009-04-24 05:16:3255#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1856#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5457#include "chrome/common/url_constants.h"
[email protected]8897c382009-05-06 17:53:2658#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3259#include "grit/locale_settings.h"
60#include "net/base/mime_util.h"
61#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2962#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3263#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:1864#include "webkit/glue/password_form.h"
65#include "webkit/glue/webpreferences.h"
[email protected]3e45ba92009-02-20 21:09:0066
[email protected]304f8792009-08-19 21:28:0967#if defined(OS_CHROMEOS)
68// For GdkScreen
69#include <gdk/gdk.h>
[email protected]0ba5c5e2009-08-20 16:47:1370#endif // defined(OS_CHROMEOS)
71
72#if defined(OS_LINUX)
73#include "chrome/browser/gtk/create_application_shortcuts_dialog_gtk.h"
74#endif // defined(OS_LINUX)
75
[email protected]420ae012009-04-24 05:16:3276// Cross-Site Navigations
77//
78// If a TabContents is told to navigate to a different web site (as determined
79// by SiteInstance), it will replace its current RenderViewHost with a new
80// RenderViewHost dedicated to the new SiteInstance. This works as follows:
81//
82// - Navigate determines whether the destination is cross-site, and if so,
83// it creates a pending_render_view_host_ and moves into the PENDING
84// RendererState.
85// - The pending RVH is "suspended," so that no navigation messages are sent to
86// its renderer until the onbeforeunload JavaScript handler has a chance to
87// run in the current RVH.
88// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
89// that it has a pending cross-site request. ResourceDispatcherHost will
90// check for this when the response arrives.
91// - The current RVH runs its onbeforeunload handler. If it returns false, we
92// cancel all the pending logic and go back to NORMAL. Otherwise we allow
93// the pending RVH to send the navigation request to its renderer.
94// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
95// checks CrossSiteRequestManager to see that the RVH responsible has a
96// pending cross-site request, and then installs a CrossSiteEventHandler.
97// - When RDH receives a response, the BufferedEventHandler determines whether
98// it is a download. If so, it sends a message to the new renderer causing
99// it to cancel the request, and the download proceeds in the download
100// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34101// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32102// doesn't affect any functionality.
103// - After RDH receives a response and determines that it is safe and not a
104// download, it pauses the response to first run the old page's onunload
105// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34106// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32107// to the current RVH.
108// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
109// the ResourceDispatcherHost, who unpauses the response. Data is then sent
110// to the pending RVH.
111// - The pending renderer sends a FrameNavigate message that invokes the
112// DidNavigate method. This replaces the current RVH with the
113// pending RVH and goes back to the NORMAL RendererState.
114
115namespace {
116
117// Amount of time we wait between when a key event is received and the renderer
118// is queried for its state and pushed to the NavigationEntry.
119const int kQueryStateDelay = 5000;
120
121const int kSyncWaitDelay = 40;
122
[email protected]304f8792009-08-19 21:28:09123#if defined(OS_CHROMEOS)
124// If a popup window is bigger than this fraction of the screen on chrome os,
125// turn it into a tab
126const float kMaxWidthFactor = 0.5;
127const float kMaxHeightFactor = 0.6;
128#endif
129
[email protected]420ae012009-04-24 05:16:32130// If another javascript message box is displayed within
131// kJavascriptMessageExpectedDelay of a previous javascript message box being
132// dismissed, display an option to suppress future message boxes from this
133// contents.
134const int kJavascriptMessageExpectedDelay = 1000;
135
[email protected]2bd6ca1c2009-08-27 16:42:20136const char kLinkDoctorBaseURL[] =
137 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl";
138
[email protected]420ae012009-04-24 05:16:32139// The list of prefs we want to observe.
140const wchar_t* kPrefsToObserve[] = {
141 prefs::kAlternateErrorPagesEnabled,
142 prefs::kWebKitJavaEnabled,
143 prefs::kWebKitJavascriptEnabled,
144 prefs::kWebKitLoadsImagesAutomatically,
145 prefs::kWebKitPluginsEnabled,
146 prefs::kWebKitUsesUniversalDetector,
147 prefs::kWebKitSerifFontFamily,
148 prefs::kWebKitSansSerifFontFamily,
149 prefs::kWebKitFixedFontFamily,
150 prefs::kWebKitDefaultFontSize,
151 prefs::kWebKitDefaultFixedFontSize,
152 prefs::kDefaultCharset
153 // kWebKitStandardFontIsSerif needs to be added
154 // if we let users pick which font to use, serif or sans-serif when
155 // no font is specified or a CSS generic family (serif or sans-serif)
156 // is not specified.
157};
158
159const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
160
[email protected]420ae012009-04-24 05:16:32161// Returns true if the entry's transition type is FORM_SUBMIT.
162bool IsFormSubmit(const NavigationEntry* entry) {
163 return (PageTransition::StripQualifier(entry->transition_type()) ==
164 PageTransition::FORM_SUBMIT);
165}
166
167#if defined(OS_WIN)
168
169BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
170 // Note: erase is required to properly paint some widgets borders. This can
171 // be seen with textfields.
172 InvalidateRect(hwnd, NULL, TRUE);
173 return TRUE;
174}
175#endif
176
[email protected]056de2d2009-06-26 16:41:34177void MakeNavigateParams(const NavigationEntry& entry, bool reload,
178 ViewMsg_Navigate_Params* params) {
179 params->page_id = entry.page_id();
180 params->url = entry.url();
181 params->referrer = entry.referrer();
182 params->transition = entry.transition_type();
183 params->state = entry.content_state();
184 params->reload = reload;
185 params->request_time = base::Time::Now();
186}
187
[email protected]420ae012009-04-24 05:16:32188} // namespace
189
190// -----------------------------------------------------------------------------
191
[email protected]fdd61c62009-04-22 19:22:57192// static
193int TabContents::find_request_id_counter_ = -1;
194
[email protected]420ae012009-04-24 05:16:32195class TabContents::GearsCreateShortcutCallbackFunctor {
196 public:
197 explicit GearsCreateShortcutCallbackFunctor(TabContents* contents)
198 : contents_(contents) {}
199
200 void Run(const GearsShortcutData2& shortcut_data, bool success) {
201 if (contents_)
202 contents_->OnGearsCreateShortcutDone(shortcut_data, success);
203 delete this;
204 }
205 void Cancel() {
206 contents_ = NULL;
207 }
208
209 private:
210 TabContents* contents_;
211};
212
[email protected]420ae012009-04-24 05:16:32213TabContents::TabContents(Profile* profile,
214 SiteInstance* site_instance,
215 int routing_id,
216 base::WaitableEvent* modal_dialog_event)
[email protected]b680ad22009-04-15 23:19:42217 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13218 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
219 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22220 TabContentsView::Create(this))),
221 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57222 property_bag_(),
223 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22224 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57225 save_package_(),
226 cancelable_consumer_(),
227 autofill_manager_(),
228 password_manager_(),
229 plugin_installer_(),
[email protected]d82ed61e2009-06-16 02:46:22230 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57231 select_file_dialog_(),
232 pending_install_(),
[email protected]d5f942ba2008-09-26 19:30:34233 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29234 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34235 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34236 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57237 current_load_start_(),
238 load_state_(net::LOAD_STATE_IDLE),
239 load_state_host_(),
240 received_page_title_(false),
241 is_starred_(false),
242 contents_mime_type_(),
243 encoding_(),
[email protected]332af7732009-03-11 13:21:35244 blocked_popups_(NULL),
[email protected]fdd61c62009-04-22 19:22:57245 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57246 find_ui_active_(false),
247 find_op_aborted_(false),
248 current_find_request_id_(find_request_id_counter_++),
249 find_text_(),
[email protected]e491f1c2009-05-22 20:28:12250 last_search_case_sensitive_(false),
251 last_search_prepopulate_text_(NULL),
252 last_search_result_(),
[email protected]fdd61c62009-04-22 19:22:57253 capturing_contents_(false),
254 is_being_destroyed_(false),
255 notify_disconnection_(false),
256 history_requests_(),
257#if defined(OS_WIN)
258 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
259#endif
260 last_javascript_message_dismissal_(),
261 suppress_javascript_messages_(false) {
[email protected]420ae012009-04-24 05:16:32262 pending_install_.page_id = 0;
263 pending_install_.callback_functor = NULL;
264
[email protected]16779842009-07-08 23:45:29265#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02266 // Make sure the thumbnailer is started before starting the render manager.
267 // The thumbnailer will want to listen for RVH creations, one of which will
268 // happen in RVHManager::Init.
269 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
270 if (generator)
271 generator->StartThumbnailing();
272#endif
273
[email protected]420ae012009-04-24 05:16:32274 render_manager_.Init(profile, site_instance, routing_id, modal_dialog_event);
275
276 view_->CreateView();
277
278 // Register for notifications about all interested prefs change.
279 PrefService* prefs = profile->GetPrefs();
280 if (prefs) {
281 for (int i = 0; i < kPrefsToObserveLength; ++i)
282 prefs->AddPrefObserver(kPrefsToObserve[i], this);
283 }
284
285 // Register for notifications about URL starredness changing on any profile.
286 registrar_.Add(this, NotificationType::URLS_STARRED,
287 NotificationService::AllSources());
288 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
289 NotificationService::AllSources());
290 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
291 NotificationService::AllSources());
292
293 // Keep a global copy of the previous search string (if any).
294 static string16 global_last_search = string16();
[email protected]e491f1c2009-05-22 20:28:12295 last_search_prepopulate_text_ = &global_last_search;
[email protected]840b1512009-07-21 16:53:46296
[email protected]c8865482009-07-23 20:40:10297 // Set-up the showing of the omnibox search infobar if applicable.
298 if (OmniboxSearchHint::IsEnabled(profile))
299 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
300
[email protected]840b1512009-07-21 16:53:46301 view_->InitRendererPrefs(&renderer_preferences_);
[email protected]332af7732009-03-11 13:21:35302}
initial.commit09911bf2008-07-26 23:55:29303
304TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32305 is_being_destroyed_ = true;
306
307 // We don't want any notifications while we're runnign our destructor.
308 registrar_.RemoveAll();
309
310 // Unregister the notifications of all observed prefs change.
311 PrefService* prefs = profile()->GetPrefs();
312 if (prefs) {
313 for (int i = 0; i < kPrefsToObserveLength; ++i)
314 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
315 }
316
317 // Clean up subwindows like plugins and the find in page bar.
318 view_->OnContentsDestroy();
319
320 NotifyDisconnected();
[email protected]d82ed61e2009-06-16 02:46:22321 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32322
323 if (pending_install_.callback_functor)
324 pending_install_.callback_functor->Cancel();
325
326 // First cleanly close all child windows.
327 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
328 // some of these to close. CloseWindows is async, so it might get called
329 // twice before it runs.
330 int size = static_cast<int>(child_windows_.size());
331 for (int i = size - 1; i >= 0; --i) {
332 ConstrainedWindow* window = child_windows_[i];
333 if (window)
334 window->CloseConstrainedWindow();
335 }
336
[email protected]66ba4932009-06-04 19:22:13337 if (blocked_popups_)
338 blocked_popups_->Destroy();
339
[email protected]420ae012009-04-24 05:16:32340 // Notify any observer that have a reference on this tab contents.
341 NotificationService::current()->Notify(
342 NotificationType::TAB_CONTENTS_DESTROYED,
343 Source<TabContents>(this),
344 NotificationService::NoDetails());
345
[email protected]1e5e74f2009-05-27 20:55:12346 // Notify any lasting InfobarDelegates that have not yet been removed that
347 // whatever infobar they were handling in this TabContents has closed,
348 // because the TabContents is going away entirely.
349 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
350 // notification may trigger infobars calls that access their delegate. (and
351 // some implementations of InfoBarDelegate do delete themselves on
352 // InfoBarClosed()).
353 for (int i = 0; i < infobar_delegate_count(); ++i) {
354 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
355 delegate->InfoBarClosed();
356 }
357 infobar_delegates_.clear();
358
[email protected]420ae012009-04-24 05:16:32359 // TODO(brettw) this should be moved to the view.
360#if defined(OS_WIN)
361 // If we still have a window handle, destroy it. GetNativeView can return
362 // NULL if this contents was part of a window that closed.
363 if (GetNativeView())
364 ::DestroyWindow(GetNativeView());
365#endif
initial.commit09911bf2008-07-26 23:55:29366}
367
[email protected]d5f942ba2008-09-26 19:30:34368// static
369void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32370 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
371
372 WebPreferences pref_defaults;
373 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
374 pref_defaults.javascript_enabled);
375 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
376 pref_defaults.web_security_enabled);
377 prefs->RegisterBooleanPref(
378 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
379 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
380 pref_defaults.loads_images_automatically);
381 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
382 pref_defaults.plugins_enabled);
383 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
384 pref_defaults.dom_paste_enabled);
385 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
386 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]0df30122009-06-03 12:13:08387 prefs->RegisterStringPref(prefs::kWebKitInspectorSettings,
388 pref_defaults.inspector_settings);
[email protected]420ae012009-04-24 05:16:32389 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
390 pref_defaults.text_areas_are_resizable);
391 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
392 pref_defaults.java_enabled);
393
394 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
395 IDS_ACCEPT_LANGUAGES);
396 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
397 IDS_DEFAULT_ENCODING);
398 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
399 IDS_STANDARD_FONT_IS_SERIF);
400 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
401 IDS_FIXED_FONT_FAMILY);
402 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
403 IDS_SERIF_FONT_FAMILY);
404 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
405 IDS_SANS_SERIF_FONT_FAMILY);
406 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
407 IDS_CURSIVE_FONT_FAMILY);
408 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
409 IDS_FANTASY_FONT_FAMILY);
410 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
411 IDS_DEFAULT_FONT_SIZE);
412 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
413 IDS_DEFAULT_FIXED_FONT_SIZE);
414 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
415 IDS_MINIMUM_FONT_SIZE);
416 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
417 IDS_MINIMUM_LOGICAL_FONT_SIZE);
418 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
419 IDS_USES_UNIVERSAL_DETECTOR);
420 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
421 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29422}
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]6e95706d2009-04-23 22:55:01429PasswordManager* TabContents::GetPasswordManager() {
430 if (password_manager_.get() == NULL)
431 password_manager_.reset(new PasswordManager(this));
432 return password_manager_.get();
433}
434
435PluginInstaller* TabContents::GetPluginInstaller() {
436 if (plugin_installer_.get() == NULL)
437 plugin_installer_.reset(new PluginInstaller(this));
438 return plugin_installer_.get();
439}
440
[email protected]d5f942ba2008-09-26 19:30:34441const GURL& TabContents::GetURL() const {
442 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57443 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54444 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34445}
446
[email protected]96d185d2009-04-24 03:28:54447const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55448 // Transient entries take precedence. They are used for interstitial pages
449 // that are shown on top of existing pages.
450 NavigationEntry* entry = controller_.GetTransientEntry();
451 if (entry)
452 return entry->GetTitleForDisplay(&controller_);
453
[email protected]96d185d2009-04-24 03:28:54454 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
455 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
456 if (our_dom_ui) {
457 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55458 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54459 if (!(entry && entry->IsViewSourceMode())) {
460 // Give the DOM UI the chance to override our title.
461 const string16& title = our_dom_ui->overridden_title();
462 if (!title.empty())
463 return title;
464 }
465 }
466
467 // We use the title for the last committed entry rather than a pending
468 // navigation entry. For example, when the user types in a URL, we want to
469 // keep the old page's title until the new load has committed and we get a new
470 // title.
[email protected]96d185d2009-04-24 03:28:54471 entry = controller_.GetLastCommittedEntry();
472 if (entry)
473 return entry->GetTitleForDisplay(&controller_);
474 else if (controller_.LoadingURLLazily())
475 return controller_.GetLazyTitle();
476 return EmptyString16();
477}
478
[email protected]d5f942ba2008-09-26 19:30:34479int32 TabContents::GetMaxPageID() {
480 if (GetSiteInstance())
481 return GetSiteInstance()->max_page_id();
482 else
483 return max_page_id_;
484}
485
486void TabContents::UpdateMaxPageID(int32 page_id) {
487 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34488 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34489 // testing.
490 if (GetSiteInstance())
491 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]57c6a652009-05-04 07:58:34492 process()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34493}
494
[email protected]96d185d2009-04-24 03:28:54495SiteInstance* TabContents::GetSiteInstance() const {
496 return render_manager_.current_host()->site_instance();
497}
498
[email protected]d5f942ba2008-09-26 19:30:34499const std::wstring TabContents::GetDefaultTitle() const {
500 return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE);
501}
502
[email protected]96d185d2009-04-24 03:28:54503bool TabContents::ShouldDisplayURL() {
504 // Don't hide the url in view source mode.
505 NavigationEntry* entry = controller_.GetActiveEntry();
506 if (entry && entry->IsViewSourceMode())
507 return true;
[email protected]83e3895b2009-06-11 00:07:16508
[email protected]96d185d2009-04-24 03:28:54509 DOMUI* dom_ui = GetDOMUIForCurrentState();
510 if (dom_ui)
511 return !dom_ui->should_hide_url();
512 return true;
513}
514
[email protected]d5f942ba2008-09-26 19:30:34515SkBitmap TabContents::GetFavIcon() const {
516 // Like GetTitle(), we also want to use the favicon for the last committed
517 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57518 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47519 if (entry)
520 return entry->favicon().bitmap();
521
[email protected]ce3fa3c2009-04-20 19:55:57522 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34523 if (entry)
524 return entry->favicon().bitmap();
[email protected]ce3fa3c2009-04-20 19:55:57525 else if (controller_.LoadingURLLazily())
526 return controller_.GetLazyFavIcon();
[email protected]d5f942ba2008-09-26 19:30:34527 return SkBitmap();
528}
529
[email protected]96d185d2009-04-24 03:28:54530bool TabContents::ShouldDisplayFavIcon() {
531 // Always display a throbber during pending loads.
532 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
533 return true;
534
535 DOMUI* dom_ui = GetDOMUIForCurrentState();
536 if (dom_ui)
537 return !dom_ui->hide_favicon();
538 return true;
539}
540
[email protected]96d185d2009-04-24 03:28:54541std::wstring TabContents::GetStatusText() const {
542 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
543 return std::wstring();
544
545 switch (load_state_) {
546 case net::LOAD_STATE_WAITING_FOR_CACHE:
547 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
548 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
549 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
550 case net::LOAD_STATE_RESOLVING_HOST:
551 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
552 case net::LOAD_STATE_CONNECTING:
553 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
554 case net::LOAD_STATE_SENDING_REQUEST:
555 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
556 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
557 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
558 load_state_host_);
559 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
560 case net::LOAD_STATE_IDLE:
561 case net::LOAD_STATE_READING_RESPONSE:
562 break;
563 }
564
565 return std::wstring();
566}
567
[email protected]d5f942ba2008-09-26 19:30:34568void TabContents::SetIsCrashed(bool state) {
569 if (state == is_crashed_)
570 return;
571
572 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50573 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34574}
575
[email protected]f9b1a7b2009-06-22 17:26:38576void TabContents::SetPageActionEnabled(const PageAction* page_action,
[email protected]d7eaf572009-07-01 21:57:00577 bool enable,
578 const std::string& title,
579 int icon_id) {
[email protected]ce5c4502009-05-06 16:46:11580 DCHECK(page_action);
581
[email protected]d7eaf572009-07-01 21:57:00582 if (!enable &&
583 enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) {
584 return; // Don't need to disable twice.
585 }
[email protected]ce5c4502009-05-06 16:46:11586
[email protected]d7eaf572009-07-01 21:57:00587 if (enable) {
588 enabled_page_actions_[page_action].reset(
589 new PageActionState(title, icon_id));
590 } else {
[email protected]f9b1a7b2009-06-22 17:26:38591 enabled_page_actions_.erase(page_action);
[email protected]d7eaf572009-07-01 21:57:00592 }
[email protected]ce5c4502009-05-06 16:46:11593}
594
[email protected]d7eaf572009-07-01 21:57:00595const PageActionState* TabContents::GetPageActionState(
596 const PageAction* page_action) {
597 if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action))
598 return NULL;
[email protected]ce5c4502009-05-06 16:46:11599
[email protected]d7eaf572009-07-01 21:57:00600 return enabled_page_actions_[page_action].get();
601}
[email protected]ce5c4502009-05-06 16:46:11602
[email protected]d5f942ba2008-09-26 19:30:34603void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
604 if (delegate_)
605 delegate_->NavigationStateChanged(this, changed_flags);
606}
607
[email protected]96d185d2009-04-24 03:28:54608void TabContents::DidBecomeSelected() {
609 controller_.SetActive(true);
610
[email protected]789e9152009-08-04 21:59:43611 if (render_widget_host_view()) {
[email protected]96d185d2009-04-24 03:28:54612 render_widget_host_view()->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43613#if defined(OS_MACOSX)
614 render_widget_host_view()->SetActive(true);
615#endif
616 }
[email protected]96d185d2009-04-24 03:28:54617
618 // If pid() is -1, that means the RenderProcessHost still hasn't been
619 // initialized. It'll register with CacheManagerHost when it is.
620 if (process()->pid() != -1)
621 WebCacheManager::GetInstance()->ObserveActivity(process()->pid());
622}
623
624void TabContents::WasHidden() {
625 if (!capturing_contents()) {
626 // |render_view_host()| can be NULL if the user middle clicks a link to open
627 // a tab in then background, then closes the tab before selecting it. This
628 // is because closing the tab calls TabContents::Destroy(), which removes
629 // the |render_view_host()|; then when we actually destroy the window,
630 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
631 if (render_widget_host_view())
632 render_widget_host_view()->WasHidden();
[email protected]96d185d2009-04-24 03:28:54633 }
634
635 NotificationService::current()->Notify(
636 NotificationType::TAB_CONTENTS_HIDDEN,
637 Source<TabContents>(this),
638 NotificationService::NoDetails());
639}
640
[email protected]d5f942ba2008-09-26 19:30:34641void TabContents::Activate() {
642 if (delegate_)
643 delegate_->ActivateContents(this);
644}
645
[email protected]96d185d2009-04-24 03:28:54646void TabContents::ShowContents() {
647 if (render_widget_host_view())
648 render_widget_host_view()->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54649}
650
651void TabContents::HideContents() {
652 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
653 // our superclass HideContents(), because some callers want to be very picky
654 // about the order in which these get called. In addition to making the code
655 // here practically impossible to understand, this also means we end up
656 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34657 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54658 WasHidden();
659}
660
[email protected]c0588052008-10-27 23:01:50661void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34662 WindowOpenDisposition disposition,
663 PageTransition::Type transition) {
664 if (delegate_)
[email protected]c0588052008-10-27 23:01:50665 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34666}
667
668bool TabContents::NavigateToPendingEntry(bool reload) {
[email protected]96d185d2009-04-24 03:28:54669 const NavigationEntry& entry = *controller_.pending_entry();
670
671 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
672 if (!dest_render_view_host)
673 return false; // Unable to create the desired render view host.
674
675 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12676 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32677 if (devtools_manager) { // NULL in unit tests.
[email protected]684b4ba22009-05-07 06:27:41678 devtools_manager->OnNavigatingToPendingEntry(
679 render_view_host(),
680 dest_render_view_host,
681 controller_.pending_entry()->url());
[email protected]7e8e6b62009-05-08 11:28:32682 }
[email protected]96d185d2009-04-24 03:28:54683
684 // Used for page load time metrics.
685 current_load_start_ = base::TimeTicks::Now();
686
687 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34688 ViewMsg_Navigate_Params navigate_params;
689 MakeNavigateParams(entry, reload, &navigate_params);
690 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
702 // Clear any provisional password saves - this stops password infobars
703 // showing up on pages the user navigates to while the right page is
704 // loading.
705 GetPasswordManager()->ClearProvisionalSave();
706
707 if (reload && !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48708 FaviconService* favicon_service =
709 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
710 if (favicon_service)
711 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54712 }
713
[email protected]d5f942ba2008-09-26 19:30:34714 return true;
715}
716
[email protected]96d185d2009-04-24 03:28:54717void TabContents::Stop() {
718 render_manager_.Stop();
719 printing_.Stop();
720}
721
722void TabContents::Cut() {
723 render_view_host()->Cut();
724}
725
726void TabContents::Copy() {
727 render_view_host()->Copy();
728}
729
730void TabContents::Paste() {
731 render_view_host()->Paste();
732}
733
734void TabContents::DisassociateFromPopupCount() {
735 render_view_host()->DisassociateFromPopupCount();
736}
737
738TabContents* TabContents::Clone() {
739 // We create a new SiteInstance so that the new tab won't share processes
740 // with the old one. This can be changed in the future if we need it to share
741 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32742 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54743 SiteInstance::CreateSiteInstance(profile()),
744 MSG_ROUTING_NONE, NULL);
745 tc->controller().CopyStateFrom(controller_);
746 return tc;
747}
748
[email protected]420ae012009-04-24 05:16:32749void TabContents::CreateShortcut() {
750 NavigationEntry* entry = controller_.GetLastCommittedEntry();
751 if (!entry)
752 return;
753
[email protected]70b8d6b2009-08-20 16:56:24754#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]0ba5c5e2009-08-20 16:47:13755 CreateApplicationShortcutsDialogGtk::Show(view()->GetTopLevelNativeWindow(),
756 GetURL(), GetTitle());
[email protected]b96aa932009-08-12 21:34:49757#else
[email protected]420ae012009-04-24 05:16:32758 // We only allow one pending install request. By resetting the page id we
759 // effectively cancel the pending install request.
760 pending_install_.page_id = entry->page_id();
761 pending_install_.icon = GetFavIcon();
762 pending_install_.title = UTF16ToWideHack(GetTitle());
763 pending_install_.url = GetURL();
764 if (pending_install_.callback_functor) {
765 pending_install_.callback_functor->Cancel();
766 pending_install_.callback_functor = NULL;
767 }
768 DCHECK(!pending_install_.icon.isNull()) << "Menu item should be disabled.";
769 if (pending_install_.title.empty())
770 pending_install_.title = UTF8ToWide(GetURL().spec());
771
772 // Request the application info. When done OnDidGetApplicationInfo is invoked
773 // and we'll create the shortcut.
774 render_view_host()->GetApplicationInfo(pending_install_.page_id);
[email protected]b96aa932009-08-12 21:34:49775#endif
[email protected]420ae012009-04-24 05:16:32776}
777
[email protected]4d677202009-07-19 07:37:12778void TabContents::ShowPageInfo(const GURL& url,
779 const NavigationEntry::SSLStatus& ssl,
780 bool show_history) {
781 if (!delegate_)
782 return;
783
[email protected]bb678332009-07-21 00:15:50784 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12785}
786
initial.commit09911bf2008-07-26 23:55:29787ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28788 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29789 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28790 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29791 child_windows_.push_back(window);
792 return window;
793}
794
795void TabContents::AddNewContents(TabContents* new_contents,
796 WindowOpenDisposition disposition,
797 const gfx::Rect& initial_pos,
[email protected]c88a70fe2009-05-05 20:00:22798 bool user_gesture,
799 const GURL& creator_url) {
initial.commit09911bf2008-07-26 23:55:29800 if (!delegate_)
801 return;
802
[email protected]35f7d212009-04-29 21:19:27803 if ((disposition == NEW_POPUP) && !user_gesture &&
804 !CommandLine::ForCurrentProcess()->HasSwitch(
805 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22806 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31807 // the whitelist. The popup owner will handle checking this.
808 delegate_->GetConstrainingContents(this)->AddPopup(new_contents,
809 initial_pos,
810 creator_url.is_valid() ? creator_url.host() : std::string());
811 } else {
[email protected]304f8792009-08-19 21:28:09812#if defined(OS_CHROMEOS)
813 if (disposition == NEW_POPUP) {
814 // If the popup is bigger than a given factor of the screen, then
815 // turn it into a foreground tab (on chrome os only)
816 GdkScreen* screen = gdk_screen_get_default();
817 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
818 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
819 if (initial_pos.width() > max_width ||
820 initial_pos.height() > max_height) {
821 disposition = NEW_FOREGROUND_TAB;
822 }
823 }
824#endif
825
[email protected]0aa55312008-10-17 21:53:08826 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29827 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
828 user_gesture);
829 }
[email protected]b6c874582009-05-08 19:38:31830 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29831}
832
initial.commit09911bf2008-07-26 23:55:29833void TabContents::CloseAllSuppressedPopups() {
[email protected]d6598c052008-11-05 19:03:25834 if (blocked_popups_)
[email protected]2c4410d2009-05-06 23:46:22835 blocked_popups_->CloseAll();
initial.commit09911bf2008-07-26 23:55:29836}
837
[email protected]96d185d2009-04-24 03:28:54838void TabContents::PopupNotificationVisibilityChanged(bool visible) {
839 render_view_host()->PopupNotificationVisibilityChanged(visible);
840}
841
842gfx::NativeView TabContents::GetContentNativeView() {
843 return view_->GetContentNativeView();
844}
845
846gfx::NativeView TabContents::GetNativeView() const {
847 return view_->GetNativeView();
848}
849
850void TabContents::GetContainerBounds(gfx::Rect *out) const {
851 view_->GetContainerBounds(out);
852}
853
854void TabContents::Focus() {
855 view_->Focus();
856}
857
[email protected]90daadb42009-06-08 21:27:28858void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54859 if (showing_interstitial_page()) {
860 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
861 return;
862 }
[email protected]96d185d2009-04-24 03:28:54863 render_view_host()->SetInitialFocus(reverse);
864}
865
866bool TabContents::FocusLocationBarByDefault() {
867 DOMUI* dom_ui = GetDOMUIForCurrentState();
868 if (dom_ui)
869 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43870 NavigationEntry* entry = controller_.GetActiveEntry();
871 if (entry && entry->url() == GURL("about:blank"))
872 return true;
[email protected]96d185d2009-04-24 03:28:54873 return false;
874}
875
[email protected]616ed5a2008-11-21 22:27:24876void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
877 // Look through the existing InfoBarDelegates we have for a match. If we've
878 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05879 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]616ed5a2008-11-21 22:27:24880 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
881 return;
882 }
883
884 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56885 NotificationService::current()->Notify(
886 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
887 Source<TabContents>(this),
888 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24889
890 // Add ourselves as an observer for navigations the first time a delegate is
891 // added. We use this notification to expire InfoBars that need to expire on
892 // page transitions.
893 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56894 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57895 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24896 }
897}
898
899void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
900 std::vector<InfoBarDelegate*>::iterator it =
901 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
902 if (it != infobar_delegates_.end()) {
903 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56904 NotificationService::current()->Notify(
905 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
906 Source<TabContents>(this),
907 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:05908 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:24909
[email protected]6a02963e2009-01-06 16:58:03910 // Remove ourselves as an observer if we are tracking no more InfoBars.
911 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:56912 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57913 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03914 }
[email protected]616ed5a2008-11-21 22:27:24915 }
916}
[email protected]3edd9522009-03-04 22:19:41917
[email protected]f81821c2009-08-07 01:29:47918void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
919 InfoBarDelegate* new_delegate) {
920 std::vector<InfoBarDelegate*>::iterator it =
921 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
922 DCHECK(it != infobar_delegates_.end());
923
924 // Notify the container about the change of plans.
925 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
926 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
927 old_delegate, new_delegate));
928 NotificationService::current()->Notify(
929 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
930 Source<TabContents>(this),
931 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
932
933 // Remove the old one.
934 infobar_delegates_.erase(it);
935
936 // Add the new one.
937 infobar_delegates_.push_back(new_delegate);
938}
939
[email protected]96d185d2009-04-24 03:28:54940bool TabContents::IsBookmarkBarAlwaysVisible() {
941 // See GetDOMUIForCurrentState() comment for more info. This case is very
942 // similar, but for non-first loads, we want to use the committed entry. This
943 // is so the bookmarks bar disappears at the same time the page does.
944 if (controller_.GetLastCommittedEntry()) {
945 // Not the first load, always use the committed DOM UI.
946 if (render_manager_.dom_ui())
947 return render_manager_.dom_ui()->force_bookmark_bar_visible();
948 return false; // Default.
949 }
950
951 // When it's the first load, we know either the pending one or the committed
952 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
953 // of them will be valid, so we can just check both.
954 if (render_manager_.pending_dom_ui())
955 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
956 if (render_manager_.dom_ui())
957 return render_manager_.dom_ui()->force_bookmark_bar_visible();
958 return false; // Default.
959}
960
[email protected]d8f16ae2009-08-30 03:47:26961bool TabContents::IsExtensionShelfAlwaysVisible() {
962 // See GetDOMUIForCurrentState() comment for more info. This case is very
963 // similar, but for non-first loads, we want to use the committed entry. This
964 // is so the bookmarks bar disappears at the same time the page does.
965 if (controller_.GetLastCommittedEntry()) {
966 // Not the first load, always use the committed DOM UI.
967 if (render_manager_.dom_ui())
968 return render_manager_.dom_ui()->force_extension_shelf_visible();
969 return false; // Default.
970 }
971
972 // When it's the first load, we know either the pending one or the committed
973 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
974 // of them will be valid, so we can just check both.
975 if (render_manager_.pending_dom_ui())
976 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
977 if (render_manager_.dom_ui())
978 return render_manager_.dom_ui()->force_extension_shelf_visible();
979 return false; // Default.
980}
981
[email protected]3edd9522009-03-04 22:19:41982void TabContents::ToolbarSizeChanged(bool is_animating) {
983 TabContentsDelegate* d = delegate();
984 if (d)
985 d->ToolbarSizeChanged(this, is_animating);
986}
[email protected]616ed5a2008-11-21 22:27:24987
[email protected]d5f942ba2008-09-26 19:30:34988void TabContents::OnStartDownload(DownloadItem* download) {
989 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:34990
991 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:31992 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:34993
[email protected]59560e0b2009-06-04 03:30:22994 if (tab_contents && tab_contents->delegate())
995 tab_contents->delegate()->OnStartDownload(download);
[email protected]3edd9522009-03-04 22:19:41996}
[email protected]3edd9522009-03-04 22:19:41997
[email protected]d5f942ba2008-09-26 19:30:34998void TabContents::WillClose(ConstrainedWindow* window) {
999 ConstrainedWindowList::iterator it =
1000 find(child_windows_.begin(), child_windows_.end(), window);
1001 if (it != child_windows_.end())
1002 child_windows_.erase(it);
[email protected]66ba4932009-06-04 19:22:131003}
[email protected]d5f942ba2008-09-26 19:30:341004
[email protected]66ba4932009-06-04 19:22:131005void TabContents::WillCloseBlockedPopupContainer(
1006 BlockedPopupContainer* container) {
1007 DCHECK(blocked_popups_ == container);
1008 blocked_popups_ = NULL;
[email protected]d5f942ba2008-09-26 19:30:341009}
1010
[email protected]d5f942ba2008-09-26 19:30:341011void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351012#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061013 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351014#endif
[email protected]d5f942ba2008-09-26 19:30:341015}
1016
[email protected]e491f1c2009-05-22 20:28:121017void TabContents::StartFinding(string16 find_text,
1018 bool forward_direction,
1019 bool case_sensitive) {
[email protected]6e95706d2009-04-23 22:55:011020 // If find_text is empty, it means FindNext was pressed with a keyboard
1021 // shortcut so unless we have something to search for we return early.
[email protected]e491f1c2009-05-22 20:28:121022 if (find_text.empty() && find_text_.empty()) {
1023 if (last_search_prepopulate_text_->empty())
1024 return;
1025 // Try whatever we searched for last in any tab.
1026 find_text = *last_search_prepopulate_text_;
1027 }
[email protected]6e95706d2009-04-23 22:55:011028
1029 // This is a FindNext operation if we are searching for the same text again,
1030 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1031 // exception to this is if the Find was aborted (then we don't want FindNext
1032 // because the highlighting has been cleared and we need it to reappear). We
1033 // therefore treat FindNext after an aborted Find operation as a full fledged
1034 // Find.
1035 bool find_next = (find_text_ == find_text || find_text.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121036 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011037 !find_op_aborted_;
1038 if (!find_next)
1039 current_find_request_id_ = find_request_id_counter_++;
1040
1041 if (!find_text.empty())
1042 find_text_ = find_text;
[email protected]e491f1c2009-05-22 20:28:121043 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011044
1045 find_op_aborted_ = false;
1046
1047 // Keep track of what the last search was across the tabs.
[email protected]e491f1c2009-05-22 20:28:121048 *last_search_prepopulate_text_ = find_text;
[email protected]6e95706d2009-04-23 22:55:011049
1050 render_view_host()->StartFinding(current_find_request_id_,
1051 find_text_,
1052 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121053 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011054 find_next);
1055}
1056
1057void TabContents::StopFinding(bool clear_selection) {
[email protected]2d2dffc2009-06-09 21:41:001058 // When |clear_selection| is true, it means the find string has been cleared
1059 // by the user, but the UI has not been dismissed.
1060 if (!clear_selection)
1061 find_ui_active_ = false;
[email protected]6e95706d2009-04-23 22:55:011062 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121063 last_search_result_ = FindNotificationDetails();
[email protected]6e95706d2009-04-23 22:55:011064 render_view_host()->StopFinding(clear_selection);
1065}
1066
[email protected]5c4266922009-07-10 16:41:271067void TabContents::GetPageLanguage() {
1068 render_view_host()->GetPageLanguage();
1069}
1070
[email protected]420ae012009-04-24 05:16:321071void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
1072 bool success,
1073 const std::wstring& prompt) {
1074 last_javascript_message_dismissal_ = base::TimeTicks::Now();
1075 render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt);
1076}
1077
[email protected]571e31152009-05-15 19:34:021078void TabContents::OnJavaScriptMessageBoxWindowDestroyed() {
1079 render_manager_.OnJavaScriptMessageBoxWindowDestroyed();
1080}
1081
[email protected]420ae012009-04-24 05:16:321082void TabContents::OnSavePage() {
1083 // If we can not save the page, try to download it.
1084 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1085 DownloadManager* dlm = profile()->GetDownloadManager();
1086 const GURL& current_page_url = GetURL();
1087 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221088 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321089 return;
1090 }
1091
1092 Stop();
1093
1094 // Create the save package and possibly prompt the user for the name to save
1095 // the page as. The user prompt is an asynchronous operation that runs on
1096 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221097 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321098 save_package_->GetSaveInfo();
1099}
1100
1101// Used in automated testing to bypass prompting the user for file names.
1102// Instead, the names and paths are hard coded rather than running them through
1103// file name sanitation and extension / mime checking.
[email protected]cdf6cc82009-08-04 21:48:591104bool TabContents::SavePage(const std::wstring& main_file,
[email protected]420ae012009-04-24 05:16:321105 const std::wstring& dir_path,
1106 SavePackage::SavePackageType save_type) {
1107 // Stop the page from navigating.
1108 Stop();
1109
[email protected]d82ed61e2009-06-16 02:46:221110 save_package_ = new SavePackage(this, save_type,
[email protected]420ae012009-04-24 05:16:321111 FilePath::FromWStringHack(main_file),
1112 FilePath::FromWStringHack(dir_path));
[email protected]cdf6cc82009-08-04 21:48:591113 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321114}
1115
1116void TabContents::PrintPreview() {
1117 // We don't show the print preview yet, only the print dialog.
1118 PrintNow();
1119}
1120
1121bool TabContents::PrintNow() {
1122 // We can't print interstitial page for now.
1123 if (showing_interstitial_page())
1124 return false;
1125
1126 return render_view_host()->PrintPages();
1127}
1128
[email protected]82270452009-06-19 15:58:011129void TabContents::PrintingDone(int document_cookie, bool success) {
1130 render_view_host()->PrintingDone(document_cookie, success);
1131}
1132
[email protected]420ae012009-04-24 05:16:321133bool TabContents::IsActiveEntry(int32 page_id) {
1134 NavigationEntry* active_entry = controller_.GetActiveEntry();
1135 return (active_entry != NULL &&
1136 active_entry->site_instance() == GetSiteInstance() &&
1137 active_entry->page_id() == page_id);
1138}
1139
[email protected]96d185d2009-04-24 03:28:541140// Notifies the RenderWidgetHost instance about the fact that the page is
1141// loading, or done loading and calls the base implementation.
1142void TabContents::SetIsLoading(bool is_loading,
1143 LoadNotificationDetails* details) {
1144 if (is_loading == is_loading_)
1145 return;
1146
1147 if (!is_loading) {
1148 load_state_ = net::LOAD_STATE_IDLE;
1149 load_state_host_.clear();
1150 }
1151
1152 render_manager_.SetIsLoading(is_loading);
1153
1154 is_loading_ = is_loading;
1155 waiting_for_response_ = is_loading;
1156
1157 if (delegate_)
1158 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351159 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541160
1161 NotificationType type = is_loading ? NotificationType::LOAD_START :
1162 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111163 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541164 if (details)
1165 det = Details<LoadNotificationDetails>(details);
1166 NotificationService::current()->Notify(type,
1167 Source<NavigationController>(&controller_),
1168 det);
1169}
1170
[email protected]2c4410d2009-05-06 23:46:221171void TabContents::CreateBlockedPopupContainerIfNecessary() {
1172 if (blocked_popups_)
1173 return;
1174
[email protected]4d4c0b92009-06-08 23:13:011175 blocked_popups_ = BlockedPopupContainer::Create(this, profile());
[email protected]2c4410d2009-05-06 23:46:221176}
1177
[email protected]b6c874582009-05-08 19:38:311178void TabContents::AddPopup(TabContents* new_contents,
1179 const gfx::Rect& initial_pos,
1180 const std::string& host) {
[email protected]2c4410d2009-05-06 23:46:221181 CreateBlockedPopupContainerIfNecessary();
1182 blocked_popups_->AddTabContents(new_contents, initial_pos, host);
[email protected]2c4410d2009-05-06 23:46:221183}
1184
[email protected]e69bce3dd2009-04-20 22:05:121185// TODO(brettw) This should be on the TabContentsView.
[email protected]66ba4932009-06-04 19:22:131186void TabContents::RepositionSupressedPopupsToFit() {
[email protected]d6598c052008-11-05 19:03:251187 if (blocked_popups_)
[email protected]4d4c0b92009-06-08 23:13:011188 blocked_popups_->RepositionBlockedPopupContainer();
[email protected]d5f942ba2008-09-26 19:30:341189}
1190
[email protected]b9681312008-11-07 00:08:261191bool TabContents::ShowingBlockedPopupNotification() const {
1192 return blocked_popups_ != NULL &&
[email protected]2c4410d2009-05-06 23:46:221193 blocked_popups_->GetBlockedPopupCount() != 0;
[email protected]b9681312008-11-07 00:08:261194}
[email protected]616ed5a2008-11-21 22:27:241195
1196namespace {
1197bool TransitionIsReload(PageTransition::Type transition) {
1198 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1199}
1200}
1201
1202void TabContents::ExpireInfoBars(
1203 const NavigationController::LoadCommittedDetails& details) {
1204 // Only hide InfoBars when the user has done something that makes the main
1205 // frame load. We don't want various automatic or subframe navigations making
1206 // it disappear.
1207 if (!details.is_user_initiated_main_frame_load())
1208 return;
1209
[email protected]f86a07022008-11-25 01:06:051210 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241211 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051212 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241213 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241214 }
1215}
[email protected]fdd61c62009-04-22 19:22:571216
1217void TabContents::OnGearsCreateShortcutDone(
1218 const GearsShortcutData2& shortcut_data, bool success) {
1219 NavigationEntry* current_entry = controller_.GetLastCommittedEntry();
1220 bool same_page =
1221 current_entry && pending_install_.page_id == current_entry->page_id();
1222
1223 if (success && same_page) {
1224 // Only switch to app mode if the user chose to create a shortcut and
1225 // we're still on the same page that it corresponded to.
1226 if (delegate())
1227 delegate()->ConvertContentsToApplication(this);
1228 }
1229
1230 // Reset the page id to indicate no requests are pending.
1231 pending_install_.page_id = 0;
1232 pending_install_.callback_functor = NULL;
1233}
[email protected]96d185d2009-04-24 03:28:541234
1235DOMUI* TabContents::GetDOMUIForCurrentState() {
1236 // When there is a pending navigation entry, we want to use the pending DOMUI
1237 // that goes along with it to control the basic flags. For example, we want to
1238 // show the pending URL in the URL bar, so we want the display_url flag to
1239 // be from the pending entry.
1240 //
1241 // The confusion comes because there are multiple possibilities for the
1242 // initial load in a tab as a side effect of the way the RenderViewHostManager
1243 // works.
1244 //
1245 // - For the very first tab the load looks "normal". The new tab DOM UI is
1246 // the pending one, and we want it to apply here.
1247 //
1248 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1249 // get switched to the one previously associated with the new tab pages.
1250 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1251 // have a committed DOM UI in this case.
1252 //
1253 // This condition handles all of these cases:
1254 //
1255 // - First load in first tab: no committed nav entry + pending nav entry +
1256 // pending dom ui:
1257 // -> Use pending DOM UI if any.
1258 //
1259 // - First load in second tab: no committed nav entry + pending nav entry +
1260 // no pending DOM UI:
1261 // -> Use the committed DOM UI if any.
1262 //
1263 // - Second navigation in any tab: committed nav entry + pending nav entry:
1264 // -> Use pending DOM UI if any.
1265 //
1266 // - Normal state with no load: committed nav entry + no pending nav entry:
1267 // -> Use committed DOM UI.
1268 if (controller_.pending_entry() &&
1269 (controller_.GetLastCommittedEntry() ||
1270 render_manager_.pending_dom_ui()))
1271 return render_manager_.pending_dom_ui();
1272 return render_manager_.dom_ui();
1273}
[email protected]420ae012009-04-24 05:16:321274
1275void TabContents::DidNavigateMainFramePostCommit(
1276 const NavigationController::LoadCommittedDetails& details,
1277 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]420ae012009-04-24 05:16:321278 if (details.is_user_initiated_main_frame_load()) {
1279 // Clear the status bubble. This is a workaround for a bug where WebKit
1280 // doesn't let us know that the cursor left an element during a
1281 // transition (this is also why the mouse cursor remains as a hand after
1282 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1283 // clear the bubble when a user navigates to a named anchor in the same
1284 // page.
1285 UpdateTargetURL(details.entry->page_id(), GURL());
1286
1287 // UpdateHelpersForDidNavigate will handle the case where the password_form
1288 // origin is valid.
1289 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1290 // cleaned up and covered by tests.
1291 if (!params.password_form.origin.is_valid())
1292 GetPasswordManager()->DidNavigate();
1293 }
1294
1295 // The keyword generator uses the navigation entries, so must be called after
1296 // the commit.
1297 GenerateKeywordIfNecessary(params);
1298
1299 // Allow the new page to set the title again.
1300 received_page_title_ = false;
1301
1302 // Get the favicon, either from history or request it from the net.
1303 fav_icon_helper_.FetchFavIcon(details.entry->url());
1304
[email protected]aece2c7f2009-08-27 20:43:171305 // Disable all page actions, unless this is an in-page navigation.
1306 if (!enabled_page_actions_.empty()) {
1307 url_canon::Replacements<char> replacements;
1308 replacements.ClearRef();
1309 if (params.url.ReplaceComponents(replacements) !=
1310 params.referrer.ReplaceComponents(replacements)) {
1311 enabled_page_actions_.clear();
1312 }
1313 }
[email protected]ce5c4502009-05-06 16:46:111314
[email protected]420ae012009-04-24 05:16:321315 // Close constrained popups if necessary.
1316 MaybeCloseChildWindows(details.previous_url, details.entry->url());
1317
1318 // Update the starred state.
1319 UpdateStarredStateForCurrentURL();
1320}
1321
1322void TabContents::DidNavigateAnyFramePostCommit(
1323 RenderViewHost* render_view_host,
1324 const NavigationController::LoadCommittedDetails& details,
1325 const ViewHostMsg_FrameNavigate_Params& params) {
1326 // If we navigate, start showing messages again. This does nothing to prevent
1327 // a malicious script from spamming messages, since the script could just
1328 // reload the page to stop blocking.
1329 suppress_javascript_messages_ = false;
1330
[email protected]420ae012009-04-24 05:16:321331 // Notify the password manager of the navigation or form submit.
1332 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1333 // cleaned up and covered by tests.
1334 if (params.password_form.origin.is_valid())
1335 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
1336}
1337
1338void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
1339 const GURL& current_url) {
1340 if (net::RegistryControlledDomainService::SameDomainOrHost(
1341 previous_url, current_url))
1342 return;
1343
1344 // Clear out any child windows since we are leaving this page entirely.
1345 // We use indices instead of iterators in case CloseWindow does something
1346 // that may invalidate an iterator.
1347 int size = static_cast<int>(child_windows_.size());
1348 for (int i = size - 1; i >= 0; --i) {
1349 ConstrainedWindow* window = child_windows_[i];
1350 if (window)
1351 window->CloseConstrainedWindow();
1352 }
[email protected]e29300cd2009-07-23 21:14:591353
1354 // Close the popup container.
1355 if (blocked_popups_) {
1356 blocked_popups_->Destroy();
1357 blocked_popups_ = NULL;
1358 }
[email protected]420ae012009-04-24 05:16:321359}
1360
1361void TabContents::UpdateStarredStateForCurrentURL() {
1362 BookmarkModel* model = profile()->GetBookmarkModel();
1363 const bool old_state = is_starred_;
1364 is_starred_ = (model && model->IsBookmarked(GetURL()));
1365
1366 if (is_starred_ != old_state && delegate())
1367 delegate()->URLStarredChanged(this, is_starred_);
1368}
1369
1370void TabContents::UpdateAlternateErrorPageURL() {
1371 GURL url = GetAlternateErrorPageURL();
1372 render_view_host()->SetAlternateErrorPageURL(url);
1373}
1374
1375void TabContents::UpdateWebPreferences() {
1376 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1377}
1378
1379void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1380 RenderViewHost* rvh) {
1381 // If we are creating a RVH for a restored controller, then we might
1382 // have more page IDs than the SiteInstance's current max page ID. We must
1383 // make sure that the max page ID is larger than any restored page ID.
1384 // Note that it is ok for conflicting page IDs to exist in another tab
1385 // (i.e., NavigationController), but if any page ID is larger than the max,
1386 // the back/forward list will get confused.
1387 int max_restored_page_id = controller_.max_restored_page_id();
1388 if (max_restored_page_id > 0) {
1389 int curr_max_page_id = site_instance->max_page_id();
1390 if (max_restored_page_id > curr_max_page_id) {
1391 // Need to update the site instance immediately.
1392 site_instance->UpdateMaxPageID(max_restored_page_id);
1393
1394 // Also tell the renderer to update its internal representation. We
1395 // need to reserve enough IDs to make all restored page IDs less than
1396 // the max.
1397 if (curr_max_page_id < 0)
1398 curr_max_page_id = 0;
1399 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1400 }
1401 }
1402}
1403
1404void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541405 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471406 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321407 const ViewHostMsg_FrameNavigate_Params& params) {
1408 if (profile()->IsOffTheRecord())
1409 return;
1410
1411 // Add to history service.
1412 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1413 if (hs) {
1414 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541415 virtual_url != params.url) {
1416 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321417 // types of URLs, we will display a magic URL that is different from where
1418 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541419 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1420 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321421 // to sub-frames.
1422 std::vector<GURL> redirects = params.redirects;
1423 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541424 redirects.back() = virtual_url;
1425 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471426 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321427 } else {
1428 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471429 params.transition, params.redirects,
1430 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321431 }
1432 }
1433}
1434
1435bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1436 const std::wstring& title) {
1437 // For file URLs without a title, use the pathname instead. In the case of a
1438 // synthesized title, we don't want the update to count toward the "one set
1439 // per page of the title to history."
1440 std::wstring final_title;
1441 bool explicit_set;
1442 if (entry->url().SchemeIsFile() && title.empty()) {
1443 final_title = UTF8ToWide(entry->url().ExtractFileName());
1444 explicit_set = false; // Don't count synthetic titles toward the set limit.
1445 } else {
1446 TrimWhitespace(title, TRIM_ALL, &final_title);
1447 explicit_set = true;
1448 }
1449
1450 if (final_title == UTF16ToWideHack(entry->title()))
1451 return false; // Nothing changed, don't bother.
1452
1453 entry->set_title(WideToUTF16Hack(final_title));
1454
1455 // Update the history system for this page.
1456 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1457 HistoryService* hs =
1458 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1459 if (hs)
[email protected]ebe89e062009-08-13 23:16:541460 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321461
1462 // Don't allow the title to be saved again for explicitly set ones.
1463 received_page_title_ = explicit_set;
1464 }
1465
1466 // Lastly, set the title for the view.
1467 view_->SetPageTitle(final_title);
1468
1469 return true;
1470}
1471
1472void TabContents::NotifySwapped() {
1473 // After sending out a swap notification, we need to send a disconnect
1474 // notification so that clients that pick up a pointer to |this| can NULL the
1475 // pointer. See Bug 1230284.
1476 notify_disconnection_ = true;
1477 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341478 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221479 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321480 NotificationService::NoDetails());
1481}
1482
1483void TabContents::NotifyConnected() {
1484 notify_disconnection_ = true;
1485 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341486 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221487 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321488 NotificationService::NoDetails());
1489}
1490
1491void TabContents::NotifyDisconnected() {
1492 if (!notify_disconnection_)
1493 return;
1494
1495 notify_disconnection_ = false;
1496 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341497 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221498 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321499 NotificationService::NoDetails());
1500}
1501
1502void TabContents::GenerateKeywordIfNecessary(
1503 const ViewHostMsg_FrameNavigate_Params& params) {
1504 if (!params.searchable_form_url.is_valid())
1505 return;
1506
1507 if (profile()->IsOffTheRecord())
1508 return;
1509
1510 int last_index = controller_.last_committed_entry_index();
1511 // When there was no previous page, the last index will be 0. This is
1512 // normally due to a form submit that opened in a new tab.
1513 // TODO(brettw) bug 916126: we should support keywords when form submits
1514 // happen in new tabs.
1515 if (last_index <= 0)
1516 return;
1517 const NavigationEntry* previous_entry =
1518 controller_.GetEntryAtIndex(last_index - 1);
1519 if (IsFormSubmit(previous_entry)) {
1520 // Only generate a keyword if the previous page wasn't itself a form
1521 // submit.
1522 return;
1523 }
1524
1525 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1526 previous_entry->user_typed_url() : previous_entry->url();
1527 std::wstring keyword =
1528 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1529 if (keyword.empty())
1530 return;
1531
1532 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1533 if (!url_model)
1534 return;
1535
1536 if (!url_model->loaded()) {
1537 url_model->Load();
1538 return;
1539 }
1540
1541 const TemplateURL* current_url;
1542 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1543 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1544 return;
1545
1546 if (current_url) {
1547 if (current_url->originating_url().is_valid()) {
1548 // The existing keyword was generated from an OpenSearch description
1549 // document, don't regenerate.
1550 return;
1551 }
1552 url_model->Remove(current_url);
1553 }
1554 TemplateURL* new_url = new TemplateURL();
1555 new_url->set_keyword(keyword);
1556 new_url->set_short_name(keyword);
1557 new_url->SetURL(url, 0, 0);
1558 new_url->add_input_encoding(params.searchable_form_encoding);
1559 DCHECK(controller_.GetLastCommittedEntry());
1560 const GURL& favicon_url =
1561 controller_.GetLastCommittedEntry()->favicon().url();
1562 if (favicon_url.is_valid()) {
1563 new_url->SetFavIconURL(favicon_url);
1564 } else {
1565 // The favicon url isn't valid. This means there really isn't a favicon,
1566 // or the favicon url wasn't obtained before the load started. This assumes
1567 // the later.
1568 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1569 // its url.
1570 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1571 }
1572 new_url->set_safe_for_autoreplace(true);
1573 url_model->Add(new_url);
1574}
1575
[email protected]bf5c2ff392009-07-08 16:24:331576void TabContents::OnUserGesture() {
1577 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1578 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1579 if (drm)
1580 drm->OnUserGesture(this);
1581 controller_.OnUserGesture();
1582}
1583
1584void TabContents::OnFindReply(int request_id,
1585 int number_of_matches,
1586 const gfx::Rect& selection_rect,
1587 int active_match_ordinal,
1588 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421589 // Ignore responses for requests that have been aborted.
1590 if (find_op_aborted_)
1591 return;
1592
[email protected]bf5c2ff392009-07-08 16:24:331593 // Ignore responses for requests other than the one we have most recently
1594 // issued. That way we won't act on stale results when the user has
1595 // already typed in another query.
1596 if (request_id != current_find_request_id_)
1597 return;
1598
1599 if (number_of_matches == -1)
1600 number_of_matches = last_search_result_.number_of_matches();
1601 if (active_match_ordinal == -1)
1602 active_match_ordinal = last_search_result_.active_match_ordinal();
1603
1604 gfx::Rect selection = selection_rect;
1605 if (selection.IsEmpty())
1606 selection = last_search_result_.selection_rect();
1607
1608 // Notify the UI, automation and any other observers that a find result was
1609 // found.
1610 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1611 selection, active_match_ordinal,
1612 final_update);
1613 NotificationService::current()->Notify(
1614 NotificationType::FIND_RESULT_AVAILABLE,
1615 Source<TabContents>(this),
1616 Details<FindNotificationDetails>(&last_search_result_));
1617}
1618
1619void TabContents::GoToEntryAtOffset(int offset) {
1620 controller_.GoToOffset(offset);
1621}
1622
1623void TabContents::GetHistoryListCount(int* back_list_count,
1624 int* forward_list_count) {
1625 int current_index = controller_.last_committed_entry_index();
1626 *back_list_count = current_index;
1627 *forward_list_count = controller_.entry_count() - current_index - 1;
1628}
1629
1630void TabContents::OnMissingPluginStatus(int status) {
1631#if defined(OS_WIN)
1632// TODO(PORT): pull in when plug-ins work
1633 GetPluginInstaller()->OnMissingPluginStatus(status);
1634#endif
1635}
1636
1637void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331638 DCHECK(!plugin_path.value().empty());
1639
1640 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351641#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331642 scoped_ptr<FileVersionInfo> version_info(
1643 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1644 if (version_info.get()) {
1645 const std::wstring& product_name = version_info->product_name();
1646 if (!product_name.empty())
1647 plugin_name = product_name;
1648 }
[email protected]4a560ed2009-07-13 23:35:261649#else
1650 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1651#endif
[email protected]bf5c2ff392009-07-08 16:24:331652 AddInfoBar(new SimpleAlertInfoBarDelegate(
1653 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
1654 NULL));
[email protected]bf5c2ff392009-07-08 16:24:331655}
1656
1657void TabContents::OnCrashedWorker() {
1658 AddInfoBar(new SimpleAlertInfoBarDelegate(
1659 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
1660 NULL));
1661}
1662
1663void TabContents::OnDidGetApplicationInfo(
1664 int32 page_id,
1665 const webkit_glue::WebApplicationInfo& info) {
1666 if (pending_install_.page_id != page_id)
1667 return; // The user clicked create on a separate page. Ignore this.
1668
1669 pending_install_.callback_functor =
1670 new GearsCreateShortcutCallbackFunctor(this);
1671 GearsCreateShortcut(
1672 info, pending_install_.title, pending_install_.url, pending_install_.icon,
1673 NewCallback(pending_install_.callback_functor,
1674 &GearsCreateShortcutCallbackFunctor::Run));
1675}
1676
1677void TabContents::DidStartProvisionalLoadForFrame(
1678 RenderViewHost* render_view_host,
1679 bool is_main_frame,
1680 const GURL& url) {
1681 ProvisionalLoadDetails details(is_main_frame,
1682 controller_.IsURLInPageNavigation(url),
1683 url, std::string(), false);
1684 NotificationService::current()->Notify(
1685 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1686 Source<NavigationController>(&controller_),
1687 Details<ProvisionalLoadDetails>(&details));
1688}
1689
1690void TabContents::DidStartReceivingResourceResponse(
1691 ResourceRequestDetails* details) {
1692 NotificationService::current()->Notify(
1693 NotificationType::RESOURCE_RESPONSE_STARTED,
1694 Source<NavigationController>(&controller()),
1695 Details<ResourceRequestDetails>(details));
1696}
1697
1698void TabContents::DidRedirectResource(ResourceRequestDetails* details) {
1699 NotificationService::current()->Notify(
1700 NotificationType::RESOURCE_RECEIVED_REDIRECT,
1701 Source<NavigationController>(&controller()),
1702 Details<ResourceRequestDetails>(details));
1703}
1704
1705void TabContents::DidLoadResourceFromMemoryCache(
1706 const GURL& url,
1707 const std::string& frame_origin,
1708 const std::string& main_frame_origin,
1709 const std::string& security_info) {
1710 // Send out a notification that we loaded a resource from our memory cache.
1711 int cert_id = 0, cert_status = 0, security_bits = 0;
1712 SSLManager::DeserializeSecurityInfo(security_info,
1713 &cert_id, &cert_status,
1714 &security_bits);
1715 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
1716 process()->pid(), cert_id, cert_status);
1717
1718 NotificationService::current()->Notify(
1719 NotificationType::LOAD_FROM_MEMORY_CACHE,
1720 Source<NavigationController>(&controller_),
1721 Details<LoadFromMemoryCacheDetails>(&details));
1722}
1723
1724void TabContents::DidFailProvisionalLoadWithError(
1725 RenderViewHost* render_view_host,
1726 bool is_main_frame,
1727 int error_code,
1728 const GURL& url,
1729 bool showing_repost_interstitial) {
1730 if (net::ERR_ABORTED == error_code) {
1731 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1732 // This means that the interstitial won't be torn down properly, which is
1733 // bad. But if we have an interstitial, go back to another tab type, and
1734 // then load the same interstitial again, we could end up getting the first
1735 // interstitial's "failed" message (as a result of the cancel) when we're on
1736 // the second one.
1737 //
1738 // We can't tell this apart, so we think we're tearing down the current page
1739 // which will cause a crash later one. There is also some code in
1740 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1741 // out because of this problem.
1742 //
1743 // http://code.google.com/p/chromium/issues/detail?id=2855
1744 // Because this will not tear down the interstitial properly, if "back" is
1745 // back to another tab type, the interstitial will still be somewhat alive
1746 // in the previous tab type. If you navigate somewhere that activates the
1747 // tab with the interstitial again, you'll see a flash before the new load
1748 // commits of the interstitial page.
1749 if (showing_interstitial_page()) {
1750 LOG(WARNING) << "Discarding message during interstitial.";
1751 return;
1752 }
1753
1754 // This will discard our pending entry if we cancelled the load (e.g., if we
1755 // decided to download the file instead of load it). Only discard the
1756 // pending entry if the URLs match, otherwise the user initiated a navigate
1757 // before the page loaded so that the discard would discard the wrong entry.
1758 NavigationEntry* pending_entry = controller_.pending_entry();
1759 if (pending_entry && pending_entry->url() == url) {
1760 controller_.DiscardNonCommittedEntries();
1761 // Update the URL display.
1762 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1763 }
1764
1765 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
1766 }
1767
1768 // Send out a notification that we failed a provisional load with an error.
1769 ProvisionalLoadDetails details(is_main_frame,
1770 controller_.IsURLInPageNavigation(url),
1771 url, std::string(), false);
1772 details.set_error_code(error_code);
1773
1774 NotificationService::current()->Notify(
1775 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1776 Source<NavigationController>(&controller_),
1777 Details<ProvisionalLoadDetails>(&details));
1778}
1779
1780void TabContents::DocumentLoadedInFrame() {
1781 controller_.DocumentLoadedInFrame();
1782}
1783
[email protected]8d3347f2009-07-09 22:00:211784RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321785 return view_.get();
1786}
1787
[email protected]8d3347f2009-07-09 22:00:211788RenderViewHostDelegate::RendererManagement*
1789TabContents::GetRendererManagementDelegate() {
1790 return &render_manager_;
1791}
1792
[email protected]bf5c2ff392009-07-08 16:24:331793RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:211794 TabContents::GetBrowserIntegrationDelegate() {
1795 return this;
[email protected]bf5c2ff392009-07-08 16:24:331796}
1797
[email protected]8d3347f2009-07-09 22:00:211798RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
1799 return this;
[email protected]bf5c2ff392009-07-08 16:24:331800}
1801
[email protected]8d3347f2009-07-09 22:00:211802RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:321803 return save_package_.get(); // May be NULL, but we can return NULL.
1804}
1805
[email protected]8d3347f2009-07-09 22:00:211806RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
1807 return &printing_;
1808}
1809
1810RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
1811 return &fav_icon_helper_;
1812}
1813
1814RenderViewHostDelegate::Autofill* TabContents::GetAutofillDelegate() {
1815 if (autofill_manager_.get() == NULL)
1816 autofill_manager_.reset(new AutofillManager(this));
1817 return autofill_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:331818}
1819
[email protected]80d96fa2009-06-10 22:34:511820RendererPreferences TabContents::GetRendererPrefs() const {
[email protected]840b1512009-07-21 16:53:461821 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511822}
1823
[email protected]57c6a652009-05-04 07:58:341824TabContents* TabContents::GetAsTabContents() {
1825 return this;
1826}
1827
[email protected]3e7cf1362009-08-21 17:47:081828void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
1829 CreateBlockedPopupContainerIfNecessary();
1830 blocked_popups_->AddBlockedNotice(url, reason);
1831}
1832
[email protected]7b291f92009-08-14 05:43:531833ViewType::Type TabContents::GetRenderViewType() const {
1834 return ViewType::TAB_CONTENTS;
1835}
1836
1837int TabContents::GetBrowserWindowID() const {
1838 return controller().window_id().id();
1839}
1840
[email protected]420ae012009-04-24 05:16:321841void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061842 NotificationService::current()->Notify(
1843 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1844 Source<TabContents>(this),
1845 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321846 NavigationEntry* entry = controller_.GetActiveEntry();
1847 if (!entry)
1848 return;
1849
1850 // When we're creating views, we're still doing initial setup, so we always
1851 // use the pending DOM UI rather than any possibly existing committed one.
1852 if (render_manager_.pending_dom_ui()) {
1853 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
1854 }
1855
1856 if (entry->IsViewSourceMode()) {
1857 // Put the renderer in view source mode.
1858 render_view_host->Send(
1859 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1860 }
[email protected]0666aef2009-05-13 19:48:081861
1862 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321863}
1864
1865void TabContents::RenderViewReady(RenderViewHost* rvh) {
1866 if (rvh != render_view_host()) {
1867 // Don't notify the world, since this came from a renderer in the
1868 // background.
1869 return;
1870 }
1871
1872 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301873 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:321874 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:301875
1876 // Restore the focus to the tab (otherwise the focus will be on the top
1877 // window).
1878 if (was_crashed && !FocusLocationBarByDefault())
1879 Focus();
[email protected]420ae012009-04-24 05:16:321880}
1881
1882void TabContents::RenderViewGone(RenderViewHost* rvh) {
1883 // Ask the print preview if this renderer was valuable.
1884 if (!printing_.OnRenderViewGone(rvh))
1885 return;
1886 if (rvh != render_view_host()) {
1887 // The pending page's RenderViewHost is gone.
1888 return;
1889 }
1890
1891 SetIsLoading(false, NULL);
1892 NotifyDisconnected();
1893 SetIsCrashed(true);
1894
[email protected]8e537302009-06-10 21:19:581895 // Tell the view that we've crashed so it can prepare the sad tab page.
1896 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:321897
1898 // Hide any visible hung renderer warning for this web contents' process.
[email protected]d82ed61e2009-06-16 02:46:221899 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:321900}
1901
[email protected]2e4633c2009-07-09 16:58:061902void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
1903 NotificationService::current()->Notify(
1904 NotificationType::RENDER_VIEW_HOST_DELETED,
1905 Source<TabContents>(this),
1906 Details<RenderViewHost>(rvh));
1907}
1908
[email protected]420ae012009-04-24 05:16:321909void TabContents::DidNavigate(RenderViewHost* rvh,
1910 const ViewHostMsg_FrameNavigate_Params& params) {
1911 if (PageTransition::IsMainFrame(params.transition))
1912 render_manager_.DidNavigateMainFrame(rvh);
1913
1914 // Update the site of the SiteInstance if it doesn't have one yet.
1915 if (!GetSiteInstance()->has_site())
1916 GetSiteInstance()->SetSite(params.url);
1917
1918 // Need to update MIME type here because it's referred to in
1919 // UpdateNavigationCommands() called by RendererDidNavigate() to
1920 // determine whether or not to enable the encoding menu.
1921 // It's updated only for the main frame. For a subframe,
1922 // RenderView::UpdateURL does not set params.contents_mime_type.
1923 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1924 // TODO(jungshik): Add a test for the encoding menu to avoid
1925 // regressing it again.
1926 if (PageTransition::IsMainFrame(params.transition))
1927 contents_mime_type_ = params.contents_mime_type;
1928
1929 NavigationController::LoadCommittedDetails details;
[email protected]3e90d4a2009-07-03 17:38:391930 bool did_navigate = controller_.RendererDidNavigate(params, &details);
1931
1932 // Update history. Note that this needs to happen after the entry is complete,
1933 // which WillNavigate[Main,Sub]Frame will do before this function is called.
1934 if (params.should_update_history) {
1935 // Most of the time, the displayURL matches the loaded URL, but for about:
1936 // URLs, we use a data: URL as the real value. We actually want to save
1937 // the about: URL to the history db and keep the data: URL hidden. This is
1938 // what the TabContents' URL getter does.
1939 UpdateHistoryForNavigation(GetURL(), details, params);
1940 }
1941
1942 if (!did_navigate)
1943 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321944
1945 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1946 // for the appropriate notification (best) or you can add it to
1947 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1948 // necessary, please).
1949
1950 // Run post-commit tasks.
1951 if (details.is_main_frame)
1952 DidNavigateMainFramePostCommit(details, params);
1953 DidNavigateAnyFramePostCommit(rvh, details, params);
1954}
1955
1956void TabContents::UpdateState(RenderViewHost* rvh,
1957 int32 page_id,
1958 const std::string& state) {
1959 DCHECK(rvh == render_view_host());
1960
1961 // We must be prepared to handle state updates for any page, these occur
1962 // when the user is scrolling and entering form data, as well as when we're
1963 // leaving a page, in which case our state may have already been moved to
1964 // the next page. The navigation controller will look up the appropriate
1965 // NavigationEntry and update it when it is notified via the delegate.
1966
1967 int entry_index = controller_.GetEntryIndexWithPageID(
1968 GetSiteInstance(), page_id);
1969 if (entry_index < 0)
1970 return;
1971 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1972
1973 if (state == entry->content_state())
1974 return; // Nothing to update.
1975 entry->set_content_state(state);
1976 controller_.NotifyEntryChanged(entry, entry_index);
1977}
1978
1979void TabContents::UpdateTitle(RenderViewHost* rvh,
1980 int32 page_id, const std::wstring& title) {
1981 // If we have a title, that's a pretty good indication that we've started
1982 // getting useful data.
1983 SetNotWaitingForResponse();
1984
1985 DCHECK(rvh == render_view_host());
1986 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
1987 page_id);
1988 if (!entry || !UpdateTitleForEntry(entry, title))
1989 return;
1990
1991 // Broadcast notifications when the UI should be updated.
1992 if (entry == controller_.GetEntryAtOffset(0))
[email protected]c9cd2222009-05-06 05:16:501993 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321994}
1995
[email protected]420ae012009-04-24 05:16:321996void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
1997 const std::wstring& encoding) {
1998 set_encoding(encoding);
1999}
2000
2001void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2002 if (delegate())
2003 delegate()->UpdateTargetURL(this, url);
2004}
2005
2006void TabContents::UpdateThumbnail(const GURL& url,
2007 const SkBitmap& bitmap,
2008 const ThumbnailScore& score) {
2009 // Tell History about this thumbnail
[email protected]449478302009-06-09 20:04:282010 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
[email protected]72d0fc72009-07-09 17:30:492011 if (!profile()->IsOffTheRecord())
[email protected]42339402009-07-17 17:27:192012 profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
2013 score, true);
[email protected]449478302009-06-09 20:04:282014 } else {
2015 HistoryService* hs;
2016 if (!profile()->IsOffTheRecord() &&
2017 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2018 hs->SetPageThumbnail(url, bitmap, score);
2019 }
[email protected]420ae012009-04-24 05:16:322020 }
2021}
2022
[email protected]0df30122009-06-03 12:13:082023void TabContents::UpdateInspectorSettings(const std::wstring& raw_settings) {
2024 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
2025 raw_settings);
2026}
2027
[email protected]420ae012009-04-24 05:16:322028void TabContents::Close(RenderViewHost* rvh) {
[email protected]24a4d1062009-07-10 23:10:422029 // If we close the tab while we're in the middle of a drag, we'll crash.
2030 // Instead, cancel the drag and close it as soon as the drag ends.
2031 if (view()->IsDoingDrag()) {
2032 view()->CancelDragAndCloseTab();
2033 return;
2034 }
2035
[email protected]420ae012009-04-24 05:16:322036 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2037 if (delegate() && rvh == render_view_host())
2038 delegate()->CloseContents(this);
2039}
2040
2041void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2042 if (delegate() && delegate()->IsPopup(this))
2043 delegate()->MoveContents(this, new_bounds);
2044}
2045
[email protected]329581b2009-04-28 06:52:352046void TabContents::DidStartLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322047 SetIsLoading(true, NULL);
2048}
2049
[email protected]329581b2009-04-28 06:52:352050void TabContents::DidStopLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322051 scoped_ptr<LoadNotificationDetails> details;
2052
2053 NavigationEntry* entry = controller_.GetActiveEntry();
2054 // An entry may not exist for a stop when loading an initial blank page or
2055 // if an iframe injected by script into a blank page finishes loading.
2056 if (entry) {
2057 scoped_ptr<base::ProcessMetrics> metrics(
2058 base::ProcessMetrics::CreateProcessMetrics(
2059 process()->process().handle()));
2060
2061 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2062
2063 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542064 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322065 entry->transition_type(),
2066 elapsed,
2067 &controller_,
2068 controller_.GetCurrentEntryIndex()));
2069 }
2070
2071 // Tell PasswordManager we've finished a page load, which serves as a
2072 // green light to save pending passwords and reset itself.
2073 GetPasswordManager()->DidStopLoading();
2074
2075 SetIsLoading(false, details.get());
2076}
2077
[email protected]420ae012009-04-24 05:16:322078void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2079 const GURL& source_url,
2080 const GURL& target_url) {
2081 NavigationEntry* entry;
2082 if (page_id == -1)
2083 entry = controller_.pending_entry();
2084 else
2085 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2086 if (!entry || entry->url() != source_url)
2087 return;
2088 entry->set_url(target_url);
2089}
2090
[email protected]420ae012009-04-24 05:16:322091void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2092 WindowOpenDisposition disposition) {
2093 if (render_manager_.dom_ui()) {
2094 // When we're a DOM UI, it will provide a page transition type for us (this
2095 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2096 // generated suggestions).
2097 //
2098 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162099 // want web sites to see a referrer of "chrome://blah" (and some
2100 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322101 // send to the site), so we send no referrer.
2102 OpenURL(url, GURL(), disposition,
2103 render_manager_.dom_ui()->link_transition_type());
2104 } else {
2105 OpenURL(url, referrer, disposition, PageTransition::LINK);
2106 }
2107}
2108
[email protected]1ee614862009-07-06 20:29:182109void TabContents::DomOperationResponse(const std::string& json_string,
2110 int automation_id) {
2111}
2112
[email protected]420ae012009-04-24 05:16:322113void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]811bfe32009-07-01 08:46:252114 const std::string& content,
2115 int request_id,
2116 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322117 if (!render_manager_.dom_ui()) {
2118 // We shouldn't get a DOM UI message when we haven't enabled the DOM UI.
2119 // Because the renderer might be owned and sending random messages, we need
2120 // to ignore these inproper ones.
2121 NOTREACHED();
2122 return;
2123 }
[email protected]811bfe32009-07-01 08:46:252124 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, request_id,
2125 has_callback);
[email protected]420ae012009-04-24 05:16:322126}
2127
2128void TabContents::ProcessExternalHostMessage(const std::string& message,
2129 const std::string& origin,
2130 const std::string& target) {
2131 if (delegate())
2132 delegate()->ForwardMessageToExternalHost(message, origin, target);
2133}
2134
[email protected]420ae012009-04-24 05:16:322135void TabContents::RunFileChooser(bool multiple_files,
2136 const string16& title,
2137 const FilePath& default_file) {
2138 if (!select_file_dialog_.get())
2139 select_file_dialog_ = SelectFileDialog::Create(this);
2140 SelectFileDialog::Type dialog_type =
2141 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE :
2142 SelectFileDialog::SELECT_OPEN_FILE;
2143 select_file_dialog_->SelectFile(dialog_type, title, default_file,
2144 NULL, 0, FILE_PATH_LITERAL(""),
2145 view_->GetTopLevelNativeWindow(), NULL);
2146}
2147
2148void TabContents::RunJavaScriptMessage(
2149 const std::wstring& message,
2150 const std::wstring& default_prompt,
2151 const GURL& frame_url,
2152 const int flags,
2153 IPC::Message* reply_msg,
2154 bool* did_suppress_message) {
2155 // Suppress javascript messages when requested and when inside a constrained
2156 // popup window (because that activates them and breaks them out of the
2157 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552158 // Also suppress messages when showing an interstitial. The interstitial is
2159 // shown over the previous page, we don't want the hidden page dialogs to
2160 // interfere with the interstitial.
2161 bool suppress_this_message = suppress_javascript_messages_ ||
2162 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322163 if (delegate())
2164 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312165 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322166
2167 *did_suppress_message = suppress_this_message;
2168
2169 if (!suppress_this_message) {
2170 base::TimeDelta time_since_last_message(
2171 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2172 bool show_suppress_checkbox = false;
2173 // Show a checkbox offering to suppress further messages if this message is
2174 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2175 if (time_since_last_message <
2176 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2177 show_suppress_checkbox = true;
2178
[email protected]d82ed61e2009-06-16 02:46:222179 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322180 show_suppress_checkbox, reply_msg);
2181 } else {
2182 // If we are suppressing messages, just reply as is if the user immediately
2183 // pressed "Cancel".
2184 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring());
2185 }
2186}
2187
2188void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2189 IPC::Message* reply_msg) {
[email protected]d82ed61e2009-06-16 02:46:222190 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322191}
2192
2193void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2194 const std::string& json_arguments,
2195 IPC::Message* reply_msg) {
2196 if (delegate()) {
2197 HtmlDialogUIDelegate* dialog_delegate =
2198 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222199 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322200 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2201 }
2202}
2203
2204void TabContents::PasswordFormsSeen(
[email protected]ed3fb032009-06-16 19:50:562205 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]420ae012009-04-24 05:16:322206 GetPasswordManager()->PasswordFormsSeen(forms);
2207}
2208
[email protected]420ae012009-04-24 05:16:322209// Checks to see if we should generate a keyword based on the OSDD, and if
2210// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2211void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2212 int32 page_id, const GURL& url,
2213 bool autodetected) {
2214 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2215 DCHECK(url.is_valid());
2216 if (!IsActiveEntry(page_id))
2217 return;
2218 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2219 if (!url_model)
2220 return;
2221 if (!url_model->loaded()) {
2222 url_model->Load();
2223 return;
2224 }
2225 if (!profile()->GetTemplateURLFetcher())
2226 return;
2227
2228 if (profile()->IsOffTheRecord())
2229 return;
2230
2231 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2232 DCHECK(entry);
2233
2234 const NavigationEntry* base_entry = entry;
2235 if (IsFormSubmit(base_entry)) {
2236 // If the current page is a form submit, find the last page that was not
2237 // a form submit and use its url to generate the keyword from.
2238 int index = controller_.last_committed_entry_index() - 1;
2239 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2240 index--;
2241 if (index >= 0)
2242 base_entry = controller_.GetEntryAtIndex(index);
2243 else
2244 base_entry = NULL;
2245 }
2246
2247 // We want to use the user typed URL if available since that represents what
2248 // the user typed to get here, and fall back on the regular URL if not.
2249 if (!base_entry)
2250 return;
2251 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2252 base_entry->user_typed_url() : base_entry->url();
2253 if (!keyword_url.is_valid())
2254 return;
2255 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2256 autodetected);
2257 if (keyword.empty())
2258 return;
2259 const TemplateURL* template_url =
2260 url_model->GetTemplateURLForKeyword(keyword);
2261 if (template_url && (!template_url->safe_for_autoreplace() ||
2262 template_url->originating_url() == url)) {
2263 // Either there is a user created TemplateURL for this keyword, or the
2264 // keyword has the same OSDD url and we've parsed it.
2265 return;
2266 }
2267
2268 // Download the OpenSearch description document. If this is successful a
2269 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322270 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2271 keyword,
2272 url,
2273 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162274 this,
[email protected]420ae012009-04-24 05:16:322275 autodetected);
2276}
2277
[email protected]420ae012009-04-24 05:16:322278GURL TabContents::GetAlternateErrorPageURL() const {
2279 GURL url;
2280 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2281 if (profile()->IsOffTheRecord())
2282 return url;
2283
2284 PrefService* prefs = profile()->GetPrefs();
2285 DCHECK(prefs);
2286 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]2bd6ca1c2009-08-27 16:42:202287 url = google_util::AppendGoogleLocaleParam(GURL(kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322288 url = google_util::AppendGoogleTLDParam(url);
2289 }
2290 return url;
2291}
2292
2293WebPreferences TabContents::GetWebkitPrefs() {
2294 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
[email protected]7ccddb8c2009-08-04 17:36:552295 bool is_dom_ui = false;
2296 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322297}
2298
[email protected]420ae012009-04-24 05:16:322299void TabContents::OnJSOutOfMemory() {
2300 AddInfoBar(new SimpleAlertInfoBarDelegate(
2301 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL));
2302}
2303
[email protected]420ae012009-04-24 05:16:322304void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2305 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342306 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322307 // delivered to a pending RenderViewHost. We must first run the onunload
2308 // handler of the old RenderViewHost before we can allow it to proceed.
2309 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2310 new_request_id);
2311}
2312
2313bool TabContents::CanBlur() const {
2314 return delegate() ? delegate()->CanBlur() : true;
2315}
2316
2317gfx::Rect TabContents::GetRootWindowResizerRect() const {
2318 if (delegate())
2319 return delegate()->GetRootWindowResizerRect();
2320 return gfx::Rect();
2321}
2322
2323void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2324 bool is_during_unload) {
2325 if (is_during_unload) {
2326 // Hang occurred while firing the beforeunload/unload handler.
2327 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112328 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322329
2330 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2331 return;
2332
2333 // If the tab hangs in the beforeunload/unload handler there's really
2334 // nothing we can do to recover. Pretend the unload listeners have
2335 // all fired and close the tab. If the hang is in the beforeunload handler
2336 // then the user will not have the option of cancelling the close.
2337 Close(rvh);
2338 return;
2339 }
2340
2341 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]d82ed61e2009-06-16 02:46:222342 HungRendererDialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322343}
2344
2345void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]d82ed61e2009-06-16 02:46:222346 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322347}
2348
2349void TabContents::LoadStateChanged(const GURL& url,
2350 net::LoadState load_state) {
2351 load_state_ = load_state;
[email protected]d686e812009-06-03 19:10:292352 std::wstring languages =
2353 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
2354 load_state_host_.clear();
2355 std::string host = url.host();
2356 net::IDNToUnicode(host.c_str(), host.size(), languages, &load_state_host_);
[email protected]420ae012009-04-24 05:16:322357 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2358 SetNotWaitingForResponse();
2359 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502360 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322361}
2362
[email protected]1ee614862009-07-06 20:29:182363bool TabContents::IsExternalTabContainer() const {
2364 if (!delegate())
2365 return false;
2366
2367 return delegate()->IsExternalTabContainer();
2368}
2369
[email protected]1ee614862009-07-06 20:29:182370void TabContents::DidInsertCSS() {
2371 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322372}
2373
2374void TabContents::FileSelected(const FilePath& path,
2375 int index, void* params) {
2376 render_view_host()->FileSelected(path);
2377}
2378
2379void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2380 void* params) {
2381 render_view_host()->MultiFilesSelected(files);
2382}
2383
2384void TabContents::FileSelectionCanceled(void* params) {
2385 // If the user cancels choosing a file to upload we pass back an
2386 // empty vector.
2387 render_view_host()->MultiFilesSelected(std::vector<FilePath>());
2388}
2389
2390void TabContents::BeforeUnloadFiredFromRenderManager(
2391 bool proceed,
2392 bool* proceed_to_fire_unload) {
2393 if (delegate())
2394 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2395}
2396
2397void TabContents::UpdateRenderViewSizeForRenderManager() {
2398 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
2399 view_->SizeContents(view_->GetContainerSize());
2400}
2401
2402DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222403 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322404}
2405
2406NavigationEntry*
2407TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2408 return controller_.GetLastCommittedEntry();
2409}
2410
2411bool TabContents::CreateRenderViewForRenderManager(
2412 RenderViewHost* render_view_host) {
[email protected]811bfe32009-07-01 08:46:252413 // If the pending navigation is to a DOMUI, tell the RenderView about any
2414 // bindings it will need enabled.
[email protected]420ae012009-04-24 05:16:322415 if (render_manager_.pending_dom_ui())
[email protected]811bfe32009-07-01 08:46:252416 render_view_host->AllowBindings(
2417 render_manager_.pending_dom_ui()->bindings());
[email protected]1adff062009-06-02 18:39:552418
[email protected]420ae012009-04-24 05:16:322419 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
2420 if (!render_view_host->CreateRenderView())
2421 return false;
2422
2423 // Now that the RenderView has been created, we need to tell it its size.
2424 rwh_view->SetSize(view_->GetContainerSize());
2425
2426 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2427 render_view_host);
2428 return true;
2429}
2430
2431void TabContents::Observe(NotificationType type,
2432 const NotificationSource& source,
2433 const NotificationDetails& details) {
2434 switch (type.value) {
2435 case NotificationType::BOOKMARK_MODEL_LOADED:
2436 // BookmarkModel finished loading, fall through to update starred state.
2437 case NotificationType::URLS_STARRED: {
2438 // Somewhere, a URL has been starred.
2439 // Ignore notifications for profiles other than our current one.
2440 Profile* source_profile = Source<Profile>(source).ptr();
2441 if (!source_profile || !source_profile->IsSameProfile(profile()))
2442 return;
2443
2444 UpdateStarredStateForCurrentURL();
2445 break;
2446 }
2447 case NotificationType::PREF_CHANGED: {
2448 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2449 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2450 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2451 UpdateAlternateErrorPageURL();
2452 } else if (*pref_name_in == prefs::kDefaultCharset ||
2453 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2454 ) {
2455 UpdateWebPreferences();
2456 } else {
2457 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2458 }
2459 break;
2460 }
2461 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2462 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2463 break;
2464
2465 case NotificationType::NAV_ENTRY_COMMITTED: {
2466 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2467
2468 NavigationController::LoadCommittedDetails& committed_details =
2469 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2470 ExpireInfoBars(committed_details);
2471 break;
2472 }
2473
2474 default:
2475 NOTREACHED();
2476 }
2477}