diff options
author | droger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 11:44:03 +0000 |
---|---|---|
committer | droger@chromium.org <droger@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-01 11:44:03 +0000 |
commit | c1b4622fe8c4dcd7114d4717323a85a26869cb40 (patch) | |
tree | d81fe2221b24ce45efebade660c858d873df6f05 /chrome/browser | |
parent | 3177c8fd4a3b00a9ee79b4c9d09d88397e0f4227 (diff) | |
download | chromium_src-c1b4622fe8c4dcd7114d4717323a85a26869cb40.zip chromium_src-c1b4622fe8c4dcd7114d4717323a85a26869cb40.tar.gz chromium_src-c1b4622fe8c4dcd7114d4717323a85a26869cb40.tar.bz2 |
Split InfoBarService core code into InfoBarManager
InfoBarService is now responsible for associating an InfoBarManager to a Tab
and handling the interactions with the rest of chrome (notifications, navigation
events).
InfoBarManager has the core logic for infobar management. It owns the list of infobars.
Eventually InfoBarManager will no longer rely on content/, but for now it still
has a reference to a WebContents instance. This reference was kept for now to
minimize the size of the change, but will be removed in a future CL.
BUG=354379
TBR=jochen
Review URL: https://codereview.chromium.org/211273007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260847 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
51 files changed, 666 insertions, 453 deletions
diff --git a/chrome/browser/accessibility/accessibility_extension_api.cc b/chrome/browser/accessibility/accessibility_extension_api.cc index 4078b44..12753b3 100644 --- a/chrome/browser/accessibility/accessibility_extension_api.cc +++ b/chrome/browser/accessibility/accessibility_extension_api.cc @@ -13,6 +13,7 @@ #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/experimental_accessibility.h" @@ -274,11 +275,12 @@ bool AccessibilityGetAlertsForTabFunction::RunImpl() { base::ListValue* alerts_value = new base::ListValue; - InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(contents)->infobar_manager(); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { // TODO(hashimoto): Make other kind of alerts available. crosbug.com/24281 ConfirmInfoBarDelegate* confirm_infobar_delegate = - infobar_service->infobar_at(i)->delegate()->AsConfirmInfoBarDelegate(); + infobar_manager->infobar_at(i)->delegate()->AsConfirmInfoBarDelegate(); if (confirm_infobar_delegate) { base::DictionaryValue* alert_value = new base::DictionaryValue; const base::string16 message_text = diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc index 91e131c..ea7f212 100644 --- a/chrome/browser/android/tab_android.cc +++ b/chrome/browser/android/tab_android.cc @@ -229,9 +229,9 @@ void TabAndroid::SwapTabContents(content::WebContents* old_contents, Java_Tab_getNativeInfoBarContainer( env, weak_java_tab_.get(env).obj())); - InfoBarService* new_infobar_service = new_contents ? - InfoBarService::FromWebContents(new_contents) : NULL; - infobar_container->ChangeInfoBarService(new_infobar_service); + InfoBarManager* new_infobar_manager = new_contents ? + InfoBarService::InfoBarManagerFromWebContents(new_contents) : NULL; + infobar_container->ChangeInfoBarManager(new_infobar_manager); Java_Tab_swapWebContents( env, diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index 723b652e..0eb543e 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -19,6 +19,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -70,8 +71,11 @@ class WindowedPersonalDataManagerObserver } virtual ~WindowedPersonalDataManagerObserver() { - if (infobar_service_ && (infobar_service_->infobar_count() > 0)) - infobar_service_->RemoveInfoBar(infobar_service_->infobar_at(0)); + if (infobar_service_ && + (infobar_service_->infobar_manager()->infobar_count() > 0)) { + InfoBarManager* infobar_manager = infobar_service_->infobar_manager(); + infobar_manager->RemoveInfoBar(infobar_manager->infobar_at(0)); + } } void Wait() { @@ -103,8 +107,9 @@ class WindowedPersonalDataManagerObserver EXPECT_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, type); infobar_service_ = InfoBarService::FromWebContents( browser_->tab_strip_model()->GetActiveWebContents()); + InfoBarManager* infobar_manager = infobar_service_->infobar_manager(); ConfirmInfoBarDelegate* infobar_delegate = - infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Accept(); } @@ -488,10 +493,9 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, InvalidCreditCardNumberIsNotAggregated) { std::string card("4408 0412 3456 7890"); ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card))); SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014"); - ASSERT_EQ(0u, - InfoBarService::FromWebContents( - browser()->tab_strip_model()->GetActiveWebContents())-> - infobar_count()); + InfoBarService* infobar_service = InfoBarService::FromWebContents( + browser()->tab_strip_model()->GetActiveWebContents()); + ASSERT_EQ(0u, infobar_service->infobar_manager()->infobar_count()); } // Test whitespaces and separator chars are stripped for valid CC numbers. @@ -675,10 +679,9 @@ IN_PROC_BROWSER_TEST_F(AutofillTest, CCInfoNotStoredWhenAutocompleteOff) { data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; FillFormAndSubmit("cc_autocomplete_off_test.html", data); - ASSERT_EQ(0u, - InfoBarService::FromWebContents( - browser()->tab_strip_model()->GetActiveWebContents())-> - infobar_count()); + InfoBarService* infobar_service = InfoBarService::FromWebContents( + browser()->tab_strip_model()->GetActiveWebContents()); + ASSERT_EQ(0u, infobar_service->infobar_manager()->infobar_count()); } // Test profile not aggregated if email found in non-email field. diff --git a/chrome/browser/autofill/autofill_interactive_uitest.cc b/chrome/browser/autofill/autofill_interactive_uitest.cc index 65ee8ee..bd7eb65 100644 --- a/chrome/browser/autofill/autofill_interactive_uitest.cc +++ b/chrome/browser/autofill/autofill_interactive_uitest.cc @@ -19,6 +19,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/translate/translate_infobar_delegate.h" @@ -146,8 +147,9 @@ class WindowedPersonalDataManagerObserver virtual ~WindowedPersonalDataManagerObserver() { if (infobar_service_) { - while (infobar_service_->infobar_count() > 0) { - infobar_service_->RemoveInfoBar(infobar_service_->infobar_at(0)); + InfoBarManager* infobar_manager = infobar_service_->infobar_manager(); + while (infobar_manager->infobar_count() > 0) { + infobar_manager->RemoveInfoBar(infobar_manager->infobar_at(0)); } } } @@ -171,8 +173,8 @@ class WindowedPersonalDataManagerObserver const content::NotificationDetails& details) OVERRIDE { infobar_service_ = InfoBarService::FromWebContents( browser_->tab_strip_model()->GetActiveWebContents()); - infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()-> - Accept(); + infobar_service_->infobar_manager()->infobar_at(0)->delegate() + ->AsConfirmInfoBarDelegate()->Accept(); } void Wait() { @@ -978,9 +980,10 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterTranslate) { // Wait for the translation bar to appear and get it. infobar_observer.Wait(); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(GetWebContents())->infobar_manager(); TranslateInfoBarDelegate* delegate = - InfoBarService::FromWebContents(GetWebContents())->infobar_at(0)-> - delegate()->AsTranslateInfoBarDelegate(); + infobar_manager->infobar_at(0)->delegate()->AsTranslateInfoBarDelegate(); ASSERT_TRUE(delegate); EXPECT_EQ(TranslateTabHelper::BEFORE_TRANSLATE, delegate->translate_step()); diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index 8dae793..fa6396f 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -36,6 +36,7 @@ #include "chrome/browser/history/history_types.h" #include "chrome/browser/history/top_sites.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/metrics/metric_event_duration_details.h" #include "chrome/browser/profiles/profile.h" @@ -1214,8 +1215,9 @@ void InfoBarCountObserver::Observe( } void InfoBarCountObserver::CheckCount() { - if (InfoBarService::FromWebContents(web_contents_)->infobar_count() != - target_count_) + InfoBarService* infobar_service = + InfoBarService::FromWebContents(web_contents_); + if (infobar_service->infobar_manager()->infobar_count() != target_count_) return; if (automation_.get()) { diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 12fc4d3..95590bb 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -63,6 +63,7 @@ #include "chrome/browser/history/top_sites.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/notifications/balloon.h" @@ -1995,10 +1996,11 @@ void TestingAutomationProvider::SetWindowDimensions( base::ListValue* TestingAutomationProvider::GetInfobarsInfo(WebContents* wc) { // Each infobar may have different properties depending on the type. base::ListValue* infobars = new base::ListValue; - InfoBarService* infobar_service = InfoBarService::FromWebContents(wc); - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(wc)->infobar_manager(); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { base::DictionaryValue* infobar_item = new base::DictionaryValue; - InfoBarDelegate* infobar = infobar_service->infobar_at(i)->delegate(); + InfoBarDelegate* infobar = infobar_manager->infobar_at(i)->delegate(); switch (infobar->GetInfoBarAutomationType()) { case InfoBarDelegate::CONFIRM_INFOBAR: infobar_item->SetString("type", "confirm_infobar"); @@ -2072,19 +2074,19 @@ void TestingAutomationProvider::PerformActionOnInfobar( return; } - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - if (infobar_index >= infobar_service->infobar_count()) { + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(web_contents)->infobar_manager(); + if (infobar_index >= infobar_manager->infobar_count()) { reply.SendError(base::StringPrintf("No such infobar at index %" PRIuS, infobar_index)); return; } - InfoBar* infobar = infobar_service->infobar_at(infobar_index); + InfoBar* infobar = infobar_manager->infobar_at(infobar_index); InfoBarDelegate* infobar_delegate = infobar->delegate(); if (action == "dismiss") { infobar_delegate->InfoBarDismissed(); - infobar_service->RemoveInfoBar(infobar); + infobar_manager->RemoveInfoBar(infobar); reply.SendSuccess(NULL); return; } @@ -2097,7 +2099,7 @@ void TestingAutomationProvider::PerformActionOnInfobar( } if ((action == "accept") ? confirm_infobar_delegate->Accept() : confirm_infobar_delegate->Cancel()) - infobar_service->RemoveInfoBar(infobar); + infobar_manager->RemoveInfoBar(infobar); reply.SendSuccess(NULL); return; } diff --git a/chrome/browser/content_settings/permission_queue_controller.cc b/chrome/browser/content_settings/permission_queue_controller.cc index 3b30691..97828d9 100644 --- a/chrome/browser/content_settings/permission_queue_controller.cc +++ b/chrome/browser/content_settings/permission_queue_controller.cc @@ -9,6 +9,7 @@ #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/media/midi_permission_infobar_delegate.h" #include "chrome/browser/profiles/profile.h" @@ -174,7 +175,7 @@ void PermissionQueueController::CancelInfoBarRequest( i != pending_infobar_requests_.end(); ++i) { if (i->id().Equals(id)) { if (i->has_infobar()) - GetInfoBarService(id)->RemoveInfoBar(i->infobar()); + GetInfoBarService(id)->infobar_manager()->RemoveInfoBar(i->infobar()); else pending_infobar_requests_.erase(i); return; @@ -208,7 +209,7 @@ void PermissionQueueController::CancelInfoBarRequests(int group_id) { for (PendingInfobarRequests::iterator i = infobar_requests_to_cancel.begin(); i != infobar_requests_to_cancel.end(); ++i) { - GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); + GetInfoBarService(i->id())->infobar_manager()->RemoveInfoBar(i->infobar()); } } @@ -254,7 +255,7 @@ void PermissionQueueController::OnPermissionSet( // Remove all infobars for the same |requesting_frame| and |embedder|. for (PendingInfobarRequests::iterator i = infobars_to_remove.begin(); i != infobars_to_remove.end(); ++i) - GetInfoBarService(i->id())->RemoveInfoBar(i->infobar()); + GetInfoBarService(i->id())->infobar_manager()->RemoveInfoBar(i->infobar()); // Send out the permission notifications. for (PendingInfobarRequests::iterator i = requests_to_notify.begin(); diff --git a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc index 6160b6e..a23ad22 100644 --- a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc +++ b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc @@ -7,6 +7,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/common/url_constants.h" #include "content/public/browser/user_metrics.h" @@ -26,8 +27,9 @@ void RegisterProtocolHandlerInfoBarDelegate::Create( scoped_ptr<ConfirmInfoBarDelegate>( new RegisterProtocolHandlerInfoBarDelegate(registry, handler)))); - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBar* existing_infobar = infobar_service->infobar_at(i); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { + InfoBar* existing_infobar = infobar_manager->infobar_at(i); RegisterProtocolHandlerInfoBarDelegate* existing_delegate = existing_infobar->delegate()-> AsRegisterProtocolHandlerInfoBarDelegate(); diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 48b0b4d..da4098c 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -43,6 +43,7 @@ #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/net/url_request_mock_util.h" #include "chrome/browser/profiles/profile.h" @@ -2791,11 +2792,12 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) { InfoBarService* infobar_service = InfoBarService::FromWebContents( browser()->tab_strip_model()->GetActiveWebContents()); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); // Verify that there is only one infobar. - ASSERT_EQ(1u, infobar_service->infobar_count()); + ASSERT_EQ(1u, infobar_manager->infobar_count()); // Get the infobar at index 0. - InfoBar* infobar = infobar_service->infobar_at(0); + InfoBar* infobar = infobar_manager->infobar_at(0); ConfirmInfoBarDelegate* confirm_infobar = infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(confirm_infobar != NULL); @@ -2806,9 +2808,9 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) { // Click on the "Allow" button to allow multiple downloads. if (confirm_infobar->Accept()) - infobar_service->RemoveInfoBar(infobar); + infobar_manager->RemoveInfoBar(infobar); // Verify that there are no more infobars. - EXPECT_EQ(0u, infobar_service->infobar_count()); + EXPECT_EQ(0u, infobar_manager->infobar_count()); // Waits for the download to complete. downloads_observer->WaitForFinished(); diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc index 46cc678..5b70d62 100644 --- a/chrome/browser/extensions/api/debugger/debugger_api.cc +++ b/chrome/browser/extensions/api/debugger/debugger_api.cc @@ -25,6 +25,7 @@ #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/webui/chrome_web_ui_controller_factory.h" @@ -339,8 +340,9 @@ ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { if (infobar_) { static_cast<ExtensionDevToolsInfoBarDelegate*>( infobar_->delegate())->set_client_host(NULL); - InfoBarService::FromWebContents(WebContents::FromRenderViewHost( - agent_host_->GetRenderViewHost()))->RemoveInfoBar(infobar_); + InfoBarService* infobar_service = InfoBarService::FromWebContents( + WebContents::FromRenderViewHost(agent_host_->GetRenderViewHost())); + infobar_service->infobar_manager()->RemoveInfoBar(infobar_); } AttachedClientHosts::GetInstance()->Remove(this); } diff --git a/chrome/browser/extensions/extension_install_ui_browsertest.cc b/chrome/browser/extensions/extension_install_ui_browsertest.cc index ca70ad8..7f3f9bb 100644 --- a/chrome/browser/extensions/extension_install_ui_browsertest.cc +++ b/chrome/browser/extensions/extension_install_ui_browsertest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" @@ -40,14 +41,14 @@ class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { WebContents* web_contents = browser()->tab_strip_model()->GetActiveWebContents(); ASSERT_TRUE(web_contents); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - ASSERT_EQ(1U, infobar_service->infobar_count()); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(web_contents)->infobar_manager(); + ASSERT_EQ(1U, infobar_manager->infobar_count()); ConfirmInfoBarDelegate* delegate = - infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate); delegate->Cancel(); - ASSERT_EQ(0U, infobar_service->infobar_count()); + ASSERT_EQ(0U, infobar_manager->infobar_count()); } // Install the given theme from the data dir and verify expected name. diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc index 986250e..68ef436 100644 --- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc +++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc @@ -10,6 +10,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" @@ -47,6 +48,7 @@ void ThemeInstalledInfoBarDelegate::Create( return; InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); scoped_ptr<InfoBar> new_infobar(ConfirmInfoBarDelegate::CreateInfoBar( scoped_ptr<ConfirmInfoBarDelegate>(new ThemeInstalledInfoBarDelegate( @@ -55,8 +57,8 @@ void ThemeInstalledInfoBarDelegate::Create( // If there's a previous theme infobar, just replace that instead of adding a // new one. - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBar* old_infobar = infobar_service->infobar_at(i); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { + InfoBar* old_infobar = infobar_manager->infobar_at(i); ThemeInstalledInfoBarDelegate* theme_infobar = old_infobar->delegate()->AsThemePreviewInfobarDelegate(); if (theme_infobar) { diff --git a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc b/chrome/browser/extensions/webstore_startup_installer_browsertest.cc index 052ad21..4f11ef9 100644 --- a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc +++ b/chrome/browser/extensions/webstore_startup_installer_browsertest.cc @@ -8,6 +8,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/startup_helper.h" #include "chrome/browser/extensions/webstore_installer_test.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/managed_mode/managed_user_service_factory.h" @@ -200,8 +201,9 @@ IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerManagedUsersTest, // No error infobar should show up. WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); - InfoBarService* info_bar_service = InfoBarService::FromWebContents(contents); - EXPECT_EQ(info_bar_service->infobar_count(), 0u); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(contents)->infobar_manager(); + EXPECT_EQ(infobar_manager->infobar_count(), 0u); } // The unpack failure test needs to use a different install .crx, which is diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 5fb8812..6bee798 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -20,6 +20,7 @@ #include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" @@ -104,11 +105,11 @@ class GeolocationPermissionContextTests PermissionRequestID RequestID(int bridge_id); PermissionRequestID RequestIDForTab(int tab, int bridge_id); - InfoBarService* infobar_service() { - return InfoBarService::FromWebContents(web_contents()); + InfoBarManager* infobar_manager() { + return InfoBarService::FromWebContents(web_contents())->infobar_manager(); } - InfoBarService* infobar_service_for_tab(int tab) { - return InfoBarService::FromWebContents(extra_tabs_[tab]); + InfoBarManager* infobar_manager_for_tab(int tab) { + return InfoBarService::FromWebContents(extra_tabs_[tab])->infobar_manager(); } void RequestGeolocationPermission(const PermissionRequestID& id, @@ -261,15 +262,15 @@ void GeolocationPermissionContextTests::TearDown() { TEST_F(GeolocationPermissionContextTests, SinglePermission) { GURL requesting_frame("http://www.example.com/geolocation"); NavigateAndCommit(requesting_frame); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - ASSERT_EQ(1U, infobar_service()->infobar_count()); - InfoBar* infobar = infobar_service()->infobar_at(0); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); + InfoBar* infobar = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate = infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Cancel(); - infobar_service()->RemoveInfoBar(infobar); + infobar_manager()->RemoveInfoBar(infobar); EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); } @@ -279,22 +280,22 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { GURL requesting_frame("http://www.example.com/geolocation"); NavigateAndCommit(requesting_frame); MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_service()-> - infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + EXPECT_EQ(1U, infobar_manager()->infobar_count()); + ConfirmInfoBarDelegate* infobar_delegate_0 = + infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); base::string16 text_0 = infobar_delegate_0->GetButtonLabel( ConfirmInfoBarDelegate::BUTTON_OK); NavigateAndCommit(requesting_frame); MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_service()-> - infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + EXPECT_EQ(1U, infobar_manager()->infobar_count()); + ConfirmInfoBarDelegate* infobar_delegate_1 = + infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); base::string16 text_1 = infobar_delegate_1->GetButtonLabel( ConfirmInfoBarDelegate::BUTTON_OK); @@ -302,20 +303,20 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { NavigateAndCommit(requesting_frame); MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); } TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { GURL requesting_frame("http://www.example.com/geolocation"); NavigateAndCommit(requesting_frame); MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> - infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + EXPECT_EQ(1U, infobar_manager()->infobar_count()); + ConfirmInfoBarDelegate* infobar_delegate = + infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Accept(); CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); @@ -326,11 +327,11 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { GURL requesting_frame("http://www.example.com/geolocation"); NavigateAndCommit(requesting_frame); MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> - infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + EXPECT_EQ(1U, infobar_manager()->infobar_count()); + ConfirmInfoBarDelegate* infobar_delegate = + infobar_manager()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Accept(); EXPECT_TRUE( @@ -351,13 +352,13 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); // Request permission for two frames. RequestGeolocationPermission(RequestID(0), requesting_frame_0); RequestGeolocationPermission(RequestID(1), requesting_frame_1); // Ensure only one infobar is created. - ASSERT_EQ(1U, infobar_service()->infobar_count()); - InfoBar* infobar_0 = infobar_service()->infobar_at(0); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); + InfoBar* infobar_0 = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); @@ -368,14 +369,14 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(0, true); - infobar_service()->RemoveInfoBar(infobar_0); + infobar_manager()->RemoveInfoBar(infobar_0); EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); closed_infobar_tracker_.Clear(); // Now we should have a new infobar for the second frame. - ASSERT_EQ(1U, infobar_service()->infobar_count()); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); - InfoBar* infobar_1 = infobar_service()->infobar_at(0); + InfoBar* infobar_1 = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); @@ -386,10 +387,10 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { infobar_delegate_1->Cancel(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); CheckPermissionMessageSent(1, false); - infobar_service()->RemoveInfoBar(infobar_1); + infobar_manager()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ALLOW, profile()->GetHostContentSettingsMap()->GetContentSetting( @@ -408,10 +409,10 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { // Navigate to the first url and check permission is requested. NavigateAndCommit(url_a); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), url_a); - ASSERT_EQ(1U, infobar_service()->infobar_count()); - InfoBar* infobar = infobar_service()->infobar_at(0); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); + InfoBar* infobar = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate = infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); @@ -426,7 +427,7 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { CheckPermissionMessageSent(0, true); // Cleanup. - infobar_service()->RemoveInfoBar(infobar); + infobar_manager()->RemoveInfoBar(infobar); EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); } @@ -434,10 +435,10 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { GURL requesting_frame("file://example/geolocation.html"); NavigateAndCommit(requesting_frame); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - EXPECT_EQ(1U, infobar_service()->infobar_count()); - InfoBar* infobar = infobar_service()->infobar_at(0); + EXPECT_EQ(1U, infobar_manager()->infobar_count()); + InfoBar* infobar = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate = infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); @@ -445,7 +446,7 @@ TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { infobar_delegate->Accept(); CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(0, true); - infobar_service()->RemoveInfoBar(infobar); + infobar_manager()->RemoveInfoBar(infobar); // Make sure the setting is not stored. EXPECT_EQ(CONTENT_SETTING_ASK, @@ -470,13 +471,13 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); // Request permission for two frames. RequestGeolocationPermission(RequestID(0), requesting_frame_0); RequestGeolocationPermission(RequestID(1), requesting_frame_1); - ASSERT_EQ(1U, infobar_service()->infobar_count()); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); - InfoBar* infobar_0 = infobar_service()->infobar_at(0); + InfoBar* infobar_0 = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); @@ -488,9 +489,9 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); closed_infobar_tracker_.Clear(); - ASSERT_EQ(1U, infobar_service()->infobar_count()); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); - InfoBar* infobar_1 = infobar_service()->infobar_at(0); + InfoBar* infobar_1 = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); @@ -501,10 +502,10 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { infobar_delegate_1->Accept(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(1, true); - infobar_service()->RemoveInfoBar(infobar_1); + infobar_manager()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ASK, profile()->GetHostContentSettingsMap()->GetContentSetting( @@ -521,9 +522,9 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) { GURL invalid_embedder("about:blank"); GURL requesting_frame; NavigateAndCommit(invalid_embedder); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); CheckPermissionMessageSent(0, false); } @@ -534,42 +535,42 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { AddNewTab(url_b); AddNewTab(url_a); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), url_a); - ASSERT_EQ(1U, infobar_service()->infobar_count()); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); - EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); + EXPECT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); - ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); + ASSERT_EQ(1U, infobar_manager_for_tab(1)->infobar_count()); - InfoBar* removed_infobar = infobar_service_for_tab(1)->infobar_at(0); + InfoBar* removed_infobar = infobar_manager_for_tab(1)->infobar_at(0); // Accept the first tab. - InfoBar* infobar_0 = infobar_service()->infobar_at(0); + InfoBar* infobar_0 = infobar_manager()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); infobar_delegate_0->Accept(); CheckPermissionMessageSent(0, true); - infobar_service()->RemoveInfoBar(infobar_0); + infobar_manager()->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); // Now the infobar for the tab with the same origin should have gone. - EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); + EXPECT_EQ(0U, infobar_manager_for_tab(1)->infobar_count()); CheckPermissionMessageSentForTab(1, 0, true); EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); closed_infobar_tracker_.Clear(); // But the other tab should still have the info bar... - ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); - InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); + ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); + InfoBar* infobar_1 = infobar_manager_for_tab(0)->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); infobar_delegate_1->Cancel(); - infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); + infobar_manager_for_tab(0)->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); } @@ -580,45 +581,45 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { NavigateAndCommit(url_a); AddNewTab(url_a); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestID(0), url_a); - ASSERT_EQ(1U, infobar_service()->infobar_count()); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); - EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); + EXPECT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); - ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); + ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); - InfoBar* removed_infobar = infobar_service()->infobar_at(0); + InfoBar* removed_infobar = infobar_manager()->infobar_at(0); // Accept the second tab. - InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); + InfoBar* infobar_0 = infobar_manager_for_tab(0)->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); infobar_delegate_0->Accept(); CheckPermissionMessageSentForTab(0, 0, true); - infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); + infobar_manager_for_tab(0)->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); // Now the infobar for the tab with the same origin should have gone. - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); CheckPermissionMessageSent(0, true); EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); closed_infobar_tracker_.Clear(); // And we should have the queued infobar displayed now. - ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); + ASSERT_EQ(1U, infobar_manager_for_tab(0)->infobar_count()); // Accept the second infobar. - InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); + InfoBar* infobar_1 = infobar_manager_for_tab(0)->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); infobar_delegate_1->Accept(); CheckPermissionMessageSentForTab(0, 1, true); - infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); + infobar_manager_for_tab(0)->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); } @@ -637,13 +638,13 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) { CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); NavigateAndCommit(requesting_frame_0); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); // Request permission for two frames. RequestGeolocationPermission(RequestID(0), requesting_frame_0); RequestGeolocationPermission(RequestID(1), requesting_frame_1); // Ensure only one infobar is created. - ASSERT_EQ(1U, infobar_service()->infobar_count()); - InfoBar* infobar = infobar_service()->infobar_at(0); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); + InfoBar* infobar = infobar_manager()->infobar_at(0); // Delete the tab contents. DeleteContents(); @@ -659,16 +660,16 @@ TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { GURL requesting_frame_1("http://www.example-2.com/geolocation"); NavigateAndCommit(requesting_frame_0); NavigateAndCommit(requesting_frame_1); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); // Go back: navigate to a pending entry before requesting geolocation // permission. web_contents()->GetController().GoBack(); // Request permission for the committed frame (not the pending one). RequestGeolocationPermission(RequestID(0), requesting_frame_1); // Ensure the infobar is created. - ASSERT_EQ(1U, infobar_service()->infobar_count()); + ASSERT_EQ(1U, infobar_manager()->infobar_count()); InfoBarDelegate* infobar_delegate = - infobar_service()->infobar_at(0)->delegate(); + infobar_manager()->infobar_at(0)->delegate(); ASSERT_TRUE(infobar_delegate); // Ensure the infobar wouldn't expire for a navigation to the committed entry. content::LoadCommittedDetails details; diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc index a55f603..6feb267 100644 --- a/chrome/browser/geolocation/geolocation_browsertest.cc +++ b/chrome/browser/geolocation/geolocation_browsertest.cc @@ -14,6 +14,7 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -420,7 +421,9 @@ void GeolocationBrowserTest::SetInfoBarResponse(const GURL& requesting_url, observer.Wait(); } - InfoBarService::FromWebContents(web_contents)->RemoveInfoBar(infobar_); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(web_contents)->infobar_manager(); + infobar_manager->RemoveInfoBar(infobar_); LOG(WARNING) << "infobar response set"; infobar_ = NULL; EXPECT_GT(usages_state.state_map().size(), state_map_size); @@ -668,10 +671,11 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { InfoBarService* infobar_service = InfoBarService::FromWebContents( current_browser()->tab_strip_model()->GetActiveWebContents()); - size_t num_infobars_before_cancel = infobar_service->infobar_count(); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); + size_t num_infobars_before_cancel = infobar_manager->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 = infobar_service->infobar_count(); + size_t num_infobars_after_cancel = infobar_manager->infobar_count(); EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); } diff --git a/chrome/browser/infobars/infobar.cc b/chrome/browser/infobars/infobar.cc index 072a009..15f04c8 100644 --- a/chrome/browser/infobars/infobar.cc +++ b/chrome/browser/infobars/infobar.cc @@ -9,7 +9,7 @@ #include "base/logging.h" #include "build/build_config.h" #include "chrome/browser/infobars/infobar_container.h" -#include "chrome/browser/infobars/infobar_service.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "ui/gfx/animation/slide_animation.h" InfoBar::InfoBar(scoped_ptr<InfoBarDelegate> delegate) @@ -51,7 +51,7 @@ SkColor InfoBar::GetBottomColor(InfoBarDelegate::Type infobar_type) { kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; } -void InfoBar::SetOwner(InfoBarService* owner) { +void InfoBar::SetOwner(InfoBarManager* owner) { DCHECK(!owner_); owner_ = owner; delegate_->StoreActiveEntryUniqueID(); diff --git a/chrome/browser/infobars/infobar.h b/chrome/browser/infobars/infobar.h index 73d3ab47..86d2b59 100644 --- a/chrome/browser/infobars/infobar.h +++ b/chrome/browser/infobars/infobar.h @@ -15,23 +15,23 @@ #include "ui/gfx/size.h" class InfoBarContainer; -class InfoBarService; +class InfoBarManager; // InfoBar is a cross-platform base class for an infobar "view" (in the MVC // sense), which owns a corresponding InfoBarDelegate "model". Typically, // a caller will call XYZInfoBarDelegate::Create() and pass in the -// InfoBarService for the relevant tab. This will create an XYZInfoBarDelegate, +// InfoBarManager for the relevant tab. This will create an XYZInfoBarDelegate, // create a platform-specific subclass of InfoBar to own it, and then call -// InfoBarService::AddInfoBar() to give it ownership of the infobar. +// InfoBarManager::AddInfoBar() to give it ownership of the infobar. // During its life, the InfoBar may be shown and hidden as the owning tab is -// switched between the foreground and background. Eventually, InfoBarService +// switched between the foreground and background. Eventually, InfoBarManager // will instruct the InfoBar to close itself. At this point, the InfoBar will // optionally animate closed; once it's no longer visible, it deletes itself, // destroying the InfoBarDelegate in the process. // // Thus, InfoBarDelegate and InfoBar implementations can assume they share // lifetimes, and not NULL-check each other; but if one needs to reach back into -// the owning InfoBarService, it must check whether that's still possible. +// the owning InfoBarManager, it must check whether that's still possible. class InfoBar : public gfx::AnimationDelegate { public: // These are the types passed as Details for infobar-related notifications. @@ -55,7 +55,7 @@ class InfoBar : public gfx::AnimationDelegate { static SkColor GetTopColor(InfoBarDelegate::Type infobar_type); static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type); - InfoBarService* owner() { return owner_; } + InfoBarManager* owner() { return owner_; } InfoBarDelegate* delegate() { return delegate_.get(); } const InfoBarDelegate* delegate() const { return delegate_.get(); } void set_container(InfoBarContainer* container) { container_ = container; } @@ -63,7 +63,7 @@ class InfoBar : public gfx::AnimationDelegate { // Sets |owner_|. This also calls StoreActiveEntryUniqueID() on |delegate_|. // This must only be called once as there's no way to extract an infobar from // its owner without deleting it, for reparenting in another tab. - void SetOwner(InfoBarService* owner); + void SetOwner(InfoBarManager* owner); // Makes the infobar visible. If |animate| is true, the infobar is then // animated to full size. @@ -129,7 +129,7 @@ class InfoBar : public gfx::AnimationDelegate { // itself. void MaybeDelete(); - InfoBarService* owner_; + InfoBarManager* owner_; scoped_ptr<InfoBarDelegate> delegate_; InfoBarContainer* container_; gfx::SlideAnimation animation_; diff --git a/chrome/browser/infobars/infobar_container.cc b/chrome/browser/infobars/infobar_container.cc index 703df3d..b9526ef 100644 --- a/chrome/browser/infobars/infobar_container.cc +++ b/chrome/browser/infobars/infobar_container.cc @@ -11,7 +11,6 @@ #include "base/logging.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_delegate.h" -#include "chrome/browser/infobars/infobar_service.h" #include "ui/gfx/animation/slide_animation.h" InfoBarContainer::Delegate::~Delegate() { @@ -19,20 +18,20 @@ InfoBarContainer::Delegate::~Delegate() { InfoBarContainer::InfoBarContainer(Delegate* delegate) : delegate_(delegate), - infobar_service_(NULL), + infobar_manager_(NULL), top_arrow_target_height_(InfoBar::kDefaultArrowTargetHeight) { } InfoBarContainer::~InfoBarContainer() { // RemoveAllInfoBarsForDestruction() should have already cleared our infobars. DCHECK(infobars_.empty()); - if (infobar_service_) - infobar_service_->RemoveObserver(this); + if (infobar_manager_) + infobar_manager_->RemoveObserver(this); } -void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { - if (infobar_service_) - infobar_service_->RemoveObserver(this); +void InfoBarContainer::ChangeInfoBarManager(InfoBarManager* infobar_manager) { + if (infobar_manager_) + infobar_manager_->RemoveObserver(this); // Hides all infobars in this container without animation. while (!infobars_.empty()) { @@ -43,14 +42,14 @@ void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { infobar->Hide(false); } - infobar_service_ = infobar_service; - if (infobar_service_) { - infobar_service_->AddObserver(this); + infobar_manager_ = infobar_manager; + if (infobar_manager_) { + infobar_manager_->AddObserver(this); - for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { + for (size_t i = 0; i < infobar_manager_->infobar_count(); ++i) { // As when we removed the infobars above, we prevent callbacks to // OnInfoBarStateChanged() for each infobar. - AddInfoBar(infobar_service_->infobar_at(i), i, false, NO_CALLBACK); + AddInfoBar(infobar_manager_->infobar_at(i), i, false, NO_CALLBACK); } } @@ -107,7 +106,7 @@ void InfoBarContainer::RemoveAllInfoBarsForDestruction() { // this point |delegate_| may be shutting down, and it's at best unimportant // and at worst disastrous to call that. delegate_ = NULL; - ChangeInfoBarService(NULL); + ChangeInfoBarManager(NULL); } void InfoBarContainer::OnInfoBarAdded(InfoBar* infobar) { @@ -130,10 +129,10 @@ void InfoBarContainer::OnInfoBarReplaced(InfoBar* old_infobar, AddInfoBar(new_infobar, position, false, WANT_CALLBACK); } -void InfoBarContainer::OnServiceShuttingDown(InfoBarService* service) { - DCHECK_EQ(infobar_service_, service); - infobar_service_->RemoveObserver(this); - infobar_service_ = NULL; +void InfoBarContainer::OnManagerShuttingDown(InfoBarManager* manager) { + DCHECK_EQ(infobar_manager_, manager); + infobar_manager_->RemoveObserver(this); + infobar_manager_ = NULL; } void InfoBarContainer::AddInfoBar(InfoBar* infobar, diff --git a/chrome/browser/infobars/infobar_container.h b/chrome/browser/infobars/infobar_container.h index c605138..683888a 100644 --- a/chrome/browser/infobars/infobar_container.h +++ b/chrome/browser/infobars/infobar_container.h @@ -9,19 +9,19 @@ #include "base/compiler_specific.h" #include "base/time/time.h" -#include "chrome/browser/infobars/infobar_service.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "third_party/skia/include/core/SkColor.h" class InfoBar; // InfoBarContainer is a cross-platform base class to handle the visibility- -// related aspects of InfoBars. While InfoBarService owns the InfoBars, the +// related aspects of InfoBars. While InfoBarManager owns the InfoBars, the // InfoBarContainer is responsible for telling particular InfoBars that they // should be hidden or visible. // // Platforms need to subclass this to implement a few platform-specific // functions, which are pure virtual here. -class InfoBarContainer : public InfoBarService::Observer { +class InfoBarContainer : public InfoBarManager::Observer { public: class Delegate { public: @@ -43,11 +43,11 @@ class InfoBarContainer : public InfoBarService::Observer { explicit InfoBarContainer(Delegate* delegate); virtual ~InfoBarContainer(); - // Changes the InfoBarService for which this container is showing infobars. + // Changes the InfoBarManager for which this container is showing infobars. // This will hide all current infobars, remove them from the container, add - // the infobars from |infobar_service|, and show them all. |infobar_service| + // the infobars from |infobar_manager|, and show them all. |infobar_manager| // may be NULL. - void ChangeInfoBarService(InfoBarService* infobar_service); + void ChangeInfoBarManager(InfoBarManager* infobar_manager); // Returns the amount by which to overlap the toolbar above, and, when // |total_height| is non-NULL, set it to the height of the InfoBarContainer @@ -99,12 +99,12 @@ class InfoBarContainer : public InfoBarService::Observer { private: typedef std::vector<InfoBar*> InfoBars; - // InfoBarService::Observer: + // InfoBarManager::Observer: virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; virtual void OnInfoBarReplaced(InfoBar* old_infobar, InfoBar* new_infobar) OVERRIDE; - virtual void OnServiceShuttingDown(InfoBarService* service) OVERRIDE; + virtual void OnManagerShuttingDown(InfoBarManager* manager) OVERRIDE; // Adds |infobar| to this container before the existing infobar at position // |position| and calls Show() on it. |animate| is passed along to @@ -121,7 +121,7 @@ class InfoBarContainer : public InfoBarService::Observer { int ArrowTargetHeightForInfoBar(size_t infobar_index) const; Delegate* delegate_; - InfoBarService* infobar_service_; + InfoBarManager* infobar_manager_; InfoBars infobars_; // Calculated in SetMaxTopArrowHeight(). diff --git a/chrome/browser/infobars/infobar_manager.cc b/chrome/browser/infobars/infobar_manager.cc new file mode 100644 index 0000000..be57b98 --- /dev/null +++ b/chrome/browser/infobars/infobar_manager.cc @@ -0,0 +1,127 @@ +// Copyright 2014 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_manager.h" + +#include "base/command_line.h" +#include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_delegate.h" +#include "chrome/common/chrome_switches.h" + +InfoBar* InfoBarManager::AddInfoBar(scoped_ptr<InfoBar> infobar) { + DCHECK(infobar); + if (!infobars_enabled_) + return NULL; + + for (InfoBars::const_iterator i(infobars_.begin()); i != infobars_.end(); + ++i) { + if ((*i)->delegate()->EqualsDelegate(infobar->delegate())) { + DCHECK_NE((*i)->delegate(), infobar->delegate()); + return NULL; + } + } + + InfoBar* infobar_ptr = infobar.release(); + infobars_.push_back(infobar_ptr); + infobar_ptr->SetOwner(this); + + FOR_EACH_OBSERVER(Observer, observer_list_, OnInfoBarAdded(infobar_ptr)); + + return infobar_ptr; +} + +void InfoBarManager::RemoveInfoBar(InfoBar* infobar) { + RemoveInfoBarInternal(infobar, true); +} + +void InfoBarManager::RemoveAllInfoBars(bool animate) { + while (!infobars_.empty()) + RemoveInfoBarInternal(infobars_.back(), animate); +} + +InfoBar* InfoBarManager::ReplaceInfoBar(InfoBar* old_infobar, + scoped_ptr<InfoBar> new_infobar) { + DCHECK(old_infobar); + if (!infobars_enabled_) + return AddInfoBar(new_infobar.Pass()); // Deletes the infobar. + DCHECK(new_infobar); + + InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), + old_infobar)); + DCHECK(i != infobars_.end()); + + InfoBar* new_infobar_ptr = new_infobar.release(); + i = infobars_.insert(i, new_infobar_ptr); + new_infobar_ptr->SetOwner(this); + + // Remove the old infobar before notifying, so that if any observers call back + // to AddInfoBar() or similar, we don't dupe-check against this infobar. + infobars_.erase(++i); + + FOR_EACH_OBSERVER(Observer, + observer_list_, + OnInfoBarReplaced(old_infobar, new_infobar_ptr)); + + old_infobar->CloseSoon(); + return new_infobar_ptr; +} + +void InfoBarManager::AddObserver(Observer* obs) { + observer_list_.AddObserver(obs); +} + +void InfoBarManager::RemoveObserver(Observer* obs) { + observer_list_.RemoveObserver(obs); +} + +InfoBarManager::InfoBarManager(content::WebContents* web_contents) + : infobars_enabled_(true), + web_contents_(web_contents) { + DCHECK(web_contents); + if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars)) + infobars_enabled_ = false; +} + +InfoBarManager::~InfoBarManager() { + // 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. + RemoveAllInfoBars(false); + FOR_EACH_OBSERVER(Observer, observer_list_, OnManagerShuttingDown(this)); +} + +void InfoBarManager::OnNavigation( + const content::LoadCommittedDetails& load_details) { + // 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) { + InfoBar* infobar = infobars_[i - 1]; + if (infobar->delegate()->ShouldExpire(load_details)) + RemoveInfoBar(infobar); + } +} + +void InfoBarManager::OnWebContentsDestroyed() { web_contents_ = NULL; } + +void InfoBarManager::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { + DCHECK(infobar); + if (!infobars_enabled_) { + DCHECK(infobars_.empty()); + return; + } + + InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); + DCHECK(i != infobars_.end()); + + // Remove the infobar before notifying, so that if any observers call back to + // AddInfoBar() or similar, we don't dupe-check against this infobar. + infobars_.erase(i); + + // This notification must happen before the call to CloseSoon() below, since + // observers may want to access |infobar| and that call can delete it. + FOR_EACH_OBSERVER(Observer, observer_list_, + OnInfoBarRemoved(infobar, animate)); + + infobar->CloseSoon(); +} diff --git a/chrome/browser/infobars/infobar_manager.h b/chrome/browser/infobars/infobar_manager.h new file mode 100644 index 0000000..f4e9b41 --- /dev/null +++ b/chrome/browser/infobars/infobar_manager.h @@ -0,0 +1,114 @@ +// Copyright 2014 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_MANAGER_H_ +#define CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_ + +#include <vector> + +#include "base/memory/scoped_ptr.h" +#include "base/observer_list.h" + +namespace content { +struct LoadCommittedDetails; +class WebContents; +} + +class InfoBar; + +// Provides access to creating, removing and enumerating info bars +// attached to a tab. +class InfoBarManager { + public: + // Observer class for infobar events. + class Observer { + public: + virtual void OnInfoBarAdded(InfoBar* infobar) = 0; + virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0; + virtual void OnInfoBarReplaced(InfoBar* old_infobar, + InfoBar* new_infobar) = 0; + virtual void OnManagerShuttingDown(InfoBarManager* manager) = 0; + }; + + explicit InfoBarManager(content::WebContents* web_contents); + ~InfoBarManager(); + + // Adds the specified |infobar|, which already owns a delegate. + // + // If infobars are disabled for this tab or the tab already has an infobar + // whose delegate returns true for + // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted + // immediately without being added. + // + // Returns the infobar if it was successfully added. + virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); + + // Removes the specified |infobar|. This in turn may close immediately or + // animate closed; at the end the infobar will delete itself. + // + // If infobars are disabled for this tab, this will do nothing, on the + // assumption that the matching AddInfoBar() call will have already deleted + // the infobar (see above). + void RemoveInfoBar(InfoBar* infobar); + + // Removes all the infobars. + void RemoveAllInfoBars(bool animate); + + // Replaces one infobar with another, without any animation in between. This + // will result in |old_infobar| being synchronously deleted. + // + // If infobars are disabled for this tab, |new_infobar| is deleted immediately + // without being added, and nothing else happens. + // + // Returns the new infobar if it was successfully added. + // + // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). + InfoBar* ReplaceInfoBar(InfoBar* old_infobar, + scoped_ptr<InfoBar> new_infobar); + + // Returns the number of infobars for this tab. + size_t infobar_count() const { return infobars_.size(); } + + // Returns the infobar at the given |index|. The InfoBarManager retains + // ownership. + // + // Warning: Does not sanity check |index|. + InfoBar* infobar_at(size_t index) { return infobars_[index]; } + + // Retrieve the WebContents for the tab this service is associated with. + // Do not add new call sites for this. + // TODO(droger): remove this method. See http://crbug.com/354379. + content::WebContents* web_contents() { return web_contents_; } + + // Must be called when a navigation happens. + void OnNavigation(const content::LoadCommittedDetails& load_details); + + // Called when the associated WebContents is being destroyed. + void OnWebContentsDestroyed(); + + void AddObserver(Observer* obs); + void RemoveObserver(Observer* obs); + + private: + // InfoBars associated with this InfoBarManager. We own these pointers. + // However, this is not a ScopedVector, because we don't delete the infobars + // directly once they've been added to this; instead, when we're done with an + // infobar, we instruct it to delete itself and then orphan it. See + // RemoveInfoBarInternal(). + typedef std::vector<InfoBar*> InfoBars; + + void RemoveInfoBarInternal(InfoBar* infobar, bool animate); + + InfoBars infobars_; + bool infobars_enabled_; + + // TODO(droger): remove this field. See http://crbug.com/354379. + content::WebContents* web_contents_; + + ObserverList<Observer, true> observer_list_; + + DISALLOW_COPY_AND_ASSIGN(InfoBarManager); +}; + +#endif // CHROME_BROWSER_INFOBARS_INFOBAR_MANAGER_H_ diff --git a/chrome/browser/infobars/infobar_service.cc b/chrome/browser/infobars/infobar_service.cc index a97d3a5..cf69c11 100644 --- a/chrome/browser/infobars/infobar_service.cc +++ b/chrome/browser/infobars/infobar_service.cc @@ -7,122 +7,53 @@ #include "base/command_line.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/infobar.h" -#include "chrome/browser/infobars/infobar_delegate.h" #include "chrome/browser/infobars/insecure_content_infobar_delegate.h" -#include "chrome/common/chrome_switches.h" #include "chrome/common/render_messages.h" -#include "content/public/browser/navigation_controller.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" - DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService); -InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) { - DCHECK(infobar); - if (!infobars_enabled_) +// static +InfoBarManager* InfoBarService::InfoBarManagerFromWebContents( + content::WebContents* web_contents) { + InfoBarService* infobar_service = FromWebContents(web_contents); + // |infobar_service| may be NULL during shutdown. + if (!infobar_service) return NULL; - - for (InfoBars::const_iterator i(infobars_.begin()); i != infobars_.end(); - ++i) { - if ((*i)->delegate()->EqualsDelegate(infobar->delegate())) { - DCHECK_NE((*i)->delegate(), infobar->delegate()); - return NULL; - } - } - - InfoBar* infobar_ptr = infobar.release(); - infobars_.push_back(infobar_ptr); - infobar_ptr->SetOwner(this); - - FOR_EACH_OBSERVER(Observer, observer_list_, OnInfoBarAdded(infobar_ptr)); - // TODO(droger): Remove the notifications and use observers instead. - // See http://crbug.com/354380 - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, - content::Source<InfoBarService>(this), - content::Details<InfoBar::AddedDetails>(infobar_ptr)); - return infobar_ptr; + return infobar_service->infobar_manager(); } -void InfoBarService::RemoveInfoBar(InfoBar* infobar) { - RemoveInfoBarInternal(infobar, true); +InfoBar* InfoBarService::AddInfoBar(scoped_ptr<InfoBar> infobar) { + return infobar_manager_.AddInfoBar(infobar.Pass()); } InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar, scoped_ptr<InfoBar> new_infobar) { - DCHECK(old_infobar); - if (!infobars_enabled_) - return AddInfoBar(new_infobar.Pass()); // Deletes the infobar. - DCHECK(new_infobar); - - InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), - old_infobar)); - DCHECK(i != infobars_.end()); - - InfoBar* new_infobar_ptr = new_infobar.release(); - i = infobars_.insert(i, new_infobar_ptr); - new_infobar_ptr->SetOwner(this); - InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar_ptr); - - // Remove the old infobar before notifying, so that if any observers call back - // to AddInfoBar() or similar, we don't dupe-check against this infobar. - infobars_.erase(++i); - - FOR_EACH_OBSERVER(Observer, - observer_list_, - OnInfoBarReplaced(old_infobar, new_infobar_ptr)); - // TODO(droger): Remove the notifications and use observers instead. - // See http://crbug.com/354380 - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, - content::Source<InfoBarService>(this), - content::Details<InfoBar::ReplacedDetails>(&replaced_details)); - - old_infobar->CloseSoon(); - return new_infobar_ptr; -} - -void InfoBarService::AddObserver(Observer* obs) { - observer_list_.AddObserver(obs); -} - -void InfoBarService::RemoveObserver(Observer* obs) { - observer_list_.RemoveObserver(obs); + return infobar_manager_.ReplaceInfoBar(old_infobar, new_infobar.Pass()); } InfoBarService::InfoBarService(content::WebContents* web_contents) : content::WebContentsObserver(web_contents), - infobars_enabled_(true) { + infobar_manager_(web_contents) { DCHECK(web_contents); - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableInfoBars)) - infobars_enabled_ = false; + infobar_manager_.AddObserver(this); } -InfoBarService::~InfoBarService() { - // 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. - RemoveAllInfoBars(false); - FOR_EACH_OBSERVER(Observer, observer_list_, OnServiceShuttingDown(this)); -} +InfoBarService::~InfoBarService() {} void InfoBarService::RenderProcessGone(base::TerminationStatus status) { - RemoveAllInfoBars(true); + infobar_manager_.RemoveAllInfoBars(true); } void InfoBarService::NavigationEntryCommitted( const content::LoadCommittedDetails& load_details) { - // 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) { - InfoBar* infobar = infobars_[i - 1]; - if (infobar->delegate()->ShouldExpire(load_details)) - RemoveInfoBar(infobar); - } + infobar_manager_.OnNavigation(load_details); } void InfoBarService::WebContentsDestroyed(content::WebContents* web_contents) { + infobar_manager_.OnWebContentsDestroyed(); + // The WebContents is going away; be aggressively paranoid and delete // ourselves lest other parts of the system attempt to add infobars or use // us otherwise during the destruction. @@ -143,38 +74,38 @@ bool InfoBarService::OnMessageReceived(const IPC::Message& message) { return handled; } -void InfoBarService::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { - DCHECK(infobar); - if (!infobars_enabled_) { - DCHECK(infobars_.empty()); - return; - } - - InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); - DCHECK(i != infobars_.end()); - - // Remove the infobar before notifying, so that if any observers call back to - // AddInfoBar() or similar, we don't dupe-check against this infobar. - infobars_.erase(i); - - // This notification must happen before the call to CloseSoon() below, since - // observers may want to access |infobar| and that call can delete it. - FOR_EACH_OBSERVER(Observer, observer_list_, - OnInfoBarRemoved(infobar, animate)); - // TODO(droger): Remove the notifications and use observers instead. - // See http://crbug.com/354380 +void InfoBarService::OnInfoBarAdded(InfoBar* infobar) { + // TODO(droger): Remove the notifications and have listeners change to be + // NavigationManager::Observers instead. See http://crbug.com/354380 + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, + content::Source<InfoBarService>(this), + content::Details<InfoBar::AddedDetails>(infobar)); +} + +void InfoBarService::OnInfoBarReplaced(InfoBar* old_infobar, + InfoBar* new_infobar) { + // TODO(droger): Remove the notifications and have listeners change to be + // NavigationManager::Observers instead. See http://crbug.com/354380 + InfoBar::ReplacedDetails replaced_details(old_infobar, new_infobar); + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED, + content::Source<InfoBarService>(this), + content::Details<InfoBar::ReplacedDetails>(&replaced_details)); +} + +void InfoBarService::OnInfoBarRemoved(InfoBar* infobar, bool animate) { + // TODO(droger): Remove the notifications and have listeners change to be + // NavigationManager::Observers instead. See http://crbug.com/354380 InfoBar::RemovedDetails removed_details(infobar, animate); content::NotificationService::current()->Notify( chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, content::Source<InfoBarService>(this), content::Details<InfoBar::RemovedDetails>(&removed_details)); - - infobar->CloseSoon(); } -void InfoBarService::RemoveAllInfoBars(bool animate) { - while (!infobars_.empty()) - RemoveInfoBarInternal(infobars_.back(), animate); +void InfoBarService::OnManagerShuttingDown(InfoBarManager* manager) { + infobar_manager_.RemoveObserver(this); } void InfoBarService::OnDidBlockDisplayingInsecureContent() { diff --git a/chrome/browser/infobars/infobar_service.h b/chrome/browser/infobars/infobar_service.h index 7be2e7c..f918da7 100644 --- a/chrome/browser/infobars/infobar_service.h +++ b/chrome/browser/infobars/infobar_service.h @@ -8,85 +8,44 @@ #include <vector> #include "base/memory/scoped_ptr.h" -#include "base/observer_list.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" +namespace content { +struct LoadCommittedDetails; +class WebContents; +} + class InfoBar; -// Provides access to creating, removing and enumerating info bars -// attached to a tab. +// Associates a Tab to a InfoBarManager and manages its lifetime. +// It manages the infobar notifications and responds to navigation events. class InfoBarService : public content::WebContentsObserver, - public content::WebContentsUserData<InfoBarService> { + public content::WebContentsUserData<InfoBarService>, + public InfoBarManager::Observer { public: - // Observer class for infobar events. - class Observer { - public: - virtual void OnInfoBarAdded(InfoBar* infobar) = 0; - virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) = 0; - virtual void OnInfoBarReplaced(InfoBar* old_infobar, - InfoBar* new_infobar) = 0; - virtual void OnServiceShuttingDown(InfoBarService* service) = 0; - }; - - // Adds the specified |infobar|, which already owns a delegate. - // - // If infobars are disabled for this tab or the tab already has an infobar - // whose delegate returns true for - // InfoBarDelegate::EqualsDelegate(infobar->delegate()), |infobar| is deleted - // immediately without being added. - // - // Returns the infobar if it was successfully added. - virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); - - // Removes the specified |infobar|. This in turn may close immediately or - // animate closed; at the end the infobar will delete itself. - // - // If infobars are disabled for this tab, this will do nothing, on the - // assumption that the matching AddInfoBar() call will have already deleted - // the infobar (see above). - void RemoveInfoBar(InfoBar* infobar); - - // Replaces one infobar with another, without any animation in between. This - // will result in |old_infobar| being synchronously deleted. - // - // If infobars are disabled for this tab, |new_infobar| is deleted immediately - // without being added, and nothing else happens. - // - // Returns the new infobar if it was successfully added. - // - // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). + // Helper function to get the InfoBarManager attached to |web_contents|. + static InfoBarManager* InfoBarManagerFromWebContents( + content::WebContents* web_contents); + + // These methods are simple pass-throughs to InfoBarManager, and are here to + // prepare for the componentization of Infobars, see http://crbug.com/354379. + InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); InfoBar* ReplaceInfoBar(InfoBar* old_infobar, scoped_ptr<InfoBar> new_infobar); - // Returns the number of infobars for this tab. - size_t infobar_count() const { return infobars_.size(); } - - // Returns the infobar at the given |index|. The InfoBarService retains - // ownership. - // - // Warning: Does not sanity check |index|. - InfoBar* infobar_at(size_t index) { return infobars_[index]; } - // Retrieve the WebContents for the tab this service is associated with. content::WebContents* web_contents() { return content::WebContentsObserver::web_contents(); } - void AddObserver(Observer* obs); - void RemoveObserver(Observer* obs); + InfoBarManager* infobar_manager() { return &infobar_manager_; } private: friend class content::WebContentsUserData<InfoBarService>; - // InfoBars associated with this InfoBarService. We own these pointers. - // However, this is not a ScopedVector, because we don't delete the infobars - // directly once they've been added to this; instead, when we're done with an - // infobar, we instruct it to delete itself and then orphan it. See - // RemoveInfoBarInternal(). - typedef std::vector<InfoBar*> InfoBars; - explicit InfoBarService(content::WebContents* web_contents); virtual ~InfoBarService(); @@ -98,16 +57,18 @@ class InfoBarService : public content::WebContentsObserver, content::WebContents* web_contents) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - void RemoveInfoBarInternal(InfoBar* infobar, bool animate); - void RemoveAllInfoBars(bool animate); + // InfoBarManager::Observer: + virtual void OnInfoBarAdded(InfoBar* infobar) OVERRIDE; + virtual void OnInfoBarReplaced(InfoBar* old_infobar, + InfoBar* new_infobar) OVERRIDE; + virtual void OnInfoBarRemoved(InfoBar* infobar, bool animate) OVERRIDE; + virtual void OnManagerShuttingDown(InfoBarManager* manager) OVERRIDE; // Message handlers. void OnDidBlockDisplayingInsecureContent(); void OnDidBlockRunningInsecureContent(); - InfoBars infobars_; - bool infobars_enabled_; - ObserverList<Observer, true> observer_list_; + InfoBarManager infobar_manager_; DISALLOW_COPY_AND_ASSIGN(InfoBarService); }; diff --git a/chrome/browser/infobars/infobars_browsertest.cc b/chrome/browser/infobars/infobars_browsertest.cc index aa68737..e384429 100644 --- a/chrome/browser/infobars/infobars_browsertest.cc +++ b/chrome/browser/infobars/infobars_browsertest.cc @@ -7,6 +7,7 @@ #include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/extension_install_prompt.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" @@ -84,7 +85,7 @@ IN_PROC_BROWSER_TEST_F(InfoBarsTest, TestInfoBarsCloseOnNewTheme) { infobar_removed_1.Wait(); EXPECT_EQ(0u, InfoBarService::FromWebContents(browser()->tab_strip_model()-> - GetWebContentsAt(0))->infobar_count()); + GetWebContentsAt(0))->infobar_manager()->infobar_count()); content::WindowedNotificationObserver infobar_removed_2( chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, @@ -93,5 +94,5 @@ IN_PROC_BROWSER_TEST_F(InfoBarsTest, TestInfoBarsCloseOnNewTheme) { infobar_removed_2.Wait(); EXPECT_EQ(0u, InfoBarService::FromWebContents(browser()->tab_strip_model()-> - GetActiveWebContents())->infobar_count()); + GetActiveWebContents())->infobar_manager()->infobar_count()); } diff --git a/chrome/browser/infobars/insecure_content_infobar_delegate.cc b/chrome/browser/infobars/insecure_content_infobar_delegate.cc index 90d1cb7..3a42319 100644 --- a/chrome/browser/infobars/insecure_content_infobar_delegate.cc +++ b/chrome/browser/infobars/insecure_content_infobar_delegate.cc @@ -8,6 +8,7 @@ #include "chrome/browser/google/google_util.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" +#include "chrome/browser/infobars/infobar_service.h" #include "chrome/common/render_messages.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" @@ -26,8 +27,9 @@ void InsecureContentInfoBarDelegate::Create(InfoBarService* infobar_service, // Only supsersede an existing insecure content infobar if we are upgrading // from DISPLAY to RUN. - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBar* old_infobar = infobar_service->infobar_at(i); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { + InfoBar* old_infobar = infobar_manager->infobar_at(i); InsecureContentInfoBarDelegate* delegate = old_infobar->delegate()->AsInsecureContentInfoBarDelegate(); if (delegate != NULL) { diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc index 75dad74..130c03a 100644 --- a/chrome/browser/managed_mode/managed_mode_interstitial.cc +++ b/chrome/browser/managed_mode/managed_mode_interstitial.cc @@ -11,6 +11,7 @@ #include "base/values.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_delegate.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/managed_mode/managed_user_service_factory.h" @@ -52,6 +53,7 @@ ManagedModeInterstitial::ManagedModeInterstitial( InfoBarService* service = InfoBarService::FromWebContents(web_contents); if (service) { + InfoBarManager* infobar_manager = service->infobar_manager(); // Remove all the infobars which are attached to |web_contents| and for // which ShouldExpire() returns true. content::LoadCommittedDetails details; @@ -67,9 +69,9 @@ ManagedModeInterstitial::ManagedModeInterstitial( details.previous_url = controller.GetLastCommittedEntry()->GetURL(); } details.type = content::NAVIGATION_TYPE_NEW_PAGE; - for (int i = service->infobar_count() - 1; i >= 0; --i) { - if (service->infobar_at(i)->delegate()->ShouldExpire(details)) - service->RemoveInfoBar(service->infobar_at(i)); + for (int i = infobar_manager->infobar_count() - 1; i >= 0; --i) { + if (infobar_manager->infobar_at(i)->delegate()->ShouldExpire(details)) + infobar_manager->RemoveInfoBar(infobar_manager->infobar_at(i)); } } diff --git a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc index bd06caf..ceddba6 100644 --- a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc +++ b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc @@ -13,6 +13,7 @@ #include "chrome/browser/history/history_types.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/managed_mode/managed_mode_interstitial.h" #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" @@ -188,7 +189,9 @@ void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( return; // If we shouldn't have a warn infobar remove it here. - InfoBarService::FromWebContents(web_contents())->RemoveInfoBar(warn_infobar_); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(web_contents())->infobar_manager(); + infobar_manager->RemoveInfoBar(warn_infobar_); warn_infobar_ = NULL; } diff --git a/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc b/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc index b3ac70a..d4e7865 100644 --- a/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc +++ b/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/media/webrtc_browsertest_base.h" #include "chrome/browser/media/webrtc_browsertest_common.h" @@ -122,9 +123,9 @@ IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", kFailedWithPermissionDeniedError, tab_contents)); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(tab_contents); - EXPECT_EQ(0u, infobar_service->infobar_count()); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(tab_contents)->infobar_manager(); + EXPECT_EQ(0u, infobar_manager->infobar_count()); } // Failing on Win Aura, so disabling on that. diff --git a/chrome/browser/media/media_stream_infobar_delegate.cc b/chrome/browser/media/media_stream_infobar_delegate.cc index f3059d5..35965c6 100644 --- a/chrome/browser/media/media_stream_infobar_delegate.cc +++ b/chrome/browser/media/media_stream_infobar_delegate.cc @@ -9,6 +9,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/common/url_constants.h" #include "content/public/browser/web_contents.h" @@ -54,8 +55,9 @@ bool MediaStreamInfoBarDelegate::Create( scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( scoped_ptr<ConfirmInfoBarDelegate>( new MediaStreamInfoBarDelegate(controller.Pass())))); - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBar* old_infobar = infobar_service->infobar_at(i); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { + InfoBar* old_infobar = infobar_manager->infobar_at(i); if (old_infobar->delegate()->AsMediaStreamInfoBarDelegate()) { infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); return true; diff --git a/chrome/browser/media/webrtc_browsertest_base.cc b/chrome/browser/media/webrtc_browsertest_base.cc index fafaacc..294c18f 100644 --- a/chrome/browser/media/webrtc_browsertest_base.cc +++ b/chrome/browser/media/webrtc_browsertest_base.cc @@ -8,6 +8,7 @@ #include "base/strings/stringprintf.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/media/media_stream_infobar_delegate.h" #include "chrome/browser/media/webrtc_browsertest_common.h" @@ -208,9 +209,9 @@ void WebRtcTestBase::CloseInfoBarInTab( chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, content::NotificationService::AllSources()); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(tab_contents); - infobar_service->RemoveInfoBar(infobar); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(tab_contents)->infobar_manager(); + infobar_manager->RemoveInfoBar(infobar); infobar_removed.Wait(); } diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc index 4f29443..671db01 100644 --- a/chrome/browser/notifications/notification_browsertest.cc +++ b/chrome/browser/notifications/notification_browsertest.cc @@ -17,6 +17,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/balloon_collection.h" @@ -318,10 +319,11 @@ void NotificationsTest::AllowAllOrigins() { void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { InfoBarService* infobar_service = InfoBarService::FromWebContents( browser->tab_strip_model()->GetWebContentsAt(index)); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); - ASSERT_EQ(1U, infobar_service->infobar_count()); + ASSERT_EQ(1U, infobar_manager->infobar_count()); ConfirmInfoBarDelegate* confirm_infobar = - infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(confirm_infobar); int buttons = confirm_infobar->GetButtons(); EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); @@ -402,17 +404,18 @@ bool NotificationsTest::PerformActionOnInfoBar( int tab_index) { InfoBarService* infobar_service = InfoBarService::FromWebContents( browser->tab_strip_model()->GetWebContentsAt(tab_index)); - if (infobar_index >= infobar_service->infobar_count()) { + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); + if (infobar_index >= infobar_manager->infobar_count()) { ADD_FAILURE(); return false; } - InfoBar* infobar = infobar_service->infobar_at(infobar_index); + InfoBar* infobar = infobar_manager->infobar_at(infobar_index); InfoBarDelegate* infobar_delegate = infobar->delegate(); switch (action) { case DISMISS: infobar_delegate->InfoBarDismissed(); - infobar_service->RemoveInfoBar(infobar); + infobar_manager->RemoveInfoBar(infobar); return true; case ALLOW: { @@ -421,7 +424,7 @@ bool NotificationsTest::PerformActionOnInfoBar( if (!confirm_infobar_delegate) { ADD_FAILURE(); } else if (confirm_infobar_delegate->Accept()) { - infobar_service->RemoveInfoBar(infobar); + infobar_manager->RemoveInfoBar(infobar); return true; } } @@ -432,7 +435,7 @@ bool NotificationsTest::PerformActionOnInfoBar( if (!confirm_infobar_delegate) { ADD_FAILURE(); } else if (confirm_infobar_delegate->Cancel()) { - infobar_service->RemoveInfoBar(infobar); + infobar_manager->RemoveInfoBar(infobar); return true; } } @@ -496,8 +499,9 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) { &result)); EXPECT_TRUE(result); - EXPECT_EQ(1U, InfoBarService::FromWebContents( - browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); + InfoBarService* infobar_service = InfoBarService::FromWebContents( + browser()->tab_strip_model()->GetWebContentsAt(0)); + EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); } // If this flakes, use http://crbug.com/62311. @@ -511,8 +515,9 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { embedded_test_server()->GetURL( "/notifications/notifications_request_inline.html")); - EXPECT_EQ(0U, InfoBarService::FromWebContents( - browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); + InfoBarService* infobar_service = InfoBarService::FromWebContents( + browser()->tab_strip_model()->GetWebContentsAt(0)); + EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); } IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateSimpleNotification) { @@ -652,8 +657,9 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestAllowNotificationsFromAllSites) { EXPECT_NE("-1", result); ASSERT_EQ(1, GetNotificationCount()); - EXPECT_EQ(0U, InfoBarService::FromWebContents( - browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); + InfoBarService* infobar_service = InfoBarService::FromWebContents( + browser()->tab_strip_model()->GetWebContentsAt(0)); + EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); } IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyNotificationsFromAllSites) { @@ -719,8 +725,9 @@ IN_PROC_BROWSER_TEST_F(NotificationsTest, TestDenyAndThenAllowDomain) { EXPECT_NE("-1", result); ASSERT_EQ(1, GetNotificationCount()); - EXPECT_EQ(0U, InfoBarService::FromWebContents( - browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count()); + InfoBarService* infobar_service = InfoBarService::FromWebContents( + browser()->tab_strip_model()->GetWebContentsAt(0)); + EXPECT_EQ(0U, infobar_service->infobar_manager()->infobar_count()); } IN_PROC_BROWSER_TEST_F(NotificationsTest, TestCreateDenyCloseNotifications) { diff --git a/chrome/browser/password_manager/password_manager_browsertest.cc b/chrome/browser/password_manager/password_manager_browsertest.cc index 4e8cff4..26adbc0 100644 --- a/chrome/browser/password_manager/password_manager_browsertest.cc +++ b/chrome/browser/password_manager/password_manager_browsertest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/password_manager/test_password_store_service.h" @@ -75,7 +76,8 @@ class NavigationObserver : public content::NotificationObserver, switch (type) { case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: if (should_automatically_accept_infobar_) { - infobar_service_->infobar_at(0) + infobar_service_->infobar_manager() + ->infobar_at(0) ->delegate() ->AsConfirmInfoBarDelegate() ->Accept(); diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index d1f49a3..1835ab0 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -40,6 +40,7 @@ #include "chrome/browser/extensions/updater/extension_cache_fake.h" #include "chrome/browser/extensions/updater/extension_updater.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/media/media_stream_devices_controller.h" @@ -1337,15 +1338,16 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, AlwaysAuthorizePlugins) { ASSERT_TRUE(contents); InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); ASSERT_TRUE(infobar_service); - EXPECT_EQ(0u, infobar_service->infobar_count()); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); + EXPECT_EQ(0u, infobar_manager->infobar_count()); base::FilePath path(FILE_PATH_LITERAL("plugin/quicktime.html")); GURL url(URLRequestMockHTTPJob::GetMockUrl(path)); ui_test_utils::NavigateToURL(browser(), url); // This should have triggered the dangerous plugin infobar. - ASSERT_EQ(1u, infobar_service->infobar_count()); + ASSERT_EQ(1u, infobar_manager->infobar_count()); EXPECT_TRUE( - infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); + infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); // And the plugin isn't running. EXPECT_EQ(0, CountPlugins()); @@ -1356,7 +1358,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, AlwaysAuthorizePlugins) { UpdateProviderPolicy(policies); // Reloading the page shouldn't trigger the infobar this time. ui_test_utils::NavigateToURL(browser(), url); - EXPECT_EQ(0u, infobar_service->infobar_count()); + EXPECT_EQ(0u, infobar_manager->infobar_count()); // And the plugin started automatically. EXPECT_EQ(1, CountPlugins()); } @@ -1876,7 +1878,8 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) { ASSERT_TRUE(contents); InfoBarService* infobar_service = InfoBarService::FromWebContents(contents); ASSERT_TRUE(infobar_service); - EXPECT_EQ(0u, infobar_service->infobar_count()); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); + EXPECT_EQ(0u, infobar_manager->infobar_count()); // Force enable the translate feature. PolicyMap policies; @@ -1909,8 +1912,8 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) { EXPECT_FALSE(language_state.IsPageTranslated()); // Verify that the translate infobar showed up. - ASSERT_EQ(1u, infobar_service->infobar_count()); - InfoBar* infobar = infobar_service->infobar_at(0); + ASSERT_EQ(1u, infobar_manager->infobar_count()); + InfoBar* infobar = infobar_manager->infobar_at(0); TranslateInfoBarDelegate* translate_infobar_delegate = infobar->delegate()->AsTranslateInfoBarDelegate(); ASSERT_TRUE(translate_infobar_delegate); @@ -1919,8 +1922,8 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) { EXPECT_EQ("fr", translate_infobar_delegate->original_language_code()); // Now force disable translate. - infobar_service->RemoveInfoBar(infobar); - EXPECT_EQ(0u, infobar_service->infobar_count()); + infobar_manager->RemoveInfoBar(infobar); + EXPECT_EQ(0u, infobar_manager->infobar_count()); policies.Set(key::kTranslateEnabled, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, base::Value::CreateBooleanValue(false), NULL); UpdateProviderPolicy(policies); @@ -1930,7 +1933,7 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) { content::NotificationService::AllSources()); ui_test_utils::NavigateToURL(browser(), url); language_observer2.Wait(); - EXPECT_EQ(0u, infobar_service->infobar_count()); + EXPECT_EQ(0u, infobar_manager->infobar_count()); } IN_PROC_BROWSER_TEST_F(PolicyTest, URLBlacklist) { diff --git a/chrome/browser/translate/translate_browsertest.cc b/chrome/browser/translate/translate_browsertest.cc index 62a7fec..e7e26c1 100644 --- a/chrome/browser/translate/translate_browsertest.cc +++ b/chrome/browser/translate/translate_browsertest.cc @@ -10,6 +10,7 @@ #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/translate/translate_infobar_delegate.h" +#include "chrome/browser/translate/translate_manager.h" #include "chrome/browser/translate/translate_service.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" @@ -91,18 +92,19 @@ class TranslateBrowserTest : public InProcessBrowserTest { } TranslateInfoBarDelegate* delegate = NULL; - for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { + InfoBarManager* infobar_manager = infobar_service_->infobar_manager(); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { // Check if the shown infobar is a confirm infobar coming from the // |kTranslateSecurityOrigin| flag specified in SetUpCommandLine(). // This infobar appears in all tests of TranslateBrowserTest and can be // ignored here. - ConfirmInfoBarDelegate* confirm = infobar_service_->infobar_at(i)-> - delegate()->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* confirm = infobar_manager->infobar_at(i) + ->delegate()->AsConfirmInfoBarDelegate(); if (confirm) continue; - TranslateInfoBarDelegate* translate = infobar_service_->infobar_at(i)-> - delegate()->AsTranslateInfoBarDelegate(); + TranslateInfoBarDelegate* translate = infobar_manager->infobar_at(i) + ->delegate()->AsTranslateInfoBarDelegate(); if (translate) { EXPECT_FALSE(delegate) << "multiple infobars are shown unexpectedly"; delegate = translate; diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/chrome/browser/translate/translate_infobar_delegate.cc index bafb6f1..e813709 100644 --- a/chrome/browser/translate/translate_infobar_delegate.cc +++ b/chrome/browser/translate/translate_infobar_delegate.cc @@ -11,6 +11,7 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/translate/translate_manager.h" @@ -89,9 +90,10 @@ void TranslateInfoBarDelegate::Create(bool replace_existing_infobar, InfoBar* old_infobar = NULL; InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); TranslateInfoBarDelegate* old_delegate = NULL; - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - old_infobar = infobar_service->infobar_at(i); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { + old_infobar = infobar_manager->infobar_at(i); old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate(); if (old_delegate) { if (!replace_existing_infobar) diff --git a/chrome/browser/translate/translate_manager_render_view_host_unittest.cc b/chrome/browser/translate/translate_manager_render_view_host_unittest.cc index 507fefe..2f1a331 100644 --- a/chrome/browser/translate/translate_manager_render_view_host_unittest.cc +++ b/chrome/browser/translate/translate_manager_render_view_host_unittest.cc @@ -14,6 +14,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/test_extension_system.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h" #include "chrome/browser/translate/translate_infobar_delegate.h" @@ -147,11 +148,15 @@ class TranslateManagerRenderViewHostTest return InfoBarService::FromWebContents(web_contents()); } + InfoBarManager* infobar_manager() { + return infobar_service()->infobar_manager(); + } + // Returns the translate infobar if there is 1 infobar and it is a translate // infobar. TranslateInfoBarDelegate* GetTranslateInfoBar() { - return (infobar_service()->infobar_count() == 1) - ? infobar_service() + return (infobar_manager()->infobar_count() == 1) + ? infobar_manager() ->infobar_at(0) ->delegate() ->AsTranslateInfoBarDelegate() @@ -165,7 +170,7 @@ class TranslateManagerRenderViewHostTest if (!infobar) return false; infobar->InfoBarDismissed(); // Simulates closing the infobar. - infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); + infobar_manager()->RemoveInfoBar(infobar_manager()->infobar_at(0)); return true; } @@ -189,7 +194,7 @@ class TranslateManagerRenderViewHostTest if (!infobar) return false; infobar->TranslationDeclined(); - infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); + infobar_manager()->RemoveInfoBar(infobar_manager()->infobar_at(0)); return true; } @@ -733,18 +738,18 @@ TEST_F(TranslateManagerRenderViewHostTest, MultipleOnPageContents) { // Simulate clicking 'Nope' (don't translate). EXPECT_TRUE(DenyTranslation()); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); // Send a new PageContents, we should not show an infobar. SimulateOnTranslateLanguageDetermined("fr", true); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->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, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); SimulateOnTranslateLanguageDetermined("fr", true); - EXPECT_EQ(0U, infobar_service()->infobar_count()); + EXPECT_EQ(0U, infobar_manager()->infobar_count()); } // Test that reloading the page brings back the infobar if the diff --git a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc index 62a5940..ca2632d 100644 --- a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc +++ b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.cc @@ -7,6 +7,7 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" @@ -28,21 +29,21 @@ void PopupBlockedInfoBarDelegate::Create(content::WebContents* web_contents, new PopupBlockedInfoBarDelegate( num_popups, url, profile->GetHostContentSettingsMap())))); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(web_contents)->infobar_manager(); // See if there is an existing popup infobar already. // TODO(dfalcantara) When triggering more than one popup the infobar // will be shown once, then hide then be shown again. // This will be fixed once we have an in place replace infobar mechanism. - for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBar* existing_infobar = infobar_service->infobar_at(i); + for (size_t i = 0; i < infobar_manager->infobar_count(); ++i) { + InfoBar* existing_infobar = infobar_manager->infobar_at(i); if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) { - infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); + infobar_manager->ReplaceInfoBar(existing_infobar, infobar.Pass()); return; } } - infobar_service->AddInfoBar(infobar.Pass()); + infobar_manager->AddInfoBar(infobar.Pass()); } PopupBlockedInfoBarDelegate::~PopupBlockedInfoBarDelegate() { diff --git a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc index 3ae87b3..5df442e 100644 --- a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc +++ b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.cc @@ -9,6 +9,7 @@ #include "base/android/jni_string.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" #include "chrome/browser/ui/auto_login_infobar_delegate.h" #include "content/public/browser/web_contents.h" @@ -105,8 +106,11 @@ void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) { // TODO(miguelg): Using SimpleAlertInfoBarDelegate::Create() animates in a new // infobar while we animate the current one closed. It would be better to use // ReplaceInfoBar(). + InfoBarService* infobar_service = + InfoBarService::FromWebContents(web_contents()); + DCHECK(infobar_service); SimpleAlertInfoBarDelegate::Create( - infobar()->owner(), IDR_INFOBAR_WARNING, + infobar_service, IDR_INFOBAR_WARNING, l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false); infobar()->RemoveSelf(); } diff --git a/chrome/browser/ui/android/infobars/infobar_container_android.cc b/chrome/browser/ui/android/infobars/infobar_container_android.cc index 6a89bc3..9c0da6e 100644 --- a/chrome/browser/ui/android/infobars/infobar_container_android.cc +++ b/chrome/browser/ui/android/infobars/infobar_container_android.cc @@ -90,8 +90,10 @@ static jlong Init(JNIEnv* env, jobject auto_login_delegate) { InfoBarContainerAndroid* infobar_container = new InfoBarContainerAndroid(env, obj, auto_login_delegate); - infobar_container->ChangeInfoBarService(InfoBarService::FromWebContents( - content::WebContents::FromJavaWebContents(web_contents))); + InfoBarManager* infobar_manager = + InfoBarService::InfoBarManagerFromWebContents( + content::WebContents::FromJavaWebContents(web_contents)); + infobar_container->ChangeInfoBarManager(infobar_manager); return reinterpret_cast<intptr_t>(infobar_container); } diff --git a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm index e7eb9d4..bd89a53 100644 --- a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm @@ -94,7 +94,8 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest, scoped_ptr<InfoBarDelegate> delegate( new MockConfirmInfoBarDelegate(this)); infobar_ = new InfoBarCocoa(delegate.Pass()); - infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); + infobar_->SetOwner(InfoBarService::FromWebContents( + web_contents_.get())->infobar_manager()); controller_.reset([[TestConfirmInfoBarController alloc] initWithInfoBar:infobar_]); diff --git a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h index b48c6a4..033400b 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h @@ -26,7 +26,7 @@ class InfoBarCocoa : public InfoBar { } // These functions allow access to protected InfoBar functions. - InfoBarService* OwnerCocoa(); + InfoBarManager* OwnerCocoa(); base::WeakPtr<InfoBarCocoa> GetWeakPtr(); diff --git a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm index b49579c..7ba03e5 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm @@ -23,7 +23,7 @@ InfoBarCocoa::~InfoBarCocoa() { [controller() infobarWillClose]; } -InfoBarService* InfoBarCocoa::OwnerCocoa() { +InfoBarManager* InfoBarCocoa::OwnerCocoa() { return owner(); } diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm index 3c8e71c..f33638c 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm @@ -68,12 +68,10 @@ - (void)changeWebContents:(content::WebContents*)contents { currentWebContents_ = contents; - if (contents) { - containerCocoa_->ChangeInfoBarService( - InfoBarService::FromWebContents(contents)); - } else { - containerCocoa_->ChangeInfoBarService(NULL); - } + InfoBarManager* infobar_manager = NULL; + if (contents) + infobar_manager = InfoBarService::InfoBarManagerFromWebContents(contents); + containerCocoa_->ChangeInfoBarManager(infobar_manager); } - (void)tabDetachedWithContents:(content::WebContents*)contents { diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm index fe8d9e9..9700ef1 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm @@ -99,7 +99,8 @@ class TranslationInfoBarTest : public CocoaProfileTest { if (infobar_) infobar_->CloseSoon(); infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); - infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); + infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get()) + ->infobar_manager()); infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( infobar_->controller()) retain]); diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc index 50b1239..7af803f 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model_unittest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/content_settings/tab_specific_content_settings.h" #include "chrome/browser/custom_handlers/protocol_handler_registry.h" #include "chrome/browser/infobars/infobar_delegate.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/profiles/profile.h" @@ -234,9 +235,9 @@ TEST_F(ContentSettingBubbleModelTest, BlockedMediastreamMicAndCamera) { CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string())); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents()); - infobar_service->RemoveInfoBar(infobar_service->infobar_at(0)); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(web_contents())->infobar_manager(); + infobar_manager->RemoveInfoBar(infobar_manager->infobar_at(0)); } TEST_F(ContentSettingBubbleModelTest, MediastreamMic) { diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 5828897..27b1792 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -802,8 +802,9 @@ void BrowserWindowGtk::OnActiveTabChanged(WebContents* old_contents, // Update various elements that are interested in knowing the current // WebContents. - infobar_container_->ChangeInfoBarService( - InfoBarService::FromWebContents(new_contents)); + InfoBarManager* infobar_manager = + InfoBarService::InfoBarManagerFromWebContents(new_contents); + infobar_container_->ChangeInfoBarManager(infobar_manager); contents_container_->SetTab(new_contents); UpdateDevToolsForContents(new_contents); @@ -1285,7 +1286,7 @@ void BrowserWindowGtk::TabDetachedAt(WebContents* contents, int index) { // browser_->tab_strip_model()->GetActiveWebContents() will return NULL or // something else. if (index == browser_->tab_strip_model()->active_index()) { - infobar_container_->ChangeInfoBarService(NULL); + infobar_container_->ChangeInfoBarManager(NULL); UpdateDevToolsForContents(NULL); } contents_container_->DetachTab(contents); diff --git a/chrome/browser/ui/hung_plugin_tab_helper.cc b/chrome/browser/ui/hung_plugin_tab_helper.cc index 229f044..5907a6c7 100644 --- a/chrome/browser/ui/hung_plugin_tab_helper.cc +++ b/chrome/browser/ui/hung_plugin_tab_helper.cc @@ -13,6 +13,7 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/common/chrome_version_info.h" #include "content/public/browser/browser_child_process_host_iterator.h" @@ -278,13 +279,14 @@ void HungPluginTabHelper::PluginCrashed(const base::FilePath& plugin_path, if (!infobar_service) return; + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); // For now, just do a brute-force search to see if we have this plugin. Since // we'll normally have 0 or 1, this is fast. for (PluginStateMap::iterator i = hung_plugins_.begin(); i != hung_plugins_.end(); ++i) { if (i->second->path == plugin_path) { if (i->second->infobar) - infobar_service->RemoveInfoBar(i->second->infobar); + infobar_manager->RemoveInfoBar(i->second->infobar); hung_plugins_.erase(i); break; } @@ -300,12 +302,13 @@ void HungPluginTabHelper::PluginHungStatusChanged( if (!infobar_service) return; + InfoBarManager* infobar_manager = infobar_service->infobar_manager(); PluginStateMap::iterator found = hung_plugins_.find(plugin_child_id); if (found != hung_plugins_.end()) { if (!is_hung) { // Hung plugin became un-hung, close the infobar and delete our info. if (found->second->infobar) - infobar_service->RemoveInfoBar(found->second->infobar); + infobar_manager->RemoveInfoBar(found->second->infobar); hung_plugins_.erase(found); } return; @@ -416,7 +419,7 @@ void HungPluginTabHelper::CloseBar(PluginState* state) { InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents()); if (infobar_service && state->infobar) { - infobar_service->RemoveInfoBar(state->infobar); + infobar_service->infobar_manager()->RemoveInfoBar(state->infobar); state->infobar = NULL; } } diff --git a/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc b/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc index 316dad3..97701e9 100644 --- a/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc +++ b/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc @@ -8,6 +8,7 @@ #include "base/prefs/testing_pref_service.h" #include "base/run_loop.h" #include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/sessions/session_service_factory.h" @@ -81,11 +82,11 @@ TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { TabStripModel* tab_strip = first_browser->tab_strip_model(); ASSERT_EQ(1, tab_strip->count()); content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - EXPECT_EQ(1U, infobar_service->infobar_count()); + InfoBarManager* infobar_manager = + InfoBarService::FromWebContents(web_contents)->infobar_manager(); + EXPECT_EQ(1U, infobar_manager->infobar_count()); ConfirmInfoBarDelegate* infobar = - infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); + infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar); // Open another browser. @@ -102,9 +103,9 @@ TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { first_browser.reset(); ASSERT_EQ(1, tab_strip->count()); - web_contents = tab_strip->GetWebContentsAt(0); - infobar_service = InfoBarService::FromWebContents(web_contents); - EXPECT_EQ(1U, infobar_service->infobar_count()); + InfoBarService* infobar_service = + InfoBarService::FromWebContents(tab_strip->GetWebContentsAt(0)); + EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); // This used to crash. infobar->Accept(); diff --git a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc index 884a709..d89227c 100644 --- a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc +++ b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc @@ -14,6 +14,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/launch_util.h" #include "chrome/browser/first_run/first_run.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" #include "chrome/browser/managed_mode/managed_user_service.h" @@ -938,8 +939,9 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) { ASSERT_EQ(1, tab_strip->count()); content::WebContents* web_contents = tab_strip->GetWebContentsAt(0); EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); - EXPECT_EQ(1U, - InfoBarService::FromWebContents(web_contents)->infobar_count()); + InfoBarService* infobar_service = + InfoBarService::FromWebContents(web_contents); + EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); // The profile which normally opens last open pages displays the new tab page. ASSERT_EQ(1u, chrome::GetBrowserCount(profile_last, @@ -950,8 +952,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) { ASSERT_EQ(1, tab_strip->count()); web_contents = tab_strip->GetWebContentsAt(0); EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); - EXPECT_EQ(1U, - InfoBarService::FromWebContents(web_contents)->infobar_count()); + infobar_service = InfoBarService::FromWebContents(web_contents); + EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); // The profile which normally opens URLs displays the new tab page. ASSERT_EQ(1u, chrome::GetBrowserCount(profile_urls, @@ -962,8 +964,8 @@ IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorTest, ProfilesLaunchedAfterCrash) { ASSERT_EQ(1, tab_strip->count()); web_contents = tab_strip->GetWebContentsAt(0); EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), web_contents->GetURL()); - EXPECT_EQ(1U, - InfoBarService::FromWebContents(web_contents)->infobar_count()); + infobar_service = InfoBarService::FromWebContents(web_contents); + EXPECT_EQ(1U, infobar_service->infobar_manager()->infobar_count()); } class ManagedModeBrowserCreatorTest : public InProcessBrowserTest { diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 75ee610..73afdb6 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -831,8 +831,10 @@ void BrowserView::OnActiveTabChanged(content::WebContents* old_contents, contents_web_view_->SetWebContents(NULL); devtools_web_view_->SetWebContents(NULL); } - infobar_container_->ChangeInfoBarService( - InfoBarService::FromWebContents(new_contents)); + + InfoBarManager* infobar_manager = + InfoBarService::InfoBarManagerFromWebContents(new_contents); + infobar_container_->ChangeInfoBarManager(infobar_manager); if (old_contents && PermissionBubbleManager::FromWebContents(old_contents)) PermissionBubbleManager::FromWebContents(old_contents)->SetView(NULL); @@ -1490,7 +1492,7 @@ void BrowserView::TabDetachedAt(WebContents* contents, int index) { // freed. This is because the focus manager performs some operations // on the selected WebContents when it is removed. contents_web_view_->SetWebContents(NULL); - infobar_container_->ChangeInfoBarService(NULL); + infobar_container_->ChangeInfoBarManager(NULL); UpdateDevToolsForContents(NULL, true); } } diff --git a/chrome/browser/ui/website_settings/website_settings_unittest.cc b/chrome/browser/ui/website_settings/website_settings_unittest.cc index fd1c622..8f1645c 100644 --- a/chrome/browser/ui/website_settings/website_settings_unittest.cc +++ b/chrome/browser/ui/website_settings/website_settings_unittest.cc @@ -13,6 +13,7 @@ #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.h" +#include "chrome/browser/infobars/infobar_manager.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/ui/website_settings/website_settings_ui.h" #include "chrome/common/content_settings.h" @@ -364,9 +365,9 @@ TEST_F(WebsiteSettingsTest, NoInfoBar) { SetDefaultUIExpectations(mock_ui()); EXPECT_CALL(*mock_ui(), SetSelectedTab( WebsiteSettingsUI::TAB_ID_PERMISSIONS)); - EXPECT_EQ(0u, infobar_service()->infobar_count()); + EXPECT_EQ(0u, infobar_service()->infobar_manager()->infobar_count()); website_settings()->OnUIClosing(); - EXPECT_EQ(0u, infobar_service()->infobar_count()); + EXPECT_EQ(0u, infobar_service()->infobar_manager()->infobar_count()); } TEST_F(WebsiteSettingsTest, ShowInfoBar) { @@ -386,11 +387,12 @@ TEST_F(WebsiteSettingsTest, ShowInfoBar) { EXPECT_CALL(*mock_ui(), SetSelectedTab( WebsiteSettingsUI::TAB_ID_PERMISSIONS)); - EXPECT_EQ(0u, infobar_service()->infobar_count()); + InfoBarManager* infobar_manager = infobar_service()->infobar_manager(); + EXPECT_EQ(0u, infobar_manager->infobar_count()); website_settings()->OnSitePermissionChanged( CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW); website_settings()->OnUIClosing(); - ASSERT_EQ(1u, infobar_service()->infobar_count()); + ASSERT_EQ(1u, infobar_manager->infobar_count()); - infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); + infobar_manager->RemoveInfoBar(infobar_manager->infobar_at(0)); } |