diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 15:24:08 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-01 15:24:08 +0000 |
commit | 2f93641aca552e88c4810924fe2135b626707b45 (patch) | |
tree | 26b29b0da55fb33174def9948f0bbdb859161edd /chrome | |
parent | 678e68ab1a5fa99f07634cce9ac22a6d700436df (diff) | |
download | chromium_src-2f93641aca552e88c4810924fe2135b626707b45.zip chromium_src-2f93641aca552e88c4810924fe2135b626707b45.tar.gz chromium_src-2f93641aca552e88c4810924fe2135b626707b45.tar.bz2 |
Move infobar handling to a tab helper, part 1.
BUG=94741
TEST=no visible change
Review URL: http://codereview.chromium.org/7810002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99187 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
47 files changed, 574 insertions, 420 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc index 6555261..4edac95 100644 --- a/chrome/browser/alternate_nav_url_fetcher.cc +++ b/chrome/browser/alternate_nav_url_fetcher.cc @@ -5,6 +5,7 @@ #include "chrome/browser/alternate_nav_url_fetcher.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/intranet_redirect_detector.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -166,5 +167,5 @@ void AlternateNavURLFetcher::ShowInfobarIfPossible() { infobar_contents_ = controller_->tab_contents(); StoreActiveEntryUniqueID(infobar_contents_); TabContentsWrapper::GetCurrentWrapperForContents(infobar_contents_)-> - AddInfoBar(this); + infobar_tab_helper()->AddInfoBar(this); } diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index c7543d4..22603c9 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -12,6 +12,7 @@ #include "chrome/browser/autofill/autofill_common_test.h" #include "chrome/browser/autofill/autofill_profile.h" #include "chrome/browser/autofill/personal_data_manager.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/translate/translate_infobar_delegate.h" @@ -509,8 +510,8 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, AutofillAfterTranslate) { render_view_host()->OnMessageReceived( ChromeViewHostMsg_TranslateLanguageDetermined(0, "ja", true)); TranslateInfoBarDelegate* infobar = - browser()->GetSelectedTabContentsWrapper()-> - GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); + browser()->GetSelectedTabContentsWrapper()->infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsTranslateInfoBarDelegate(); ASSERT_TRUE(infobar != NULL); EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, infobar->type()); diff --git a/chrome/browser/autofill/autofill_manager.cc b/chrome/browser/autofill/autofill_manager.cc index 6f0f8669..c5d4755 100644 --- a/chrome/browser/autofill/autofill_manager.cc +++ b/chrome/browser/autofill/autofill_manager.cc @@ -29,6 +29,7 @@ #include "chrome/browser/autofill/phone_number.h" #include "chrome/browser/autofill/phone_number_i18n.h" #include "chrome/browser/autofill/select_control_handler.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -209,7 +210,7 @@ void CheckForPopularForms(const std::vector<FormStructure*>& forms, ASCIIToUTF16(form_signature), UTF8ToUTF16((*it)->source_url().spec())); - tab_contents_wrapper->AddInfoBar( + tab_contents_wrapper->infobar_tab_helper()->AddInfoBar( new AutofillFeedbackInfoBarDelegate(tab_contents, text, link, message)); break; @@ -736,7 +737,7 @@ void AutofillManager::ImportFormData(const FormStructure& submitted_form) { // it. scoped_ptr<const CreditCard> scoped_credit_card(imported_credit_card); if (imported_credit_card && tab_contents()) { - tab_contents_wrapper_->AddInfoBar( + tab_contents_wrapper_->infobar_tab_helper()->AddInfoBar( new AutofillCCInfoBarDelegate(tab_contents(), scoped_credit_card.release(), personal_data_, diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 0679c97..8de225a 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -33,6 +33,7 @@ #include "chrome/browser/extensions/extension_updater.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/top_sites.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/metrics/metric_event_duration_details.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/balloon_collection.h" @@ -1372,7 +1373,7 @@ void InfoBarCountObserver::Observe(int type, } void InfoBarCountObserver::CheckCount() { - if (tab_contents_->infobar_count() != target_count_) + if (tab_contents_->infobar_tab_helper()->infobar_count() != target_count_) return; if (automation_) { @@ -2288,10 +2289,11 @@ AutofillFormSubmittedObserver::~AutofillFormSubmittedObserver() { pdm_->RemoveObserver(this); if (tab_contents_) { + InfoBarTabHelper* infobar_helper = tab_contents_->infobar_tab_helper(); InfoBarDelegate* infobar = NULL; - if (tab_contents_->infobar_count() > 0 && - (infobar = tab_contents_->GetInfoBarDelegateAt(0))) { - tab_contents_->RemoveInfoBar(infobar); + if (infobar_helper->infobar_count() > 0 && + (infobar = infobar_helper->GetInfoBarDelegateAt(0))) { + infobar_helper->RemoveInfoBar(infobar); } } } @@ -2317,20 +2319,14 @@ void AutofillFormSubmittedObserver::Observe( const NotificationSource& source, const NotificationDetails& details) { DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED); + // Accept in the infobar. tab_contents_ = Source<TabContentsWrapper>(source).ptr(); InfoBarDelegate* infobar = NULL; - if (!(infobar = tab_contents_->GetInfoBarDelegateAt(0))) { - if (automation_) { - AutomationJSONReply( - automation_, reply_message_.release()).SendError( - "Could not identify the infobar delegate."); - } - delete this; - return; - } - ConfirmInfoBarDelegate* confirm_infobar; - if (!(confirm_infobar = infobar->AsConfirmInfoBarDelegate())) { + infobar = tab_contents_->infobar_tab_helper()->GetInfoBarDelegateAt(0); + + ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate(); + if (!confirm_infobar) { if (automation_) { AutomationJSONReply( automation_, reply_message_.release()).SendError( @@ -2339,7 +2335,8 @@ void AutofillFormSubmittedObserver::Observe( delete this; return; } - if (!(confirm_infobar->Accept())) { + + if (!confirm_infobar->Accept()) { if (automation_) { AutomationJSONReply( automation_, reply_message_.release()).SendError( diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index a103455..eaaf5b3 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -53,6 +53,7 @@ #include "chrome/browser/history/top_sites.h" #include "chrome/browser/importer/importer_host.h" #include "chrome/browser/importer/importer_list.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/balloon_collection.h" @@ -1885,7 +1886,7 @@ void TestingAutomationProvider::GetInfoBarCount(int handle, size_t* count) { TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents( nav_controller->tab_contents()); - *count = wrapper->infobar_count(); + *count = wrapper->infobar_tab_helper()->infobar_count(); } } } @@ -1899,18 +1900,16 @@ void TestingAutomationProvider::ClickInfoBarAccept( if (tab_tracker_->ContainsHandle(handle)) { NavigationController* nav_controller = tab_tracker_->GetResource(handle); if (nav_controller) { - TabContentsWrapper* wrapper = + InfoBarTabHelper* infobar_helper = TabContentsWrapper::GetCurrentWrapperForContents( - nav_controller->tab_contents()); - if (info_bar_index < wrapper->infobar_count()) { + nav_controller->tab_contents())->infobar_tab_helper(); + if (info_bar_index < infobar_helper->infobar_count()) { if (wait_for_navigation) { new NavigationNotificationObserver(nav_controller, this, reply_message, 1, false, false); } InfoBarDelegate* delegate = - TabContentsWrapper::GetCurrentWrapperForContents( - nav_controller->tab_contents())->GetInfoBarDelegateAt( - info_bar_index); + infobar_helper->GetInfoBarDelegateAt(info_bar_index); if (delegate->AsConfirmInfoBarDelegate()) delegate->AsConfirmInfoBarDelegate()->Accept(); success = true; @@ -2528,11 +2527,12 @@ void TestingAutomationProvider::SetWindowDimensions( ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) { // Each infobar may have different properties depending on the type. ListValue* infobars = new ListValue; - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(tc); - for (size_t i = 0; i < wrapper->infobar_count(); ++i) { + InfoBarTabHelper* infobar_helper = + TabContentsWrapper::GetCurrentWrapperForContents(tc)-> + infobar_tab_helper(); + for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { DictionaryValue* infobar_item = new DictionaryValue; - InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); + InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i); if (infobar->AsConfirmInfoBarDelegate()) { // Also covers ThemeInstalledInfoBarDelegate. infobar_item->SetString("type", "confirm_infobar"); @@ -2596,23 +2596,27 @@ void TestingAutomationProvider::PerformActionOnInfobar( reply.SendError("Invalid or missing args"); return; } + TabContentsWrapper* tab_contents = browser->GetTabContentsWrapperAt(tab_index); if (!tab_contents) { reply.SendError(StringPrintf("No such tab at index %d", tab_index)); return; } + InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); + InfoBarDelegate* infobar = NULL; size_t infobar_index = static_cast<size_t>(infobar_index_int); - if (infobar_index >= tab_contents->infobar_count() || - !(infobar = tab_contents->GetInfoBarDelegateAt(infobar_index))) { + if (infobar_index >= infobar_helper->infobar_count()) { reply.SendError(StringPrintf("No such infobar at index %" PRIuS, infobar_index)); return; } + infobar = infobar_helper->GetInfoBarDelegateAt(infobar_index); + if ("dismiss" == action) { infobar->InfoBarDismissed(); - tab_contents->RemoveInfoBar(infobar); + infobar_helper->RemoveInfoBar(infobar); reply.SendSuccess(NULL); return; } @@ -2624,10 +2628,10 @@ void TestingAutomationProvider::PerformActionOnInfobar( } if ("accept" == action) { if (confirm_infobar->Accept()) - tab_contents->RemoveInfoBar(infobar); + infobar_helper->RemoveInfoBar(infobar); } else if ("cancel" == action) { if (confirm_infobar->Cancel()) - tab_contents->RemoveInfoBar(infobar); + infobar_helper->RemoveInfoBar(infobar); } reply.SendSuccess(NULL); return; @@ -3896,10 +3900,11 @@ TabContentsWrapper* GetTabContentsWrapperFromDict(const Browser* browser, // Get the TranslateInfoBarDelegate from TabContents. TranslateInfoBarDelegate* GetTranslateInfoBarDelegate( TabContents* tab_contents) { - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); - for (size_t i = 0; i < wrapper->infobar_count(); i++) { - InfoBarDelegate* infobar = wrapper->GetInfoBarDelegateAt(i); + InfoBarTabHelper* infobar_helper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents)-> + infobar_tab_helper(); + for (size_t i = 0; i < infobar_helper->infobar_count(); i++) { + InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(i); if (infobar->AsTranslateInfoBarDelegate()) return infobar->AsTranslateInfoBarDelegate(); } @@ -4101,7 +4106,7 @@ void TestingAutomationProvider::SelectTranslateOption( // This is the function called when an infobar is dismissed or when the // user clicks the 'Nope' translate button. translate_bar->TranslationDeclined(); - tab_contents_wrapper->RemoveInfoBar(translate_bar); + tab_contents_wrapper->infobar_tab_helper()->RemoveInfoBar(translate_bar); reply.SendSuccess(NULL); } else { reply.SendError("Invalid string found for option."); diff --git a/chrome/browser/chrome_plugin_message_filter.cc b/chrome/browser/chrome_plugin_message_filter.cc index 733358c..7720fb5 100644 --- a/chrome/browser/chrome_plugin_message_filter.cc +++ b/chrome/browser/chrome_plugin_message_filter.cc @@ -5,6 +5,7 @@ #include "chrome/browser/chrome_plugin_message_filter.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/plugin_download_helper.h" #include "chrome/browser/plugin_installer_infobar_delegate.h" #include "chrome/browser/plugin_observer.h" @@ -106,9 +107,10 @@ void ChromePluginMessageFilter::HandleMissingPluginStatus( host->delegate()->GetAsTabContents()); if (!tcw) return; + InfoBarTabHelper* infobar_helper = tcw->infobar_tab_helper(); if (status == webkit::npapi::default_plugin::MISSING_PLUGIN_AVAILABLE) { - tcw->AddInfoBar( + infobar_helper->AddInfoBar( new PluginInstallerInfoBarDelegate( host->delegate()->GetAsTabContents(), window)); return; @@ -116,10 +118,10 @@ void ChromePluginMessageFilter::HandleMissingPluginStatus( DCHECK_EQ(webkit::npapi::default_plugin::MISSING_PLUGIN_USER_STARTED_DOWNLOAD, status); - for (size_t i = 0; i < tcw->infobar_count(); ++i) { - InfoBarDelegate* delegate = tcw->GetInfoBarDelegateAt(i); + for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { + InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); if (delegate->AsPluginInstallerInfoBarDelegate() != NULL) { - tcw->RemoveInfoBar(delegate); + infobar_helper->RemoveInfoBar(delegate); return; } } @@ -128,5 +130,5 @@ void ChromePluginMessageFilter::HandleMissingPluginStatus( // Linux: http://crbug.com/10952 // Mac: http://crbug.com/17392 NOTIMPLEMENTED(); -#endif // OS_WIN} +#endif // OS_WIN } diff --git a/chrome/browser/chrome_quota_permission_context.cc b/chrome/browser/chrome_quota_permission_context.cc index 8f13bbb..a557b64 100644 --- a/chrome/browser/chrome_quota_permission_context.cc +++ b/chrome/browser/chrome_quota_permission_context.cc @@ -7,6 +7,7 @@ #include <string> #include "base/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" @@ -143,7 +144,7 @@ void ChromeQuotaPermissionContext::RequestQuotaPermission( TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); - wrapper->AddInfoBar(new RequestQuotaInfoBarDelegate( + wrapper->infobar_tab_helper()->AddInfoBar(new RequestQuotaInfoBarDelegate( tab_contents, this, origin_url, requested_quota, wrapper->profile()->GetPrefs()->GetString(prefs::kAcceptLanguages), diff --git a/chrome/browser/download/download_request_limiter.cc b/chrome/browser/download/download_request_limiter.cc index ea9c73f..011f2c1 100644 --- a/chrome/browser/download/download_request_limiter.cc +++ b/chrome/browser/download/download_request_limiter.cc @@ -6,6 +6,7 @@ #include "base/stl_util.h" #include "chrome/browser/download/download_request_infobar_delegate.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/browser_thread.h" @@ -76,7 +77,7 @@ void DownloadRequestLimiter::TabDownloadState::PromptUserForDownload( infobar_ = new DownloadRequestInfoBarDelegate(tab, this); TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab); - wrapper->AddInfoBar(infobar_); + wrapper->infobar_tab_helper()->AddInfoBar(infobar_); } } diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc index e457f6d..4f996a3 100644 --- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc @@ -10,6 +10,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/extension_install_ui.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -184,8 +185,8 @@ void ShowExtensionDisabledUI(ExtensionService* service, Profile* profile, if (!tab_contents) return; - tab_contents->AddInfoBar(new ExtensionDisabledInfobarDelegate( - tab_contents, service, extension)); + tab_contents->infobar_tab_helper()->AddInfoBar( + new ExtensionDisabledInfobarDelegate(tab_contents, service, extension)); } void ShowExtensionDisabledDialog(ExtensionService* service, Profile* profile, diff --git a/chrome/browser/extensions/extension_infobar_module.cc b/chrome/browser/extensions/extension_infobar_module.cc index 6c39189..3b263b0 100644 --- a/chrome/browser/extensions/extension_infobar_module.cc +++ b/chrome/browser/extensions/extension_infobar_module.cc @@ -12,6 +12,7 @@ #include "chrome/browser/extensions/extension_infobar_module_constants.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/extensions/extension_tabs_module_constants.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -56,7 +57,7 @@ bool ShowInfoBarFunction::RunImpl() { return false; } - tab_contents->AddInfoBar( + tab_contents->infobar_tab_helper()->AddInfoBar( new ExtensionInfoBarDelegate(browser, tab_contents->tab_contents(), GetExtension(), url, height)); diff --git a/chrome/browser/extensions/extension_install_ui.cc b/chrome/browser/extensions/extension_install_ui.cc index 44c7b5e..7d6ac03 100644 --- a/chrome/browser/extensions/extension_install_ui.cc +++ b/chrome/browser/extensions/extension_install_ui.cc @@ -14,6 +14,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/extensions/extension_install_dialog.h" #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/simple_message_box.h" #include "chrome/browser/tabs/tab_strip_model.h" @@ -259,11 +260,12 @@ void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, TabContentsWrapper* tab_contents = browser->GetSelectedTabContentsWrapper(); if (!tab_contents) return; + InfoBarTabHelper* infobar_helper = tab_contents->infobar_tab_helper(); // First find any previous theme preview infobars. InfoBarDelegate* old_delegate = NULL; - for (size_t i = 0; i < tab_contents->infobar_count(); ++i) { - InfoBarDelegate* delegate = tab_contents->GetInfoBarDelegateAt(i); + for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { + InfoBarDelegate* delegate = infobar_helper->GetInfoBarDelegateAt(i); ThemeInstalledInfoBarDelegate* theme_infobar = delegate->AsThemePreviewInfobarDelegate(); if (theme_infobar) { @@ -283,9 +285,9 @@ void ExtensionInstallUI::ShowThemeInfoBar(const std::string& previous_theme_id, previous_using_native_theme); if (old_delegate) - tab_contents->ReplaceInfoBar(old_delegate, new_delegate); + infobar_helper->ReplaceInfoBar(old_delegate, new_delegate); else - tab_contents->AddInfoBar(new_delegate); + infobar_helper->AddInfoBar(new_delegate); } void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { diff --git a/chrome/browser/extensions/extension_install_ui_browsertest.cc b/chrome/browser/extensions/extension_install_ui_browsertest.cc index 23ddbb7..1ac2196 100644 --- a/chrome/browser/extensions/extension_install_ui_browsertest.cc +++ b/chrome/browser/extensions/extension_install_ui_browsertest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -20,12 +21,13 @@ class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { void VerifyThemeInfoBarAndUndoInstall() { TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); ASSERT_TRUE(tab); - ASSERT_EQ(1U, tab->infobar_count()); - ConfirmInfoBarDelegate* delegate = - tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); + ASSERT_EQ(1U, infobar_helper->infobar_count()); + ConfirmInfoBarDelegate* delegate = infobar_helper-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate); delegate->Cancel(); - ASSERT_EQ(0U, tab->infobar_count()); + ASSERT_EQ(0U, infobar_helper->infobar_count()); } const Extension* GetTheme() const { diff --git a/chrome/browser/extensions/extension_management_browsertest.cc b/chrome/browser/extensions/extension_management_browsertest.cc index cd018a42..dd5357b 100644 --- a/chrome/browser/extensions/extension_management_browsertest.cc +++ b/chrome/browser/extensions/extension_management_browsertest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_test_message_listener.h" #include "chrome/browser/extensions/extension_updater.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/scoped_user_pref_update.h" #include "chrome/browser/profiles/profile.h" @@ -177,14 +178,15 @@ IN_PROC_BROWSER_TEST_F(ExtensionManagementTest, UpdatePermissionsAndUninstall) { // Make sure the "disable extension" infobar is present. ASSERT_EQ(0, browser()->active_index()); - TabContentsWrapper* wrapper = browser()->GetTabContentsWrapperAt(0); - ASSERT_EQ(1U, wrapper->infobar_count()); + InfoBarTabHelper* infobar_helper = browser()->GetTabContentsWrapperAt(0)-> + infobar_tab_helper(); + ASSERT_EQ(1U, infobar_helper->infobar_count()); // Uninstall, and check that the infobar went away. ExtensionService* service = browser()->profile()->GetExtensionService(); std::string id = service->disabled_extensions()->at(0)->id(); UninstallExtension(id); - ASSERT_EQ(0U, wrapper->infobar_count()); + ASSERT_EQ(0U, infobar_helper->infobar_count()); // Now select a new tab, and switch back to the first tab which had the // infobar. We should not crash. diff --git a/chrome/browser/external_tab_container_win.cc b/chrome/browser/external_tab_container_win.cc index 5f77e24..253c586 100644 --- a/chrome/browser/external_tab_container_win.cc +++ b/chrome/browser/external_tab_container_win.cc @@ -19,6 +19,7 @@ #include "chrome/browser/google/google_util.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/history_tab_helper.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/page_info_window.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" @@ -193,7 +194,7 @@ bool ExternalTabContainer::Init(Profile* profile, } if (!infobars_enabled) - tab_contents_->set_infobars_enabled(false); + tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); tab_contents_->tab_contents()->set_delegate(this); diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc index d41be1c..fc7af06 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context.cc @@ -13,6 +13,7 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" @@ -465,7 +466,7 @@ void GeolocationInfoBarQueueController::ShowQueuedInfoBar(int render_process_id, tab_contents, this, render_process_id, render_view_id, i->bridge_id, i->requesting_frame, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); - wrapper->AddInfoBar(i->infobar_delegate); + wrapper->infobar_tab_helper()->AddInfoBar(i->infobar_delegate); } break; } @@ -489,7 +490,7 @@ GeolocationInfoBarQueueController::PendingInfoBarRequests::iterator // asynchronously. TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); - wrapper->RemoveInfoBar(i->infobar_delegate); + wrapper->infobar_tab_helper()->RemoveInfoBar(i->infobar_delegate); return ++i; } diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 3109341..22836ed 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/infobar.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -101,6 +102,9 @@ class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { return extra_tabs_[tab]->tab_contents()->render_view_host()->routing_id(); } int bridge_id() const { return 42; } // Not relevant at this level. + InfoBarTabHelper* infobar_tab_helper() { + return contents_wrapper()->infobar_tab_helper(); + } void CheckPermissionMessageSent(int bridge_id, bool allowed); void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); @@ -211,14 +215,14 @@ void GeolocationPermissionContextTests::TearDown() { TEST_F(GeolocationPermissionContextTests, SinglePermission) { GURL requesting_frame("http://www.example.com/geolocation"); NavigateAndCommit(requesting_frame); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); infobar_0->Cancel(); - contents_wrapper()->RemoveInfoBar(infobar_0); + infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); infobar_0->InfoBarClosed(); @@ -242,16 +246,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Request permission for two frames. geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame_0); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id() + 1, requesting_frame_1); // Ensure only one infobar is created. - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); string16 text_0 = infobar_0->GetMessageText(); @@ -260,16 +264,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(bridge_id(), true); - contents_wrapper()->RemoveInfoBar(infobar_0); + infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); closed_delegate_tracker_.Clear(); infobar_0->InfoBarClosed(); // Now we should have a new infobar for the second frame. - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_1 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); string16 text_1 = infobar_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -278,11 +282,11 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { infobar_1->Cancel(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); CheckPermissionMessageSent(bridge_id() + 1, false); - contents_wrapper()->RemoveInfoBar(infobar_1); + infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ALLOW, profile()->GetHostContentSettingsMap()->GetContentSetting( @@ -318,16 +322,16 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Request permission for two frames. geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame_0); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id() + 1, requesting_frame_1); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); string16 text_0 = infobar_0->GetMessageText(); @@ -339,10 +343,10 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); closed_delegate_tracker_.Clear(); infobar_0->InfoBarClosed(); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_1 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); string16 text_1 = infobar_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -351,11 +355,11 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { infobar_1->Accept(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(bridge_id() + 1, true); - contents_wrapper()->RemoveInfoBar(infobar_1); + infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ASK, profile()->GetHostContentSettingsMap()->GetContentSetting( @@ -376,10 +380,10 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) { GURL invalid_embedder; GURL requesting_frame("about:blank"); NavigateAndCommit(invalid_embedder); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); CheckPermissionMessageSent(bridge_id(), false); } @@ -390,34 +394,34 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { AddNewTab(url_b); AddNewTab(url_a); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), url_a); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); - EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); + EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); - ASSERT_EQ(1U, extra_tabs_[1]->infobar_count()); + ASSERT_EQ(1U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); - ConfirmInfoBarDelegate* removed_infobar = - extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* removed_infobar = extra_tabs_[1]-> + infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); // Accept the first tab. - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); infobar_0->Accept(); CheckPermissionMessageSent(bridge_id(), true); - contents_wrapper()->RemoveInfoBar(infobar_0); + infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); infobar_0->InfoBarClosed(); // Now the infobar for the tab with the same origin should have gone. - EXPECT_EQ(0U, extra_tabs_[1]->infobar_count()); + EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); CheckPermissionMessageSentForTab(1, bridge_id(), true); EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); closed_delegate_tracker_.Clear(); @@ -425,11 +429,11 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { removed_infobar->InfoBarClosed(); // But the other tab should still have the info bar... - ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); - ConfirmInfoBarDelegate* infobar_1 = - extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); infobar_1->Cancel(); - extra_tabs_[0]->RemoveInfoBar(infobar_1); + extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); @@ -443,34 +447,34 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { NavigateAndCommit(url_a); AddNewTab(url_a); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), url_a); - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); - EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); + EXPECT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); geolocation_permission_context_->RequestGeolocationPermission( process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); - ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); + ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); ConfirmInfoBarDelegate* removed_infobar = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); // Accept the second tab. - ConfirmInfoBarDelegate* infobar_0 = - extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); infobar_0->Accept(); CheckPermissionMessageSentForTab(0, bridge_id(), true); - extra_tabs_[0]->RemoveInfoBar(infobar_0); + extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); infobar_0->InfoBarClosed(); // Now the infobar for the tab with the same origin should have gone. - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); CheckPermissionMessageSent(bridge_id(), true); EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); closed_delegate_tracker_.Clear(); @@ -478,15 +482,15 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { removed_infobar->InfoBarClosed(); // And we should have the queued infobar displayed now. - ASSERT_EQ(1U, extra_tabs_[0]->infobar_count()); + ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); // Accept the second infobar. - ConfirmInfoBarDelegate* infobar_1 = - extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_1); infobar_1->Accept(); CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); - extra_tabs_[0]->RemoveInfoBar(infobar_1); + extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_delegate_tracker_.size()); EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); infobar_1->InfoBarClosed(); @@ -514,16 +518,16 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) { std::string())); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Request permission for two frames. geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id(), requesting_frame_0); geolocation_permission_context_->RequestGeolocationPermission( process_id(), render_id(), bridge_id() + 1, requesting_frame_1); // Ensure only one infobar is created. - ASSERT_EQ(1U, contents_wrapper()->infobar_count()); - ConfirmInfoBarDelegate* infobar_0 = - contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); + ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_0); // Delete the tab contents. diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc index 43d89bd..c80f49c 100644 --- a/chrome/browser/geolocation/geolocation_browsertest.cc +++ b/chrome/browser/geolocation/geolocation_browsertest.cc @@ -13,6 +13,7 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/dom_operation_notification_details.h" #include "chrome/browser/geolocation/geolocation_settings_state.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/infobar.h" @@ -331,7 +332,7 @@ class GeolocationBrowserTest : public InProcessBrowserTest { observer.Wait(); } - tab_contents_wrapper->RemoveInfoBar(infobar_); + tab_contents_wrapper->infobar_tab_helper()->RemoveInfoBar(infobar_); LOG(WARNING) << "infobar response set"; infobar_ = NULL; EXPECT_GT(settings_state.state_map().size(), state_map_size); @@ -576,12 +577,12 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, iframe_xpath_ = L"//iframe[@id='iframe_1']"; AddGeolocationWatch(true); - size_t num_infobars_before_cancel = - current_browser_->GetSelectedTabContentsWrapper()->infobar_count(); + InfoBarTabHelper* infobar_helper = current_browser_-> + GetSelectedTabContentsWrapper()->infobar_tab_helper(); + size_t num_infobars_before_cancel = infobar_helper->infobar_count(); // Change the iframe, and ensure the infobar is gone. IFrameLoader change_iframe_1(current_browser_, 1, current_url_); - size_t num_infobars_after_cancel = - current_browser_->GetSelectedTabContentsWrapper()->infobar_count(); + size_t num_infobars_after_cancel = infobar_helper->infobar_count(); EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); } diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index dd719fb..8c0bf46 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -12,6 +12,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -36,7 +37,7 @@ InfoBarDelegate* CreateInfobar(TabContents* tab_contents, google_url_tracker, new_google_url); TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); - wrapper->AddInfoBar(infobar); + wrapper->infobar_tab_helper()->AddInfoBar(infobar); return infobar; } diff --git a/chrome/browser/infobars/infobar_tab_helper.cc b/chrome/browser/infobars/infobar_tab_helper.cc new file mode 100644 index 0000000..4109189 --- /dev/null +++ b/chrome/browser/infobars/infobar_tab_helper.cc @@ -0,0 +1,199 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/infobars/infobar_tab_helper.h" + +#include "chrome/browser/tab_contents/infobar.h" +#include "chrome/browser/tab_contents/infobar_delegate.h" +#include "chrome/browser/tab_contents/insecure_content_infobar_delegate.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/common/chrome_notification_types.h" +#include "chrome/common/render_messages.h" +#include "content/common/notification_service.h" +#include "content/browser/tab_contents/tab_contents.h" + +InfoBarTabHelper::InfoBarTabHelper(TabContentsWrapper* tab_contents) + : TabContentsObserver(tab_contents->tab_contents()), + infobars_enabled_(true), + tab_contents_wrapper_(tab_contents) { + DCHECK(tab_contents); +} + +InfoBarTabHelper::~InfoBarTabHelper() { + // Destroy all remaining InfoBars. It's important to not animate here so that + // we guarantee that we'll delete all delegates before we do anything else. + // + // TODO(pkasting): If there is no InfoBarContainer, this leaks all the + // InfoBarDelegates. This will be fixed once we call CloseSoon() directly on + // Infobars. + RemoveAllInfoBars(false); +} + +void InfoBarTabHelper::AddInfoBar(InfoBarDelegate* delegate) { + if (!infobars_enabled_) { + delegate->InfoBarClosed(); + return; + } + + for (size_t i = 0; i < infobars_.size(); ++i) { + if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { + delegate->InfoBarClosed(); + return; + } + } + + infobars_.push_back(delegate); + NotificationService::current()->Notify( + chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, + Source<TabContentsWrapper>(tab_contents_wrapper_), + Details<InfoBarAddedDetails>(delegate)); + + // Add ourselves as an observer for navigations the first time a delegate is + // added. We use this notification to expire InfoBars that need to expire on + // page transitions. + if (infobars_.size() == 1) { + registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, + Source<NavigationController>(&tab_contents()->controller())); + } +} + +void InfoBarTabHelper::RemoveInfoBar(InfoBarDelegate* delegate) { + RemoveInfoBarInternal(delegate, true); +} + +void InfoBarTabHelper::ReplaceInfoBar(InfoBarDelegate* old_delegate, + InfoBarDelegate* new_delegate) { + if (!infobars_enabled_) { + AddInfoBar(new_delegate); // Deletes the delegate. + return; + } + + size_t i; + for (i = 0; i < infobars_.size(); ++i) { + if (GetInfoBarDelegateAt(i) == old_delegate) + break; + } + DCHECK_LT(i, infobars_.size()); + + infobars_.insert(infobars_.begin() + i, new_delegate); + + old_delegate->clear_owner(); + InfoBarReplacedDetails replaced_details(old_delegate, new_delegate); + NotificationService::current()->Notify( + chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, + Source<TabContentsWrapper>(tab_contents_wrapper_), + Details<InfoBarReplacedDetails>(&replaced_details)); + + infobars_.erase(infobars_.begin() + i + 1); +} + +InfoBarDelegate* InfoBarTabHelper::GetInfoBarDelegateAt(size_t index) { + return infobars_[index]; +} + +void InfoBarTabHelper::RemoveInfoBarInternal(InfoBarDelegate* delegate, + bool animate) { + if (!infobars_enabled_) { + DCHECK(infobars_.empty()); + return; + } + + size_t i; + for (i = 0; i < infobars_.size(); ++i) { + if (GetInfoBarDelegateAt(i) == delegate) + break; + } + DCHECK_LT(i, infobars_.size()); + InfoBarDelegate* infobar = infobars_[i]; + + infobar->clear_owner(); + InfoBarRemovedDetails removed_details(infobar, animate); + NotificationService::current()->Notify( + chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, + Source<TabContentsWrapper>(tab_contents_wrapper_), + Details<InfoBarRemovedDetails>(&removed_details)); + + infobars_.erase(infobars_.begin() + i); + // Remove ourselves as an observer if we are tracking no more InfoBars. + if (infobars_.empty()) { + registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, + Source<NavigationController>(&tab_contents()->controller())); + } +} + +void InfoBarTabHelper::RemoveAllInfoBars(bool animate) { + while (!infobars_.empty()) + RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); +} + +void InfoBarTabHelper::OnDidBlockDisplayingInsecureContent() { + // At most one infobar and do not supersede the stronger running content bar. + for (size_t i = 0; i < infobars_.size(); ++i) { + if (GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate()) + return; + } + AddInfoBar(new InsecureContentInfoBarDelegate(tab_contents_wrapper_, + InsecureContentInfoBarDelegate::DISPLAY)); +} + +void InfoBarTabHelper::OnDidBlockRunningInsecureContent() { + // At most one infobar superseding any weaker displaying content bar. + for (size_t i = 0; i < infobars_.size(); ++i) { + InsecureContentInfoBarDelegate* delegate = + GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate(); + if (delegate) { + if (delegate->type() != InsecureContentInfoBarDelegate::RUN) { + ReplaceInfoBar(delegate, new InsecureContentInfoBarDelegate( + tab_contents_wrapper_, + InsecureContentInfoBarDelegate::RUN)); + } + return; + } + } + AddInfoBar(new InsecureContentInfoBarDelegate(tab_contents_wrapper_, + InsecureContentInfoBarDelegate::RUN)); +} + +void InfoBarTabHelper::RenderViewGone() { + RemoveAllInfoBars(true); +} + +bool InfoBarTabHelper::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(InfoBarTabHelper, message) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, + OnDidBlockDisplayingInsecureContent) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, + OnDidBlockRunningInsecureContent) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +void InfoBarTabHelper::Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) { + switch (type) { + case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { + DCHECK(&tab_contents()->controller() == + Source<NavigationController>(source).ptr()); + + content::LoadCommittedDetails& committed_details = + *(Details<content::LoadCommittedDetails>(details).ptr()); + + // NOTE: It is not safe to change the following code to count upwards or + // use iterators, as the RemoveInfoBar() call synchronously modifies our + // delegate list. + for (size_t i = infobars_.size(); i > 0; --i) { + InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1); + if (delegate->ShouldExpire(committed_details)) + RemoveInfoBar(delegate); + } + + break; + } + default: + NOTREACHED(); + } +} diff --git a/chrome/browser/infobars/infobar_tab_helper.h b/chrome/browser/infobars/infobar_tab_helper.h new file mode 100644 index 0000000..9d15d36 --- /dev/null +++ b/chrome/browser/infobars/infobar_tab_helper.h @@ -0,0 +1,81 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ +#define CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ +#pragma once + +#include "base/basictypes.h" +#include "content/browser/tab_contents/tab_contents_observer.h" +#include "content/common/notification_registrar.h" + +class InfoBarDelegate; +class TabContentsWrapper; + +// Per-tab info bar manager. +class InfoBarTabHelper : public TabContentsObserver, + public NotificationObserver { + public: + explicit InfoBarTabHelper(TabContentsWrapper* tab_contents); + virtual ~InfoBarTabHelper(); + + // Adds an InfoBar for the specified |delegate|. + // + // If infobars are disabled for this tab or the tab already has a delegate + // which returns true for InfoBarDelegate::EqualsDelegate(delegate), + // |delegate| is closed immediately without being added. + void AddInfoBar(InfoBarDelegate* delegate); + + // Removes the InfoBar for the specified |delegate|. + // + // If infobars are disabled for this tab, this will do nothing, on the + // assumption that the matching AddInfoBar() call will have already closed the + // delegate (see above). + void RemoveInfoBar(InfoBarDelegate* delegate); + + // Replaces one infobar with another, without any animation in between. + // + // If infobars are disabled for this tab, |new_delegate| is closed immediately + // without being added, and nothing else happens. + // + // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). + void ReplaceInfoBar(InfoBarDelegate* old_delegate, + InfoBarDelegate* new_delegate); + + // Enumeration and access functions. + size_t infobar_count() const { return infobars_.size(); } + // WARNING: This does not sanity-check |index|! + InfoBarDelegate* GetInfoBarDelegateAt(size_t index); + void set_infobars_enabled(bool value) { infobars_enabled_ = value; } + + // TabContentsObserver overrides: + virtual void RenderViewGone() OVERRIDE; + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + // NotificationObserver overrides: + virtual void Observe(int type, + const NotificationSource& source, + const NotificationDetails& details) OVERRIDE; + + private: + void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate); + void RemoveAllInfoBars(bool animate); + + // Message handlers. + void OnDidBlockDisplayingInsecureContent(); + void OnDidBlockRunningInsecureContent(); + + // Delegates for InfoBars associated with this InfoBarTabHelper. + std::vector<InfoBarDelegate*> infobars_; + bool infobars_enabled_; + + NotificationRegistrar registrar_; + + // Owning TabContentsWrapper. + TabContentsWrapper* tab_contents_wrapper_; + + DISALLOW_COPY_AND_ASSIGN(InfoBarTabHelper); +}; + +#endif // CHROME_BROWSER_INFOBARS_INFOBAR_TAB_HELPER_H_ diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index bd46686..89e7d38 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -12,6 +12,7 @@ #include "chrome/browser/content_settings/content_settings_provider.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_object_proxy.h" @@ -337,9 +338,6 @@ void DesktopNotificationService::RequestPermission( if (!tab) return; - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(tab); - // If |origin| hasn't been seen before and the default content setting for // notifications is "ask", show an infobar. // The cache can only answer queries on the IO thread once it's initialized, @@ -347,7 +345,9 @@ void DesktopNotificationService::RequestPermission( ContentSetting setting = GetContentSetting(origin); if (setting == CONTENT_SETTING_ASK) { // Show an info bar requesting permission. - wrapper->AddInfoBar( + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab); + wrapper->infobar_tab_helper()->AddInfoBar( new NotificationPermissionInfoBarDelegate( tab, origin, DisplayNameForOrigin(origin), process_id, route_id, callback_context)); diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc index 542fb08..edca3be 100644 --- a/chrome/browser/omnibox_search_hint.cc +++ b/chrome/browser/omnibox_search_hint.cc @@ -12,6 +12,7 @@ #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" #include "chrome/browser/autocomplete/autocomplete_match.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" @@ -201,7 +202,7 @@ void OmniboxSearchHint::Observe(int type, } void OmniboxSearchHint::ShowInfoBar() { - tab_->AddInfoBar(new HintInfoBar(this)); + tab_->infobar_tab_helper()->AddInfoBar(new HintInfoBar(this)); } void OmniboxSearchHint::ShowEnteringQuery() { diff --git a/chrome/browser/password_manager_delegate_impl.cc b/chrome/browser/password_manager_delegate_impl.cc index b873b2e..c30c638 100644 --- a/chrome/browser/password_manager_delegate_impl.cc +++ b/chrome/browser/password_manager_delegate_impl.cc @@ -6,6 +6,7 @@ #include "base/memory/singleton.h" #include "base/metrics/histogram.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/password_manager/password_form_manager.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" @@ -115,8 +116,9 @@ void PasswordManagerDelegateImpl::FillPasswordForm( void PasswordManagerDelegateImpl::AddSavePasswordInfoBar( PasswordFormManager* form_to_save) { - tab_contents_->AddInfoBar(new SavePasswordInfoBarDelegate( - tab_contents_->tab_contents(), form_to_save)); + tab_contents_->infobar_tab_helper()->AddInfoBar( + new SavePasswordInfoBarDelegate( + tab_contents_->tab_contents(), form_to_save)); } Profile* PasswordManagerDelegateImpl::GetProfileForPasswordManager() { diff --git a/chrome/browser/pdf_unsupported_feature.cc b/chrome/browser/pdf_unsupported_feature.cc index 860ceec..a599401 100644 --- a/chrome/browser/pdf_unsupported_feature.cc +++ b/chrome/browser/pdf_unsupported_feature.cc @@ -7,6 +7,7 @@ #include "base/utf_string_conversions.h" #include "base/values.h" #include "base/version.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/plugin_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -155,9 +156,9 @@ void OpenUsingReader(TabContentsWrapper* tab, if (new_delegate) { if (old_delegate) { - tab->ReplaceInfoBar(old_delegate, new_delegate); + tab->infobar_tab_helper()->ReplaceInfoBar(old_delegate, new_delegate); } else { - tab->AddInfoBar(new_delegate); + tab->infobar_tab_helper()->AddInfoBar(new_delegate); } } } @@ -386,5 +387,6 @@ void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { } } - tab->AddInfoBar(new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); + tab->infobar_tab_helper()->AddInfoBar( + new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group)); } diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc index c7a323d..44d414e 100644 --- a/chrome/browser/plugin_observer.cc +++ b/chrome/browser/plugin_observer.cc @@ -7,6 +7,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" @@ -320,15 +321,17 @@ void PluginObserver::OnCrashedPlugin(const FilePath& plugin_path) { } gfx::Image* icon = &ResourceBundle::GetSharedInstance().GetNativeImageNamed( IDR_INFOBAR_PLUGIN_CRASHED); - tab_contents_->AddInfoBar(new SimpleAlertInfoBarDelegate(tab_contents(), - icon, - l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), - true)); + tab_contents_->infobar_tab_helper()->AddInfoBar( + new SimpleAlertInfoBarDelegate( + tab_contents(), + icon, + l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), + true)); } void PluginObserver::OnBlockedOutdatedPlugin(const string16& name, const GURL& update_url) { - tab_contents_->AddInfoBar(update_url.is_empty() ? + tab_contents_->infobar_tab_helper()->AddInfoBar(update_url.is_empty() ? static_cast<InfoBarDelegate*>(new BlockedPluginInfoBarDelegate( tab_contents(), name)) : new OutdatedPluginInfoBarDelegate(tab_contents(), name, update_url)); diff --git a/chrome/browser/tab_contents/infobar.cc b/chrome/browser/tab_contents/infobar.cc index d8dacb2..b20bd8d 100644 --- a/chrome/browser/tab_contents/infobar.cc +++ b/chrome/browser/tab_contents/infobar.cc @@ -8,6 +8,7 @@ #include "build/build_config.h" #include "base/logging.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/infobar_container.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "ui/base/animation/slide_animation.h" @@ -104,7 +105,7 @@ void InfoBar::RemoveSelf() { // |owner_| can be NULL here, e.g. because the user clicks the close button // when the infobar is already closing. if (delegate_ && owner_) - owner_->RemoveInfoBar(delegate_); + owner_->infobar_tab_helper()->RemoveInfoBar(delegate_); } void InfoBar::SetBarTargetHeight(int height) { diff --git a/chrome/browser/tab_contents/infobar_container.cc b/chrome/browser/tab_contents/infobar_container.cc index cfd66e6..e01d38a 100644 --- a/chrome/browser/tab_contents/infobar_container.cc +++ b/chrome/browser/tab_contents/infobar_container.cc @@ -9,6 +9,7 @@ #include "chrome/browser/tab_contents/infobar_container.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/infobar.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -51,11 +52,14 @@ void InfoBarContainer::ChangeTabContents(TabContentsWrapper* contents) { registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, tc_source); - for (size_t i = 0; i < tab_contents_->infobar_count(); ++i) { + for (size_t i = 0; + i < tab_contents_->infobar_tab_helper()->infobar_count(); + ++i) { // As when we removed the infobars above, we prevent callbacks to // OnInfoBarAnimated() for each infobar. AddInfoBar( - tab_contents_->GetInfoBarDelegateAt(i)->CreateInfoBar(tab_contents_), + tab_contents_->infobar_tab_helper()->GetInfoBarDelegateAt(i)-> + CreateInfoBar(tab_contents_), i, false, NO_CALLBACK); } } diff --git a/chrome/browser/tab_contents/infobar_delegate.cc b/chrome/browser/tab_contents/infobar_delegate.cc index f6d88a8..e2b9477 100644 --- a/chrome/browser/tab_contents/infobar_delegate.cc +++ b/chrome/browser/tab_contents/infobar_delegate.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "build/build_config.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "content/browser/tab_contents/navigation_details.h" #include "content/browser/tab_contents/navigation_entry.h" @@ -96,6 +97,6 @@ bool InfoBarDelegate::ShouldExpireInternal( void InfoBarDelegate::RemoveSelf() { if (owner_) { TabContentsWrapper::GetCurrentWrapperForContents(owner_)-> - RemoveInfoBar(this); // Clears |owner_|. + infobar_tab_helper()->RemoveInfoBar(this); // Clears |owner_|. } } diff --git a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc index 3ae8a2e..a15bfa2 100644 --- a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc +++ b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc @@ -12,6 +12,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/certificate_viewer.h" #include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ssl/ssl_add_cert_handler.h" #include "chrome/browser/ssl_client_certificate_selector.h" @@ -150,9 +151,10 @@ TabContentsSSLHelper::SSLAddCertData::~SSLAddCertData() { void TabContentsSSLHelper::SSLAddCertData::ShowInfoBar( InfoBarDelegate* delegate) { if (infobar_delegate_) - tab_contents_->ReplaceInfoBar(infobar_delegate_, delegate); + tab_contents_->infobar_tab_helper()->ReplaceInfoBar(infobar_delegate_, + delegate); else - tab_contents_->AddInfoBar(delegate); + tab_contents_->infobar_tab_helper()->AddInfoBar(delegate); infobar_delegate_ = delegate; } diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc index 2fe1ad4..fa9369a 100644 --- a/chrome/browser/task_manager/task_manager_browsertest.cc +++ b/chrome/browser/task_manager/task_manager_browsertest.cc @@ -11,6 +11,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/notification.h" #include "chrome/browser/notifications/notification_test_util.h" @@ -373,10 +374,11 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, // Reload the extension using the "crashed extension" infobar while the task // manager is still visible. Make sure we don't crash and the extension // gets reloaded and noticed in the task manager. - TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); - ASSERT_EQ(1U, current_tab->infobar_count()); - ConfirmInfoBarDelegate* delegate = - current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); + InfoBarTabHelper* infobar_helper = + browser()->GetSelectedTabContentsWrapper()->infobar_tab_helper(); + ASSERT_EQ(1U, infobar_helper->infobar_count()); + ConfirmInfoBarDelegate* delegate = infobar_helper-> + GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate); delegate->Accept(); TaskManagerBrowserTestUtil::WaitForResourceChange(3); diff --git a/chrome/browser/translate/translate_manager.cc b/chrome/browser/translate/translate_manager.cc index 94a499c..0adff98 100644 --- a/chrome/browser/translate/translate_manager.cc +++ b/chrome/browser/translate/translate_manager.cc @@ -14,6 +14,7 @@ #include "base/values.h" #include "chrome/browser/autofill/autofill_manager.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/language_state.h" @@ -512,9 +513,10 @@ void TranslateManager::InitiateTranslation(TabContents* tab, } // Prompts the user if he/she wants the page translated. - wrapper->AddInfoBar(TranslateInfoBarDelegate::CreateDelegate( - TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab, language_code, - target_lang)); + wrapper->infobar_tab_helper()->AddInfoBar( + TranslateInfoBarDelegate::CreateDelegate( + TranslateInfoBarDelegate::BEFORE_TRANSLATE, tab, language_code, + target_lang)); } void TranslateManager::InitiateTranslationPosted( @@ -763,9 +765,9 @@ void TranslateManager::ShowInfoBar(TabContents* tab, return; if (old_infobar) { // There already is a translate infobar, simply replace it. - wrapper->ReplaceInfoBar(old_infobar, infobar); + wrapper->infobar_tab_helper()->ReplaceInfoBar(old_infobar, infobar); } else { - wrapper->AddInfoBar(infobar); + wrapper->infobar_tab_helper()->AddInfoBar(infobar); } } @@ -801,10 +803,11 @@ TranslateInfoBarDelegate* TranslateManager::GetTranslateInfoBarDelegate( TabContentsWrapper::GetCurrentWrapperForContents(tab); if (!wrapper) return NULL; + InfoBarTabHelper* infobar_helper = wrapper->infobar_tab_helper(); - for (size_t i = 0; i < wrapper->infobar_count(); ++i) { + for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { TranslateInfoBarDelegate* delegate = - wrapper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); + infobar_helper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); if (delegate) return delegate; } diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index 0900f3f..c0e32ff 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -10,6 +10,7 @@ #include "base/utf_string_conversions.h" #include "base/stringprintf.h" #include "chrome/app/chrome_command_ids.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/tab_contents/infobar.h" @@ -52,7 +53,7 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, : ui_thread_(BrowserThread::UI, &message_loop_) { } - // Simluates navigating to a page and getting the page contents and language + // Simulates navigating to a page and getting the page contents and language // for that navigation. void SimulateNavigation(const GURL& url, const std::string& lang, @@ -87,11 +88,15 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, return true; } + InfoBarTabHelper* infobar_tab_helper() { + return contents_wrapper()->infobar_tab_helper(); + } + // Returns the translate infobar if there is 1 infobar and it is a translate // infobar. TranslateInfoBarDelegate* GetTranslateInfoBar() { - return (contents_wrapper()->infobar_count() == 1) ? - contents_wrapper()->GetInfoBarDelegateAt(0)-> + return (infobar_tab_helper()->infobar_count() == 1) ? + infobar_tab_helper()->GetInfoBarDelegateAt(0)-> AsTranslateInfoBarDelegate() : NULL; } @@ -102,7 +107,7 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, if (!infobar) return false; infobar->InfoBarDismissed(); // Simulates closing the infobar. - contents_wrapper()->RemoveInfoBar(infobar); + infobar_tab_helper()->RemoveInfoBar(infobar); return true; } @@ -135,7 +140,7 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, if (!infobar) return false; infobar->TranslationDeclined(); - contents_wrapper()->RemoveInfoBar(infobar); + infobar_tab_helper()->RemoveInfoBar(infobar); return true; } @@ -632,18 +637,18 @@ TEST_F(TranslateManagerTest, MultipleOnPageContents) { // Simulate clicking 'Nope' (don't translate). EXPECT_TRUE(DenyTranslation()); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Send a new PageContents, we should not show an infobar. SimulateOnTranslateLanguageDetermined("fr", true); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); // Do the same steps but simulate closing the infobar this time. SimulateNavigation(GURL("http://www.youtube.fr"), "fr", true); EXPECT_TRUE(CloseTranslateInfoBar()); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); SimulateOnTranslateLanguageDetermined("fr", true); - EXPECT_EQ(0U, contents_wrapper()->infobar_count()); + EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); } // Test that reloading the page brings back the infobar. diff --git a/chrome/browser/ui/autologin_infobar_delegate.cc b/chrome/browser/ui/autologin_infobar_delegate.cc index ddf3c95..0b2f078 100644 --- a/chrome/browser/ui/autologin_infobar_delegate.cc +++ b/chrome/browser/ui/autologin_infobar_delegate.cc @@ -10,6 +10,7 @@ #include "base/string_split.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/net/gaia/token_service.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -249,7 +250,7 @@ void AutoLoginInfoBarDelegate::Observe(int type, const NotificationDetails& details) { if (type == content::NOTIFICATION_LOAD_STOP) { // The wrapper takes ownership of this delegate. - tab_contents_wrapper_->AddInfoBar(this); + tab_contents_wrapper_->infobar_tab_helper()->AddInfoBar(this); registrar_.RemoveAll(); } else if (type == content::NOTIFICATION_TAB_CONTENTS_DESTROYED) { // The tab contents was destroyed before the naviagation completed, so diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index e7d3e46..92491f8 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -51,6 +51,7 @@ #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/instant/instant_unload_handler.h" #include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" @@ -2435,7 +2436,7 @@ void Browser::JSOutOfMemoryHelper(TabContents* tab) { TabContentsWrapper* tcw = TabContentsWrapper::GetCurrentWrapperForContents( tab); if (tcw) { - tcw->AddInfoBar(new SimpleAlertInfoBarDelegate( + tcw->infobar_tab_helper()->AddInfoBar(new SimpleAlertInfoBarDelegate( tab, NULL, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true)); } @@ -2469,9 +2470,8 @@ void Browser::RegisterProtocolHandlerHelper(TabContents* tab, registry->CanSchemeBeOverridden(handler.protocol())) { UserMetrics::RecordAction( UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); - tcw->AddInfoBar(new RegisterProtocolHandlerInfoBarDelegate(tab, - registry, - handler)); + tcw->infobar_tab_helper()->AddInfoBar( + new RegisterProtocolHandlerInfoBarDelegate(tab, registry, handler)); } } @@ -2500,7 +2500,8 @@ void Browser::RegisterIntentHandlerHelper(TabContents* tab, intent.action = action; intent.type = type; intent.title = title; - tcw->AddInfoBar(new RegisterIntentHandlerInfoBarDelegate(tab, intent)); + tcw->infobar_tab_helper()->AddInfoBar( + new RegisterIntentHandlerInfoBarDelegate(tab, intent)); } // static @@ -3710,7 +3711,7 @@ void Browser::RendererResponsive(TabContents* source) { void Browser::WorkerCrashed(TabContents* source) { TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source); - wrapper->AddInfoBar(new SimpleAlertInfoBarDelegate( + wrapper->infobar_tab_helper()->AddInfoBar(new SimpleAlertInfoBarDelegate( source, NULL, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true)); } diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index 1e082ba..7aed22f 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -30,6 +30,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/pack_extension_job.h" #include "chrome/browser/first_run/first_run.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/net/predictor_api.h" #include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/notifications/desktop_notification_service.h" @@ -258,9 +259,10 @@ void NotifyNotDefaultBrowserTask::Run() { // In ChromeBot tests, there might be a race. This line appears to get // called during shutdown and |tab| can be NULL. TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); - if (!tab || tab->infobar_count() > 0) + if (!tab || tab->infobar_tab_helper()->infobar_count() > 0) return; - tab->AddInfoBar(new DefaultBrowserInfoBarDelegate(tab->tab_contents())); + tab->infobar_tab_helper()->AddInfoBar( + new DefaultBrowserInfoBarDelegate(tab->tab_contents())); } @@ -1104,7 +1106,7 @@ void BrowserInit::LaunchWithProfile::AddCrashedInfoBarIfNecessary( // The last session didn't exit cleanly. Show an infobar to the user // so that they can restore if they want. The delegate deletes itself when // it is closed. - tab->AddInfoBar( + tab->infobar_tab_helper()->AddInfoBar( new SessionCrashedInfoBarDelegate(profile_, tab->tab_contents())); } } @@ -1130,10 +1132,13 @@ void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary( } if (bad_flag) { - tab->AddInfoBar(new SimpleAlertInfoBarDelegate(tab->tab_contents(), NULL, - l10n_util::GetStringFUTF16(IDS_BAD_FLAGS_WARNING_MESSAGE, - UTF8ToUTF16(std::string("--") + bad_flag)), - false)); + tab->infobar_tab_helper()->AddInfoBar( + new SimpleAlertInfoBarDelegate( + tab->tab_contents(), NULL, + l10n_util::GetStringFUTF16( + IDS_BAD_FLAGS_WARNING_MESSAGE, + UTF8ToUTF16(std::string("--") + bad_flag)), + false)); } } @@ -1197,9 +1202,10 @@ void BrowserInit::LaunchWithProfile:: "http://dev.chromium.org/dnscertprovenancechecking"; string16 message = l10n_util::GetStringUTF16( IDS_DNS_CERT_PROVENANCE_CHECKING_WARNING_MESSAGE); - tab->AddInfoBar(new LearnMoreInfoBar(tab->tab_contents(), - message, - GURL(kLearnMoreURL))); + tab->infobar_tab_helper()->AddInfoBar( + new LearnMoreInfoBar(tab->tab_contents(), + message, + GURL(kLearnMoreURL))); } void BrowserInit::LaunchWithProfile::AddObsoleteSystemInfoBarIfNecessary( @@ -1220,9 +1226,10 @@ void BrowserInit::LaunchWithProfile::AddObsoleteSystemInfoBarIfNecessary( // Link to an article in the help center on minimum system requirements. const char* kLearnMoreURL = "http://www.google.com/support/chrome/bin/answer.py?answer=95411"; - tab->AddInfoBar(new LearnMoreInfoBar(tab->tab_contents(), - message, - GURL(kLearnMoreURL))); + tab->infobar_tab_helper()->AddInfoBar( + new LearnMoreInfoBar(tab->tab_contents(), + message, + GURL(kLearnMoreURL))); } #endif } diff --git a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm index 34fa8f9..35b43f1 100644 --- a/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm +++ b/chrome/browser/ui/cocoa/content_settings/collected_cookies_mac.mm @@ -10,6 +10,7 @@ #include "base/sys_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/cocoa/constrained_window_mac.h" #import "chrome/browser/ui/cocoa/content_settings/cookie_details_view_controller.h" @@ -219,7 +220,8 @@ void CollectedCookiesMac::OnSheetDidEnd(NSWindow* sheet) { - (void)windowWillClose:(NSNotification*)notif { if (contentSettingsChanged_) { TabContentsWrapper::GetCurrentWrapperForContents(tabContents_)-> - AddInfoBar(new CollectedCookiesInfoBarDelegate(tabContents_)); + infobar_tab_helper()->AddInfoBar( + new CollectedCookiesInfoBarDelegate(tabContents_)); } [allowedOutlineView_ setDelegate:nil]; [blockedOutlineView_ setDelegate:nil]; diff --git a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm index 94e5cbd..66757a7 100644 --- a/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm +++ b/chrome/browser/ui/cocoa/extensions/extension_installed_bubble_bridge.mm @@ -6,6 +6,7 @@ #include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" #include "chrome/browser/ui/browser.h" @@ -43,7 +44,7 @@ static void ShowGenericExtensionInstalledInfoBar( l10n_util::GetStringUTF16(IDS_EXTENSION_INSTALLED_MANAGE_INFO_MAC); InfoBarDelegate* delegate = new SimpleAlertInfoBarDelegate( wrapper->tab_contents(), new gfx::Image(new SkBitmap(icon)), msg, true); - wrapper->AddInfoBar(delegate); + wrapper->infobar_tab_helper()->AddInfoBar(delegate); } namespace browser { diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm index e377d18..0d19573 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm @@ -4,6 +4,7 @@ #include "base/logging.h" #include "base/mac/mac_util.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/infobar.h" #import "chrome/browser/ui/cocoa/animatable_view.h" @@ -139,9 +140,11 @@ class InfoBarNotificationObserver : public NotificationObserver { currentTabContents_ = contents; if (currentTabContents_) { - for (size_t i = 0; i < currentTabContents_->infobar_count(); ++i) { - InfoBar* infobar = currentTabContents_->GetInfoBarDelegateAt(i)-> - CreateInfoBar(currentTabContents_); + InfoBarTabHelper* infobar_helper = + currentTabContents_->infobar_tab_helper(); + for (size_t i = 0; i < infobar_helper->infobar_count(); ++i) { + InfoBar* infobar = infobar_helper-> + GetInfoBarDelegateAt(i)->CreateInfoBar(currentTabContents_); [self addInfoBar:infobar animate:NO]; } diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm index b0659b9..f8640f8 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm @@ -7,6 +7,7 @@ #include "base/logging.h" // for NOTREACHED() #include "base/mac/mac_util.h" #include "base/sys_string_conversions.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/browser/tab_contents/link_infobar_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -281,7 +282,7 @@ const float kTextBaselineShift = -1.0; // so that inner event loops don't cause us to try and remove the infobar // twice? http://crbug.com/54253 if (owner_) - owner_->RemoveInfoBar(delegate_); + owner_->infobar_tab_helper()->RemoveInfoBar(delegate_); owner_ = NULL; } diff --git a/chrome/browser/ui/cocoa/keystone_infobar.mm b/chrome/browser/ui/cocoa/keystone_infobar.mm index 81700f4..653d07a 100644 --- a/chrome/browser/ui/cocoa/keystone_infobar.mm +++ b/chrome/browser/ui/cocoa/keystone_infobar.mm @@ -12,6 +12,7 @@ #include "base/message_loop.h" #include "base/task.h" #include "chrome/browser/first_run/first_run.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #import "chrome/browser/mac/keystone_glue.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -190,9 +191,9 @@ bool KeystonePromotionInfoBarDelegate::Cancel() { // Only show if no other info bars are showing, because that's how the // default browser info bar works. - if (wrapper && wrapper->infobar_count() == 0) { - wrapper->AddInfoBar(new KeystonePromotionInfoBarDelegate( - wrapper->tab_contents())); + if (wrapper && wrapper->infobar_tab_helper()->infobar_count() == 0) { + wrapper->infobar_tab_helper()->AddInfoBar( + new KeystonePromotionInfoBarDelegate(wrapper->tab_contents())); } } } diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc index fa18272..bda976a 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc @@ -9,6 +9,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/favicon/favicon_tab_helper.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" @@ -317,7 +318,7 @@ class ContentSettingCookiesBubbleModel : public ContentSettingSingleRadioGroup { virtual ~ContentSettingCookiesBubbleModel() { if (settings_changed()) { - tab_contents()->AddInfoBar( + tab_contents()->infobar_tab_helper()->AddInfoBar( new CollectedCookiesInfoBarDelegate(tab_contents()->tab_contents())); } } diff --git a/chrome/browser/ui/gtk/collected_cookies_gtk.cc b/chrome/browser/ui/gtk/collected_cookies_gtk.cc index e73a8a2..cb9e5e1 100644 --- a/chrome/browser/ui/gtk/collected_cookies_gtk.cc +++ b/chrome/browser/ui/gtk/collected_cookies_gtk.cc @@ -9,6 +9,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/cookies_tree_model.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" #include "chrome/browser/ui/gtk/constrained_window_gtk.h" @@ -432,8 +433,9 @@ void CollectedCookiesGtk::Observe(int type, void CollectedCookiesGtk::OnClose(GtkWidget* close_button) { if (status_changed_) { - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)->AddInfoBar( - new CollectedCookiesInfoBarDelegate(tab_contents_)); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> + infobar_tab_helper()->AddInfoBar( + new CollectedCookiesInfoBarDelegate(tab_contents_)); } window_->CloseConstrainedWindow(); } diff --git a/chrome/browser/ui/shell_dialogs.cc b/chrome/browser/ui/shell_dialogs.cc index 603c75f..13fddd9 100644 --- a/chrome/browser/ui/shell_dialogs.cc +++ b/chrome/browser/ui/shell_dialogs.cc @@ -7,6 +7,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -54,7 +55,7 @@ void SelectFileDialog::SelectFile(Type type, if (source_contents) { TabContentsWrapper* wrapper = TabContentsWrapper::GetCurrentWrapperForContents(source_contents); - wrapper->AddInfoBar(new SimpleAlertInfoBarDelegate( + wrapper->infobar_tab_helper()->AddInfoBar(new SimpleAlertInfoBarDelegate( source_contents, NULL, l10n_util::GetStringUTF16(IDS_FILE_SELECTION_DIALOG_INFOBAR), diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index 4c42de2..4f68103 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -6,9 +6,8 @@ #include "base/utf_string_conversions.h" -#include "base/command_line.h" #include "base/lazy_instance.h" -#include "base/utf_string_conversions.h" +#include "base/stringprintf.h" #include "chrome/browser/autocomplete_history_manager.h" #include "chrome/browser/autofill/autofill_manager.h" #include "chrome/browser/automation/automation_tab_helper.h" @@ -20,10 +19,9 @@ #include "chrome/browser/extensions/extension_webnavigation_api.h" #include "chrome/browser/external_protocol/external_protocol_observer.h" #include "chrome/browser/favicon/favicon_tab_helper.h" -#include "chrome/browser/file_select_helper.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/history/history_tab_helper.h" -#include "chrome/browser/intents/web_intent_data.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/omnibox_search_hint.h" #include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager_delegate_impl.h" @@ -33,17 +31,11 @@ #include "chrome/browser/prerender/prerender_tab_helper.h" #include "chrome/browser/printing/print_preview_message_handler.h" #include "chrome/browser/printing/print_view_manager.h" -#include "chrome/browser/profiles/profile.h" #include "chrome/browser/remoting/firewall_traversal_observer.h" #include "chrome/browser/renderer_host/web_cache_manager.h" #include "chrome/browser/renderer_preferences_util.h" #include "chrome/browser/sessions/restore_tab_helper.h" #include "chrome/browser/safe_browsing/client_side_detection_host.h" -#include "chrome/browser/sync/glue/synced_tab_delegate.h" -#include "chrome/browser/tab_contents/infobar.h" -#include "chrome/browser/tab_contents/infobar_delegate.h" -#include "chrome/browser/tab_contents/insecure_content_infobar_delegate.h" -#include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/browser/themes/theme_service.h" @@ -60,12 +52,8 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/render_messages.h" -#include "content/browser/child_process_security_policy.h" #include "content/browser/renderer_host/render_view_host.h" -#include "content/browser/tab_contents/navigation_details.h" -#include "content/browser/tab_contents/tab_contents.h" #include "content/browser/tab_contents/tab_contents_view.h" -#include "content/browser/user_metrics.h" #include "content/common/notification_service.h" #include "content/common/view_messages.h" #include "grit/generated_resources.h" @@ -212,7 +200,6 @@ const size_t kPerScriptFontDefaultsLength = arraysize(kPerScriptFontDefaults); TabContentsWrapper::TabContentsWrapper(TabContents* contents) : TabContentsObserver(contents), delegate_(NULL), - infobars_enabled_(true), ALLOW_THIS_IN_INITIALIZER_LIST( synced_tab_delegate_(new TabContentsWrapperSyncedTabDelegate(this))), in_destructor_(false), @@ -233,6 +220,7 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) favicon_tab_helper_.reset(new FaviconTabHelper(contents)); find_tab_helper_.reset(new FindTabHelper(contents)); history_tab_helper_.reset(new HistoryTabHelper(contents)); + infobar_tab_helper_.reset(new InfoBarTabHelper(this)); password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this)); password_manager_.reset( new PasswordManager(contents, password_manager_delegate_.get())); @@ -298,13 +286,8 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) TabContentsWrapper::~TabContentsWrapper() { in_destructor_ = true; - // Destroy all remaining InfoBars. It's important to not animate here so that - // we guarantee that we'll delete all delegates before we do anything else. - // - // TODO(pkasting): If there is no InfoBarContainer, this leaks all the - // InfoBarDelegates. This will be fixed once we call CloseSoon() directly on - // Infobars. - RemoveAllInfoBars(false); + // Need to tear down infobars before the TabContents goes away. + infobar_tab_helper_.reset(); } PropertyAccessor<TabContentsWrapper*>* TabContentsWrapper::property_accessor() { @@ -521,8 +504,6 @@ void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) { } void TabContentsWrapper::RenderViewGone() { - RemoveAllInfoBars(true); - // Tell the view that we've crashed so it can prepare the sad tab page. // Only do this if we're not in browser shutdown, so that TabContents // objects that are not in a browser (e.g., HTML dialogs) and thus are @@ -544,10 +525,6 @@ bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) { IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, OnPDFHasUnsupportedFeature) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockDisplayingInsecureContent, - OnDidBlockDisplayingInsecureContent) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidBlockRunningInsecureContent, - OnDidBlockRunningInsecureContent) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -564,24 +541,6 @@ void TabContentsWrapper::Observe(int type, const NotificationSource& source, const NotificationDetails& details) { switch (type) { - case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { - DCHECK(&tab_contents_->controller() == - Source<NavigationController>(source).ptr()); - - content::LoadCommittedDetails& committed_details = - *(Details<content::LoadCommittedDetails>(details).ptr()); - - // NOTE: It is not safe to change the following code to count upwards or - // use iterators, as the RemoveInfoBar() call synchronously modifies our - // delegate list. - for (size_t i = infobars_.size(); i > 0; --i) { - InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1); - if (delegate->ShouldExpire(committed_details)) - RemoveInfoBar(delegate); - } - - break; - } case chrome::NOTIFICATION_GOOGLE_URL_UPDATED: UpdateAlternateErrorPageURL(render_view_host()); break; @@ -619,67 +578,6 @@ void TabContentsWrapper::Observe(int type, } } -void TabContentsWrapper::AddInfoBar(InfoBarDelegate* delegate) { - if (!infobars_enabled_) { - delegate->InfoBarClosed(); - return; - } - - for (size_t i = 0; i < infobars_.size(); ++i) { - if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { - delegate->InfoBarClosed(); - return; - } - } - - infobars_.push_back(delegate); - NotificationService::current()->Notify( - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, - Source<TabContentsWrapper>(this), Details<InfoBarAddedDetails>(delegate)); - - // Add ourselves as an observer for navigations the first time a delegate is - // added. We use this notification to expire InfoBars that need to expire on - // page transitions. - if (infobars_.size() == 1) { - registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&tab_contents_->controller())); - } -} - -void TabContentsWrapper::RemoveInfoBar(InfoBarDelegate* delegate) { - RemoveInfoBarInternal(delegate, true); -} - -void TabContentsWrapper::ReplaceInfoBar(InfoBarDelegate* old_delegate, - InfoBarDelegate* new_delegate) { - if (!infobars_enabled_) { - AddInfoBar(new_delegate); // Deletes the delegate. - return; - } - - size_t i; - for (i = 0; i < infobars_.size(); ++i) { - if (GetInfoBarDelegateAt(i) == old_delegate) - break; - } - DCHECK_LT(i, infobars_.size()); - - infobars_.insert(infobars_.begin() + i, new_delegate); - - old_delegate->clear_owner(); - InfoBarReplacedDetails replaced_details(old_delegate, new_delegate); - NotificationService::current()->Notify( - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, - Source<TabContentsWrapper>(this), - Details<InfoBarReplacedDetails>(&replaced_details)); - - infobars_.erase(infobars_.begin() + i + 1); -} - -InfoBarDelegate* TabContentsWrapper::GetInfoBarDelegateAt(size_t index) { - return infobars_[index]; -} - //////////////////////////////////////////////////////////////////////////////// // Internal helpers @@ -694,33 +592,6 @@ void TabContentsWrapper::OnPDFHasUnsupportedFeature() { PDFHasUnsupportedFeature(this); } -void TabContentsWrapper::OnDidBlockDisplayingInsecureContent() { - // At most one infobar and do not supersede the stronger running content bar. - for (size_t i = 0; i < infobars_.size(); ++i) { - if (GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate()) - return; - } - AddInfoBar(new InsecureContentInfoBarDelegate(this, - InsecureContentInfoBarDelegate::DISPLAY)); -} - -void TabContentsWrapper::OnDidBlockRunningInsecureContent() { - // At most one infobar superseding any weaker displaying content bar. - for (size_t i = 0; i < infobars_.size(); ++i) { - InsecureContentInfoBarDelegate* delegate = - GetInfoBarDelegateAt(i)->AsInsecureContentInfoBarDelegate(); - if (delegate) { - if (delegate->type() != InsecureContentInfoBarDelegate::RUN) { - ReplaceInfoBar(delegate, new InsecureContentInfoBarDelegate(this, - InsecureContentInfoBarDelegate::RUN)); - } - return; - } - } - AddInfoBar(new InsecureContentInfoBarDelegate(this, - InsecureContentInfoBarDelegate::RUN)); -} - GURL TabContentsWrapper::GetAlternateErrorPageURL() const { GURL url; // Disable alternate error pages when in Incognito mode. @@ -771,41 +642,6 @@ void TabContentsWrapper::UpdateSafebrowsingDetectionHost() { #endif } -void TabContentsWrapper::RemoveInfoBarInternal(InfoBarDelegate* delegate, - bool animate) { - if (!infobars_enabled_) { - DCHECK(infobars_.empty()); - return; - } - - size_t i; - for (i = 0; i < infobars_.size(); ++i) { - if (GetInfoBarDelegateAt(i) == delegate) - break; - } - DCHECK_LT(i, infobars_.size()); - InfoBarDelegate* infobar = infobars_[i]; - - infobar->clear_owner(); - InfoBarRemovedDetails removed_details(infobar, animate); - NotificationService::current()->Notify( - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - Source<TabContentsWrapper>(this), - Details<InfoBarRemovedDetails>(&removed_details)); - - infobars_.erase(infobars_.begin() + i); - // Remove ourselves as an observer if we are tracking no more InfoBars. - if (infobars_.empty()) { - registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, - Source<NavigationController>(&tab_contents_->controller())); - } -} - -void TabContentsWrapper::RemoveAllInfoBars(bool animate) { - while (!infobars_.empty()) - RemoveInfoBarInternal(GetInfoBarDelegateAt(infobar_count() - 1), animate); -} - void TabContentsWrapper::ExitFullscreenMode() { Send(new ViewMsg_ExitFullscreen(routing_id())); } diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h index 4eec779..019c0b7 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h @@ -32,7 +32,7 @@ class FaviconTabHelper; class FileSelectObserver; class FindTabHelper; class FirewallTraversalObserver; -class InfoBarDelegate; +class InfoBarTabHelper; class HistoryTabHelper; class NavigationController; class OmniboxSearchHint; @@ -104,6 +104,9 @@ class TabContentsWrapper : public TabContentsObserver, // Captures a snapshot of the page. void CaptureSnapshot(); + // Stop this tab rendering in fullscreen mode. + void ExitFullscreenMode(); + // Helper to retrieve the existing instance that wraps a given TabContents. // Returns NULL if there is no such existing instance. // NOTE: This is not intended for general use. It is intended for situations @@ -166,6 +169,7 @@ class TabContentsWrapper : public TabContentsObserver, FaviconTabHelper* favicon_tab_helper() { return favicon_tab_helper_.get(); } FindTabHelper* find_tab_helper() { return find_tab_helper_.get(); } HistoryTabHelper* history_tab_helper() { return history_tab_helper_.get(); } + InfoBarTabHelper* infobar_tab_helper() { return infobar_tab_helper_.get(); } PasswordManager* password_manager() { return password_manager_.get(); } prerender::PrerenderTabHelper* prerender_tab_helper() { @@ -220,48 +224,12 @@ class TabContentsWrapper : public TabContentsObserver, const NotificationSource& source, const NotificationDetails& details) OVERRIDE; - // Infobars ------------------------------------------------------------------ - - // Adds an InfoBar for the specified |delegate|. - // - // If infobars are disabled for this tab or the tab already has a delegate - // which returns true for InfoBarDelegate::EqualsDelegate(delegate), - // |delegate| is closed immediately without being added. - void AddInfoBar(InfoBarDelegate* delegate); - - // Removes the InfoBar for the specified |delegate|. - // - // If infobars are disabled for this tab, this will do nothing, on the - // assumption that the matching AddInfoBar() call will have already closed the - // delegate (see above). - void RemoveInfoBar(InfoBarDelegate* delegate); - - // Replaces one infobar with another, without any animation in between. - // - // If infobars are disabled for this tab, |new_delegate| is closed immediately - // without being added, and nothing else happens. - // - // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). - void ReplaceInfoBar(InfoBarDelegate* old_delegate, - InfoBarDelegate* new_delegate); - - // Enumeration and access functions. - size_t infobar_count() const { return infobars_.size(); } - // WARNING: This does not sanity-check |index|! - InfoBarDelegate* GetInfoBarDelegateAt(size_t index); - void set_infobars_enabled(bool value) { infobars_enabled_ = value; } - - // Stop this tab rendering in fullscreen mode. - void ExitFullscreenMode(); - private: // Internal helpers ---------------------------------------------------------- // Message handlers. void OnSnapshot(const SkBitmap& bitmap); void OnPDFHasUnsupportedFeature(); - void OnDidBlockDisplayingInsecureContent(); - void OnDidBlockRunningInsecureContent(); // Returns the server that can provide alternate error pages. If the returned // URL is empty, the default error page built into WebKit will be used. @@ -280,18 +248,11 @@ class TabContentsWrapper : public TabContentsObserver, // safe browsing preference has changed. void UpdateSafebrowsingDetectionHost(); - void RemoveInfoBarInternal(InfoBarDelegate* delegate, bool animate); - void RemoveAllInfoBars(bool animate); - // Data for core operation --------------------------------------------------- // Delegate for notifying our owner about stuff. Not owned by us. TabContentsWrapperDelegate* delegate_; - // Delegates for InfoBars associated with this TabContentsWrapper. - std::vector<InfoBarDelegate*> infobars_; - bool infobars_enabled_; - NotificationRegistrar registrar_; PrefChangeRegistrar pref_change_registrar_; @@ -317,6 +278,7 @@ class TabContentsWrapper : public TabContentsObserver, scoped_ptr<FaviconTabHelper> favicon_tab_helper_; scoped_ptr<FindTabHelper> find_tab_helper_; scoped_ptr<HistoryTabHelper> history_tab_helper_; + scoped_ptr<InfoBarTabHelper> infobar_tab_helper_; // PasswordManager and its delegate. The delegate must outlive the manager, // per documentation in password_manager.h. diff --git a/chrome/browser/ui/views/collected_cookies_win.cc b/chrome/browser/ui/views/collected_cookies_win.cc index 833c973..3ab5d43 100644 --- a/chrome/browser/ui/views/collected_cookies_win.cc +++ b/chrome/browser/ui/views/collected_cookies_win.cc @@ -7,6 +7,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/cookies_tree_model.h" +#include "chrome/browser/infobars/infobar_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -378,8 +379,9 @@ void CollectedCookiesWin::DeleteDelegate() { bool CollectedCookiesWin::Cancel() { if (status_changed_) { - TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)->AddInfoBar( - new CollectedCookiesInfoBarDelegate(tab_contents_)); + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents_)-> + infobar_tab_helper()->AddInfoBar( + new CollectedCookiesInfoBarDelegate(tab_contents_)); } return true; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 91935bb..c221df0 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1372,6 +1372,8 @@ 'browser/importer/toolbar_importer.h', 'browser/importer/toolbar_importer_utils.cc', 'browser/importer/toolbar_importer_utils.h', + 'browser/infobars/infobar_tab_helper.cc', + 'browser/infobars/infobar_tab_helper.h', 'browser/instant/instant_commit_type.h', 'browser/instant/instant_confirm_dialog.cc', 'browser/instant/instant_confirm_dialog.h', @@ -2378,8 +2380,8 @@ 'browser/ui/cocoa/browser_window_controller_private.h', 'browser/ui/cocoa/browser_window_controller_private.mm', 'browser/ui/cocoa/browser_window_factory.mm', - 'browser/ui/cocoa/browser_window_utils.h', - 'browser/ui/cocoa/browser_window_utils.mm', + 'browser/ui/cocoa/browser_window_utils.h', + 'browser/ui/cocoa/browser_window_utils.mm', 'browser/ui/cocoa/bubble_view.h', 'browser/ui/cocoa/bubble_view.mm', 'browser/ui/cocoa/certificate_viewer.mm', |