blob: cfdde6c39915ed991a7175b2b8857ee5bb8afd26 [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);
[email protected]789e9152009-08-04 21:59:43610 if (render_widget_host_view()) {
[email protected]96d185d2009-04-24 03:28:54611 render_widget_host_view()->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43612#if defined(OS_MACOSX)
613 render_widget_host_view()->SetActive(true);
614#endif
615 }
[email protected]96d185d2009-04-24 03:28:54616
[email protected]76543b92009-08-31 17:27:45617 WebCacheManager::GetInstance()->ObserveActivity(process()->id());
[email protected]96d185d2009-04-24 03:28:54618}
619
620void TabContents::WasHidden() {
621 if (!capturing_contents()) {
622 // |render_view_host()| can be NULL if the user middle clicks a link to open
623 // a tab in then background, then closes the tab before selecting it. This
624 // is because closing the tab calls TabContents::Destroy(), which removes
625 // the |render_view_host()|; then when we actually destroy the window,
626 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
627 if (render_widget_host_view())
628 render_widget_host_view()->WasHidden();
[email protected]96d185d2009-04-24 03:28:54629 }
630
631 NotificationService::current()->Notify(
632 NotificationType::TAB_CONTENTS_HIDDEN,
633 Source<TabContents>(this),
634 NotificationService::NoDetails());
635}
636
[email protected]d5f942ba2008-09-26 19:30:34637void TabContents::Activate() {
638 if (delegate_)
639 delegate_->ActivateContents(this);
640}
641
[email protected]96d185d2009-04-24 03:28:54642void TabContents::ShowContents() {
643 if (render_widget_host_view())
644 render_widget_host_view()->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54645}
646
647void TabContents::HideContents() {
648 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
649 // our superclass HideContents(), because some callers want to be very picky
650 // about the order in which these get called. In addition to making the code
651 // here practically impossible to understand, this also means we end up
652 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34653 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54654 WasHidden();
655}
656
[email protected]c0588052008-10-27 23:01:50657void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34658 WindowOpenDisposition disposition,
659 PageTransition::Type transition) {
660 if (delegate_)
[email protected]c0588052008-10-27 23:01:50661 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34662}
663
664bool TabContents::NavigateToPendingEntry(bool reload) {
[email protected]96d185d2009-04-24 03:28:54665 const NavigationEntry& entry = *controller_.pending_entry();
666
667 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
668 if (!dest_render_view_host)
669 return false; // Unable to create the desired render view host.
670
671 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12672 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32673 if (devtools_manager) { // NULL in unit tests.
[email protected]684b4ba22009-05-07 06:27:41674 devtools_manager->OnNavigatingToPendingEntry(
675 render_view_host(),
676 dest_render_view_host,
677 controller_.pending_entry()->url());
[email protected]7e8e6b62009-05-08 11:28:32678 }
[email protected]96d185d2009-04-24 03:28:54679
680 // Used for page load time metrics.
681 current_load_start_ = base::TimeTicks::Now();
682
683 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34684 ViewMsg_Navigate_Params navigate_params;
685 MakeNavigateParams(entry, reload, &navigate_params);
686 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54687
688 if (entry.page_id() == -1) {
689 // HACK!! This code suppresses javascript: URLs from being added to
690 // session history, which is what we want to do for javascript: URLs that
691 // do not generate content. What we really need is a message from the
692 // renderer telling us that a new page was not created. The same message
693 // could be used for mailto: URLs and the like.
694 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
695 return false;
696 }
697
698 // Clear any provisional password saves - this stops password infobars
699 // showing up on pages the user navigates to while the right page is
700 // loading.
701 GetPasswordManager()->ClearProvisionalSave();
702
703 if (reload && !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48704 FaviconService* favicon_service =
705 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
706 if (favicon_service)
707 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54708 }
709
[email protected]d5f942ba2008-09-26 19:30:34710 return true;
711}
712
[email protected]96d185d2009-04-24 03:28:54713void TabContents::Stop() {
714 render_manager_.Stop();
715 printing_.Stop();
716}
717
718void TabContents::Cut() {
719 render_view_host()->Cut();
720}
721
722void TabContents::Copy() {
723 render_view_host()->Copy();
724}
725
726void TabContents::Paste() {
727 render_view_host()->Paste();
728}
729
730void TabContents::DisassociateFromPopupCount() {
731 render_view_host()->DisassociateFromPopupCount();
732}
733
734TabContents* TabContents::Clone() {
735 // We create a new SiteInstance so that the new tab won't share processes
736 // with the old one. This can be changed in the future if we need it to share
737 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32738 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54739 SiteInstance::CreateSiteInstance(profile()),
740 MSG_ROUTING_NONE, NULL);
741 tc->controller().CopyStateFrom(controller_);
742 return tc;
743}
744
[email protected]420ae012009-04-24 05:16:32745void TabContents::CreateShortcut() {
746 NavigationEntry* entry = controller_.GetLastCommittedEntry();
747 if (!entry)
748 return;
749
[email protected]70b8d6b2009-08-20 16:56:24750#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]0ba5c5e2009-08-20 16:47:13751 CreateApplicationShortcutsDialogGtk::Show(view()->GetTopLevelNativeWindow(),
752 GetURL(), GetTitle());
[email protected]b96aa932009-08-12 21:34:49753#else
[email protected]420ae012009-04-24 05:16:32754 // We only allow one pending install request. By resetting the page id we
755 // effectively cancel the pending install request.
756 pending_install_.page_id = entry->page_id();
757 pending_install_.icon = GetFavIcon();
758 pending_install_.title = UTF16ToWideHack(GetTitle());
759 pending_install_.url = GetURL();
760 if (pending_install_.callback_functor) {
761 pending_install_.callback_functor->Cancel();
762 pending_install_.callback_functor = NULL;
763 }
764 DCHECK(!pending_install_.icon.isNull()) << "Menu item should be disabled.";
765 if (pending_install_.title.empty())
766 pending_install_.title = UTF8ToWide(GetURL().spec());
767
768 // Request the application info. When done OnDidGetApplicationInfo is invoked
769 // and we'll create the shortcut.
770 render_view_host()->GetApplicationInfo(pending_install_.page_id);
[email protected]b96aa932009-08-12 21:34:49771#endif
[email protected]420ae012009-04-24 05:16:32772}
773
[email protected]4d677202009-07-19 07:37:12774void TabContents::ShowPageInfo(const GURL& url,
775 const NavigationEntry::SSLStatus& ssl,
776 bool show_history) {
777 if (!delegate_)
778 return;
779
[email protected]bb678332009-07-21 00:15:50780 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12781}
782
initial.commit09911bf2008-07-26 23:55:29783ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28784 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29785 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28786 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29787 child_windows_.push_back(window);
788 return window;
789}
790
791void TabContents::AddNewContents(TabContents* new_contents,
792 WindowOpenDisposition disposition,
793 const gfx::Rect& initial_pos,
[email protected]c88a70fe2009-05-05 20:00:22794 bool user_gesture,
795 const GURL& creator_url) {
initial.commit09911bf2008-07-26 23:55:29796 if (!delegate_)
797 return;
798
[email protected]35f7d212009-04-29 21:19:27799 if ((disposition == NEW_POPUP) && !user_gesture &&
800 !CommandLine::ForCurrentProcess()->HasSwitch(
801 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22802 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31803 // the whitelist. The popup owner will handle checking this.
804 delegate_->GetConstrainingContents(this)->AddPopup(new_contents,
805 initial_pos,
806 creator_url.is_valid() ? creator_url.host() : std::string());
807 } else {
[email protected]304f8792009-08-19 21:28:09808#if defined(OS_CHROMEOS)
809 if (disposition == NEW_POPUP) {
810 // If the popup is bigger than a given factor of the screen, then
811 // turn it into a foreground tab (on chrome os only)
812 GdkScreen* screen = gdk_screen_get_default();
813 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
814 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
815 if (initial_pos.width() > max_width ||
816 initial_pos.height() > max_height) {
817 disposition = NEW_FOREGROUND_TAB;
818 }
819 }
820#endif
821
[email protected]0aa55312008-10-17 21:53:08822 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29823 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
824 user_gesture);
825 }
[email protected]b6c874582009-05-08 19:38:31826 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29827}
828
initial.commit09911bf2008-07-26 23:55:29829void TabContents::CloseAllSuppressedPopups() {
[email protected]d6598c052008-11-05 19:03:25830 if (blocked_popups_)
[email protected]2c4410d2009-05-06 23:46:22831 blocked_popups_->CloseAll();
initial.commit09911bf2008-07-26 23:55:29832}
833
[email protected]96d185d2009-04-24 03:28:54834void TabContents::PopupNotificationVisibilityChanged(bool visible) {
835 render_view_host()->PopupNotificationVisibilityChanged(visible);
836}
837
838gfx::NativeView TabContents::GetContentNativeView() {
839 return view_->GetContentNativeView();
840}
841
842gfx::NativeView TabContents::GetNativeView() const {
843 return view_->GetNativeView();
844}
845
846void TabContents::GetContainerBounds(gfx::Rect *out) const {
847 view_->GetContainerBounds(out);
848}
849
850void TabContents::Focus() {
851 view_->Focus();
852}
853
[email protected]90daadb42009-06-08 21:27:28854void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54855 if (showing_interstitial_page()) {
856 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
857 return;
858 }
[email protected]96d185d2009-04-24 03:28:54859 render_view_host()->SetInitialFocus(reverse);
860}
861
862bool TabContents::FocusLocationBarByDefault() {
863 DOMUI* dom_ui = GetDOMUIForCurrentState();
864 if (dom_ui)
865 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43866 NavigationEntry* entry = controller_.GetActiveEntry();
867 if (entry && entry->url() == GURL("about:blank"))
868 return true;
[email protected]96d185d2009-04-24 03:28:54869 return false;
870}
871
[email protected]616ed5a2008-11-21 22:27:24872void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
873 // Look through the existing InfoBarDelegates we have for a match. If we've
874 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05875 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]616ed5a2008-11-21 22:27:24876 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
877 return;
878 }
879
880 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56881 NotificationService::current()->Notify(
882 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
883 Source<TabContents>(this),
884 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24885
886 // Add ourselves as an observer for navigations the first time a delegate is
887 // added. We use this notification to expire InfoBars that need to expire on
888 // page transitions.
889 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56890 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57891 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24892 }
893}
894
895void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
896 std::vector<InfoBarDelegate*>::iterator it =
897 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
898 if (it != infobar_delegates_.end()) {
899 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56900 NotificationService::current()->Notify(
901 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
902 Source<TabContents>(this),
903 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:05904 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:24905
[email protected]6a02963e2009-01-06 16:58:03906 // Remove ourselves as an observer if we are tracking no more InfoBars.
907 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:56908 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57909 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03910 }
[email protected]616ed5a2008-11-21 22:27:24911 }
912}
[email protected]3edd9522009-03-04 22:19:41913
[email protected]f81821c2009-08-07 01:29:47914void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
915 InfoBarDelegate* new_delegate) {
916 std::vector<InfoBarDelegate*>::iterator it =
917 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
918 DCHECK(it != infobar_delegates_.end());
919
920 // Notify the container about the change of plans.
921 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
922 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
923 old_delegate, new_delegate));
924 NotificationService::current()->Notify(
925 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
926 Source<TabContents>(this),
927 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
928
929 // Remove the old one.
930 infobar_delegates_.erase(it);
931
932 // Add the new one.
933 infobar_delegates_.push_back(new_delegate);
934}
935
[email protected]96d185d2009-04-24 03:28:54936bool TabContents::IsBookmarkBarAlwaysVisible() {
937 // See GetDOMUIForCurrentState() comment for more info. This case is very
938 // similar, but for non-first loads, we want to use the committed entry. This
939 // is so the bookmarks bar disappears at the same time the page does.
940 if (controller_.GetLastCommittedEntry()) {
941 // Not the first load, always use the committed DOM UI.
942 if (render_manager_.dom_ui())
943 return render_manager_.dom_ui()->force_bookmark_bar_visible();
944 return false; // Default.
945 }
946
947 // When it's the first load, we know either the pending one or the committed
948 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
949 // of them will be valid, so we can just check both.
950 if (render_manager_.pending_dom_ui())
951 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
952 if (render_manager_.dom_ui())
953 return render_manager_.dom_ui()->force_bookmark_bar_visible();
954 return false; // Default.
955}
956
[email protected]d8f16ae2009-08-30 03:47:26957bool TabContents::IsExtensionShelfAlwaysVisible() {
958 // See GetDOMUIForCurrentState() comment for more info. This case is very
959 // similar, but for non-first loads, we want to use the committed entry. This
960 // is so the bookmarks bar disappears at the same time the page does.
961 if (controller_.GetLastCommittedEntry()) {
962 // Not the first load, always use the committed DOM UI.
963 if (render_manager_.dom_ui())
964 return render_manager_.dom_ui()->force_extension_shelf_visible();
965 return false; // Default.
966 }
967
968 // When it's the first load, we know either the pending one or the committed
969 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
970 // of them will be valid, so we can just check both.
971 if (render_manager_.pending_dom_ui())
972 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
973 if (render_manager_.dom_ui())
974 return render_manager_.dom_ui()->force_extension_shelf_visible();
975 return false; // Default.
976}
977
[email protected]3edd9522009-03-04 22:19:41978void TabContents::ToolbarSizeChanged(bool is_animating) {
979 TabContentsDelegate* d = delegate();
980 if (d)
981 d->ToolbarSizeChanged(this, is_animating);
982}
[email protected]616ed5a2008-11-21 22:27:24983
[email protected]d5f942ba2008-09-26 19:30:34984void TabContents::OnStartDownload(DownloadItem* download) {
985 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:34986
987 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:31988 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:34989
[email protected]59560e0b2009-06-04 03:30:22990 if (tab_contents && tab_contents->delegate())
991 tab_contents->delegate()->OnStartDownload(download);
[email protected]3edd9522009-03-04 22:19:41992}
[email protected]3edd9522009-03-04 22:19:41993
[email protected]d5f942ba2008-09-26 19:30:34994void TabContents::WillClose(ConstrainedWindow* window) {
995 ConstrainedWindowList::iterator it =
996 find(child_windows_.begin(), child_windows_.end(), window);
997 if (it != child_windows_.end())
998 child_windows_.erase(it);
[email protected]66ba4932009-06-04 19:22:13999}
[email protected]d5f942ba2008-09-26 19:30:341000
[email protected]66ba4932009-06-04 19:22:131001void TabContents::WillCloseBlockedPopupContainer(
1002 BlockedPopupContainer* container) {
1003 DCHECK(blocked_popups_ == container);
1004 blocked_popups_ = NULL;
[email protected]d5f942ba2008-09-26 19:30:341005}
1006
[email protected]d5f942ba2008-09-26 19:30:341007void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351008#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061009 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351010#endif
[email protected]d5f942ba2008-09-26 19:30:341011}
1012
[email protected]e491f1c2009-05-22 20:28:121013void TabContents::StartFinding(string16 find_text,
1014 bool forward_direction,
1015 bool case_sensitive) {
[email protected]6e95706d2009-04-23 22:55:011016 // If find_text is empty, it means FindNext was pressed with a keyboard
1017 // shortcut so unless we have something to search for we return early.
[email protected]e491f1c2009-05-22 20:28:121018 if (find_text.empty() && find_text_.empty()) {
1019 if (last_search_prepopulate_text_->empty())
1020 return;
1021 // Try whatever we searched for last in any tab.
1022 find_text = *last_search_prepopulate_text_;
1023 }
[email protected]6e95706d2009-04-23 22:55:011024
1025 // This is a FindNext operation if we are searching for the same text again,
1026 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1027 // exception to this is if the Find was aborted (then we don't want FindNext
1028 // because the highlighting has been cleared and we need it to reappear). We
1029 // therefore treat FindNext after an aborted Find operation as a full fledged
1030 // Find.
1031 bool find_next = (find_text_ == find_text || find_text.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121032 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011033 !find_op_aborted_;
1034 if (!find_next)
1035 current_find_request_id_ = find_request_id_counter_++;
1036
1037 if (!find_text.empty())
1038 find_text_ = find_text;
[email protected]e491f1c2009-05-22 20:28:121039 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011040
1041 find_op_aborted_ = false;
1042
1043 // Keep track of what the last search was across the tabs.
[email protected]e491f1c2009-05-22 20:28:121044 *last_search_prepopulate_text_ = find_text;
[email protected]6e95706d2009-04-23 22:55:011045
1046 render_view_host()->StartFinding(current_find_request_id_,
1047 find_text_,
1048 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121049 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011050 find_next);
1051}
1052
1053void TabContents::StopFinding(bool clear_selection) {
[email protected]2d2dffc2009-06-09 21:41:001054 // When |clear_selection| is true, it means the find string has been cleared
1055 // by the user, but the UI has not been dismissed.
1056 if (!clear_selection)
1057 find_ui_active_ = false;
[email protected]6e95706d2009-04-23 22:55:011058 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121059 last_search_result_ = FindNotificationDetails();
[email protected]6e95706d2009-04-23 22:55:011060 render_view_host()->StopFinding(clear_selection);
1061}
1062
[email protected]5c4266922009-07-10 16:41:271063void TabContents::GetPageLanguage() {
1064 render_view_host()->GetPageLanguage();
1065}
1066
[email protected]420ae012009-04-24 05:16:321067void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
1068 bool success,
1069 const std::wstring& prompt) {
1070 last_javascript_message_dismissal_ = base::TimeTicks::Now();
1071 render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt);
1072}
1073
[email protected]571e31152009-05-15 19:34:021074void TabContents::OnJavaScriptMessageBoxWindowDestroyed() {
1075 render_manager_.OnJavaScriptMessageBoxWindowDestroyed();
1076}
1077
[email protected]420ae012009-04-24 05:16:321078void TabContents::OnSavePage() {
1079 // If we can not save the page, try to download it.
1080 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1081 DownloadManager* dlm = profile()->GetDownloadManager();
1082 const GURL& current_page_url = GetURL();
1083 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221084 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321085 return;
1086 }
1087
1088 Stop();
1089
1090 // Create the save package and possibly prompt the user for the name to save
1091 // the page as. The user prompt is an asynchronous operation that runs on
1092 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221093 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321094 save_package_->GetSaveInfo();
1095}
1096
1097// Used in automated testing to bypass prompting the user for file names.
1098// Instead, the names and paths are hard coded rather than running them through
1099// file name sanitation and extension / mime checking.
[email protected]cdf6cc82009-08-04 21:48:591100bool TabContents::SavePage(const std::wstring& main_file,
[email protected]420ae012009-04-24 05:16:321101 const std::wstring& dir_path,
1102 SavePackage::SavePackageType save_type) {
1103 // Stop the page from navigating.
1104 Stop();
1105
[email protected]d82ed61e2009-06-16 02:46:221106 save_package_ = new SavePackage(this, save_type,
[email protected]420ae012009-04-24 05:16:321107 FilePath::FromWStringHack(main_file),
1108 FilePath::FromWStringHack(dir_path));
[email protected]cdf6cc82009-08-04 21:48:591109 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321110}
1111
1112void TabContents::PrintPreview() {
1113 // We don't show the print preview yet, only the print dialog.
1114 PrintNow();
1115}
1116
1117bool TabContents::PrintNow() {
1118 // We can't print interstitial page for now.
1119 if (showing_interstitial_page())
1120 return false;
1121
1122 return render_view_host()->PrintPages();
1123}
1124
[email protected]82270452009-06-19 15:58:011125void TabContents::PrintingDone(int document_cookie, bool success) {
1126 render_view_host()->PrintingDone(document_cookie, success);
1127}
1128
[email protected]420ae012009-04-24 05:16:321129bool TabContents::IsActiveEntry(int32 page_id) {
1130 NavigationEntry* active_entry = controller_.GetActiveEntry();
1131 return (active_entry != NULL &&
1132 active_entry->site_instance() == GetSiteInstance() &&
1133 active_entry->page_id() == page_id);
1134}
1135
[email protected]96d185d2009-04-24 03:28:541136// Notifies the RenderWidgetHost instance about the fact that the page is
1137// loading, or done loading and calls the base implementation.
1138void TabContents::SetIsLoading(bool is_loading,
1139 LoadNotificationDetails* details) {
1140 if (is_loading == is_loading_)
1141 return;
1142
1143 if (!is_loading) {
1144 load_state_ = net::LOAD_STATE_IDLE;
1145 load_state_host_.clear();
1146 }
1147
1148 render_manager_.SetIsLoading(is_loading);
1149
1150 is_loading_ = is_loading;
1151 waiting_for_response_ = is_loading;
1152
1153 if (delegate_)
1154 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351155 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541156
1157 NotificationType type = is_loading ? NotificationType::LOAD_START :
1158 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111159 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541160 if (details)
1161 det = Details<LoadNotificationDetails>(details);
1162 NotificationService::current()->Notify(type,
1163 Source<NavigationController>(&controller_),
1164 det);
1165}
1166
[email protected]2c4410d2009-05-06 23:46:221167void TabContents::CreateBlockedPopupContainerIfNecessary() {
1168 if (blocked_popups_)
1169 return;
1170
[email protected]4d4c0b92009-06-08 23:13:011171 blocked_popups_ = BlockedPopupContainer::Create(this, profile());
[email protected]2c4410d2009-05-06 23:46:221172}
1173
[email protected]b6c874582009-05-08 19:38:311174void TabContents::AddPopup(TabContents* new_contents,
1175 const gfx::Rect& initial_pos,
1176 const std::string& host) {
[email protected]2c4410d2009-05-06 23:46:221177 CreateBlockedPopupContainerIfNecessary();
1178 blocked_popups_->AddTabContents(new_contents, initial_pos, host);
[email protected]2c4410d2009-05-06 23:46:221179}
1180
[email protected]e69bce3dd2009-04-20 22:05:121181// TODO(brettw) This should be on the TabContentsView.
[email protected]66ba4932009-06-04 19:22:131182void TabContents::RepositionSupressedPopupsToFit() {
[email protected]d6598c052008-11-05 19:03:251183 if (blocked_popups_)
[email protected]4d4c0b92009-06-08 23:13:011184 blocked_popups_->RepositionBlockedPopupContainer();
[email protected]d5f942ba2008-09-26 19:30:341185}
1186
[email protected]b9681312008-11-07 00:08:261187bool TabContents::ShowingBlockedPopupNotification() const {
1188 return blocked_popups_ != NULL &&
[email protected]2c4410d2009-05-06 23:46:221189 blocked_popups_->GetBlockedPopupCount() != 0;
[email protected]b9681312008-11-07 00:08:261190}
[email protected]616ed5a2008-11-21 22:27:241191
1192namespace {
1193bool TransitionIsReload(PageTransition::Type transition) {
1194 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1195}
1196}
1197
1198void TabContents::ExpireInfoBars(
1199 const NavigationController::LoadCommittedDetails& details) {
1200 // Only hide InfoBars when the user has done something that makes the main
1201 // frame load. We don't want various automatic or subframe navigations making
1202 // it disappear.
1203 if (!details.is_user_initiated_main_frame_load())
1204 return;
1205
[email protected]f86a07022008-11-25 01:06:051206 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241207 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051208 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241209 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241210 }
1211}
[email protected]fdd61c62009-04-22 19:22:571212
1213void TabContents::OnGearsCreateShortcutDone(
1214 const GearsShortcutData2& shortcut_data, bool success) {
1215 NavigationEntry* current_entry = controller_.GetLastCommittedEntry();
1216 bool same_page =
1217 current_entry && pending_install_.page_id == current_entry->page_id();
1218
1219 if (success && same_page) {
1220 // Only switch to app mode if the user chose to create a shortcut and
1221 // we're still on the same page that it corresponded to.
1222 if (delegate())
1223 delegate()->ConvertContentsToApplication(this);
1224 }
1225
1226 // Reset the page id to indicate no requests are pending.
1227 pending_install_.page_id = 0;
1228 pending_install_.callback_functor = NULL;
1229}
[email protected]96d185d2009-04-24 03:28:541230
1231DOMUI* TabContents::GetDOMUIForCurrentState() {
1232 // When there is a pending navigation entry, we want to use the pending DOMUI
1233 // that goes along with it to control the basic flags. For example, we want to
1234 // show the pending URL in the URL bar, so we want the display_url flag to
1235 // be from the pending entry.
1236 //
1237 // The confusion comes because there are multiple possibilities for the
1238 // initial load in a tab as a side effect of the way the RenderViewHostManager
1239 // works.
1240 //
1241 // - For the very first tab the load looks "normal". The new tab DOM UI is
1242 // the pending one, and we want it to apply here.
1243 //
1244 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1245 // get switched to the one previously associated with the new tab pages.
1246 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1247 // have a committed DOM UI in this case.
1248 //
1249 // This condition handles all of these cases:
1250 //
1251 // - First load in first tab: no committed nav entry + pending nav entry +
1252 // pending dom ui:
1253 // -> Use pending DOM UI if any.
1254 //
1255 // - First load in second tab: no committed nav entry + pending nav entry +
1256 // no pending DOM UI:
1257 // -> Use the committed DOM UI if any.
1258 //
1259 // - Second navigation in any tab: committed nav entry + pending nav entry:
1260 // -> Use pending DOM UI if any.
1261 //
1262 // - Normal state with no load: committed nav entry + no pending nav entry:
1263 // -> Use committed DOM UI.
1264 if (controller_.pending_entry() &&
1265 (controller_.GetLastCommittedEntry() ||
1266 render_manager_.pending_dom_ui()))
1267 return render_manager_.pending_dom_ui();
1268 return render_manager_.dom_ui();
1269}
[email protected]420ae012009-04-24 05:16:321270
1271void TabContents::DidNavigateMainFramePostCommit(
1272 const NavigationController::LoadCommittedDetails& details,
1273 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]420ae012009-04-24 05:16:321274 if (details.is_user_initiated_main_frame_load()) {
1275 // Clear the status bubble. This is a workaround for a bug where WebKit
1276 // doesn't let us know that the cursor left an element during a
1277 // transition (this is also why the mouse cursor remains as a hand after
1278 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1279 // clear the bubble when a user navigates to a named anchor in the same
1280 // page.
1281 UpdateTargetURL(details.entry->page_id(), GURL());
1282
1283 // UpdateHelpersForDidNavigate will handle the case where the password_form
1284 // origin is valid.
1285 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1286 // cleaned up and covered by tests.
1287 if (!params.password_form.origin.is_valid())
1288 GetPasswordManager()->DidNavigate();
1289 }
1290
1291 // The keyword generator uses the navigation entries, so must be called after
1292 // the commit.
1293 GenerateKeywordIfNecessary(params);
1294
1295 // Allow the new page to set the title again.
1296 received_page_title_ = false;
1297
1298 // Get the favicon, either from history or request it from the net.
1299 fav_icon_helper_.FetchFavIcon(details.entry->url());
1300
[email protected]aece2c7f2009-08-27 20:43:171301 // Disable all page actions, unless this is an in-page navigation.
1302 if (!enabled_page_actions_.empty()) {
1303 url_canon::Replacements<char> replacements;
1304 replacements.ClearRef();
1305 if (params.url.ReplaceComponents(replacements) !=
1306 params.referrer.ReplaceComponents(replacements)) {
1307 enabled_page_actions_.clear();
1308 }
1309 }
[email protected]ce5c4502009-05-06 16:46:111310
[email protected]420ae012009-04-24 05:16:321311 // Close constrained popups if necessary.
1312 MaybeCloseChildWindows(details.previous_url, details.entry->url());
1313
1314 // Update the starred state.
1315 UpdateStarredStateForCurrentURL();
1316}
1317
1318void TabContents::DidNavigateAnyFramePostCommit(
1319 RenderViewHost* render_view_host,
1320 const NavigationController::LoadCommittedDetails& details,
1321 const ViewHostMsg_FrameNavigate_Params& params) {
1322 // If we navigate, start showing messages again. This does nothing to prevent
1323 // a malicious script from spamming messages, since the script could just
1324 // reload the page to stop blocking.
1325 suppress_javascript_messages_ = false;
1326
[email protected]420ae012009-04-24 05:16:321327 // Notify the password manager of the navigation or form submit.
1328 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1329 // cleaned up and covered by tests.
1330 if (params.password_form.origin.is_valid())
1331 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
1332}
1333
1334void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
1335 const GURL& current_url) {
1336 if (net::RegistryControlledDomainService::SameDomainOrHost(
1337 previous_url, current_url))
1338 return;
1339
1340 // Clear out any child windows since we are leaving this page entirely.
1341 // We use indices instead of iterators in case CloseWindow does something
1342 // that may invalidate an iterator.
1343 int size = static_cast<int>(child_windows_.size());
1344 for (int i = size - 1; i >= 0; --i) {
1345 ConstrainedWindow* window = child_windows_[i];
1346 if (window)
1347 window->CloseConstrainedWindow();
1348 }
[email protected]e29300cd2009-07-23 21:14:591349
1350 // Close the popup container.
1351 if (blocked_popups_) {
1352 blocked_popups_->Destroy();
1353 blocked_popups_ = NULL;
1354 }
[email protected]420ae012009-04-24 05:16:321355}
1356
1357void TabContents::UpdateStarredStateForCurrentURL() {
1358 BookmarkModel* model = profile()->GetBookmarkModel();
1359 const bool old_state = is_starred_;
1360 is_starred_ = (model && model->IsBookmarked(GetURL()));
1361
1362 if (is_starred_ != old_state && delegate())
1363 delegate()->URLStarredChanged(this, is_starred_);
1364}
1365
1366void TabContents::UpdateAlternateErrorPageURL() {
1367 GURL url = GetAlternateErrorPageURL();
1368 render_view_host()->SetAlternateErrorPageURL(url);
1369}
1370
1371void TabContents::UpdateWebPreferences() {
1372 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1373}
1374
1375void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1376 RenderViewHost* rvh) {
1377 // If we are creating a RVH for a restored controller, then we might
1378 // have more page IDs than the SiteInstance's current max page ID. We must
1379 // make sure that the max page ID is larger than any restored page ID.
1380 // Note that it is ok for conflicting page IDs to exist in another tab
1381 // (i.e., NavigationController), but if any page ID is larger than the max,
1382 // the back/forward list will get confused.
1383 int max_restored_page_id = controller_.max_restored_page_id();
1384 if (max_restored_page_id > 0) {
1385 int curr_max_page_id = site_instance->max_page_id();
1386 if (max_restored_page_id > curr_max_page_id) {
1387 // Need to update the site instance immediately.
1388 site_instance->UpdateMaxPageID(max_restored_page_id);
1389
1390 // Also tell the renderer to update its internal representation. We
1391 // need to reserve enough IDs to make all restored page IDs less than
1392 // the max.
1393 if (curr_max_page_id < 0)
1394 curr_max_page_id = 0;
1395 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1396 }
1397 }
1398}
1399
1400void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541401 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471402 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321403 const ViewHostMsg_FrameNavigate_Params& params) {
1404 if (profile()->IsOffTheRecord())
1405 return;
1406
1407 // Add to history service.
1408 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1409 if (hs) {
1410 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541411 virtual_url != params.url) {
1412 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321413 // types of URLs, we will display a magic URL that is different from where
1414 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541415 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1416 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321417 // to sub-frames.
1418 std::vector<GURL> redirects = params.redirects;
1419 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541420 redirects.back() = virtual_url;
1421 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471422 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321423 } else {
1424 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471425 params.transition, params.redirects,
1426 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321427 }
1428 }
1429}
1430
1431bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1432 const std::wstring& title) {
1433 // For file URLs without a title, use the pathname instead. In the case of a
1434 // synthesized title, we don't want the update to count toward the "one set
1435 // per page of the title to history."
1436 std::wstring final_title;
1437 bool explicit_set;
1438 if (entry->url().SchemeIsFile() && title.empty()) {
1439 final_title = UTF8ToWide(entry->url().ExtractFileName());
1440 explicit_set = false; // Don't count synthetic titles toward the set limit.
1441 } else {
1442 TrimWhitespace(title, TRIM_ALL, &final_title);
1443 explicit_set = true;
1444 }
1445
1446 if (final_title == UTF16ToWideHack(entry->title()))
1447 return false; // Nothing changed, don't bother.
1448
1449 entry->set_title(WideToUTF16Hack(final_title));
1450
1451 // Update the history system for this page.
1452 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1453 HistoryService* hs =
1454 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1455 if (hs)
[email protected]ebe89e062009-08-13 23:16:541456 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321457
1458 // Don't allow the title to be saved again for explicitly set ones.
1459 received_page_title_ = explicit_set;
1460 }
1461
1462 // Lastly, set the title for the view.
1463 view_->SetPageTitle(final_title);
1464
1465 return true;
1466}
1467
1468void TabContents::NotifySwapped() {
1469 // After sending out a swap notification, we need to send a disconnect
1470 // notification so that clients that pick up a pointer to |this| can NULL the
1471 // pointer. See Bug 1230284.
1472 notify_disconnection_ = true;
1473 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341474 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221475 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321476 NotificationService::NoDetails());
1477}
1478
1479void TabContents::NotifyConnected() {
1480 notify_disconnection_ = true;
1481 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341482 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221483 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321484 NotificationService::NoDetails());
1485}
1486
1487void TabContents::NotifyDisconnected() {
1488 if (!notify_disconnection_)
1489 return;
1490
1491 notify_disconnection_ = false;
1492 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341493 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221494 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321495 NotificationService::NoDetails());
1496}
1497
1498void TabContents::GenerateKeywordIfNecessary(
1499 const ViewHostMsg_FrameNavigate_Params& params) {
1500 if (!params.searchable_form_url.is_valid())
1501 return;
1502
1503 if (profile()->IsOffTheRecord())
1504 return;
1505
1506 int last_index = controller_.last_committed_entry_index();
1507 // When there was no previous page, the last index will be 0. This is
1508 // normally due to a form submit that opened in a new tab.
1509 // TODO(brettw) bug 916126: we should support keywords when form submits
1510 // happen in new tabs.
1511 if (last_index <= 0)
1512 return;
1513 const NavigationEntry* previous_entry =
1514 controller_.GetEntryAtIndex(last_index - 1);
1515 if (IsFormSubmit(previous_entry)) {
1516 // Only generate a keyword if the previous page wasn't itself a form
1517 // submit.
1518 return;
1519 }
1520
1521 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1522 previous_entry->user_typed_url() : previous_entry->url();
1523 std::wstring keyword =
1524 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1525 if (keyword.empty())
1526 return;
1527
1528 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1529 if (!url_model)
1530 return;
1531
1532 if (!url_model->loaded()) {
1533 url_model->Load();
1534 return;
1535 }
1536
1537 const TemplateURL* current_url;
1538 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1539 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1540 return;
1541
1542 if (current_url) {
1543 if (current_url->originating_url().is_valid()) {
1544 // The existing keyword was generated from an OpenSearch description
1545 // document, don't regenerate.
1546 return;
1547 }
1548 url_model->Remove(current_url);
1549 }
1550 TemplateURL* new_url = new TemplateURL();
1551 new_url->set_keyword(keyword);
1552 new_url->set_short_name(keyword);
1553 new_url->SetURL(url, 0, 0);
1554 new_url->add_input_encoding(params.searchable_form_encoding);
1555 DCHECK(controller_.GetLastCommittedEntry());
1556 const GURL& favicon_url =
1557 controller_.GetLastCommittedEntry()->favicon().url();
1558 if (favicon_url.is_valid()) {
1559 new_url->SetFavIconURL(favicon_url);
1560 } else {
1561 // The favicon url isn't valid. This means there really isn't a favicon,
1562 // or the favicon url wasn't obtained before the load started. This assumes
1563 // the later.
1564 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1565 // its url.
1566 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1567 }
1568 new_url->set_safe_for_autoreplace(true);
1569 url_model->Add(new_url);
1570}
1571
[email protected]bf5c2ff392009-07-08 16:24:331572void TabContents::OnUserGesture() {
1573 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1574 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1575 if (drm)
1576 drm->OnUserGesture(this);
1577 controller_.OnUserGesture();
1578}
1579
1580void TabContents::OnFindReply(int request_id,
1581 int number_of_matches,
1582 const gfx::Rect& selection_rect,
1583 int active_match_ordinal,
1584 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421585 // Ignore responses for requests that have been aborted.
1586 if (find_op_aborted_)
1587 return;
1588
[email protected]bf5c2ff392009-07-08 16:24:331589 // Ignore responses for requests other than the one we have most recently
1590 // issued. That way we won't act on stale results when the user has
1591 // already typed in another query.
1592 if (request_id != current_find_request_id_)
1593 return;
1594
1595 if (number_of_matches == -1)
1596 number_of_matches = last_search_result_.number_of_matches();
1597 if (active_match_ordinal == -1)
1598 active_match_ordinal = last_search_result_.active_match_ordinal();
1599
1600 gfx::Rect selection = selection_rect;
1601 if (selection.IsEmpty())
1602 selection = last_search_result_.selection_rect();
1603
1604 // Notify the UI, automation and any other observers that a find result was
1605 // found.
1606 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1607 selection, active_match_ordinal,
1608 final_update);
1609 NotificationService::current()->Notify(
1610 NotificationType::FIND_RESULT_AVAILABLE,
1611 Source<TabContents>(this),
1612 Details<FindNotificationDetails>(&last_search_result_));
1613}
1614
1615void TabContents::GoToEntryAtOffset(int offset) {
1616 controller_.GoToOffset(offset);
1617}
1618
1619void TabContents::GetHistoryListCount(int* back_list_count,
1620 int* forward_list_count) {
1621 int current_index = controller_.last_committed_entry_index();
1622 *back_list_count = current_index;
1623 *forward_list_count = controller_.entry_count() - current_index - 1;
1624}
1625
1626void TabContents::OnMissingPluginStatus(int status) {
1627#if defined(OS_WIN)
1628// TODO(PORT): pull in when plug-ins work
1629 GetPluginInstaller()->OnMissingPluginStatus(status);
1630#endif
1631}
1632
1633void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331634 DCHECK(!plugin_path.value().empty());
1635
1636 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351637#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331638 scoped_ptr<FileVersionInfo> version_info(
1639 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1640 if (version_info.get()) {
1641 const std::wstring& product_name = version_info->product_name();
1642 if (!product_name.empty())
1643 plugin_name = product_name;
1644 }
[email protected]4a560ed2009-07-13 23:35:261645#else
1646 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1647#endif
[email protected]bf5c2ff392009-07-08 16:24:331648 AddInfoBar(new SimpleAlertInfoBarDelegate(
1649 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
1650 NULL));
[email protected]bf5c2ff392009-07-08 16:24:331651}
1652
1653void TabContents::OnCrashedWorker() {
1654 AddInfoBar(new SimpleAlertInfoBarDelegate(
1655 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
1656 NULL));
1657}
1658
1659void TabContents::OnDidGetApplicationInfo(
1660 int32 page_id,
1661 const webkit_glue::WebApplicationInfo& info) {
1662 if (pending_install_.page_id != page_id)
1663 return; // The user clicked create on a separate page. Ignore this.
1664
1665 pending_install_.callback_functor =
1666 new GearsCreateShortcutCallbackFunctor(this);
1667 GearsCreateShortcut(
1668 info, pending_install_.title, pending_install_.url, pending_install_.icon,
1669 NewCallback(pending_install_.callback_functor,
1670 &GearsCreateShortcutCallbackFunctor::Run));
1671}
1672
1673void TabContents::DidStartProvisionalLoadForFrame(
1674 RenderViewHost* render_view_host,
1675 bool is_main_frame,
1676 const GURL& url) {
1677 ProvisionalLoadDetails details(is_main_frame,
1678 controller_.IsURLInPageNavigation(url),
1679 url, std::string(), false);
1680 NotificationService::current()->Notify(
1681 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1682 Source<NavigationController>(&controller_),
1683 Details<ProvisionalLoadDetails>(&details));
1684}
1685
1686void TabContents::DidStartReceivingResourceResponse(
1687 ResourceRequestDetails* details) {
1688 NotificationService::current()->Notify(
1689 NotificationType::RESOURCE_RESPONSE_STARTED,
1690 Source<NavigationController>(&controller()),
1691 Details<ResourceRequestDetails>(details));
1692}
1693
1694void TabContents::DidRedirectResource(ResourceRequestDetails* details) {
1695 NotificationService::current()->Notify(
1696 NotificationType::RESOURCE_RECEIVED_REDIRECT,
1697 Source<NavigationController>(&controller()),
1698 Details<ResourceRequestDetails>(details));
1699}
1700
1701void TabContents::DidLoadResourceFromMemoryCache(
1702 const GURL& url,
1703 const std::string& frame_origin,
1704 const std::string& main_frame_origin,
1705 const std::string& security_info) {
1706 // Send out a notification that we loaded a resource from our memory cache.
1707 int cert_id = 0, cert_status = 0, security_bits = 0;
1708 SSLManager::DeserializeSecurityInfo(security_info,
1709 &cert_id, &cert_status,
1710 &security_bits);
1711 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]76543b92009-08-31 17:27:451712 process()->id(), cert_id, cert_status);
[email protected]bf5c2ff392009-07-08 16:24:331713
1714 NotificationService::current()->Notify(
1715 NotificationType::LOAD_FROM_MEMORY_CACHE,
1716 Source<NavigationController>(&controller_),
1717 Details<LoadFromMemoryCacheDetails>(&details));
1718}
1719
1720void TabContents::DidFailProvisionalLoadWithError(
1721 RenderViewHost* render_view_host,
1722 bool is_main_frame,
1723 int error_code,
1724 const GURL& url,
1725 bool showing_repost_interstitial) {
1726 if (net::ERR_ABORTED == error_code) {
1727 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1728 // This means that the interstitial won't be torn down properly, which is
1729 // bad. But if we have an interstitial, go back to another tab type, and
1730 // then load the same interstitial again, we could end up getting the first
1731 // interstitial's "failed" message (as a result of the cancel) when we're on
1732 // the second one.
1733 //
1734 // We can't tell this apart, so we think we're tearing down the current page
1735 // which will cause a crash later one. There is also some code in
1736 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1737 // out because of this problem.
1738 //
1739 // http://code.google.com/p/chromium/issues/detail?id=2855
1740 // Because this will not tear down the interstitial properly, if "back" is
1741 // back to another tab type, the interstitial will still be somewhat alive
1742 // in the previous tab type. If you navigate somewhere that activates the
1743 // tab with the interstitial again, you'll see a flash before the new load
1744 // commits of the interstitial page.
1745 if (showing_interstitial_page()) {
1746 LOG(WARNING) << "Discarding message during interstitial.";
1747 return;
1748 }
1749
1750 // This will discard our pending entry if we cancelled the load (e.g., if we
1751 // decided to download the file instead of load it). Only discard the
1752 // pending entry if the URLs match, otherwise the user initiated a navigate
1753 // before the page loaded so that the discard would discard the wrong entry.
1754 NavigationEntry* pending_entry = controller_.pending_entry();
1755 if (pending_entry && pending_entry->url() == url) {
1756 controller_.DiscardNonCommittedEntries();
1757 // Update the URL display.
1758 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1759 }
1760
1761 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
1762 }
1763
1764 // Send out a notification that we failed a provisional load with an error.
1765 ProvisionalLoadDetails details(is_main_frame,
1766 controller_.IsURLInPageNavigation(url),
1767 url, std::string(), false);
1768 details.set_error_code(error_code);
1769
1770 NotificationService::current()->Notify(
1771 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1772 Source<NavigationController>(&controller_),
1773 Details<ProvisionalLoadDetails>(&details));
1774}
1775
1776void TabContents::DocumentLoadedInFrame() {
1777 controller_.DocumentLoadedInFrame();
1778}
1779
[email protected]8d3347f2009-07-09 22:00:211780RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321781 return view_.get();
1782}
1783
[email protected]8d3347f2009-07-09 22:00:211784RenderViewHostDelegate::RendererManagement*
1785TabContents::GetRendererManagementDelegate() {
1786 return &render_manager_;
1787}
1788
[email protected]bf5c2ff392009-07-08 16:24:331789RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:211790 TabContents::GetBrowserIntegrationDelegate() {
1791 return this;
[email protected]bf5c2ff392009-07-08 16:24:331792}
1793
[email protected]8d3347f2009-07-09 22:00:211794RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
1795 return this;
[email protected]bf5c2ff392009-07-08 16:24:331796}
1797
[email protected]8d3347f2009-07-09 22:00:211798RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:321799 return save_package_.get(); // May be NULL, but we can return NULL.
1800}
1801
[email protected]8d3347f2009-07-09 22:00:211802RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
1803 return &printing_;
1804}
1805
1806RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
1807 return &fav_icon_helper_;
1808}
1809
1810RenderViewHostDelegate::Autofill* TabContents::GetAutofillDelegate() {
1811 if (autofill_manager_.get() == NULL)
1812 autofill_manager_.reset(new AutofillManager(this));
1813 return autofill_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:331814}
1815
[email protected]80d96fa2009-06-10 22:34:511816RendererPreferences TabContents::GetRendererPrefs() const {
[email protected]840b1512009-07-21 16:53:461817 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511818}
1819
[email protected]57c6a652009-05-04 07:58:341820TabContents* TabContents::GetAsTabContents() {
1821 return this;
1822}
1823
[email protected]3e7cf1362009-08-21 17:47:081824void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
1825 CreateBlockedPopupContainerIfNecessary();
1826 blocked_popups_->AddBlockedNotice(url, reason);
1827}
1828
[email protected]7b291f92009-08-14 05:43:531829ViewType::Type TabContents::GetRenderViewType() const {
1830 return ViewType::TAB_CONTENTS;
1831}
1832
1833int TabContents::GetBrowserWindowID() const {
1834 return controller().window_id().id();
1835}
1836
[email protected]420ae012009-04-24 05:16:321837void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061838 NotificationService::current()->Notify(
1839 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1840 Source<TabContents>(this),
1841 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321842 NavigationEntry* entry = controller_.GetActiveEntry();
1843 if (!entry)
1844 return;
1845
1846 // When we're creating views, we're still doing initial setup, so we always
1847 // use the pending DOM UI rather than any possibly existing committed one.
1848 if (render_manager_.pending_dom_ui()) {
1849 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
1850 }
1851
1852 if (entry->IsViewSourceMode()) {
1853 // Put the renderer in view source mode.
1854 render_view_host->Send(
1855 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1856 }
[email protected]0666aef2009-05-13 19:48:081857
1858 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321859}
1860
1861void TabContents::RenderViewReady(RenderViewHost* rvh) {
1862 if (rvh != render_view_host()) {
1863 // Don't notify the world, since this came from a renderer in the
1864 // background.
1865 return;
1866 }
1867
1868 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301869 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:321870 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:301871
1872 // Restore the focus to the tab (otherwise the focus will be on the top
1873 // window).
1874 if (was_crashed && !FocusLocationBarByDefault())
1875 Focus();
[email protected]420ae012009-04-24 05:16:321876}
1877
1878void TabContents::RenderViewGone(RenderViewHost* rvh) {
1879 // Ask the print preview if this renderer was valuable.
1880 if (!printing_.OnRenderViewGone(rvh))
1881 return;
1882 if (rvh != render_view_host()) {
1883 // The pending page's RenderViewHost is gone.
1884 return;
1885 }
1886
1887 SetIsLoading(false, NULL);
1888 NotifyDisconnected();
1889 SetIsCrashed(true);
1890
[email protected]8e537302009-06-10 21:19:581891 // Tell the view that we've crashed so it can prepare the sad tab page.
1892 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:321893
1894 // Hide any visible hung renderer warning for this web contents' process.
[email protected]d82ed61e2009-06-16 02:46:221895 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:321896}
1897
[email protected]2e4633c2009-07-09 16:58:061898void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
1899 NotificationService::current()->Notify(
1900 NotificationType::RENDER_VIEW_HOST_DELETED,
1901 Source<TabContents>(this),
1902 Details<RenderViewHost>(rvh));
1903}
1904
[email protected]420ae012009-04-24 05:16:321905void TabContents::DidNavigate(RenderViewHost* rvh,
1906 const ViewHostMsg_FrameNavigate_Params& params) {
1907 if (PageTransition::IsMainFrame(params.transition))
1908 render_manager_.DidNavigateMainFrame(rvh);
1909
1910 // Update the site of the SiteInstance if it doesn't have one yet.
1911 if (!GetSiteInstance()->has_site())
1912 GetSiteInstance()->SetSite(params.url);
1913
1914 // Need to update MIME type here because it's referred to in
1915 // UpdateNavigationCommands() called by RendererDidNavigate() to
1916 // determine whether or not to enable the encoding menu.
1917 // It's updated only for the main frame. For a subframe,
1918 // RenderView::UpdateURL does not set params.contents_mime_type.
1919 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1920 // TODO(jungshik): Add a test for the encoding menu to avoid
1921 // regressing it again.
1922 if (PageTransition::IsMainFrame(params.transition))
1923 contents_mime_type_ = params.contents_mime_type;
1924
1925 NavigationController::LoadCommittedDetails details;
[email protected]3e90d4a2009-07-03 17:38:391926 bool did_navigate = controller_.RendererDidNavigate(params, &details);
1927
1928 // Update history. Note that this needs to happen after the entry is complete,
1929 // which WillNavigate[Main,Sub]Frame will do before this function is called.
1930 if (params.should_update_history) {
1931 // Most of the time, the displayURL matches the loaded URL, but for about:
1932 // URLs, we use a data: URL as the real value. We actually want to save
1933 // the about: URL to the history db and keep the data: URL hidden. This is
1934 // what the TabContents' URL getter does.
1935 UpdateHistoryForNavigation(GetURL(), details, params);
1936 }
1937
[email protected]76543b92009-08-31 17:27:451938 if (!did_navigate)
1939 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321940
1941 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1942 // for the appropriate notification (best) or you can add it to
1943 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1944 // necessary, please).
1945
1946 // Run post-commit tasks.
1947 if (details.is_main_frame)
1948 DidNavigateMainFramePostCommit(details, params);
1949 DidNavigateAnyFramePostCommit(rvh, details, params);
1950}
1951
1952void TabContents::UpdateState(RenderViewHost* rvh,
1953 int32 page_id,
1954 const std::string& state) {
1955 DCHECK(rvh == render_view_host());
1956
1957 // We must be prepared to handle state updates for any page, these occur
1958 // when the user is scrolling and entering form data, as well as when we're
1959 // leaving a page, in which case our state may have already been moved to
1960 // the next page. The navigation controller will look up the appropriate
1961 // NavigationEntry and update it when it is notified via the delegate.
1962
1963 int entry_index = controller_.GetEntryIndexWithPageID(
1964 GetSiteInstance(), page_id);
1965 if (entry_index < 0)
1966 return;
1967 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1968
1969 if (state == entry->content_state())
1970 return; // Nothing to update.
1971 entry->set_content_state(state);
1972 controller_.NotifyEntryChanged(entry, entry_index);
1973}
1974
1975void TabContents::UpdateTitle(RenderViewHost* rvh,
1976 int32 page_id, const std::wstring& title) {
1977 // If we have a title, that's a pretty good indication that we've started
1978 // getting useful data.
1979 SetNotWaitingForResponse();
1980
1981 DCHECK(rvh == render_view_host());
1982 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
1983 page_id);
1984 if (!entry || !UpdateTitleForEntry(entry, title))
1985 return;
1986
1987 // Broadcast notifications when the UI should be updated.
1988 if (entry == controller_.GetEntryAtOffset(0))
[email protected]c9cd2222009-05-06 05:16:501989 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321990}
1991
[email protected]420ae012009-04-24 05:16:321992void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
1993 const std::wstring& encoding) {
1994 set_encoding(encoding);
1995}
1996
1997void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1998 if (delegate())
1999 delegate()->UpdateTargetURL(this, url);
2000}
2001
2002void TabContents::UpdateThumbnail(const GURL& url,
2003 const SkBitmap& bitmap,
2004 const ThumbnailScore& score) {
2005 // Tell History about this thumbnail
[email protected]449478302009-06-09 20:04:282006 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
[email protected]72d0fc72009-07-09 17:30:492007 if (!profile()->IsOffTheRecord())
[email protected]42339402009-07-17 17:27:192008 profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
2009 score, true);
[email protected]449478302009-06-09 20:04:282010 } else {
2011 HistoryService* hs;
2012 if (!profile()->IsOffTheRecord() &&
2013 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2014 hs->SetPageThumbnail(url, bitmap, score);
2015 }
[email protected]420ae012009-04-24 05:16:322016 }
2017}
2018
[email protected]0df30122009-06-03 12:13:082019void TabContents::UpdateInspectorSettings(const std::wstring& raw_settings) {
2020 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
2021 raw_settings);
2022}
2023
[email protected]420ae012009-04-24 05:16:322024void TabContents::Close(RenderViewHost* rvh) {
[email protected]24a4d1062009-07-10 23:10:422025 // If we close the tab while we're in the middle of a drag, we'll crash.
2026 // Instead, cancel the drag and close it as soon as the drag ends.
2027 if (view()->IsDoingDrag()) {
2028 view()->CancelDragAndCloseTab();
2029 return;
2030 }
2031
[email protected]420ae012009-04-24 05:16:322032 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2033 if (delegate() && rvh == render_view_host())
2034 delegate()->CloseContents(this);
2035}
2036
2037void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2038 if (delegate() && delegate()->IsPopup(this))
2039 delegate()->MoveContents(this, new_bounds);
2040}
2041
[email protected]329581b2009-04-28 06:52:352042void TabContents::DidStartLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322043 SetIsLoading(true, NULL);
2044}
2045
[email protected]329581b2009-04-28 06:52:352046void TabContents::DidStopLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322047 scoped_ptr<LoadNotificationDetails> details;
2048
2049 NavigationEntry* entry = controller_.GetActiveEntry();
2050 // An entry may not exist for a stop when loading an initial blank page or
2051 // if an iframe injected by script into a blank page finishes loading.
2052 if (entry) {
2053 scoped_ptr<base::ProcessMetrics> metrics(
2054 base::ProcessMetrics::CreateProcessMetrics(
2055 process()->process().handle()));
2056
2057 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2058
2059 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542060 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322061 entry->transition_type(),
2062 elapsed,
2063 &controller_,
2064 controller_.GetCurrentEntryIndex()));
2065 }
2066
2067 // Tell PasswordManager we've finished a page load, which serves as a
2068 // green light to save pending passwords and reset itself.
2069 GetPasswordManager()->DidStopLoading();
2070
2071 SetIsLoading(false, details.get());
2072}
2073
[email protected]420ae012009-04-24 05:16:322074void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2075 const GURL& source_url,
2076 const GURL& target_url) {
2077 NavigationEntry* entry;
2078 if (page_id == -1)
2079 entry = controller_.pending_entry();
2080 else
2081 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2082 if (!entry || entry->url() != source_url)
2083 return;
2084 entry->set_url(target_url);
2085}
2086
[email protected]420ae012009-04-24 05:16:322087void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2088 WindowOpenDisposition disposition) {
2089 if (render_manager_.dom_ui()) {
2090 // When we're a DOM UI, it will provide a page transition type for us (this
2091 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2092 // generated suggestions).
2093 //
2094 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162095 // want web sites to see a referrer of "chrome://blah" (and some
2096 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322097 // send to the site), so we send no referrer.
2098 OpenURL(url, GURL(), disposition,
2099 render_manager_.dom_ui()->link_transition_type());
2100 } else {
2101 OpenURL(url, referrer, disposition, PageTransition::LINK);
2102 }
2103}
2104
[email protected]1ee614862009-07-06 20:29:182105void TabContents::DomOperationResponse(const std::string& json_string,
2106 int automation_id) {
2107}
2108
[email protected]420ae012009-04-24 05:16:322109void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]811bfe32009-07-01 08:46:252110 const std::string& content,
2111 int request_id,
2112 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322113 if (!render_manager_.dom_ui()) {
2114 // We shouldn't get a DOM UI message when we haven't enabled the DOM UI.
2115 // Because the renderer might be owned and sending random messages, we need
2116 // to ignore these inproper ones.
2117 NOTREACHED();
2118 return;
2119 }
[email protected]811bfe32009-07-01 08:46:252120 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, request_id,
2121 has_callback);
[email protected]420ae012009-04-24 05:16:322122}
2123
2124void TabContents::ProcessExternalHostMessage(const std::string& message,
2125 const std::string& origin,
2126 const std::string& target) {
2127 if (delegate())
2128 delegate()->ForwardMessageToExternalHost(message, origin, target);
2129}
2130
[email protected]420ae012009-04-24 05:16:322131void TabContents::RunFileChooser(bool multiple_files,
2132 const string16& title,
2133 const FilePath& default_file) {
2134 if (!select_file_dialog_.get())
2135 select_file_dialog_ = SelectFileDialog::Create(this);
2136 SelectFileDialog::Type dialog_type =
2137 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE :
2138 SelectFileDialog::SELECT_OPEN_FILE;
2139 select_file_dialog_->SelectFile(dialog_type, title, default_file,
2140 NULL, 0, FILE_PATH_LITERAL(""),
2141 view_->GetTopLevelNativeWindow(), NULL);
2142}
2143
2144void TabContents::RunJavaScriptMessage(
2145 const std::wstring& message,
2146 const std::wstring& default_prompt,
2147 const GURL& frame_url,
2148 const int flags,
2149 IPC::Message* reply_msg,
2150 bool* did_suppress_message) {
2151 // Suppress javascript messages when requested and when inside a constrained
2152 // popup window (because that activates them and breaks them out of the
2153 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552154 // Also suppress messages when showing an interstitial. The interstitial is
2155 // shown over the previous page, we don't want the hidden page dialogs to
2156 // interfere with the interstitial.
2157 bool suppress_this_message = suppress_javascript_messages_ ||
2158 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322159 if (delegate())
2160 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312161 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322162
2163 *did_suppress_message = suppress_this_message;
2164
2165 if (!suppress_this_message) {
2166 base::TimeDelta time_since_last_message(
2167 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2168 bool show_suppress_checkbox = false;
2169 // Show a checkbox offering to suppress further messages if this message is
2170 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2171 if (time_since_last_message <
2172 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2173 show_suppress_checkbox = true;
2174
[email protected]d82ed61e2009-06-16 02:46:222175 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322176 show_suppress_checkbox, reply_msg);
2177 } else {
2178 // If we are suppressing messages, just reply as is if the user immediately
2179 // pressed "Cancel".
2180 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring());
2181 }
2182}
2183
2184void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2185 IPC::Message* reply_msg) {
[email protected]d82ed61e2009-06-16 02:46:222186 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322187}
2188
2189void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2190 const std::string& json_arguments,
2191 IPC::Message* reply_msg) {
2192 if (delegate()) {
2193 HtmlDialogUIDelegate* dialog_delegate =
2194 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222195 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322196 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2197 }
2198}
2199
2200void TabContents::PasswordFormsSeen(
[email protected]ed3fb032009-06-16 19:50:562201 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]420ae012009-04-24 05:16:322202 GetPasswordManager()->PasswordFormsSeen(forms);
2203}
2204
[email protected]420ae012009-04-24 05:16:322205// Checks to see if we should generate a keyword based on the OSDD, and if
2206// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2207void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2208 int32 page_id, const GURL& url,
2209 bool autodetected) {
2210 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2211 DCHECK(url.is_valid());
2212 if (!IsActiveEntry(page_id))
2213 return;
2214 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2215 if (!url_model)
2216 return;
2217 if (!url_model->loaded()) {
2218 url_model->Load();
2219 return;
2220 }
2221 if (!profile()->GetTemplateURLFetcher())
2222 return;
2223
2224 if (profile()->IsOffTheRecord())
2225 return;
2226
2227 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2228 DCHECK(entry);
2229
2230 const NavigationEntry* base_entry = entry;
2231 if (IsFormSubmit(base_entry)) {
2232 // If the current page is a form submit, find the last page that was not
2233 // a form submit and use its url to generate the keyword from.
2234 int index = controller_.last_committed_entry_index() - 1;
2235 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2236 index--;
2237 if (index >= 0)
2238 base_entry = controller_.GetEntryAtIndex(index);
2239 else
2240 base_entry = NULL;
2241 }
2242
2243 // We want to use the user typed URL if available since that represents what
2244 // the user typed to get here, and fall back on the regular URL if not.
2245 if (!base_entry)
2246 return;
2247 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2248 base_entry->user_typed_url() : base_entry->url();
2249 if (!keyword_url.is_valid())
2250 return;
2251 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2252 autodetected);
2253 if (keyword.empty())
2254 return;
2255 const TemplateURL* template_url =
2256 url_model->GetTemplateURLForKeyword(keyword);
2257 if (template_url && (!template_url->safe_for_autoreplace() ||
2258 template_url->originating_url() == url)) {
2259 // Either there is a user created TemplateURL for this keyword, or the
2260 // keyword has the same OSDD url and we've parsed it.
2261 return;
2262 }
2263
2264 // Download the OpenSearch description document. If this is successful a
2265 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322266 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2267 keyword,
2268 url,
2269 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162270 this,
[email protected]420ae012009-04-24 05:16:322271 autodetected);
2272}
2273
[email protected]420ae012009-04-24 05:16:322274GURL TabContents::GetAlternateErrorPageURL() const {
2275 GURL url;
2276 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2277 if (profile()->IsOffTheRecord())
2278 return url;
2279
2280 PrefService* prefs = profile()->GetPrefs();
2281 DCHECK(prefs);
2282 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]2bd6ca1c2009-08-27 16:42:202283 url = google_util::AppendGoogleLocaleParam(GURL(kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322284 url = google_util::AppendGoogleTLDParam(url);
2285 }
2286 return url;
2287}
2288
2289WebPreferences TabContents::GetWebkitPrefs() {
2290 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
[email protected]7ccddb8c2009-08-04 17:36:552291 bool is_dom_ui = false;
2292 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322293}
2294
[email protected]420ae012009-04-24 05:16:322295void TabContents::OnJSOutOfMemory() {
2296 AddInfoBar(new SimpleAlertInfoBarDelegate(
2297 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL));
2298}
2299
[email protected]420ae012009-04-24 05:16:322300void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2301 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342302 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322303 // delivered to a pending RenderViewHost. We must first run the onunload
2304 // handler of the old RenderViewHost before we can allow it to proceed.
2305 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2306 new_request_id);
2307}
2308
2309bool TabContents::CanBlur() const {
2310 return delegate() ? delegate()->CanBlur() : true;
2311}
2312
2313gfx::Rect TabContents::GetRootWindowResizerRect() const {
2314 if (delegate())
2315 return delegate()->GetRootWindowResizerRect();
2316 return gfx::Rect();
2317}
2318
2319void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2320 bool is_during_unload) {
2321 if (is_during_unload) {
2322 // Hang occurred while firing the beforeunload/unload handler.
2323 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112324 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322325
2326 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2327 return;
2328
2329 // If the tab hangs in the beforeunload/unload handler there's really
2330 // nothing we can do to recover. Pretend the unload listeners have
2331 // all fired and close the tab. If the hang is in the beforeunload handler
2332 // then the user will not have the option of cancelling the close.
2333 Close(rvh);
2334 return;
2335 }
2336
2337 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]d82ed61e2009-06-16 02:46:222338 HungRendererDialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322339}
2340
2341void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]d82ed61e2009-06-16 02:46:222342 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322343}
2344
2345void TabContents::LoadStateChanged(const GURL& url,
2346 net::LoadState load_state) {
2347 load_state_ = load_state;
[email protected]d686e812009-06-03 19:10:292348 std::wstring languages =
2349 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
2350 load_state_host_.clear();
2351 std::string host = url.host();
2352 net::IDNToUnicode(host.c_str(), host.size(), languages, &load_state_host_);
[email protected]420ae012009-04-24 05:16:322353 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2354 SetNotWaitingForResponse();
2355 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502356 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322357}
2358
[email protected]1ee614862009-07-06 20:29:182359bool TabContents::IsExternalTabContainer() const {
2360 if (!delegate())
2361 return false;
2362
2363 return delegate()->IsExternalTabContainer();
2364}
2365
[email protected]1ee614862009-07-06 20:29:182366void TabContents::DidInsertCSS() {
2367 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322368}
2369
2370void TabContents::FileSelected(const FilePath& path,
2371 int index, void* params) {
2372 render_view_host()->FileSelected(path);
2373}
2374
2375void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2376 void* params) {
2377 render_view_host()->MultiFilesSelected(files);
2378}
2379
2380void TabContents::FileSelectionCanceled(void* params) {
2381 // If the user cancels choosing a file to upload we pass back an
2382 // empty vector.
2383 render_view_host()->MultiFilesSelected(std::vector<FilePath>());
2384}
2385
2386void TabContents::BeforeUnloadFiredFromRenderManager(
2387 bool proceed,
2388 bool* proceed_to_fire_unload) {
2389 if (delegate())
2390 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2391}
2392
2393void TabContents::UpdateRenderViewSizeForRenderManager() {
2394 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
2395 view_->SizeContents(view_->GetContainerSize());
2396}
2397
2398DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222399 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322400}
2401
2402NavigationEntry*
2403TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2404 return controller_.GetLastCommittedEntry();
2405}
2406
2407bool TabContents::CreateRenderViewForRenderManager(
2408 RenderViewHost* render_view_host) {
[email protected]811bfe32009-07-01 08:46:252409 // If the pending navigation is to a DOMUI, tell the RenderView about any
2410 // bindings it will need enabled.
[email protected]420ae012009-04-24 05:16:322411 if (render_manager_.pending_dom_ui())
[email protected]811bfe32009-07-01 08:46:252412 render_view_host->AllowBindings(
2413 render_manager_.pending_dom_ui()->bindings());
[email protected]1adff062009-06-02 18:39:552414
[email protected]420ae012009-04-24 05:16:322415 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
2416 if (!render_view_host->CreateRenderView())
2417 return false;
2418
2419 // Now that the RenderView has been created, we need to tell it its size.
2420 rwh_view->SetSize(view_->GetContainerSize());
2421
2422 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2423 render_view_host);
2424 return true;
2425}
2426
2427void TabContents::Observe(NotificationType type,
2428 const NotificationSource& source,
2429 const NotificationDetails& details) {
2430 switch (type.value) {
2431 case NotificationType::BOOKMARK_MODEL_LOADED:
2432 // BookmarkModel finished loading, fall through to update starred state.
2433 case NotificationType::URLS_STARRED: {
2434 // Somewhere, a URL has been starred.
2435 // Ignore notifications for profiles other than our current one.
2436 Profile* source_profile = Source<Profile>(source).ptr();
2437 if (!source_profile || !source_profile->IsSameProfile(profile()))
2438 return;
2439
2440 UpdateStarredStateForCurrentURL();
2441 break;
2442 }
2443 case NotificationType::PREF_CHANGED: {
2444 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2445 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2446 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2447 UpdateAlternateErrorPageURL();
2448 } else if (*pref_name_in == prefs::kDefaultCharset ||
2449 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2450 ) {
2451 UpdateWebPreferences();
2452 } else {
2453 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2454 }
2455 break;
2456 }
2457 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2458 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2459 break;
2460
2461 case NotificationType::NAV_ENTRY_COMMITTED: {
2462 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2463
2464 NavigationController::LoadCommittedDetails& committed_details =
2465 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2466 ExpireInfoBars(committed_details);
2467 break;
2468 }
2469
2470 default:
2471 NOTREACHED();
2472 }
2473}