diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-06 03:01:48 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-06 03:01:48 +0000 |
commit | 39308cbb5bb0d795fbe0790d03e99b0d5932fb0e (patch) | |
tree | bd37514d76675cb4029d8de933f23d1eee5e5c3d | |
parent | 0bfa772f76cf3f2bd2f9f570a8bf1595cde911b3 (diff) | |
download | chromium_src-39308cbb5bb0d795fbe0790d03e99b0d5932fb0e.zip chromium_src-39308cbb5bb0d795fbe0790d03e99b0d5932fb0e.tar.gz chromium_src-39308cbb5bb0d795fbe0790d03e99b0d5932fb0e.tar.bz2 |
Infobar system refactor.
This changes the ownership model of infobars so that InfoBars are long-lived and
own their InfoBarDelegates directly. The InfoBarService pseudo-owns the
InfoBars (instead of deleting them directly, it tells them when they're unowned
and expects them to delete themselves).
This fixes leaks when infobars are closed while not visible (e.g. in a
background tab) and in general makes the system clearer and easier to reason
about.
BUG=62154
TEST=none
TBR=sky
Review URL: https://codereview.chromium.org/103993003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239110 0039d316-1c4b-4281-b951-d872f2087c98
165 files changed, 1249 insertions, 1479 deletions
diff --git a/chrome/browser/accessibility/accessibility_extension_api.cc b/chrome/browser/accessibility/accessibility_extension_api.cc index f0a1ffd..9ba0335 100644 --- a/chrome/browser/accessibility/accessibility_extension_api.cc +++ b/chrome/browser/accessibility/accessibility_extension_api.cc @@ -14,7 +14,7 @@ #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/extension_tab_util.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" -#include "chrome/browser/infobars/infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/extensions/api/experimental_accessibility.h" @@ -278,7 +278,7 @@ bool AccessibilityGetAlertsForTabFunction::RunImpl() { for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { // TODO(hashimoto): Make other kind of alerts available. crosbug.com/24281 ConfirmInfoBarDelegate* confirm_infobar_delegate = - infobar_service->infobar_at(i)->AsConfirmInfoBarDelegate(); + infobar_service->infobar_at(i)->delegate()->AsConfirmInfoBarDelegate(); if (confirm_infobar_delegate) { DictionaryValue* alert_value = new DictionaryValue; const base::string16 message_text = diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index cbc132e..69156ad 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -18,6 +18,7 @@ #include "chrome/browser/autofill/personal_data_manager_factory.h" #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_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -100,7 +101,7 @@ class WindowedPersonalDataManagerObserver infobar_service_ = InfoBarService::FromWebContents( browser_->tab_strip_model()->GetActiveWebContents()); ConfirmInfoBarDelegate* infobar_delegate = - infobar_service_->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Accept(); } diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc index 997577d..a3cebc1 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc @@ -5,6 +5,7 @@ #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" #include "base/logging.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/personal_data_manager.h" @@ -24,16 +25,15 @@ void AutofillCCInfoBarDelegate::Create( InfoBarService* infobar_service, const AutofillMetrics* metric_logger, const base::Closure& save_card_callback) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new AutofillCCInfoBarDelegate( - infobar_service, metric_logger, save_card_callback))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new AutofillCCInfoBarDelegate( + metric_logger, save_card_callback)))); } AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate( - InfoBarService* infobar_service, const AutofillMetrics* metric_logger, const base::Closure& save_card_callback) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), metric_logger_(metric_logger), save_card_callback_(save_card_callback), had_user_interaction_(false) { diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.h b/chrome/browser/autofill/autofill_cc_infobar_delegate.h index d0dff50..fce8616 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_delegate.h +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.h @@ -27,8 +27,8 @@ namespace autofill { // card information gathered from a form submission. class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an autofill credit card infobar delegate and adds it to - // |infobar_service|. + // Creates an autofill credit card infobar and delegate and adds the infobar + // to |infobar_service|. static void Create(InfoBarService* infobar_service, const AutofillMetrics* metric_logger, const base::Closure& save_card_callback); @@ -38,13 +38,12 @@ class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate { const AutofillMetrics* metric_logger, const base::Closure& save_card_callback) { return scoped_ptr<ConfirmInfoBarDelegate>( - new AutofillCCInfoBarDelegate(NULL, metric_logger, save_card_callback)); + new AutofillCCInfoBarDelegate(metric_logger, save_card_callback)); } #endif private: - AutofillCCInfoBarDelegate(InfoBarService* infobar_service, - const AutofillMetrics* metric_logger, + AutofillCCInfoBarDelegate(const AutofillMetrics* metric_logger, const base::Closure& save_card_callback); virtual ~AutofillCCInfoBarDelegate(); diff --git a/chrome/browser/autofill/autofill_interactive_uitest.cc b/chrome/browser/autofill/autofill_interactive_uitest.cc index 5ea8a0d..8591154 100644 --- a/chrome/browser/autofill/autofill_interactive_uitest.cc +++ b/chrome/browser/autofill/autofill_interactive_uitest.cc @@ -18,6 +18,7 @@ #include "chrome/browser/autofill/personal_data_manager_factory.h" #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_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/translate/translate_infobar_delegate.h" @@ -168,7 +169,8 @@ class WindowedPersonalDataManagerObserver const content::NotificationDetails& details) OVERRIDE { infobar_service_ = InfoBarService::FromWebContents( browser_->tab_strip_model()->GetActiveWebContents()); - infobar_service_->infobar_at(0)->AsConfirmInfoBarDelegate()->Accept(); + infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()-> + Accept(); } void Wait() { @@ -831,8 +833,9 @@ IN_PROC_BROWSER_TEST_F(AutofillInteractiveTest, AutofillAfterTranslate) { // Wait for the translation bar to appear and get it. infobar_observer.Wait(); - TranslateInfoBarDelegate* delegate = InfoBarService::FromWebContents( - GetWebContents())->infobar_at(0)->AsTranslateInfoBarDelegate(); + TranslateInfoBarDelegate* delegate = + InfoBarService::FromWebContents(GetWebContents())->infobar_at(0)-> + delegate()->AsTranslateInfoBarDelegate(); ASSERT_TRUE(delegate); EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, delegate->infobar_type()); diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index f3bc7fb..28a55c9 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -64,6 +64,7 @@ #include "chrome/browser/history/history_service_factory.h" #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_service.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/notifications/balloon.h" @@ -1999,7 +2000,7 @@ ListValue* TestingAutomationProvider::GetInfobarsInfo(WebContents* wc) { InfoBarService* infobar_service = InfoBarService::FromWebContents(wc); for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { DictionaryValue* infobar_item = new DictionaryValue; - InfoBarDelegate* infobar = infobar_service->infobar_at(i); + InfoBarDelegate* infobar = infobar_service->infobar_at(i)->delegate(); switch (infobar->GetInfoBarAutomationType()) { case InfoBarDelegate::CONFIRM_INFOBAR: infobar_item->SetString("type", "confirm_infobar"); @@ -2080,12 +2081,12 @@ void TestingAutomationProvider::PerformActionOnInfobar( infobar_index)); return; } - InfoBarDelegate* infobar_delegate = - infobar_service->infobar_at(infobar_index); + InfoBar* infobar = infobar_service->infobar_at(infobar_index); + InfoBarDelegate* infobar_delegate = infobar->delegate(); if (action == "dismiss") { infobar_delegate->InfoBarDismissed(); - infobar_service->RemoveInfoBar(infobar_delegate); + infobar_service->RemoveInfoBar(infobar); reply.SendSuccess(NULL); return; } @@ -2098,7 +2099,7 @@ void TestingAutomationProvider::PerformActionOnInfobar( } if ((action == "accept") ? confirm_infobar_delegate->Accept() : confirm_infobar_delegate->Cancel()) - infobar_service->RemoveInfoBar(infobar_delegate); + infobar_service->RemoveInfoBar(infobar); reply.SendSuccess(NULL); return; } diff --git a/chrome/browser/chrome_quota_permission_context.cc b/chrome/browser/chrome_quota_permission_context.cc index 968ac4a..80831a0 100644 --- a/chrome/browser/chrome_quota_permission_context.cc +++ b/chrome/browser/chrome_quota_permission_context.cc @@ -10,6 +10,7 @@ #include "base/prefs/pref_service.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/tab_util.h" @@ -32,7 +33,8 @@ namespace { class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a request quota infobar delegate and adds it to |infobar_service|. + // Creates a request quota infobar and delegate and adds the infobar to + // |infobar_service|. static void Create( InfoBarService* infobar_service, ChromeQuotaPermissionContext* context, @@ -43,7 +45,6 @@ class RequestQuotaInfoBarDelegate : public ConfirmInfoBarDelegate { private: RequestQuotaInfoBarDelegate( - InfoBarService* infobar_service, ChromeQuotaPermissionContext* context, const GURL& origin_url, int64 requested_quota, @@ -75,20 +76,18 @@ void RequestQuotaInfoBarDelegate::Create( int64 requested_quota, const std::string& display_languages, const content::QuotaPermissionContext::PermissionCallback& callback) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new RequestQuotaInfoBarDelegate(infobar_service, context, origin_url, - requested_quota, display_languages, - callback))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new RequestQuotaInfoBarDelegate( + context, origin_url, requested_quota, display_languages, callback)))); } RequestQuotaInfoBarDelegate::RequestQuotaInfoBarDelegate( - InfoBarService* infobar_service, ChromeQuotaPermissionContext* context, const GURL& origin_url, int64 requested_quota, const std::string& display_languages, const content::QuotaPermissionContext::PermissionCallback& callback) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), context_(context), origin_url_(origin_url), display_languages_(display_languages), diff --git a/chrome/browser/content_settings/permission_queue_controller.cc b/chrome/browser/content_settings/permission_queue_controller.cc index a4e08c4..480f6a7 100644 --- a/chrome/browser/content_settings/permission_queue_controller.cc +++ b/chrome/browser/content_settings/permission_queue_controller.cc @@ -51,7 +51,7 @@ class PermissionQueueController::PendingInfoBarRequest { const PermissionRequestID& id() const { return id_; } const GURL& requesting_frame() const { return requesting_frame_; } bool has_infobar() const { return !!infobar_; } - InfoBarDelegate* infobar() { return infobar_; } + InfoBar* infobar() { return infobar_; } void RunCallback(bool allowed); void CreateInfoBar(PermissionQueueController* controller, @@ -63,7 +63,7 @@ class PermissionQueueController::PendingInfoBarRequest { GURL requesting_frame_; GURL embedder_; PermissionDecidedCallback callback_; - InfoBarDelegate* infobar_; + InfoBar* infobar_; // Purposefully do not disable copying, as this is stored in STL containers. }; @@ -196,10 +196,10 @@ void PermissionQueueController::OnPermissionSet( if (i->IsForPair(requesting_frame, embedder)) { requests_to_notify.push_back(*i); if (i->id().Equals(id)) { - // The infobar that called us is i->infobar(), and it's currently in - // either Accept() or Cancel(). This means that RemoveInfoBar() will be - // called later on, and that will trigger a notification we're - // observing. + // The infobar that called us is i->infobar(), and its delegate is + // currently in either Accept() or Cancel(). This means that + // RemoveInfoBar() will be called later on, and that will trigger a + // notification we're observing. ++i; } else if (i->has_infobar()) { // This infobar is for the same frame/embedder pair, but in a different @@ -240,8 +240,7 @@ void PermissionQueueController::Observe( // pending_infobar_requests_ will not have received any new entries between // the NotificationService's call to InfoBarContainer::Observe and this // method. - InfoBarDelegate* infobar = - content::Details<InfoBar::RemovedDetails>(details)->first; + InfoBar* infobar = content::Details<InfoBar::RemovedDetails>(details)->first; for (PendingInfoBarRequests::iterator i = pending_infobar_requests_.begin(); i != pending_infobar_requests_.end(); ++i) { if (i->infobar() == infobar) { diff --git a/chrome/browser/content_settings/permission_queue_controller_unittest.cc b/chrome/browser/content_settings/permission_queue_controller_unittest.cc index 161b754..2e69923 100644 --- a/chrome/browser/content_settings/permission_queue_controller_unittest.cc +++ b/chrome/browser/content_settings/permission_queue_controller_unittest.cc @@ -7,13 +7,10 @@ #include "base/synchronization/waitable_event.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/content_settings/permission_request_id.h" -#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/common/content_settings_types.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/test_browser_thread.h" @@ -22,14 +19,9 @@ // PermissionQueueControllerTests --------------------------------------------- -class PermissionQueueControllerTests : public ChromeRenderViewHostTestHarness, - public content::NotificationObserver { +class PermissionQueueControllerTests : public ChromeRenderViewHostTestHarness { protected: - PermissionQueueControllerTests() { - registrar_.Add(this, - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::NotificationService::AllSources()); - } + PermissionQueueControllerTests() {} virtual ~PermissionQueueControllerTests() {} PermissionRequestID RequestID(int bridge_id) { @@ -46,22 +38,6 @@ class PermissionQueueControllerTests : public ChromeRenderViewHostTestHarness, InfoBarService::CreateForWebContents(web_contents()); } - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE { - DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); - // Delete the removed infobar. In normal Chrome code, this would be handled - // by the InfoBarContainer. It's safe to do this even if the queue - // controller Observe() function has not yet been called; see comments in - // PermissionQueueController::Observe(). - // TODO(pkasting): This will no longer be necessary once the InfoBarService - // truly owns infobars. - delete content::Details<InfoBar::RemovedDetails>(details)->first; - } - - content::NotificationRegistrar registrar_; - DISALLOW_COPY_AND_ASSIGN(PermissionQueueControllerTests); }; 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 a2f83e0..76e70b8 100644 --- a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc +++ b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc @@ -6,6 +6,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_service.h" #include "chrome/common/url_constants.h" #include "content/public/browser/user_metrics.h" @@ -21,17 +22,18 @@ void RegisterProtocolHandlerInfoBarDelegate::Create( content::RecordAction( content::UserMetricsAction("RegisterProtocolHandler.InfoBar_Shown")); - scoped_ptr<InfoBarDelegate> infobar( - new RegisterProtocolHandlerInfoBarDelegate(infobar_service, registry, - handler)); + scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( + 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); RegisterProtocolHandlerInfoBarDelegate* existing_delegate = - infobar_service->infobar_at(i)-> + existing_infobar->delegate()-> AsRegisterProtocolHandlerInfoBarDelegate(); if ((existing_delegate != NULL) && existing_delegate->handler_.IsEquivalent(handler)) { - infobar_service->ReplaceInfoBar(existing_delegate, infobar.Pass()); + infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); return; } } @@ -40,10 +42,9 @@ void RegisterProtocolHandlerInfoBarDelegate::Create( } RegisterProtocolHandlerInfoBarDelegate::RegisterProtocolHandlerInfoBarDelegate( - InfoBarService* infobar_service, ProtocolHandlerRegistry* registry, const ProtocolHandler& handler) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), registry_(registry), handler_(handler) { } diff --git a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h index 4e71933..22f263c 100644 --- a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h +++ b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h @@ -16,17 +16,16 @@ class ProtocolHandlerRegistry; // card information gathered from a form submission. class RegisterProtocolHandlerInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a new register protocol handler infobar delegate. Searches - // |infobar_service| for an existing delegate for the same |handler|; replaces - // it with the new delegate if found, otherwise adds the new infobar to + // Creates a new register protocol handler infobar and delegate. Searches + // |infobar_service| for an existing infobar for the same |handler|; replaces + // it with the new infobar if found, otherwise adds the new infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service, ProtocolHandlerRegistry* registry, const ProtocolHandler& handler); private: - RegisterProtocolHandlerInfoBarDelegate(InfoBarService* infobar_service, - ProtocolHandlerRegistry* registry, + RegisterProtocolHandlerInfoBarDelegate(ProtocolHandlerRegistry* registry, const ProtocolHandler& handler); virtual ~RegisterProtocolHandlerInfoBarDelegate(); diff --git a/chrome/browser/devtools/devtools_window.cc b/chrome/browser/devtools/devtools_window.cc index b197934..4cb6734 100644 --- a/chrome/browser/devtools/devtools_window.cc +++ b/chrome/browser/devtools/devtools_window.cc @@ -23,6 +23,7 @@ #include "chrome/browser/extensions/extension_web_contents_observer.h" #include "chrome/browser/file_select_helper.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sessions/session_tab_helper.h" @@ -85,7 +86,6 @@ class DevToolsConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { private: DevToolsConfirmInfoBarDelegate( - InfoBarService* infobar_service, const DevToolsWindow::InfoBarCallback& callback, const base::string16& message); virtual ~DevToolsConfirmInfoBarDelegate(); @@ -110,15 +110,15 @@ void DevToolsConfirmInfoBarDelegate::Create( return; } - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new DevToolsConfirmInfoBarDelegate(infobar_service, callback, message))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new DevToolsConfirmInfoBarDelegate(callback, message)))); } DevToolsConfirmInfoBarDelegate::DevToolsConfirmInfoBarDelegate( - InfoBarService* infobar_service, const DevToolsWindow::InfoBarCallback& callback, const base::string16& message) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), callback_(callback), message_(message) { } diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 99165e0..d2f1076 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -42,6 +42,7 @@ #include "chrome/browser/history/history_service.h" #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_service.h" #include "chrome/browser/net/url_request_mock_util.h" #include "chrome/browser/profiles/profile.h" @@ -2815,8 +2816,9 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, TestMultipleDownloadsInfobar) { ASSERT_EQ(1u, infobar_service->infobar_count()); // Get the infobar at index 0. - InfoBarDelegate* infobar = infobar_service->infobar_at(0); - ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate(); + InfoBar* infobar = infobar_service->infobar_at(0); + ConfirmInfoBarDelegate* confirm_infobar = + infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(confirm_infobar != NULL); // Verify multi download warning infobar message. diff --git a/chrome/browser/download/download_request_infobar_delegate.cc b/chrome/browser/download/download_request_infobar_delegate.cc index c61ea2c..7fdf95e 100644 --- a/chrome/browser/download/download_request_infobar_delegate.cc +++ b/chrome/browser/download/download_request_infobar_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/browser/download/download_request_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "grit/generated_resources.h" #include "grit/theme_resources.h" @@ -35,8 +36,9 @@ void DownloadRequestInfoBarDelegate::Create( // "downloads" permission) to automatically download >1 files. host->Cancel(); } else { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new DownloadRequestInfoBarDelegate(infobar_service, host))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new DownloadRequestInfoBarDelegate(host)))); } } @@ -47,9 +49,8 @@ void DownloadRequestInfoBarDelegate::SetCallbackForTesting( } DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate( - InfoBarService* infobar_service, base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), responded_(false), host_(host) { } diff --git a/chrome/browser/download/download_request_infobar_delegate.h b/chrome/browser/download/download_request_infobar_delegate.h index 418d029..f0563c1 100644 --- a/chrome/browser/download/download_request_infobar_delegate.h +++ b/chrome/browser/download/download_request_infobar_delegate.h @@ -34,7 +34,7 @@ class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate { static scoped_ptr<DownloadRequestInfoBarDelegate> Create( base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host) { return scoped_ptr<DownloadRequestInfoBarDelegate>( - new DownloadRequestInfoBarDelegate(NULL, host)); + new DownloadRequestInfoBarDelegate(host)); } #endif @@ -43,8 +43,7 @@ class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate { private: static FakeCreateCallback* callback_; - DownloadRequestInfoBarDelegate( - InfoBarService* infobar_service, + explicit DownloadRequestInfoBarDelegate( base::WeakPtr<DownloadRequestLimiter::TabDownloadState> host); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/extensions/api/debugger/debugger_api.cc b/chrome/browser/extensions/api/debugger/debugger_api.cc index 7f8c8b8..b9bace4 100644 --- a/chrome/browser/extensions/api/debugger/debugger_api.cc +++ b/chrome/browser/extensions/api/debugger/debugger_api.cc @@ -66,10 +66,6 @@ namespace OnDetach = extensions::api::debugger::OnDetach; namespace OnEvent = extensions::api::debugger::OnEvent; namespace SendCommand = extensions::api::debugger::SendCommand; -namespace { -class ExtensionDevToolsInfoBarDelegate; -} // namespace - // ExtensionDevToolsClientHost ------------------------------------------------ @@ -82,7 +78,7 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, const std::string& extension_id, const std::string& extension_name, const Debuggee& debuggee, - ExtensionDevToolsInfoBarDelegate* infobar); + InfoBar* infobar); virtual ~ExtensionDevToolsClientHost(); @@ -117,7 +113,7 @@ class ExtensionDevToolsClientHost : public DevToolsClientHost, typedef std::map<int, scoped_refptr<DebuggerSendCommandFunction> > PendingRequests; PendingRequests pending_requests_; - ExtensionDevToolsInfoBarDelegate* infobar_; + InfoBar* infobar_; OnDetach::Reason detach_reason_; DISALLOW_COPY_AND_ASSIGN(ExtensionDevToolsClientHost); @@ -145,20 +141,17 @@ void CopyDebuggee(Debuggee* dst, const Debuggee& src) { class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an extension dev tools infobar delegate and adds it to the - // InfoBarService associated with |rvh|. Returns the delegate if it was + // Creates an extension dev tools infobar and delegate and adds the infobar to + // the InfoBarService associated with |rvh|. Returns the infobar if it was // successfully added. - static ExtensionDevToolsInfoBarDelegate* Create( - RenderViewHost* rvh, - const std::string& client_name); + static InfoBar* Create(RenderViewHost* rvh, const std::string& client_name); void set_client_host(ExtensionDevToolsClientHost* client_host) { client_host_ = client_host; } private: - ExtensionDevToolsInfoBarDelegate(InfoBarService* infobar_service, - const std::string& client_name); + explicit ExtensionDevToolsInfoBarDelegate(const std::string& client_name); virtual ~ExtensionDevToolsInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -177,7 +170,7 @@ class ExtensionDevToolsInfoBarDelegate : public ConfirmInfoBarDelegate { }; // static -ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( +InfoBar* ExtensionDevToolsInfoBarDelegate::Create( RenderViewHost* rvh, const std::string& client_name) { if (!rvh) @@ -192,15 +185,14 @@ ExtensionDevToolsInfoBarDelegate* ExtensionDevToolsInfoBarDelegate::Create( if (!infobar_service) return NULL; - return static_cast<ExtensionDevToolsInfoBarDelegate*>( - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ExtensionDevToolsInfoBarDelegate(infobar_service, client_name)))); + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new ExtensionDevToolsInfoBarDelegate(client_name)))); } ExtensionDevToolsInfoBarDelegate::ExtensionDevToolsInfoBarDelegate( - InfoBarService* infobar_service, const std::string& client_name) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), client_name_(client_name), client_host_(NULL) { } @@ -303,7 +295,7 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( const std::string& extension_id, const std::string& extension_name, const Debuggee& debuggee, - ExtensionDevToolsInfoBarDelegate* infobar) + InfoBar* infobar) : profile_(profile), agent_host_(agent_host), extension_id_(extension_id), @@ -329,7 +321,8 @@ ExtensionDevToolsClientHost::ExtensionDevToolsClientHost( agent_host_.get(), this); if (infobar_) { - infobar_->set_client_host(this); + static_cast<ExtensionDevToolsInfoBarDelegate*>( + infobar_->delegate())->set_client_host(this); registrar_.Add( this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, content::Source<InfoBarService>(InfoBarService::FromWebContents( @@ -344,7 +337,8 @@ ExtensionDevToolsClientHost::~ExtensionDevToolsClientHost() { registrar_.RemoveAll(); if (infobar_) { - infobar_->set_client_host(NULL); + static_cast<ExtensionDevToolsInfoBarDelegate*>( + infobar_->delegate())->set_client_host(NULL); InfoBarService::FromWebContents(WebContents::FromRenderViewHost( agent_host_->GetRenderViewHost()))->RemoveInfoBar(infobar_); } @@ -569,13 +563,13 @@ bool DebuggerAttachFunction::RunImpl() { return false; } - ExtensionDevToolsInfoBarDelegate* infobar = NULL; + InfoBar* infobar = NULL; if (!CommandLine::ForCurrentProcess()-> HasSwitch(switches::kSilentDebuggerExtensionAPI)) { // Do not attach to the target if for any reason the infobar cannot be shown // for this WebContents instance. infobar = ExtensionDevToolsInfoBarDelegate::Create( - agent_host_->GetRenderViewHost(), GetExtension()->name()); + agent_host_->GetRenderViewHost(), GetExtension()->name()); if (!infobar) { error_ = ErrorUtils::FormatErrorMessage( keys::kSilentDebuggingRequired, diff --git a/chrome/browser/extensions/extension_infobar_delegate.cc b/chrome/browser/extensions/extension_infobar_delegate.cc index 1c74eef..601da47 100644 --- a/chrome/browser/extensions/extension_infobar_delegate.cc +++ b/chrome/browser/extensions/extension_infobar_delegate.cc @@ -16,8 +16,6 @@ #include "extensions/common/extension.h" ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { - if (observer_) - observer_->OnDelegateDeleted(); } // static @@ -26,25 +24,22 @@ void ExtensionInfoBarDelegate::Create(content::WebContents* web_contents, const extensions::Extension* extension, const GURL& url, int height) { - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ExtensionInfoBarDelegate(browser, infobar_service, extension, url, - web_contents, height))); + InfoBarService::FromWebContents(web_contents)->AddInfoBar( + ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate( + browser, extension, url, web_contents, height)))); } ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( Browser* browser, - InfoBarService* infobar_service, const extensions::Extension* extension, const GURL& url, content::WebContents* web_contents, int height) - : InfoBarDelegate(infobar_service), + : InfoBarDelegate(), #if defined(TOOLKIT_VIEWS) browser_(browser), #endif - observer_(NULL), extension_(extension), closing_(false) { extension_view_host_.reset( @@ -56,21 +51,15 @@ ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, content::Source<Profile>(browser->profile())); -#if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) || defined(OS_ANDROID) - // TODO(dtrainor): On Android, this is not used. Might need to pull this from - // Android UI level in the future. Tracked via issue 115303. - int default_height = InfoBar::kDefaultBarTargetHeight; -#elif defined(OS_MACOSX) - // TODO(pkasting): Once Infobars have been ported to Mac, we can remove the - // ifdefs and just use the Infobar constant below. - int default_height = 36; -#endif height_ = std::max(0, height); - height_ = std::min(2 * default_height, height_); + height_ = std::min(2 * InfoBar::kDefaultBarTargetHeight, height_); if (height_ == 0) - height_ = default_height; + height_ = InfoBar::kDefaultBarTargetHeight; } +// ExtensionInfoBarDelegate::CreateInfoBar() is implemented in platform-specific +// files. + bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { ExtensionInfoBarDelegate* extension_delegate = delegate->AsExtensionInfoBarDelegate(); @@ -107,11 +96,11 @@ void ExtensionInfoBarDelegate::Observe( if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { if (extension_view_host_.get() == content::Details<extensions::ExtensionHost>(details).ptr()) - RemoveSelf(); + infobar()->RemoveSelf(); } else { DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( details)->extension) - RemoveSelf(); + infobar()->RemoveSelf(); } } diff --git a/chrome/browser/extensions/extension_infobar_delegate.h b/chrome/browser/extensions/extension_infobar_delegate.h index 3b4ba5b..b9a337f 100644 --- a/chrome/browser/extensions/extension_infobar_delegate.h +++ b/chrome/browser/extensions/extension_infobar_delegate.h @@ -23,19 +23,10 @@ class ExtensionViewHost; class ExtensionInfoBarDelegate : public InfoBarDelegate, public content::NotificationObserver { public: - // The observer for when the delegate dies. - class DelegateObserver { - public: - virtual void OnDelegateDeleted() = 0; - - protected: - virtual ~DelegateObserver() {} - }; - virtual ~ExtensionInfoBarDelegate(); - // Creates an extension infobar delegate and adds it to the infobar service - // for |web_contents|. + // Creates an extension infobar and delegate and adds the infobar to the + // infobar service for |web_contents|. static void Create(content::WebContents* web_contents, Browser* browser, const extensions::Extension* extension, @@ -48,20 +39,20 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate, } int height() { return height_; } - void set_observer(DelegateObserver* observer) { observer_ = observer; } - bool closing() const { return closing_; } private: ExtensionInfoBarDelegate(Browser* browser, - InfoBarService* infobar_service, const extensions::Extension* extension, const GURL& url, content::WebContents* web_contents, int height); + // Returns an extension infobar that owns |delegate|. + static scoped_ptr<InfoBar> CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate); + // InfoBarDelegate: - virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE; virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; virtual void InfoBarDismissed() OVERRIDE; virtual Type GetInfoBarType() const OVERRIDE; @@ -76,15 +67,10 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate, Browser* browser_; // We pass this to the ExtensionInfoBar. #endif - // The extension host we are showing the InfoBar for. The delegate needs to - // own this since the InfoBar gets deleted and recreated when you switch tabs - // and come back (and we don't want the user's interaction with the InfoBar to - // get lost at that point). + // The extension host we are showing the InfoBar for. + // TODO(pkasting): Should this live on the InfoBar instead? scoped_ptr<extensions::ExtensionViewHost> extension_view_host_; - // The observer monitoring when the delegate dies. - DelegateObserver* observer_; - const extensions::Extension* extension_; content::NotificationRegistrar registrar_; diff --git a/chrome/browser/extensions/extension_install_ui_browsertest.cc b/chrome/browser/extensions/extension_install_ui_browsertest.cc index 72d8069..d91cf30 100644 --- a/chrome/browser/extensions/extension_install_ui_browsertest.cc +++ b/chrome/browser/extensions/extension_install_ui_browsertest.cc @@ -9,6 +9,7 @@ #include "chrome/browser/extensions/extension_browsertest.h" #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_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" @@ -42,7 +43,7 @@ class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { InfoBarService::FromWebContents(web_contents); ASSERT_EQ(1U, infobar_service->infobar_count()); ConfirmInfoBarDelegate* delegate = - infobar_service->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate); delegate->Cancel(); ASSERT_EQ(0U, infobar_service->infobar_count()); diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc index 11766fa..2c22bc6 100644 --- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc +++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc @@ -9,6 +9,7 @@ #include "base/strings/utf_string_conversions.h" #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_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/theme_service.h" @@ -47,16 +48,17 @@ void ThemeInstalledInfoBarDelegate::Create( InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile); - scoped_ptr<InfoBarDelegate> new_infobar(new ThemeInstalledInfoBarDelegate( - infobar_service, profile->GetExtensionService(), theme_service, new_theme, - previous_theme_id, previous_using_native_theme)); + scoped_ptr<InfoBar> new_infobar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new ThemeInstalledInfoBarDelegate( + profile->GetExtensionService(), theme_service, new_theme, + previous_theme_id, previous_using_native_theme)))); // 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) { - InfoBarDelegate* old_infobar = infobar_service->infobar_at(i); + InfoBar* old_infobar = infobar_service->infobar_at(i); ThemeInstalledInfoBarDelegate* theme_infobar = - old_infobar->AsThemePreviewInfobarDelegate(); + old_infobar->delegate()->AsThemePreviewInfobarDelegate(); if (theme_infobar) { // If the user installed the same theme twice, ignore the second install // and keep the first install info bar, so that they can easily undo to @@ -75,13 +77,12 @@ void ThemeInstalledInfoBarDelegate::Create( } ThemeInstalledInfoBarDelegate::ThemeInstalledInfoBarDelegate( - InfoBarService* infobar_service, ExtensionService* extension_service, ThemeService* theme_service, const extensions::Extension* new_theme, const std::string& previous_theme_id, bool previous_using_native_theme) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), extension_service_(extension_service), theme_service_(theme_service), name_(new_theme->name()), @@ -154,5 +155,5 @@ void ThemeInstalledInfoBarDelegate::Observe( // If the new theme is different from what this info bar is associated with, // close this info bar since it is no longer relevant. if (theme_id_ != theme_service_->GetThemeID()) - RemoveSelf(); + infobar()->RemoveSelf(); } diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.h b/chrome/browser/extensions/theme_installed_infobar_delegate.h index f37efcc..94727a7 100644 --- a/chrome/browser/extensions/theme_installed_infobar_delegate.h +++ b/chrome/browser/extensions/theme_installed_infobar_delegate.h @@ -26,16 +26,15 @@ class Extension; class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate, public content::NotificationObserver { public: - // Creates a theme installed infobar delegate and adds it to the last active - // tab on |profile|. + // Creates a theme installed infobar and delegate and adds the infobar to the + // last active tab on |profile|. static void Create(const extensions::Extension* new_theme, Profile* profile, const std::string& previous_theme_id, bool previous_using_native_theme); private: - ThemeInstalledInfoBarDelegate(InfoBarService* infobar_service, - ExtensionService* extension_service, + ThemeInstalledInfoBarDelegate(ExtensionService* extension_service, ThemeService* theme_service, const extensions::Extension* new_theme, const std::string& previous_theme_id, diff --git a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc index 367a27a..3c7664a 100644 --- a/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc +++ b/chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc @@ -56,13 +56,13 @@ class ClosedInfoBarTracker : public content::NotificationObserver { size_t size() const { return removed_infobars_.size(); } - bool Contains(InfoBarDelegate* infobar) const; + bool Contains(InfoBar* infobar) const; void Clear(); private: FRIEND_TEST_ALL_PREFIXES(GeolocationPermissionContextTests, TabDestroyed); content::NotificationRegistrar registrar_; - std::set<InfoBarDelegate*> removed_infobars_; + std::set<InfoBar*> removed_infobars_; }; ClosedInfoBarTracker::ClosedInfoBarTracker() { @@ -82,7 +82,7 @@ void ClosedInfoBarTracker::Observe( content::Details<InfoBar::RemovedDetails>(details)->first); } -bool ClosedInfoBarTracker::Contains(InfoBarDelegate* infobar) const { +bool ClosedInfoBarTracker::Contains(InfoBar* infobar) const { return removed_infobars_.count(infobar) != 0; } @@ -258,14 +258,14 @@ TEST_F(GeolocationPermissionContextTests, SinglePermission) { EXPECT_EQ(0U, infobar_service()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); ASSERT_EQ(1U, infobar_service()->infobar_count()); + InfoBar* infobar = infobar_service()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Cancel(); - infobar_service()->RemoveInfoBar(infobar_delegate); + infobar_service()->RemoveInfoBar(infobar); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate)); - delete infobar_delegate; + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); } #if defined(OS_ANDROID) @@ -276,8 +276,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { EXPECT_EQ(0U, infobar_service()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate_0 = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_service()-> + infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); string16 text_0 = infobar_delegate_0->GetButtonLabel( ConfirmInfoBarDelegate::BUTTON_OK); @@ -287,8 +287,8 @@ TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { EXPECT_EQ(0U, infobar_service()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate_1 = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_service()-> + infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); string16 text_1 = infobar_delegate_1->GetButtonLabel( ConfirmInfoBarDelegate::BUTTON_OK); @@ -308,8 +308,8 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { EXPECT_EQ(0U, infobar_service()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> + infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Accept(); CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); @@ -323,8 +323,8 @@ TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { EXPECT_EQ(0U, infobar_service()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); EXPECT_EQ(1U, infobar_service()->infobar_count()); - ConfirmInfoBarDelegate* infobar_delegate = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> + infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); infobar_delegate->Accept(); EXPECT_TRUE( @@ -351,8 +351,9 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 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); ConfirmInfoBarDelegate* infobar_delegate_0 = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); string16 text_0 = infobar_delegate_0->GetMessageText(); @@ -361,16 +362,16 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(0, true); - infobar_service()->RemoveInfoBar(infobar_delegate_0); + infobar_service()->RemoveInfoBar(infobar_0); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); closed_infobar_tracker_.Clear(); - delete infobar_delegate_0; // Now we should have a new infobar for the second frame. ASSERT_EQ(1U, infobar_service()->infobar_count()); + InfoBar* infobar_1 = infobar_service()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_1 = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_1->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); string16 text_1 = infobar_delegate_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -379,10 +380,9 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { infobar_delegate_1->Cancel(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); CheckPermissionMessageSent(1, false); - infobar_service()->RemoveInfoBar(infobar_delegate_1); + infobar_service()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); - delete infobar_delegate_1; + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); EXPECT_EQ(0U, infobar_service()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ALLOW, @@ -405,8 +405,9 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { EXPECT_EQ(0U, infobar_service()->infobar_count()); RequestGeolocationPermission(RequestID(0), url_a); ASSERT_EQ(1U, infobar_service()->infobar_count()); + InfoBar* infobar = infobar_service()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); // Change the hash, we'll still be on the same page. @@ -419,11 +420,9 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { CheckPermissionMessageSent(0, true); // Cleanup. - infobar_service()->RemoveInfoBar(infobar_delegate); + infobar_service()->RemoveInfoBar(infobar); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate)); - closed_infobar_tracker_.Clear(); - delete infobar_delegate; + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); } TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { @@ -432,15 +431,15 @@ TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { EXPECT_EQ(0U, infobar_service()->infobar_count()); RequestGeolocationPermission(RequestID(0), requesting_frame); EXPECT_EQ(1U, infobar_service()->infobar_count()); + InfoBar* infobar = infobar_service()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate); // Accept the frame. infobar_delegate->Accept(); CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(0, true); - infobar_service()->RemoveInfoBar(infobar_delegate); - delete infobar_delegate; + infobar_service()->RemoveInfoBar(infobar); // Make sure the setting is not stored. EXPECT_EQ(CONTENT_SETTING_ASK, @@ -471,8 +470,9 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { RequestGeolocationPermission(RequestID(1), requesting_frame_1); ASSERT_EQ(1U, infobar_service()->infobar_count()); + InfoBar* infobar_0 = infobar_service()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_0 = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); string16 text_0 = infobar_delegate_0->GetMessageText(); @@ -480,13 +480,13 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { // is removed and the next pending infobar is created. CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); closed_infobar_tracker_.Clear(); - delete infobar_delegate_0; ASSERT_EQ(1U, infobar_service()->infobar_count()); + InfoBar* infobar_1 = infobar_service()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_1 = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_1->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); string16 text_1 = infobar_delegate_1->GetMessageText(); EXPECT_NE(text_0, text_1); @@ -495,10 +495,9 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { infobar_delegate_1->Accept(); CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); CheckPermissionMessageSent(1, true); - infobar_service()->RemoveInfoBar(infobar_delegate_1); + infobar_service()->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); - delete infobar_delegate_1; + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); EXPECT_EQ(0U, infobar_service()->infobar_count()); // Ensure the persisted permissions are ok. EXPECT_EQ(CONTENT_SETTING_ASK, @@ -539,36 +538,34 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); - ConfirmInfoBarDelegate* removed_infobar = - infobar_service_for_tab(1)->infobar_at(0)->AsConfirmInfoBarDelegate(); + InfoBar* removed_infobar = infobar_service_for_tab(1)->infobar_at(0); // Accept the first tab. + InfoBar* infobar_0 = infobar_service()->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_0 = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); infobar_delegate_0->Accept(); CheckPermissionMessageSent(0, true); - infobar_service()->RemoveInfoBar(infobar_delegate_0); + infobar_service()->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); - delete infobar_delegate_0; + 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()); CheckPermissionMessageSentForTab(1, 0, true); EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); closed_infobar_tracker_.Clear(); - // Destroy the infobar that has just been removed. - delete removed_infobar; // 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); ConfirmInfoBarDelegate* infobar_delegate_1 = - infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_1->delegate()->AsConfirmInfoBarDelegate(); + ASSERT_TRUE(infobar_delegate_1); infobar_delegate_1->Cancel(); - infobar_service_for_tab(0)->RemoveInfoBar(infobar_delegate_1); + infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); - delete infobar_delegate_1; + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); } TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { @@ -587,39 +584,37 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); - ConfirmInfoBarDelegate* removed_infobar = - infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); + InfoBar* removed_infobar = infobar_service()->infobar_at(0); // Accept the second tab. + InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_0 = - infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_0->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_0); infobar_delegate_0->Accept(); CheckPermissionMessageSentForTab(0, 0, true); - infobar_service_for_tab(0)->RemoveInfoBar(infobar_delegate_0); + infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); EXPECT_EQ(2U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); - delete infobar_delegate_0; + 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()); CheckPermissionMessageSent(0, true); EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); closed_infobar_tracker_.Clear(); - delete removed_infobar; // And we should have the queued infobar displayed now. ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); // Accept the second infobar. + InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); ConfirmInfoBarDelegate* infobar_delegate_1 = - infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_1->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar_delegate_1); infobar_delegate_1->Accept(); CheckPermissionMessageSentForTab(0, 1, true); - infobar_service_for_tab(0)->RemoveInfoBar(infobar_delegate_1); + infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); EXPECT_EQ(1U, closed_infobar_tracker_.size()); - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); - delete infobar_delegate_1; + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); } TEST_F(GeolocationPermissionContextTests, TabDestroyed) { @@ -642,11 +637,10 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) { RequestGeolocationPermission(RequestID(1), requesting_frame_1); // Ensure only one infobar is created. ASSERT_EQ(1U, infobar_service()->infobar_count()); - InfoBarDelegate* infobar = infobar_service()->infobar_at(0); + InfoBar* infobar = infobar_service()->infobar_at(0); // Delete the tab contents. DeleteContents(); - delete infobar; // During contents destruction, the infobar will have been closed, and the // pending request should have been cleared without an infobar being created. @@ -667,7 +661,8 @@ TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { RequestGeolocationPermission(RequestID(0), requesting_frame_1); // Ensure the infobar is created. ASSERT_EQ(1U, infobar_service()->infobar_count()); - InfoBarDelegate* infobar_delegate = infobar_service()->infobar_at(0); + InfoBarDelegate* infobar_delegate = + infobar_service()->infobar_at(0)->delegate(); ASSERT_TRUE(infobar_delegate); // Ensure the infobar wouldn't expire for a navigation to the committed entry. content::LoadCommittedDetails details; @@ -679,5 +674,4 @@ TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { // Delete the tab contents. DeleteContents(); - delete infobar_delegate; } diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc index ec1f7a2..caa9231 100644 --- a/chrome/browser/geolocation/geolocation_browsertest.cc +++ b/chrome/browser/geolocation/geolocation_browsertest.cc @@ -141,12 +141,12 @@ class GeolocationNotificationObserver : public content::NotificationObserver { const std::string& iframe_xpath); bool has_infobar() const { return !!infobar_; } - InfoBarDelegate* infobar() { return infobar_; } + InfoBar* infobar() { return infobar_; } private: content::NotificationRegistrar registrar_; bool wait_for_infobar_; - InfoBarDelegate* infobar_; + InfoBar* infobar_; bool navigation_started_; bool navigation_completed_; std::string javascript_response_; @@ -184,8 +184,8 @@ void GeolocationNotificationObserver::Observe( const content::NotificationDetails& details) { if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) { infobar_ = content::Details<InfoBar::AddedDetails>(details).ptr(); - ASSERT_FALSE(infobar_->GetIcon().IsEmpty()); - ASSERT_TRUE(infobar_->AsConfirmInfoBarDelegate()); + ASSERT_FALSE(infobar_->delegate()->GetIcon().IsEmpty()); + ASSERT_TRUE(infobar_->delegate()->AsConfirmInfoBarDelegate()); } else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) { content::Details<DomOperationNotificationDetails> dom_op_details(details); javascript_response_ = dom_op_details->json; @@ -298,7 +298,7 @@ class GeolocationBrowserTest : public InProcessBrowserTest { void NotifyGeoposition(double latitude, double longitude); private: - InfoBarDelegate* infobar_; + InfoBar* infobar_; Browser* current_browser_; // path element of a URL referencing the html content for this test. std::string html_for_tests_; @@ -407,9 +407,9 @@ void GeolocationBrowserTest::SetInfoBarResponse(const GURL& requesting_url, content::NOTIFICATION_LOAD_STOP, content::Source<NavigationController>(&web_contents->GetController())); if (allowed) - infobar_->AsConfirmInfoBarDelegate()->Accept(); + infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); else - infobar_->AsConfirmInfoBarDelegate()->Cancel(); + infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); observer.Wait(); } diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate.cc b/chrome/browser/geolocation/geolocation_infobar_delegate.cc index 3a8675d..d7f0276 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate.cc +++ b/chrome/browser/geolocation/geolocation_infobar_delegate.cc @@ -7,6 +7,7 @@ #include "base/metrics/histogram.h" #include "chrome/browser/content_settings/permission_queue_controller.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_entry.h" @@ -61,7 +62,7 @@ void RecordUmaEvent(GeolocationInfoBarDelegateEvent event) { } // namespace // static -InfoBarDelegate* GeolocationInfoBarDelegate::Create( +InfoBar* GeolocationInfoBarDelegate::Create( InfoBarService* infobar_service, PermissionQueueController* controller, const PermissionRequestID& id, @@ -70,20 +71,20 @@ InfoBarDelegate* GeolocationInfoBarDelegate::Create( RecordUmaEvent(GEOLOCATION_INFO_BAR_DELEGATE_EVENT_CREATE); const content::NavigationEntry* committed_entry = infobar_service->web_contents()->GetController().GetLastCommittedEntry(); - return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new DelegateType(infobar_service, controller, id, requesting_frame, - committed_entry ? committed_entry->GetUniqueID() : 0, - display_languages))); + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new DelegateType( + controller, id, requesting_frame, + committed_entry ? committed_entry->GetUniqueID() : 0, + display_languages)))); } GeolocationInfoBarDelegate::GeolocationInfoBarDelegate( - InfoBarService* infobar_service, PermissionQueueController* controller, const PermissionRequestID& id, const GURL& requesting_frame, int contents_unique_id, const std::string& display_languages) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), controller_(controller), id_(id), requesting_frame_(requesting_frame.GetOrigin()), diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate.h b/chrome/browser/geolocation/geolocation_infobar_delegate.h index 7444a678..342b821 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate.h +++ b/chrome/browser/geolocation/geolocation_infobar_delegate.h @@ -19,17 +19,16 @@ class InfoBarService; // and handling of geolocation permission infobars to the user. class GeolocationInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a geolocation infobar delegate and adds it to |infobar_service|. - // Returns the delegate if it was successfully added. - static InfoBarDelegate* Create(InfoBarService* infobar_service, - PermissionQueueController* controller, - const PermissionRequestID& id, - const GURL& requesting_frame, - const std::string& display_languages); + // Creates a geolocation infobar and delegate and adds the infobar to + // |infobar_service|. Returns the infobar if it was successfully added. + static InfoBar* Create(InfoBarService* infobar_service, + PermissionQueueController* controller, + const PermissionRequestID& id, + const GURL& requesting_frame, + const std::string& display_languages); protected: - GeolocationInfoBarDelegate(InfoBarService* infobar_service, - PermissionQueueController* controller, + GeolocationInfoBarDelegate(PermissionQueueController* controller, const PermissionRequestID& id, const GURL& requesting_frame, int contents_unique_id, diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc b/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc index 4193181..1fb136a 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc +++ b/chrome/browser/geolocation/geolocation_infobar_delegate_android.cc @@ -35,15 +35,13 @@ void RecordUmaEvent(GeolocationInfoBarDelegateAndroidEvent event) { } // namespace GeolocationInfoBarDelegateAndroid::GeolocationInfoBarDelegateAndroid( - InfoBarService* infobar_service, PermissionQueueController* controller, const PermissionRequestID& id, const GURL& requesting_frame_url, int contents_unique_id, const std::string& display_languages) - : GeolocationInfoBarDelegate(infobar_service, controller, id, - requesting_frame_url, contents_unique_id, - display_languages), + : GeolocationInfoBarDelegate(controller, id, requesting_frame_url, + contents_unique_id, display_languages), google_location_settings_helper_( GoogleLocationSettingsHelper::Create()) { } diff --git a/chrome/browser/geolocation/geolocation_infobar_delegate_android.h b/chrome/browser/geolocation/geolocation_infobar_delegate_android.h index e247f7f..bca3425 100644 --- a/chrome/browser/geolocation/geolocation_infobar_delegate_android.h +++ b/chrome/browser/geolocation/geolocation_infobar_delegate_android.h @@ -13,7 +13,6 @@ class GoogleLocationSettingsHelper; class GeolocationInfoBarDelegateAndroid : public GeolocationInfoBarDelegate { public: GeolocationInfoBarDelegateAndroid( - InfoBarService* infobar_service, PermissionQueueController* controller, const PermissionRequestID& id, const GURL& requesting_frame_url, diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index edae47e..c6160af 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -13,6 +13,7 @@ #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" #include "chrome/browser/google/google_url_tracker_navigation_helper.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_switches.h" @@ -348,12 +349,13 @@ void GoogleURLTracker::OnNavigationCommitted(InfoBarService* infobar_service, if (map_entry->has_infobar_delegate()) { map_entry->infobar_delegate()->Update(search_url); } else { - GoogleURLTrackerInfoBarDelegate* infobar = - infobar_creator_.Run(infobar_service, this, search_url); - if (infobar) - map_entry->SetInfoBarDelegate(infobar); - else + InfoBar* infobar = infobar_creator_.Run(infobar_service, this, search_url); + if (infobar) { + map_entry->SetInfoBarDelegate( + static_cast<GoogleURLTrackerInfoBarDelegate*>(infobar->delegate())); + } else { map_entry->Close(false); + } } } diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h index 5f2c85e..f572322 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -21,6 +21,7 @@ #include "url/gurl.h" class GoogleURLTrackerNavigationHelper; +class InfoBar; class PrefService; class Profile; @@ -175,13 +176,11 @@ class GoogleURLTracker : public net::URLFetcherDelegate, scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper_; - // Creates an infobar delegate and adds it to the provided InfoBarService. - // Returns the delegate pointer on success or NULL on failure. The caller - // does not own the returned object, the InfoBarService does. - base::Callback<GoogleURLTrackerInfoBarDelegate*( - InfoBarService*, - GoogleURLTracker*, - const GURL&)> infobar_creator_; + // Creates an infobar and adds it to the provided InfoBarService. Returns the + // infobar on success or NULL on failure. The caller does not own the + // returned object, the InfoBarService does. + base::Callback<InfoBar*(InfoBarService*, GoogleURLTracker*, const GURL&)> + infobar_creator_; GURL google_url_; GURL fetched_google_url_; diff --git a/chrome/browser/google/google_url_tracker_infobar_delegate.cc b/chrome/browser/google/google_url_tracker_infobar_delegate.cc index 3369943..7dc1c69 100644 --- a/chrome/browser/google/google_url_tracker_infobar_delegate.cc +++ b/chrome/browser/google/google_url_tracker_infobar_delegate.cc @@ -6,6 +6,7 @@ #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_entry.h" @@ -17,14 +18,13 @@ // static -GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerInfoBarDelegate::Create( +InfoBar* GoogleURLTrackerInfoBarDelegate::Create( InfoBarService* infobar_service, GoogleURLTracker* google_url_tracker, const GURL& search_url) { - return static_cast<GoogleURLTrackerInfoBarDelegate*>( - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new GoogleURLTrackerInfoBarDelegate( - infobar_service, google_url_tracker, search_url)))); + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( + google_url_tracker, search_url)))); } bool GoogleURLTrackerInfoBarDelegate::Accept() { @@ -60,7 +60,7 @@ void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { } content::WebContents* contents = web_contents(); - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); // WARNING: |this| may be deleted at this point! Do not access any members! if (new_search_url.is_valid()) { @@ -71,10 +71,9 @@ void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { } GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( - InfoBarService* infobar_service, GoogleURLTracker* google_url_tracker, const GURL& search_url) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), google_url_tracker_(google_url_tracker), search_url_(search_url), pending_id_(0) { diff --git a/chrome/browser/google/google_url_tracker_infobar_delegate.h b/chrome/browser/google/google_url_tracker_infobar_delegate.h index b0be8f5..36b482a 100644 --- a/chrome/browser/google/google_url_tracker_infobar_delegate.h +++ b/chrome/browser/google/google_url_tracker_infobar_delegate.h @@ -14,12 +14,11 @@ class GoogleURLTracker; // changed. class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a Google URL tracker infobar delegate and adds it to - // |infobar_service|. Returns the delegate if it was successfully added. - static GoogleURLTrackerInfoBarDelegate* Create( - InfoBarService* infobar_service, - GoogleURLTracker* google_url_tracker, - const GURL& search_url); + // Creates a Google URL tracker infobar and delegate and adds the infobar to + // |infobar_service|. Returns the infobar if it was successfully added. + static InfoBar* Create(InfoBarService* infobar_service, + GoogleURLTracker* google_url_tracker, + const GURL& search_url); // ConfirmInfoBarDelegate: virtual bool Accept() OVERRIDE; @@ -36,8 +35,7 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { virtual void Close(bool redo_search); protected: - GoogleURLTrackerInfoBarDelegate(InfoBarService* infobar_service, - GoogleURLTracker* google_url_tracker, + GoogleURLTrackerInfoBarDelegate(GoogleURLTracker* google_url_tracker, const GURL& search_url); virtual ~GoogleURLTrackerInfoBarDelegate(); diff --git a/chrome/browser/google/google_url_tracker_map_entry.cc b/chrome/browser/google/google_url_tracker_map_entry.cc index 88b507c..9e39363fa 100644 --- a/chrome/browser/google/google_url_tracker_map_entry.cc +++ b/chrome/browser/google/google_url_tracker_map_entry.cc @@ -32,7 +32,7 @@ void GoogleURLTrackerMapEntry::Observe( DCHECK(infobar_delegate_); DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); DCHECK_EQ(infobar_service_, content::Source<InfoBarService>(source).ptr()); - if (content::Details<InfoBar::RemovedDetails>(details)->first == + if (content::Details<InfoBar::RemovedDetails>(details)->first->delegate() == infobar_delegate_) { google_url_tracker_->DeleteMapEntryForService(infobar_service_); // WARNING: At this point |this| has been deleted! diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index 114637a..6f70c32 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -31,17 +31,16 @@ namespace { class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { public: - // Creates a test delegate and returns it. Unlike the parent class, this does - // not add the infobar to |infobar_service|, since that "pointer" is really - // just a magic number. Thus there is no InfoBarService ownership of the - // returned object; and since the caller doesn't own the returned object, we - // rely on |test_harness| cleaning this up eventually in - // GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks. - static GoogleURLTrackerInfoBarDelegate* Create( - GoogleURLTrackerTest* test_harness, - InfoBarService* infobar_service, - GoogleURLTracker* google_url_tracker, - const GURL& search_url); + // Creates a test infobar and delegate and returns the infobar. Unlike the + // parent class, this does not add the infobar to |infobar_service|, since + // that "pointer" is really just a magic number. Thus there is no + // InfoBarService ownership of the returned object; and since the caller + // doesn't own the returned object, we rely on |test_harness| cleaning this up + // eventually in GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks. + static InfoBar* Create(GoogleURLTrackerTest* test_harness, + InfoBarService* infobar_service, + GoogleURLTracker* google_url_tracker, + const GURL& search_url); private: TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, @@ -200,7 +199,7 @@ bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction( class GoogleURLTrackerTest : public testing::Test { public: // Called by TestInfoBarDelegate::Close(). - void OnInfoBarClosed(scoped_ptr<InfoBarDelegate> infobar, + void OnInfoBarClosed(scoped_ptr<InfoBar> infobar, InfoBarService* infobar_service); protected: @@ -241,10 +240,9 @@ class GoogleURLTrackerTest : public testing::Test { // object, we don't add the created infobar to it. Instead we will simulate // any helper<->infobar interaction necessary. The returned object will be // cleaned up in OnInfoBarClosed(). - GoogleURLTrackerInfoBarDelegate* CreateTestInfoBar( - InfoBarService* infobar_service, - GoogleURLTracker* google_url_tracker, - const GURL& search_url); + InfoBar* CreateTestInfoBar(InfoBarService* infobar_service, + GoogleURLTracker* google_url_tracker, + const GURL& search_url); // These are required by the TestURLFetchers GoogleURLTracker will create (see // test_url_fetcher_factory.h). @@ -263,7 +261,7 @@ class GoogleURLTrackerTest : public testing::Test { std::set<int> unique_ids_seen_; }; -void GoogleURLTrackerTest::OnInfoBarClosed(scoped_ptr<InfoBarDelegate> infobar, +void GoogleURLTrackerTest::OnInfoBarClosed(scoped_ptr<InfoBar> infobar, InfoBarService* infobar_service) { // First, simulate the InfoBarService firing INFOBAR_REMOVED. InfoBar::RemovedDetails removed_details(infobar.get(), false); @@ -271,7 +269,7 @@ void GoogleURLTrackerTest::OnInfoBarClosed(scoped_ptr<InfoBarDelegate> infobar, google_url_tracker_->entry_map_.find(infobar_service); ASSERT_FALSE(i == google_url_tracker_->entry_map_.end()); GoogleURLTrackerMapEntry* map_entry = i->second; - ASSERT_EQ(infobar, map_entry->infobar_delegate()); + ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate()); map_entry->Observe( chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, content::Source<InfoBarService>(infobar_service), @@ -448,7 +446,7 @@ void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, } } -GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar( +InfoBar* GoogleURLTrackerTest::CreateTestInfoBar( InfoBarService* infobar_service, GoogleURLTracker* google_url_tracker, const GURL& search_url) { @@ -462,20 +460,21 @@ GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar( namespace { // static -GoogleURLTrackerInfoBarDelegate* TestInfoBarDelegate::Create( - GoogleURLTrackerTest* test_harness, - InfoBarService* infobar_service, - GoogleURLTracker* google_url_tracker, - const GURL& search_url) { - return new TestInfoBarDelegate(test_harness, infobar_service, - google_url_tracker, search_url); +InfoBar* TestInfoBarDelegate::Create(GoogleURLTrackerTest* test_harness, + InfoBarService* infobar_service, + GoogleURLTracker* google_url_tracker, + const GURL& search_url) { + return ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate( + test_harness, infobar_service, google_url_tracker, + search_url))).release(); } TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, InfoBarService* infobar_service, GoogleURLTracker* google_url_tracker, const GURL& search_url) - : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, search_url), + : GoogleURLTrackerInfoBarDelegate(google_url_tracker, search_url), test_harness_(test_harness), infobar_service_(infobar_service) { } @@ -489,7 +488,7 @@ void TestInfoBarDelegate::Update(const GURL& search_url) { } void TestInfoBarDelegate::Close(bool redo_search) { - test_harness_->OnInfoBarClosed(scoped_ptr<InfoBarDelegate>(this), + test_harness_->OnInfoBarClosed(scoped_ptr<InfoBar>(infobar()), infobar_service_); // WARNING: At this point |this| has been deleted! } diff --git a/chrome/browser/infobars/confirm_infobar_delegate.cc b/chrome/browser/infobars/confirm_infobar_delegate.cc index eaf6d30..d7d1ac3 100644 --- a/chrome/browser/infobars/confirm_infobar_delegate.cc +++ b/chrome/browser/infobars/confirm_infobar_delegate.cc @@ -44,9 +44,8 @@ bool ConfirmInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { return true; } -ConfirmInfoBarDelegate::ConfirmInfoBarDelegate( - InfoBarService* infobar_service) - : InfoBarDelegate(infobar_service) { +ConfirmInfoBarDelegate::ConfirmInfoBarDelegate() + : InfoBarDelegate() { } bool ConfirmInfoBarDelegate::ShouldExpireInternal( diff --git a/chrome/browser/infobars/confirm_infobar_delegate.h b/chrome/browser/infobars/confirm_infobar_delegate.h index 6d10883..1dd7da0 100644 --- a/chrome/browser/infobars/confirm_infobar_delegate.h +++ b/chrome/browser/infobars/confirm_infobar_delegate.h @@ -5,11 +5,12 @@ #ifndef CHROME_BROWSER_INFOBARS_CONFIRM_INFOBAR_DELEGATE_H_ #define CHROME_BROWSER_INFOBARS_CONFIRM_INFOBAR_DELEGATE_H_ -#include "base/basictypes.h" -#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "base/strings/string16.h" #include "chrome/browser/infobars/infobar_delegate.h" +class InfoBar; + // An interface derived from InfoBarDelegate implemented by objects wishing to // control a ConfirmInfoBar. class ConfirmInfoBarDelegate : public InfoBarDelegate { @@ -60,14 +61,17 @@ class ConfirmInfoBarDelegate : public InfoBarDelegate { virtual bool LinkClicked(WindowOpenDisposition disposition); protected: - explicit ConfirmInfoBarDelegate(InfoBarService* infobar_service); + ConfirmInfoBarDelegate(); + + // Returns a confirm infobar that owns |delegate|. + static scoped_ptr<InfoBar> CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate); virtual bool ShouldExpireInternal( const content::LoadCommittedDetails& details) const OVERRIDE; private: // InfoBarDelegate: - virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE; virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE; virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate() OVERRIDE; diff --git a/chrome/browser/infobars/infobar.cc b/chrome/browser/infobars/infobar.cc index 1491d73..ab61ad1 100644 --- a/chrome/browser/infobars/infobar.cc +++ b/chrome/browser/infobars/infobar.cc @@ -12,9 +12,9 @@ #include "chrome/browser/infobars/infobar_service.h" #include "ui/gfx/animation/slide_animation.h" -InfoBar::InfoBar(InfoBarService* owner, InfoBarDelegate* delegate) - : owner_(owner), - delegate_(delegate), +InfoBar::InfoBar(scoped_ptr<InfoBarDelegate> delegate) + : owner_(NULL), + delegate_(delegate.Pass()), container_(NULL), animation_(this), arrow_height_(0), @@ -22,12 +22,13 @@ InfoBar::InfoBar(InfoBarService* owner, InfoBarDelegate* delegate) arrow_half_width_(0), bar_height_(0), bar_target_height_(kDefaultBarTargetHeight) { - DCHECK(owner_ != NULL); DCHECK(delegate_ != NULL); animation_.SetTweenType(gfx::Tween::LINEAR); + delegate_->set_infobar(this); } InfoBar::~InfoBar() { + DCHECK(!owner_); } // static @@ -50,6 +51,13 @@ SkColor InfoBar::GetBottomColor(InfoBarDelegate::Type infobar_type) { kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; } +void InfoBar::SetOwner(InfoBarService* owner) { + DCHECK(!owner_); + owner_ = owner; + delegate_->StoreActiveEntryUniqueID(); + PlatformSpecificSetOwner(); +} + void InfoBar::Show(bool animate) { PlatformSpecificShow(animate); if (animate) { @@ -90,6 +98,11 @@ void InfoBar::CloseSoon() { MaybeDelete(); } +void InfoBar::RemoveSelf() { + if (owner_) + owner_->RemoveInfoBar(this); +} + void InfoBar::SetBarTargetHeight(int height) { if (bar_target_height_ != height) { bar_target_height_ = height; @@ -101,19 +114,6 @@ void InfoBar::AnimationProgressed(const gfx::Animation* animation) { RecalculateHeights(false); } -void InfoBar::RemoveSelf() { - // |owner_| should never be NULL here. If it is, then someone violated what - // they were supposed to do -- e.g. a ConfirmInfoBarDelegate subclass returned - // true from Accept() or Cancel() even though the infobar was already closing. - // In the worst case, if we also switched tabs during that process, then - // |this| has already been destroyed. But if that's the case, then we're - // going to deref a garbage |this| pointer here whether we check |owner_| or - // not, and in other cases (where we're still closing and |this| is valid), - // checking |owner_| here will avoid a NULL deref. - if (owner_) - owner_->RemoveInfoBar(delegate_); -} - int InfoBar::OffsetY(const gfx::Size& prefsize) const { return arrow_height_ + std::max((bar_target_height_ - prefsize.height()) / 2, 0) - @@ -173,10 +173,9 @@ void InfoBar::RecalculateHeights(bool force_notify) { } void InfoBar::MaybeDelete() { - if (!owner_ && delegate_ && (animation_.GetCurrentValue() == 0.0)) { + if (!owner_ && (animation_.GetCurrentValue() == 0.0)) { if (container_) container_->RemoveInfoBar(this); - delete delegate_; - delegate_ = NULL; + delete this; } } diff --git a/chrome/browser/infobars/infobar.h b/chrome/browser/infobars/infobar.h index 172586f..2355688 100644 --- a/chrome/browser/infobars/infobar.h +++ b/chrome/browser/infobars/infobar.h @@ -7,9 +7,7 @@ #include <utility> -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "build/build_config.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/infobars/infobar_delegate.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/animation/animation_delegate.h" @@ -19,12 +17,27 @@ class InfoBarContainer; class InfoBarService; +// 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, +// create a platform-specific subclass of InfoBar to own it, and then call +// InfoBarService::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 +// 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. class InfoBar : public gfx::AnimationDelegate { public: // These are the types passed as Details for infobar-related notifications. - typedef InfoBarDelegate AddedDetails; - typedef std::pair<InfoBarDelegate*, bool> RemovedDetails; - typedef std::pair<InfoBarDelegate*, InfoBarDelegate*> ReplacedDetails; + typedef InfoBar AddedDetails; + typedef std::pair<InfoBar*, bool> RemovedDetails; + typedef std::pair<InfoBar*, InfoBar*> ReplacedDetails; // Platforms must define these. static const int kDefaultBarTargetHeight; @@ -36,32 +49,44 @@ class InfoBar : public gfx::AnimationDelegate { static const int kDefaultArrowTargetHalfWidth; static const int kMaximumArrowTargetHalfWidth; - InfoBar(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBar(scoped_ptr<InfoBarDelegate> delegate); virtual ~InfoBar(); static SkColor GetTopColor(InfoBarDelegate::Type infobar_type); static SkColor GetBottomColor(InfoBarDelegate::Type infobar_type); - InfoBarDelegate* delegate() { return delegate_; } + InfoBarService* owner() { return owner_; } + InfoBarDelegate* delegate() { return delegate_.get(); } + const InfoBarDelegate* delegate() const { return delegate_.get(); } void set_container(InfoBarContainer* container) { container_ = container; } + // 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); + // Makes the infobar visible. If |animate| is true, the infobar is then // animated to full size. void Show(bool animate); - // Makes the infobar hidden. If |animate| is true, the infobar is first - // animated to zero size. Once the infobar is hidden, it is removed from its - // container (triggering its deletion), and its delegate is closed. + // Makes the infobar hidden. If |animate| is false, the infobar is + // immediately removed from the container, and, if now unowned, deleted. If + // |animate| is true, the infobar is animated to zero size, ultimately + // triggering a call to AnimationEnded(). void Hide(bool animate); // Changes the target height of the arrow portion of the infobar. This has no // effect once the infobar is animating closed. void SetArrowTargetHeight(int height); - // Notifies the infobar that it is no longer owned and should close its - // delegate once it is invisible. + // Notifies the infobar that it is no longer owned and should delete itself + // once it is invisible. void CloseSoon(); + // Forwards a close request to our owner. This is a no-op if we're already + // unowned. + void RemoveSelf(); + // Changes the target height of the main ("bar") portion of the infobar. void SetBarTargetHeight(int height); @@ -75,16 +100,11 @@ class InfoBar : public gfx::AnimationDelegate { // gfx::AnimationDelegate: virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; - // Forwards a close request to our owner. - // NOTE: Subclasses should not call this if we're already unowned. - void RemoveSelf(); - // Given a control with size |prefsize|, returns the centered y position // within us, taking into account animation so the control "slides in" (or // out) as we animate open and closed. int OffsetY(const gfx::Size& prefsize) const; - InfoBarService* owner() const { return owner_; } const InfoBarContainer* container() const { return container_; } InfoBarContainer* container() { return container_; } gfx::SlideAnimation* animation() { return &animation_; } @@ -93,6 +113,7 @@ class InfoBar : public gfx::AnimationDelegate { // Platforms may optionally override these if they need to do work during // processing of the given calls. + virtual void PlatformSpecificSetOwner() {} virtual void PlatformSpecificShow(bool animate) {} virtual void PlatformSpecificHide(bool animate) {} virtual void PlatformSpecificOnCloseSoon() {} @@ -108,13 +129,13 @@ class InfoBar : public gfx::AnimationDelegate { // |force_notify| is set. void RecalculateHeights(bool force_notify); - // Checks whether we're closed. If so, notifies the container that it should - // remove us (which will cause the platform-specific code to asynchronously - // delete us) and closes the delegate. + // Checks whether the infobar is unowned and done with all animations. If so, + // notifies the container that it should remove this infobar, and deletes + // itself. void MaybeDelete(); InfoBarService* owner_; - InfoBarDelegate* delegate_; + 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 8acf573..f9713e5 100644 --- a/chrome/browser/infobars/infobar_container.cc +++ b/chrome/browser/infobars/infobar_container.cc @@ -47,9 +47,7 @@ void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { for (size_t i = 0; i < infobar_service_->infobar_count(); ++i) { // As when we removed the infobars above, we prevent callbacks to // OnInfoBarAnimated() for each infobar. - AddInfoBar( - infobar_service_->infobar_at(i)->CreateInfoBar(infobar_service_), - i, false, NO_CALLBACK); + AddInfoBar(infobar_service_->infobar_at(i), i, false, NO_CALLBACK); } } @@ -114,28 +112,30 @@ void InfoBarContainer::Observe(int type, const content::NotificationDetails& details) { switch (type) { case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED: - AddInfoBar( - content::Details<InfoBar::AddedDetails>(details)->CreateInfoBar( - infobar_service_), - infobars_.size(), true, WANT_CALLBACK); + AddInfoBar(content::Details<InfoBar::AddedDetails>(details).ptr(), + infobars_.size(), true, WANT_CALLBACK); break; case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: { InfoBar::RemovedDetails* removed_details = content::Details<InfoBar::RemovedDetails>(details).ptr(); - HideInfoBar(FindInfoBar(removed_details->first), removed_details->second); + removed_details->first->Hide(removed_details->second); + UpdateInfoBarArrowTargetHeights(); break; } case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REPLACED: { InfoBar::ReplacedDetails* replaced_details = content::Details<InfoBar::ReplacedDetails>(details).ptr(); - InfoBar* old_infobar = FindInfoBar(replaced_details->first); - InfoBar* new_infobar = - replaced_details->second->CreateInfoBar(infobar_service_); + InfoBar* old_infobar = replaced_details->first; + InfoBar* new_infobar = replaced_details->second; PlatformSpecificReplaceInfoBar(old_infobar, new_infobar); - AddInfoBar(new_infobar, HideInfoBar(old_infobar, false), false, - WANT_CALLBACK); + InfoBars::const_iterator i(std::find(infobars_.begin(), infobars_.end(), + old_infobar)); + DCHECK(i != infobars_.end()); + size_t position = i - infobars_.begin(); + old_infobar->Hide(false); + AddInfoBar(new_infobar, position, false, WANT_CALLBACK); break; } @@ -145,40 +145,14 @@ void InfoBarContainer::Observe(int type, } } -InfoBar* InfoBarContainer::FindInfoBar(InfoBarDelegate* delegate) { - // Search for the infobar associated with |delegate|. We cannot search for - // |delegate| in |tab_helper_|, because an InfoBar remains alive until its - // close animation completes, while the delegate is removed from the tab - // immediately. - for (InfoBars::iterator i(infobars_.begin()); i != infobars_.end(); ++i) { - InfoBar* infobar = *i; - if (infobar->delegate() == delegate) - return infobar; - } - NOTREACHED(); - return NULL; -} - -size_t InfoBarContainer::HideInfoBar(InfoBar* infobar, bool use_animation) { - InfoBars::iterator it = - std::find(infobars_.begin(), infobars_.end(), infobar); - DCHECK(it != infobars_.end()); - size_t position = it - infobars_.begin(); - // We merely need hide the infobar; it will call back to RemoveInfoBar() - // itself once it's hidden. - infobar->Hide(use_animation); - infobar->CloseSoon(); - UpdateInfoBarArrowTargetHeights(); - return position; -} - void InfoBarContainer::HideAllInfoBars() { registrar_.RemoveAll(); while (!infobars_.empty()) { InfoBar* infobar = infobars_.front(); // Inform the infobar that it's hidden. If it was already closing, this - // closes its delegate. + // deletes it. Otherwise, this ensures the infobar will be deleted if it's + // closed while it's not in an InfoBarContainer. infobar->Hide(false); } } diff --git a/chrome/browser/infobars/infobar_container.h b/chrome/browser/infobars/infobar_container.h index 571bc2e..6cfaacf 100644 --- a/chrome/browser/infobars/infobar_container.h +++ b/chrome/browser/infobars/infobar_container.h @@ -14,11 +14,10 @@ #include "third_party/skia/include/core/SkColor.h" class InfoBar; -class InfoBarDelegate; class InfoBarService; // InfoBarContainer is a cross-platform base class to handle the visibility- -// related aspects of InfoBars. While InfoBars own themselves, the +// related aspects of InfoBars. While InfoBarService owns the InfoBars, the // InfoBarContainer is responsible for telling particular InfoBars that they // should be hidden or visible. // @@ -47,8 +46,9 @@ class InfoBarContainer : public content::NotificationObserver { virtual ~InfoBarContainer(); // Changes the InfoBarService for which this container is showing infobars. - // This will remove all current infobars from the container, add the infobars - // from |infobar_service|, and show them all. |infobar_service| may be NULL. + // This will hide all current infobars, remove them from the container, add + // the infobars from |infobar_service|, and show them all. |infobar_service| + // may be NULL. void ChangeInfoBarService(InfoBarService* infobar_service); // Returns the amount by which to overlap the toolbar above, and, when @@ -73,8 +73,7 @@ class InfoBarContainer : public content::NotificationObserver { void OnInfoBarStateChanged(bool is_animating); // Called by |infobar| to request that it be removed from the container. At - // this point, |infobar| should already be hidden. Once the infobar is - // removed, it is guaranteed to delete itself and will not be re-added again. + // this point, |infobar| should already be hidden. void RemoveInfoBar(InfoBar* infobar); const Delegate* delegate() const { return delegate_; } @@ -107,17 +106,6 @@ class InfoBarContainer : public content::NotificationObserver { const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - // Hides an InfoBar for the specified delegate, in response to a notification - // from the selected InfoBarService. The InfoBar's disappearance will be - // animated if |use_animation| is true. The InfoBar will call back to - // RemoveInfoBar() to remove itself once it's hidden (which may mean - // synchronously). Returns the position within |infobars_| the infobar was - // previously at. - size_t HideInfoBar(InfoBar* infobar, bool use_animation); - - // Find an existing infobar in the container. - InfoBar* FindInfoBar(InfoBarDelegate* delegate); - // Hides all infobars in this container without animation. void HideAllInfoBars(); @@ -126,10 +114,6 @@ class InfoBarContainer : public content::NotificationObserver { // infobar->Show(). Depending on the value of |callback_status|, this calls // infobar->set_container(this) either before or after the call to Show() so // that OnInfoBarStateChanged() either will or won't be called as a result. - // - // This should be called only once for an infobar -- once it's added, it can - // be repeatedly shown and hidden, but not removed and then re-added (see - // comments on RemoveInfoBar()). enum CallbackStatus { NO_CALLBACK, WANT_CALLBACK }; void AddInfoBar(InfoBar* infobar, size_t position, diff --git a/chrome/browser/infobars/infobar_delegate.cc b/chrome/browser/infobars/infobar_delegate.cc index dd87c8e..bef38aa 100644 --- a/chrome/browser/infobars/infobar_delegate.cc +++ b/chrome/browser/infobars/infobar_delegate.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "build/build_config.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/navigation_controller.h" #include "content/public/browser/navigation_details.h" @@ -98,24 +99,25 @@ TranslateInfoBarDelegate* InfoBarDelegate::AsTranslateInfoBarDelegate() { return NULL; } +void InfoBarDelegate::StoreActiveEntryUniqueID() { + DCHECK(web_contents()); + NavigationEntry* active_entry = + web_contents()->GetController().GetActiveEntry(); + contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; +} + gfx::Image InfoBarDelegate::GetIcon() const { int icon_id = GetIconID(); return (icon_id == kNoIconID) ? gfx::Image() : ResourceBundle::GetSharedInstance().GetNativeImageNamed(icon_id); } -InfoBarDelegate::InfoBarDelegate(InfoBarService* owner) - : contents_unique_id_(0), - owner_(owner) { - if (owner_) - StoreActiveEntryUniqueID(); +content::WebContents* InfoBarDelegate::web_contents() { + return (infobar_ && infobar_->owner()) ? + infobar_->owner()->web_contents() : NULL; } -void InfoBarDelegate::StoreActiveEntryUniqueID() { - DCHECK(web_contents()); - NavigationEntry* active_entry = - web_contents()->GetController().GetActiveEntry(); - contents_unique_id_ = active_entry ? active_entry->GetUniqueID() : 0; +InfoBarDelegate::InfoBarDelegate() : contents_unique_id_(0) { } bool InfoBarDelegate::ShouldExpireInternal( @@ -127,8 +129,3 @@ bool InfoBarDelegate::ShouldExpireInternal( details.entry->GetTransitionType()) == content::PAGE_TRANSITION_RELOAD); } - -void InfoBarDelegate::RemoveSelf() { - if (owner_) - owner_->RemoveInfoBar(this); // Clears |owner_|. -} diff --git a/chrome/browser/infobars/infobar_delegate.h b/chrome/browser/infobars/infobar_delegate.h index 6ac3ef0..fc37ddd 100644 --- a/chrome/browser/infobars/infobar_delegate.h +++ b/chrome/browser/infobars/infobar_delegate.h @@ -51,19 +51,12 @@ class InfoBarDelegate { // Value to use when the InfoBar has no icon to show. static const int kNoIconID; + // Called when the InfoBar that owns this delegate is being destroyed. At + // this point nothing is visible onscreen. virtual ~InfoBarDelegate(); virtual InfoBarAutomationType GetInfoBarAutomationType() const; - // Called to create the InfoBar. Implementation of this method is - // platform-specific. - virtual InfoBar* CreateInfoBar(InfoBarService* owner) = 0; - - // TODO(pkasting): Move to InfoBar once InfoBars own their delegates. - InfoBarService* owner() { return owner_; } - - void clear_owner() { owner_ = NULL; } - // Returns true if the supplied |delegate| is equal to this one. Equality is // left to the implementation to define. This function is called by the // InfoBarService when determining whether or not a delegate should be @@ -104,41 +97,38 @@ class InfoBarDelegate { virtual ThreeDAPIInfoBarDelegate* AsThreeDAPIInfoBarDelegate(); virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate(); - // Return the icon to be shown for this InfoBar. If the returned Image is - // empty, no icon is shown. - virtual gfx::Image GetIcon() const; - - content::WebContents* web_contents() { - return owner_ ? owner_->web_contents() : NULL; - } - - protected: - // If |contents| is non-NULL, its active entry's unique ID will be stored - // using StoreActiveEntryUniqueID automatically. - explicit InfoBarDelegate(InfoBarService* owner); + void set_infobar(InfoBar* infobar) { infobar_ = infobar; } // Store the unique id for the active entry in our WebContents, to be used // later upon navigation to determine if this InfoBarDelegate should be // expired. void StoreActiveEntryUniqueID(); - int contents_unique_id() const { return contents_unique_id_; } + // Return the icon to be shown for this InfoBar. If the returned Image is + // empty, no icon is shown. + virtual gfx::Image GetIcon() const; + + // This trivial getter is defined out-of-line in order to avoid needing to + // #include infobar.h, which would lead to circular #includes. + content::WebContents* web_contents(); + + protected: + InfoBarDelegate(); // Returns true if the navigation is to a new URL or a reload occured. virtual bool ShouldExpireInternal( const content::LoadCommittedDetails& details) const; - // Removes ourself from |owner_| if we haven't already been removed. - // TODO(pkasting): Move to InfoBar. - void RemoveSelf(); + int contents_unique_id() const { return contents_unique_id_; } + InfoBar* infobar() { return infobar_; } private: // The unique id of the active NavigationEntry of the WebContents that we were // opened for. Used to help expire on navigations. int contents_unique_id_; - // TODO(pkasting): Remove. - InfoBarService* owner_; + // The InfoBar associated with us. + InfoBar* infobar_; DISALLOW_COPY_AND_ASSIGN(InfoBarDelegate); }; diff --git a/chrome/browser/infobars/infobar_service.cc b/chrome/browser/infobars/infobar_service.cc index 3d5746c..2baf2b3 100644 --- a/chrome/browser/infobars/infobar_service.cc +++ b/chrome/browser/infobars/infobar_service.cc @@ -16,24 +16,22 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(InfoBarService); -InfoBarDelegate* InfoBarService::AddInfoBar( - scoped_ptr<InfoBarDelegate> infobar) { +InfoBar* InfoBarService::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)->EqualsDelegate(infobar.get())) { - DCHECK_NE(*i, infobar.get()); + if ((*i)->delegate()->EqualsDelegate(infobar->delegate())) { + DCHECK_NE((*i)->delegate(), infobar->delegate()); return NULL; } } - InfoBarDelegate* infobar_ptr = infobar.release(); + InfoBar* infobar_ptr = infobar.release(); infobars_.push_back(infobar_ptr); - // TODO(pkasting): Remove InfoBarService arg from delegate constructors and - // instead use a setter from here. + infobar_ptr->SetOwner(this); content::NotificationService::current()->Notify( chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, @@ -42,35 +40,36 @@ InfoBarDelegate* InfoBarService::AddInfoBar( return infobar_ptr; } -void InfoBarService::RemoveInfoBar(InfoBarDelegate* infobar) { +void InfoBarService::RemoveInfoBar(InfoBar* infobar) { RemoveInfoBarInternal(infobar, true); } -InfoBarDelegate* InfoBarService::ReplaceInfoBar( - InfoBarDelegate* old_infobar, - scoped_ptr<InfoBarDelegate> new_infobar) { +InfoBar* InfoBarService::ReplaceInfoBar(InfoBar* old_infobar, + scoped_ptr<InfoBar> new_infobar) { DCHECK(old_infobar); if (!infobars_enabled_) - return AddInfoBar(new_infobar.Pass()); // Deletes the delegate. + 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()); - InfoBarDelegate* new_infobar_ptr = new_infobar.release(); + 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. + // 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); - old_infobar->clear_owner(); 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; } @@ -83,10 +82,6 @@ InfoBarService::InfoBarService(content::WebContents* web_contents) 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. - // - // TODO(pkasting): If there is no InfoBarContainer, this leaks all the - // InfoBarDelegates. This will be fixed once we call CloseSoon() directly on - // Infobars. RemoveAllInfoBars(false); } @@ -100,8 +95,8 @@ void InfoBarService::NavigationEntryCommitted( // use iterators, as the RemoveInfoBar() call synchronously modifies our // delegate list. for (size_t i = infobars_.size(); i > 0; --i) { - InfoBarDelegate* infobar = infobars_[i - 1]; - if (infobar->ShouldExpire(load_details)) + InfoBar* infobar = infobars_[i - 1]; + if (infobar->delegate()->ShouldExpire(load_details)) RemoveInfoBar(infobar); } } @@ -127,8 +122,7 @@ bool InfoBarService::OnMessageReceived(const IPC::Message& message) { return handled; } -void InfoBarService::RemoveInfoBarInternal(InfoBarDelegate* infobar, - bool animate) { +void InfoBarService::RemoveInfoBarInternal(InfoBar* infobar, bool animate) { DCHECK(infobar); if (!infobars_enabled_) { DCHECK(infobars_.empty()); @@ -138,16 +132,19 @@ void InfoBarService::RemoveInfoBarInternal(InfoBarDelegate* infobar, InfoBars::iterator i(std::find(infobars_.begin(), infobars_.end(), infobar)); DCHECK(i != infobars_.end()); - infobar->clear_owner(); // 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. 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) { diff --git a/chrome/browser/infobars/infobar_service.h b/chrome/browser/infobars/infobar_service.h index d90b70d..935b8f5 100644 --- a/chrome/browser/infobars/infobar_service.h +++ b/chrome/browser/infobars/infobar_service.h @@ -11,7 +11,7 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" -class InfoBarDelegate; +class InfoBar; // Provides access to creating, removing and enumerating info bars // attached to a tab. @@ -21,32 +21,35 @@ class InfoBarService : public content::WebContentsObserver, // Changes whether infobars are enabled. The default is true. void set_infobars_enabled(bool enabled) { infobars_enabled_ = enabled; } - // Adds an InfoBar for the specified |delegate|. + // Adds the specified |infobar|, which already owns a delegate. // - // If infobars are disabled for this tab or the tab already has a delegate - // which returns true for InfoBarDelegate::EqualsDelegate(delegate), - // |delegate| is closed immediately without being added. + // 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 delegate if it was successfully added. - InfoBarDelegate* AddInfoBar(scoped_ptr<InfoBarDelegate> infobar); + // Returns the infobar if it was successfully added. + virtual InfoBar* AddInfoBar(scoped_ptr<InfoBar> infobar); - // Removes the InfoBar for the specified |delegate|. + // 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 closed the - // delegate (see above). - void RemoveInfoBar(InfoBarDelegate* infobar); + // 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. + // 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_delegate| is closed immediately + // If infobars are disabled for this tab, |new_infobar| is deleted immediately // without being added, and nothing else happens. // - // Returns the new delegate if it was successfully added. + // Returns the new infobar if it was successfully added. // // NOTE: This does not perform any EqualsDelegate() checks like AddInfoBar(). - InfoBarDelegate* ReplaceInfoBar(InfoBarDelegate* old_infobar, - scoped_ptr<InfoBarDelegate> new_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(); } @@ -55,7 +58,7 @@ class InfoBarService : public content::WebContentsObserver, // ownership. // // Warning: Does not sanity check |index|. - InfoBarDelegate* infobar_at(size_t index) { return infobars_[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() { @@ -65,12 +68,13 @@ class InfoBarService : public content::WebContentsObserver, private: friend class content::WebContentsUserData<InfoBarService>; - typedef std::vector<InfoBarDelegate*> InfoBars; + // 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; - // Delegates for InfoBars associated with this InfoBarService. We do not own - // these pointers; they own themselves and are deleted in response to being - // closed. - // TODO(pkasting): These leak if closed while not visible. explicit InfoBarService(content::WebContents* web_contents); virtual ~InfoBarService(); @@ -82,7 +86,7 @@ class InfoBarService : public content::WebContentsObserver, content::WebContents* web_contents) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; - void RemoveInfoBarInternal(InfoBarDelegate* infobar, bool animate); + void RemoveInfoBarInternal(InfoBar* infobar, bool animate); void RemoveAllInfoBars(bool animate); // Message handlers. diff --git a/chrome/browser/infobars/insecure_content_infobar_delegate.cc b/chrome/browser/infobars/insecure_content_infobar_delegate.cc index 66278c9..2223c20 100644 --- a/chrome/browser/infobars/insecure_content_infobar_delegate.cc +++ b/chrome/browser/infobars/insecure_content_infobar_delegate.cc @@ -6,6 +6,7 @@ #include "base/metrics/histogram.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/common/render_messages.h" #include "content/public/browser/render_view_host.h" @@ -18,18 +19,20 @@ // static void InsecureContentInfoBarDelegate::Create(InfoBarService* infobar_service, InfoBarType type) { - scoped_ptr<InfoBarDelegate> new_infobar( - new InsecureContentInfoBarDelegate(infobar_service, type)); + scoped_ptr<InfoBar> new_infobar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new InsecureContentInfoBarDelegate(type)))); // 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); InsecureContentInfoBarDelegate* delegate = - infobar_service->infobar_at(i)->AsInsecureContentInfoBarDelegate(); + old_infobar->delegate()->AsInsecureContentInfoBarDelegate(); if (delegate != NULL) { if ((type == RUN) && (delegate->type_ == DISPLAY)) return; - infobar_service->ReplaceInfoBar(delegate, new_infobar.Pass()); + infobar_service->ReplaceInfoBar(old_infobar, new_infobar.Pass()); break; } } @@ -41,10 +44,8 @@ void InsecureContentInfoBarDelegate::Create(InfoBarService* infobar_service, NUM_EVENTS); } -InsecureContentInfoBarDelegate::InsecureContentInfoBarDelegate( - InfoBarService* infobar_service, - InfoBarType type) - : ConfirmInfoBarDelegate(infobar_service), +InsecureContentInfoBarDelegate::InsecureContentInfoBarDelegate(InfoBarType type) + : ConfirmInfoBarDelegate(), type_(type) { } diff --git a/chrome/browser/infobars/insecure_content_infobar_delegate.h b/chrome/browser/infobars/insecure_content_infobar_delegate.h index f2be21a..65d729f 100644 --- a/chrome/browser/infobars/insecure_content_infobar_delegate.h +++ b/chrome/browser/infobars/insecure_content_infobar_delegate.h @@ -18,7 +18,7 @@ class InsecureContentInfoBarDelegate : public ConfirmInfoBarDelegate { // Depending on the |type| requested and whether an insecure content infobar // is already present in |infobar_service|, may do nothing; otherwise, creates - // an insecure content infobar delegate and either adds it to + // an insecure content infobar and delegate and either adds the infobar to // |infobar_service| or replaces the existing infobar. static void Create(InfoBarService* infobar_service, InfoBarType type); @@ -35,8 +35,7 @@ class InsecureContentInfoBarDelegate : public ConfirmInfoBarDelegate { NUM_EVENTS }; - InsecureContentInfoBarDelegate(InfoBarService* infobar_service, - InfoBarType type); + explicit InsecureContentInfoBarDelegate(InfoBarType type); virtual ~InsecureContentInfoBarDelegate(); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/infobars/simple_alert_infobar_delegate.cc b/chrome/browser/infobars/simple_alert_infobar_delegate.cc index 6e8b82c..0c092f2 100644 --- a/chrome/browser/infobars/simple_alert_infobar_delegate.cc +++ b/chrome/browser/infobars/simple_alert_infobar_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -12,17 +13,16 @@ void SimpleAlertInfoBarDelegate::Create(InfoBarService* infobar_service, int icon_id, const string16& message, bool auto_expire) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new SimpleAlertInfoBarDelegate(infobar_service, icon_id, message, - auto_expire))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new SimpleAlertInfoBarDelegate(icon_id, message, auto_expire)))); } SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate( - InfoBarService* infobar_service, int icon_id, const string16& message, bool auto_expire) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), icon_id_(icon_id), message_(message), auto_expire_(auto_expire) { diff --git a/chrome/browser/infobars/simple_alert_infobar_delegate.h b/chrome/browser/infobars/simple_alert_infobar_delegate.h index a5cef30..d2a1ed0 100644 --- a/chrome/browser/infobars/simple_alert_infobar_delegate.h +++ b/chrome/browser/infobars/simple_alert_infobar_delegate.h @@ -12,15 +12,15 @@ class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a simple alert infobar delegate and adds it to |infobar_service|. + // Creates a simple alert infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, int icon_id, // May be |kNoIconID| if no icon is shown. const string16& message, bool auto_expire); private: - SimpleAlertInfoBarDelegate(InfoBarService* infobar_service, - int icon_id, + SimpleAlertInfoBarDelegate(int icon_id, const string16& message, bool auto_expire); virtual ~SimpleAlertInfoBarDelegate(); diff --git a/chrome/browser/managed_mode/managed_mode_interstitial.cc b/chrome/browser/managed_mode/managed_mode_interstitial.cc index 11b796d..18cb691 100644 --- a/chrome/browser/managed_mode/managed_mode_interstitial.cc +++ b/chrome/browser/managed_mode/managed_mode_interstitial.cc @@ -9,6 +9,7 @@ #include "base/prefs/pref_service.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_delegate.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/managed_mode/managed_user_service.h" @@ -67,7 +68,7 @@ ManagedModeInterstitial::ManagedModeInterstitial( } details.type = content::NAVIGATION_TYPE_NEW_PAGE; for (int i = service->infobar_count() - 1; i >= 0; --i) { - if (service->infobar_at(i)->ShouldExpire(details)) + if (service->infobar_at(i)->delegate()->ShouldExpire(details)) service->RemoveInfoBar(service->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 9fa8210..ad5a00d 100644 --- a/chrome/browser/managed_mode/managed_mode_navigation_observer.cc +++ b/chrome/browser/managed_mode/managed_mode_navigation_observer.cc @@ -12,6 +12,7 @@ #include "chrome/browser/history/history_service_factory.h" #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_service.h" #include "chrome/browser/managed_mode/managed_mode_interstitial.h" #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" @@ -80,12 +81,12 @@ void GoBackToSafety(content::WebContents* web_contents) { class ManagedModeWarningInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a managed mode warning infobar delegate and adds it to - // |infobar_service|. Returns the delegate if it was successfully added. - static InfoBarDelegate* Create(InfoBarService* infobar_service); + // Creates a managed mode warning infobar and delegate and adds the infobar to + // |infobar_service|. Returns the infobar if it was successfully added. + static InfoBar* Create(InfoBarService* infobar_service); private: - explicit ManagedModeWarningInfoBarDelegate(InfoBarService* infobar_service); + ManagedModeWarningInfoBarDelegate(); virtual ~ManagedModeWarningInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -101,15 +102,15 @@ class ManagedModeWarningInfoBarDelegate : public ConfirmInfoBarDelegate { }; // static -InfoBarDelegate* ManagedModeWarningInfoBarDelegate::Create( +InfoBar* ManagedModeWarningInfoBarDelegate::Create( InfoBarService* infobar_service) { - return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ManagedModeWarningInfoBarDelegate(infobar_service))); + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new ManagedModeWarningInfoBarDelegate()))); } -ManagedModeWarningInfoBarDelegate::ManagedModeWarningInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +ManagedModeWarningInfoBarDelegate::ManagedModeWarningInfoBarDelegate() + : ConfirmInfoBarDelegate() { } ManagedModeWarningInfoBarDelegate::~ManagedModeWarningInfoBarDelegate() { diff --git a/chrome/browser/managed_mode/managed_mode_navigation_observer.h b/chrome/browser/managed_mode/managed_mode_navigation_observer.h index ac19d81..ec40b14 100644 --- a/chrome/browser/managed_mode/managed_mode_navigation_observer.h +++ b/chrome/browser/managed_mode/managed_mode_navigation_observer.h @@ -14,7 +14,7 @@ #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" -class InfoBarDelegate; +class InfoBar; class ManagedModeURLFilter; class ManagedUserService; @@ -68,7 +68,7 @@ class ManagedModeNavigationObserver const ManagedModeURLFilter* url_filter_; // Owned by the InfoBarService, which has the same lifetime as this object. - InfoBarDelegate* warn_infobar_; + InfoBar* warn_infobar_; ScopedVector<const content::NavigationEntry> blocked_navigations_; diff --git a/chrome/browser/media/media_stream_infobar_delegate.cc b/chrome/browser/media/media_stream_infobar_delegate.cc index d421476..a2f90ec 100644 --- a/chrome/browser/media/media_stream_infobar_delegate.cc +++ b/chrome/browser/media/media_stream_infobar_delegate.cc @@ -8,6 +8,7 @@ #include "base/metrics/histogram.h" #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_service.h" #include "chrome/common/url_constants.h" #include "content/public/browser/web_contents.h" @@ -50,12 +51,12 @@ bool MediaStreamInfoBarDelegate::Create( return false; } - scoped_ptr<InfoBarDelegate> infobar( - new MediaStreamInfoBarDelegate(infobar_service, controller.Pass())); + scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new MediaStreamInfoBarDelegate(controller.Pass())))); for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - InfoBarDelegate* old_infobar = - infobar_service->infobar_at(i)->AsMediaStreamInfoBarDelegate(); - if (old_infobar) { + InfoBar* old_infobar = infobar_service->infobar_at(i); + if (old_infobar->delegate()->AsMediaStreamInfoBarDelegate()) { infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); return true; } @@ -65,9 +66,8 @@ bool MediaStreamInfoBarDelegate::Create( } MediaStreamInfoBarDelegate::MediaStreamInfoBarDelegate( - InfoBarService* infobar_service, scoped_ptr<MediaStreamDevicesController> controller) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), controller_(controller.Pass()) { DCHECK(controller_.get()); DCHECK(controller_->HasAudio() || controller_->HasVideo()); diff --git a/chrome/browser/media/media_stream_infobar_delegate.h b/chrome/browser/media/media_stream_infobar_delegate.h index 2860c54..5f3de56 100644 --- a/chrome/browser/media/media_stream_infobar_delegate.h +++ b/chrome/browser/media/media_stream_infobar_delegate.h @@ -22,10 +22,10 @@ class MediaStreamInfoBarDelegate : public ConfirmInfoBarDelegate { virtual ~MediaStreamInfoBarDelegate(); // Handles a permission request (in |request|) for |web_contents|. If this - // involves prompting the user, creates a media stream infobar delegate, then - // checks for an existing infobar for |web_contents| and replaces it if found, - // or just adds the new infobar otherwise. Returns whether an infobar was - // created. + // involves prompting the user, creates a media stream infobar and delegate, + // then checks for an existing infobar for |web_contents| and replaces it if + // found, or just adds the new infobar otherwise. Returns whether an infobar + // was created. static bool Create(content::WebContents* web_contents, const content::MediaStreamRequest& request, const content::MediaResponseCallback& callback); @@ -33,8 +33,7 @@ class MediaStreamInfoBarDelegate : public ConfirmInfoBarDelegate { private: friend class WebRtcTestBase; - MediaStreamInfoBarDelegate( - InfoBarService* infobar_service, + explicit MediaStreamInfoBarDelegate( scoped_ptr<MediaStreamDevicesController> controller); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/media/midi_permission_infobar_delegate.cc b/chrome/browser/media/midi_permission_infobar_delegate.cc index a468b23..1f351cf 100644 --- a/chrome/browser/media/midi_permission_infobar_delegate.cc +++ b/chrome/browser/media/midi_permission_infobar_delegate.cc @@ -6,6 +6,7 @@ #include "chrome/browser/content_settings/permission_queue_controller.h" #include "chrome/browser/content_settings/permission_request_id.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_entry.h" @@ -17,7 +18,7 @@ #include "ui/base/l10n/l10n_util.h" // static -InfoBarDelegate* MIDIPermissionInfoBarDelegate::Create( +InfoBar* MIDIPermissionInfoBarDelegate::Create( InfoBarService* infobar_service, PermissionQueueController* controller, const PermissionRequestID& id, @@ -25,21 +26,20 @@ InfoBarDelegate* MIDIPermissionInfoBarDelegate::Create( const std::string& display_languages) { const content::NavigationEntry* committed_entry = infobar_service->web_contents()->GetController().GetLastCommittedEntry(); - return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new MIDIPermissionInfoBarDelegate( - infobar_service, controller, id, requesting_frame, + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new MIDIPermissionInfoBarDelegate( + controller, id, requesting_frame, committed_entry ? committed_entry->GetUniqueID() : 0, - display_languages))); + display_languages)))); } MIDIPermissionInfoBarDelegate::MIDIPermissionInfoBarDelegate( - InfoBarService* infobar_service, PermissionQueueController* controller, const PermissionRequestID& id, const GURL& requesting_frame, int contents_unique_id, const std::string& display_languages) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), controller_(controller), id_(id), requesting_frame_(requesting_frame), diff --git a/chrome/browser/media/midi_permission_infobar_delegate.h b/chrome/browser/media/midi_permission_infobar_delegate.h index 2fcdd54..21c35b1 100644 --- a/chrome/browser/media/midi_permission_infobar_delegate.h +++ b/chrome/browser/media/midi_permission_infobar_delegate.h @@ -22,17 +22,16 @@ class InfoBarService; // permission infobars to the user. class MIDIPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a MIDI permission infobar delegate and adds it to - // |infobar_service|. Returns the delegate if it was successfully added. - static InfoBarDelegate* Create(InfoBarService* infobar_service, - PermissionQueueController* controller, - const PermissionRequestID& id, - const GURL& requesting_frame, - const std::string& display_languages); + // Creates a MIDI permission infobar and delegate and adds the infobar to + // |infobar_service|. Returns the infobar if it was successfully added. + static InfoBar* Create(InfoBarService* infobar_service, + PermissionQueueController* controller, + const PermissionRequestID& id, + const GURL& requesting_frame, + const std::string& display_languages); private: - MIDIPermissionInfoBarDelegate(InfoBarService* infobar_service, - PermissionQueueController* controller, + MIDIPermissionInfoBarDelegate(PermissionQueueController* controller, const PermissionRequestID& id, const GURL& requesting_frame, int contents_unique_id, diff --git a/chrome/browser/media/protected_media_identifier_infobar_delegate.cc b/chrome/browser/media/protected_media_identifier_infobar_delegate.cc index c90c66d6..e73fa15 100644 --- a/chrome/browser/media/protected_media_identifier_infobar_delegate.cc +++ b/chrome/browser/media/protected_media_identifier_infobar_delegate.cc @@ -5,6 +5,7 @@ #include "chrome/browser/media/protected_media_identifier_infobar_delegate.h" #include "chrome/browser/content_settings/permission_queue_controller.h" +#include "chrome/browser/infobars/infobar.h" #include "content/public/browser/navigation_details.h" #include "content/public/browser/navigation_entry.h" #include "grit/generated_resources.h" @@ -17,7 +18,7 @@ #endif // static -InfoBarDelegate* ProtectedMediaIdentifierInfoBarDelegate::Create( +InfoBar* ProtectedMediaIdentifierInfoBarDelegate::Create( InfoBarService* infobar_service, PermissionQueueController* controller, const PermissionRequestID& id, @@ -25,23 +26,23 @@ InfoBarDelegate* ProtectedMediaIdentifierInfoBarDelegate::Create( const std::string& display_languages) { const content::NavigationEntry* committed_entry = infobar_service->web_contents()->GetController().GetLastCommittedEntry(); - return infobar_service->AddInfoBar( - scoped_ptr<InfoBarDelegate>(new ProtectedMediaIdentifierInfoBarDelegate( - infobar_service, controller, id, requesting_frame, - committed_entry ? committed_entry->GetUniqueID() : 0, - display_languages))); + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new ProtectedMediaIdentifierInfoBarDelegate( + controller, id, requesting_frame, + committed_entry ? committed_entry->GetUniqueID() : 0, + display_languages)))); } ProtectedMediaIdentifierInfoBarDelegate:: ProtectedMediaIdentifierInfoBarDelegate( - InfoBarService* infobar_service, - PermissionQueueController* controller, - const PermissionRequestID& id, - const GURL& requesting_frame, - int contents_unique_id, - const std::string& display_languages) - : ConfirmInfoBarDelegate(infobar_service), + PermissionQueueController* controller, + const PermissionRequestID& id, + const GURL& requesting_frame, + int contents_unique_id, + const std::string& display_languages) + : ConfirmInfoBarDelegate(), controller_(controller), id_(id), requesting_frame_(requesting_frame), diff --git a/chrome/browser/media/protected_media_identifier_infobar_delegate.h b/chrome/browser/media/protected_media_identifier_infobar_delegate.h index 9fd719f..a9b7353 100644 --- a/chrome/browser/media/protected_media_identifier_infobar_delegate.h +++ b/chrome/browser/media/protected_media_identifier_infobar_delegate.h @@ -19,16 +19,16 @@ class InfoBarService; class ProtectedMediaIdentifierInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a protected media identifier infobar delegate and adds it to - // |infobar_service|. Returns the delegate if it was successfully added. - static InfoBarDelegate* Create(InfoBarService* infobar_service, - PermissionQueueController* controller, - const PermissionRequestID& id, - const GURL& requesting_frame, - const std::string& display_languages); + // Creates a protected media identifier infobar and delegate and adds the + // infobar to |infobar_service|. Returns the infobar if it was successfully + // added. + static InfoBar* Create(InfoBarService* infobar_service, + PermissionQueueController* controller, + const PermissionRequestID& id, + const GURL& requesting_frame, + const std::string& display_languages); protected: - ProtectedMediaIdentifierInfoBarDelegate(InfoBarService* infobar_service, - PermissionQueueController* controller, + ProtectedMediaIdentifierInfoBarDelegate(PermissionQueueController* controller, const PermissionRequestID& id, const GURL& requesting_frame, int contents_unique_id, diff --git a/chrome/browser/media/webrtc_browsertest_base.cc b/chrome/browser/media/webrtc_browsertest_base.cc index ad073ad..0c1d8d5 100644 --- a/chrome/browser/media/webrtc_browsertest_base.cc +++ b/chrome/browser/media/webrtc_browsertest_base.cc @@ -38,9 +38,8 @@ void WebRtcTestBase::GetUserMediaAndAccept( void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( content::WebContents* tab_contents, const std::string& constraints) const { - MediaStreamInfoBarDelegate* infobar = - GetUserMediaAndWaitForInfoBar(tab_contents, constraints); - infobar->Accept(); + InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); + infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); CloseInfoBarInTab(tab_contents, infobar); // Wait for WebRTC to call the success callback. @@ -57,9 +56,8 @@ void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( content::WebContents* tab_contents, const std::string& constraints) const { - MediaStreamInfoBarDelegate* infobar = - GetUserMediaAndWaitForInfoBar(tab_contents, constraints); - infobar->Cancel(); + InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); + infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); CloseInfoBarInTab(tab_contents, infobar); // Wait for WebRTC to call the fail callback. @@ -69,9 +67,9 @@ void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( void WebRtcTestBase::GetUserMediaAndDismiss( content::WebContents* tab_contents) const { - MediaStreamInfoBarDelegate* infobar = + InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); - infobar->InfoBarDismissed(); + infobar->delegate()->InfoBarDismissed(); CloseInfoBarInTab(tab_contents, infobar); // A dismiss should be treated like a deny. @@ -99,7 +97,7 @@ void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, EXPECT_EQ("ok-requested", result); } -MediaStreamInfoBarDelegate* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( +InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( content::WebContents* tab_contents, const std::string& constraints) const { content::WindowedNotificationObserver infobar_added( @@ -112,9 +110,8 @@ MediaStreamInfoBarDelegate* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( // Wait for the bar to pop up, then return it. infobar_added.Wait(); content::Details<InfoBar::AddedDetails> details(infobar_added.details()); - MediaStreamInfoBarDelegate* infobar = details->AsMediaStreamInfoBarDelegate(); - EXPECT_TRUE(infobar); - return infobar; + EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate()); + return details.ptr(); } content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( @@ -130,10 +127,9 @@ content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( content::WebContents* tab_contents = browser()->tab_strip_model()->GetActiveWebContents(); content::Details<InfoBar::AddedDetails> details(infobar_added.details()); - MediaStreamInfoBarDelegate* infobar = - details->AsMediaStreamInfoBarDelegate(); + InfoBar* infobar = details.ptr(); EXPECT_TRUE(infobar); - infobar->Accept(); + infobar->delegate()->AsMediaStreamInfoBarDelegate()->Accept(); CloseInfoBarInTab(tab_contents, infobar); return tab_contents; @@ -141,7 +137,7 @@ content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( void WebRtcTestBase::CloseInfoBarInTab( content::WebContents* tab_contents, - MediaStreamInfoBarDelegate* infobar) const { + InfoBar* infobar) const { content::WindowedNotificationObserver infobar_removed( chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, content::NotificationService::AllSources()); diff --git a/chrome/browser/media/webrtc_browsertest_base.h b/chrome/browser/media/webrtc_browsertest_base.h index b1b546b..ce26f20 100644 --- a/chrome/browser/media/webrtc_browsertest_base.h +++ b/chrome/browser/media/webrtc_browsertest_base.h @@ -9,12 +9,12 @@ #include "chrome/test/base/in_process_browser_test.h" +class InfoBar; + namespace content { class WebContents; } -class MediaStreamInfoBarDelegate; - // Base class for WebRTC browser tests with useful primitives for interacting // getUserMedia. We use inheritance here because it makes the test code look // as clean as it can be. @@ -51,10 +51,9 @@ class WebRtcTestBase : public InProcessBrowserTest { private: void CloseInfoBarInTab(content::WebContents* tab_contents, - MediaStreamInfoBarDelegate* infobar) const; - MediaStreamInfoBarDelegate* GetUserMediaAndWaitForInfoBar( - content::WebContents* tab_contents, - const std::string& constraints) const; + InfoBar* infobar) const; + InfoBar* GetUserMediaAndWaitForInfoBar(content::WebContents* tab_contents, + const std::string& constraints) const; DISALLOW_COPY_AND_ASSIGN(WebRtcTestBase); }; diff --git a/chrome/browser/nacl_host/nacl_infobar_delegate.cc b/chrome/browser/nacl_host/nacl_infobar_delegate.cc index fecad03..99770c9 100644 --- a/chrome/browser/nacl_host/nacl_infobar_delegate.cc +++ b/chrome/browser/nacl_host/nacl_infobar_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/browser/nacl_host/nacl_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" @@ -25,13 +26,12 @@ void NaClInfoBarDelegate::Create(int render_process_id, int render_view_id) { InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); if (infobar_service) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new NaClInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new NaClInfoBarDelegate()))); } } -NaClInfoBarDelegate::NaClInfoBarDelegate(InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +NaClInfoBarDelegate::NaClInfoBarDelegate() : ConfirmInfoBarDelegate() { } NaClInfoBarDelegate::~NaClInfoBarDelegate() { diff --git a/chrome/browser/nacl_host/nacl_infobar_delegate.h b/chrome/browser/nacl_host/nacl_infobar_delegate.h index 2b3b4e9..c1cbf5e 100644 --- a/chrome/browser/nacl_host/nacl_infobar_delegate.h +++ b/chrome/browser/nacl_host/nacl_infobar_delegate.h @@ -9,12 +9,12 @@ class NaClInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a NaCl infobar delegate and adds it to the infobar service - // corresponding to the given render process and view IDs. + // Creates a NaCl infobar and delegate and adds the infobar to the infobar + // service corresponding to the given render process and view IDs. static void Create(int render_process_id, int render_view_id); private: - explicit NaClInfoBarDelegate(InfoBarService* infobar_service); + NaClInfoBarDelegate(); virtual ~NaClInfoBarDelegate(); virtual string16 GetMessageText() const OVERRIDE; diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index afbf55d..2aed905 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -17,6 +17,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/notifications/desktop_notification_service_factory.h" #include "chrome/browser/notifications/notification.h" @@ -67,8 +68,8 @@ using blink::WebTextDirection; // permissions. class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a notification permission infobar delegate and adds it to - // |infobar_service|. + // Creates a notification permission infobar and delegate and adds the infobar + // to |infobar_service|. static void Create(InfoBarService* infobar_service, DesktopNotificationService* notification_service, const GURL& origin, @@ -79,7 +80,6 @@ class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { private: NotificationPermissionInfoBarDelegate( - InfoBarService* infobar_service, DesktopNotificationService* notification_service, const GURL& origin, const string16& display_name, @@ -127,21 +127,21 @@ void NotificationPermissionInfoBarDelegate::Create( int process_id, int route_id, int callback_context) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new NotificationPermissionInfoBarDelegate( - infobar_service, notification_service, origin, display_name, - process_id, route_id, callback_context))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new NotificationPermissionInfoBarDelegate( + notification_service, origin, display_name, process_id, route_id, + callback_context)))); } NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate( - InfoBarService* infobar_service, DesktopNotificationService* notification_service, const GURL& origin, const string16& display_name, int process_id, int route_id, int callback_context) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), origin_(origin), display_name_(display_name), notification_service_(notification_service), diff --git a/chrome/browser/notifications/notification_browsertest.cc b/chrome/browser/notifications/notification_browsertest.cc index de06963..f475b4e 100644 --- a/chrome/browser/notifications/notification_browsertest.cc +++ b/chrome/browser/notifications/notification_browsertest.cc @@ -16,6 +16,7 @@ #include "chrome/browser/browser_process.h" #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_service.h" #include "chrome/browser/notifications/balloon.h" #include "chrome/browser/notifications/balloon_collection.h" @@ -320,7 +321,7 @@ void NotificationsTest::VerifyInfoBar(const Browser* browser, int index) { ASSERT_EQ(1U, infobar_service->infobar_count()); ConfirmInfoBarDelegate* confirm_infobar = - infobar_service->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(confirm_infobar); int buttons = confirm_infobar->GetButtons(); EXPECT_TRUE(buttons & ConfirmInfoBarDelegate::BUTTON_OK); @@ -406,12 +407,12 @@ bool NotificationsTest::PerformActionOnInfoBar( return false; } - InfoBarDelegate* infobar_delegate = - infobar_service->infobar_at(infobar_index); + InfoBar* infobar = infobar_service->infobar_at(infobar_index); + InfoBarDelegate* infobar_delegate = infobar->delegate(); switch (action) { case DISMISS: infobar_delegate->InfoBarDismissed(); - infobar_service->RemoveInfoBar(infobar_delegate); + infobar_service->RemoveInfoBar(infobar); return true; case ALLOW: { @@ -420,7 +421,7 @@ bool NotificationsTest::PerformActionOnInfoBar( if (!confirm_infobar_delegate) { ADD_FAILURE(); } else if (confirm_infobar_delegate->Accept()) { - infobar_service->RemoveInfoBar(infobar_delegate); + infobar_service->RemoveInfoBar(infobar); return true; } } @@ -431,7 +432,7 @@ bool NotificationsTest::PerformActionOnInfoBar( if (!confirm_infobar_delegate) { ADD_FAILURE(); } else if (confirm_infobar_delegate->Cancel()) { - infobar_service->RemoveInfoBar(infobar_delegate); + infobar_service->RemoveInfoBar(infobar); return true; } } diff --git a/chrome/browser/password_manager/password_manager_browsertest.cc b/chrome/browser/password_manager/password_manager_browsertest.cc index ee3c7e0..db3c84c 100644 --- a/chrome/browser/password_manager/password_manager_browsertest.cc +++ b/chrome/browser/password_manager/password_manager_browsertest.cc @@ -9,6 +9,7 @@ #include "base/metrics/statistics_recorder.h" #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_service.h" #include "chrome/browser/password_manager/password_store_factory.h" #include "chrome/browser/password_manager/test_password_store.h" @@ -64,7 +65,8 @@ class NavigationObserver : public content::NotificationObserver, virtual void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE { - infobar_service_->infobar_at(0)->AsConfirmInfoBarDelegate()->Accept(); + infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()-> + Accept(); infobar_shown_ = true; } diff --git a/chrome/browser/password_manager/password_manager_delegate_impl.cc b/chrome/browser/password_manager/password_manager_delegate_impl.cc index 491812e..6bb5f97 100644 --- a/chrome/browser/password_manager/password_manager_delegate_impl.cc +++ b/chrome/browser/password_manager/password_manager_delegate_impl.cc @@ -9,6 +9,7 @@ #include "base/strings/utf_string_conversions.h" #include "base/timer/elapsed_timer.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/password_manager/password_form_manager.h" #include "chrome/browser/password_manager/password_manager.h" @@ -42,11 +43,11 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { public: // If we won't be showing the one-click signin infobar, creates a save - // password infobar delegate and adds it to the InfoBarService for - // |web_contents|. |uma_histogram_suffix| is empty, or one of the "group_X" - // suffixes used in the histogram names for infobar usage reporting; if empty, - // the usage is not reported, otherwise the suffix is used to choose the right - // histogram. + // password infobar and delegate and adds the infobar to the InfoBarService + // for |web_contents|. |uma_histogram_suffix| is empty, or one of the + // "group_X" suffixes used in the histogram names for infobar usage reporting; + // if empty, the usage is not reported, otherwise the suffix is used to choose + // the right histogram. static void Create(content::WebContents* web_contents, PasswordFormManager* form_to_save, const std::string& uma_histogram_suffix); @@ -60,8 +61,7 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { NUM_RESPONSE_TYPES, }; - SavePasswordInfoBarDelegate(InfoBarService* infobar_service, - PasswordFormManager* form_to_save, + SavePasswordInfoBarDelegate(PasswordFormManager* form_to_save, const std::string& uma_histogram_suffix); virtual ~SavePasswordInfoBarDelegate(); @@ -113,18 +113,16 @@ void SavePasswordInfoBarDelegate::Create( return; #endif - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar( - scoped_ptr<InfoBarDelegate>(new SavePasswordInfoBarDelegate( - infobar_service, form_to_save, uma_histogram_suffix))); + InfoBarService::FromWebContents(web_contents)->AddInfoBar( + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( + new SavePasswordInfoBarDelegate(form_to_save, + uma_histogram_suffix)))); } SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( - InfoBarService* infobar_service, PasswordFormManager* form_to_save, const std::string& uma_histogram_suffix) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), form_to_save_(form_to_save), infobar_response_(NO_RESPONSE), uma_histogram_suffix_(uma_histogram_suffix) { diff --git a/chrome/browser/pepper_broker_infobar_delegate.cc b/chrome/browser/pepper_broker_infobar_delegate.cc index 9ca7068..f8cf6ad 100644 --- a/chrome/browser/pepper_broker_infobar_delegate.cc +++ b/chrome/browser/pepper_broker_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/content_settings/tab_specific_content_settings.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/plugins/plugin_finder.h" #include "chrome/browser/plugins/plugin_metadata.h" @@ -95,11 +96,11 @@ void PepperBrokerInfoBarDelegate::Create( content::UserMetricsAction("PPAPI.BrokerInfobarDisplayed")); InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new PepperBrokerInfoBarDelegate( - infobar_service, url, plugin_path, + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new PepperBrokerInfoBarDelegate( + url, plugin_path, profile->GetPrefs()->GetString(prefs::kAcceptLanguages), - content_settings, tab_content_settings, callback))); + content_settings, tab_content_settings, callback)))); return; } @@ -112,14 +113,13 @@ void PepperBrokerInfoBarDelegate::Create( } PepperBrokerInfoBarDelegate::PepperBrokerInfoBarDelegate( - InfoBarService* infobar_service, const GURL& url, const base::FilePath& plugin_path, const std::string& languages, HostContentSettingsMap* content_settings, TabSpecificContentSettings* tab_content_settings, const base::Callback<void(bool)>& callback) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), url_(url), plugin_path_(plugin_path), languages_(languages), diff --git a/chrome/browser/pepper_broker_infobar_delegate.h b/chrome/browser/pepper_broker_infobar_delegate.h index 220297c..f6186ca 100644 --- a/chrome/browser/pepper_broker_infobar_delegate.h +++ b/chrome/browser/pepper_broker_infobar_delegate.h @@ -25,16 +25,15 @@ class PepperBrokerInfoBarDelegate : public ConfirmInfoBarDelegate { public: // Determines whether the broker setting is allow, deny, or ask. In the first // two cases, runs the callback directly. In the third, creates a pepper - // broker infobar delegate and adds it to the InfoBarService associated with - // |web_contents|. + // broker infobar and delegate and adds the infobar to the InfoBarService + // associated with |web_contents|. static void Create(content::WebContents* web_contents, const GURL& url, const base::FilePath& plugin_path, const base::Callback<void(bool)>& callback); private: - PepperBrokerInfoBarDelegate(InfoBarService* infobar_service, - const GURL& url, + PepperBrokerInfoBarDelegate(const GURL& url, const base::FilePath& plugin_path, const std::string& languages, HostContentSettingsMap* content_settings, diff --git a/chrome/browser/plugins/plugin_infobar_delegates.cc b/chrome/browser/plugins/plugin_infobar_delegates.cc index ea4eb4b..922ac78 100644 --- a/chrome/browser/plugins/plugin_infobar_delegates.cc +++ b/chrome/browser/plugins/plugin_infobar_delegates.cc @@ -8,6 +8,7 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h" @@ -48,9 +49,8 @@ using content::UserMetricsAction; // PluginInfoBarDelegate ------------------------------------------------------ -PluginInfoBarDelegate::PluginInfoBarDelegate(InfoBarService* infobar_service, - const std::string& identifier) - : ConfirmInfoBarDelegate(infobar_service), +PluginInfoBarDelegate::PluginInfoBarDelegate(const std::string& identifier) + : ConfirmInfoBarDelegate(), identifier_(identifier) { } @@ -90,9 +90,9 @@ void UnauthorizedPluginInfoBarDelegate::Create( HostContentSettingsMap* content_settings, const string16& name, const std::string& identifier) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new UnauthorizedPluginInfoBarDelegate(infobar_service, content_settings, - name, identifier))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new UnauthorizedPluginInfoBarDelegate( + content_settings, name, identifier)))); content::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown")); std::string utf8_name(UTF16ToUTF8(name)); @@ -114,11 +114,10 @@ void UnauthorizedPluginInfoBarDelegate::Create( } UnauthorizedPluginInfoBarDelegate::UnauthorizedPluginInfoBarDelegate( - InfoBarService* infobar_service, HostContentSettingsMap* content_settings, const string16& name, const std::string& identifier) - : PluginInfoBarDelegate(infobar_service, identifier), + : PluginInfoBarDelegate(identifier), content_settings_(content_settings), name_(name) { } @@ -179,21 +178,19 @@ void OutdatedPluginInfoBarDelegate::Create( // Copy the name out of |plugin_metadata| now, since the Pass() call below // will make it impossible to get at. string16 name(plugin_metadata->name()); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new OutdatedPluginInfoBarDelegate( - infobar_service, installer, plugin_metadata.Pass(), - l10n_util::GetStringFUTF16( + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new OutdatedPluginInfoBarDelegate( + installer, plugin_metadata.Pass(), l10n_util::GetStringFUTF16( (installer->state() == PluginInstaller::INSTALLER_STATE_IDLE) ? IDS_PLUGIN_OUTDATED_PROMPT : IDS_PLUGIN_DOWNLOADING, - name)))); + name))))); } OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate( - InfoBarService* infobar_service, PluginInstaller* installer, scoped_ptr<PluginMetadata> plugin_metadata, const string16& message) - : PluginInfoBarDelegate(infobar_service, plugin_metadata->identifier()), + : PluginInfoBarDelegate(plugin_metadata->identifier()), WeakPluginInstallerObserver(installer), plugin_metadata_(plugin_metadata.Pass()), message_(message) { @@ -290,8 +287,7 @@ void OutdatedPluginInfoBarDelegate::DownloadFinished() { } void OutdatedPluginInfoBarDelegate::OnlyWeakObserversLeft() { - if (owner()) - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( @@ -299,10 +295,10 @@ void OutdatedPluginInfoBarDelegate::ReplaceWithInfoBar( // Return early if the message doesn't change. This is important in case the // PluginInstaller is still iterating over its observers (otherwise we would // keep replacing infobar delegates infinitely). - if ((message_ == message) || !owner()) + if ((message_ == message) || !infobar()->owner()) return; PluginInstallerInfoBarDelegate::Replace( - this, installer(), plugin_metadata_->Clone(), false, message); + infobar(), installer(), plugin_metadata_->Clone(), false, message); } @@ -321,39 +317,39 @@ void PluginInstallerInfoBarDelegate::Create( return; } #endif - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new PluginInstallerInfoBarDelegate( - infobar_service, installer, plugin_metadata.Pass(), callback, true, + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new PluginInstallerInfoBarDelegate( + installer, plugin_metadata.Pass(), callback, true, l10n_util::GetStringFUTF16( (installer->state() == PluginInstaller::INSTALLER_STATE_IDLE) ? IDS_PLUGININSTALLER_INSTALLPLUGIN_PROMPT : IDS_PLUGIN_DOWNLOADING, - name)))); - + name))))); } + void PluginInstallerInfoBarDelegate::Replace( - InfoBarDelegate* infobar, + InfoBar* infobar, PluginInstaller* installer, scoped_ptr<PluginMetadata> plugin_metadata, bool new_install, const string16& message) { DCHECK(infobar->owner()); - infobar->owner()->ReplaceInfoBar(infobar, scoped_ptr<InfoBarDelegate>( - new PluginInstallerInfoBarDelegate( - infobar->owner(), installer, plugin_metadata.Pass(), - PluginInstallerInfoBarDelegate::InstallCallback(), new_install, - message))); + infobar->owner()->ReplaceInfoBar(infobar, + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( + new PluginInstallerInfoBarDelegate( + installer, plugin_metadata.Pass(), + PluginInstallerInfoBarDelegate::InstallCallback(), new_install, + message)))); } PluginInstallerInfoBarDelegate::PluginInstallerInfoBarDelegate( - InfoBarService* infobar_service, PluginInstaller* installer, scoped_ptr<PluginMetadata> plugin_metadata, const InstallCallback& callback, bool new_install, const string16& message) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), WeakPluginInstallerObserver(installer), plugin_metadata_(plugin_metadata.Pass()), callback_(callback), @@ -430,8 +426,7 @@ void PluginInstallerInfoBarDelegate::DownloadFinished() { } void PluginInstallerInfoBarDelegate::OnlyWeakObserversLeft() { - if (owner()) - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( @@ -439,9 +434,10 @@ void PluginInstallerInfoBarDelegate::ReplaceWithInfoBar( // Return early if the message doesn't change. This is important in case the // PluginInstaller is still iterating over its observers (otherwise we would // keep replacing infobar delegates infinitely). - if ((message_ == message) || !owner()) + if ((message_ == message) || !infobar()->owner()) return; - Replace(this, installer(), plugin_metadata_->Clone(), new_install_, message); + Replace(infobar(), installer(), plugin_metadata_->Clone(), new_install_, + message); } @@ -454,15 +450,15 @@ void PluginMetroModeInfoBarDelegate::Create( InfoBarService* infobar_service, PluginMetroModeInfoBarDelegate::Mode mode, const string16& name) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new PluginMetroModeInfoBarDelegate(infobar_service, mode, name))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new PluginMetroModeInfoBarDelegate(mode, name)))); } PluginMetroModeInfoBarDelegate::PluginMetroModeInfoBarDelegate( - InfoBarService* infobar_service, PluginMetroModeInfoBarDelegate::Mode mode, const string16& name) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), mode_(mode), name_(name) { } diff --git a/chrome/browser/plugins/plugin_infobar_delegates.h b/chrome/browser/plugins/plugin_infobar_delegates.h index d03e5af..3f8ffea 100644 --- a/chrome/browser/plugins/plugin_infobar_delegates.h +++ b/chrome/browser/plugins/plugin_infobar_delegates.h @@ -24,8 +24,7 @@ class WebContents; // Base class for blocked plug-in infobars. class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { protected: - PluginInfoBarDelegate(InfoBarService* infobar_service, - const std::string& identifier); + explicit PluginInfoBarDelegate(const std::string& identifier); virtual ~PluginInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -48,7 +47,7 @@ class PluginInfoBarDelegate : public ConfirmInfoBarDelegate { // Infobar that's shown when a plug-in requires user authorization to run. class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate { public: - // Creates an unauthorized plugin infobar delegate and adds it to + // Creates an unauthorized plugin infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service, HostContentSettingsMap* content_settings, @@ -56,8 +55,7 @@ class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate { const std::string& identifier); private: - UnauthorizedPluginInfoBarDelegate(InfoBarService* infobar_service, - HostContentSettingsMap* content_settings, + UnauthorizedPluginInfoBarDelegate(HostContentSettingsMap* content_settings, const string16& name, const std::string& identifier); virtual ~UnauthorizedPluginInfoBarDelegate(); @@ -82,15 +80,14 @@ class UnauthorizedPluginInfoBarDelegate : public PluginInfoBarDelegate { class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate, public WeakPluginInstallerObserver { public: - // Creates an outdated plugin infobar delegate and adds it to + // Creates an outdated plugin infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service, PluginInstaller* installer, scoped_ptr<PluginMetadata> metadata); private: - OutdatedPluginInfoBarDelegate(InfoBarService* infobar_service, - PluginInstaller* installer, + OutdatedPluginInfoBarDelegate(PluginInstaller* installer, scoped_ptr<PluginMetadata> metadata, const string16& message); virtual ~OutdatedPluginInfoBarDelegate(); @@ -142,16 +139,15 @@ class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate, // Replaces |infobar|, which must currently be owned, with an infobar asking // the user to install or update a particular plugin. - static void Replace(InfoBarDelegate* infobar, + static void Replace(InfoBar* infobar, PluginInstaller* installer, scoped_ptr<PluginMetadata> plugin_metadata, bool new_install, const string16& message); private: - PluginInstallerInfoBarDelegate(InfoBarService* infobar_service, - PluginInstaller* installer, - scoped_ptr<PluginMetadata> plugin_metadata, + PluginInstallerInfoBarDelegate(PluginInstaller* installer, + scoped_ptr<PluginMetadata> metadata, const InstallCallback& callback, bool new_install, const string16& message); @@ -210,9 +206,7 @@ class PluginMetroModeInfoBarDelegate : public ConfirmInfoBarDelegate { const string16& name); private: - PluginMetroModeInfoBarDelegate(InfoBarService* infobar_service, - Mode mode, - const string16& name); + PluginMetroModeInfoBarDelegate(Mode mode, const string16& name); virtual ~PluginMetroModeInfoBarDelegate(); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index 39220e7..f9bfddd 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -39,6 +39,7 @@ #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/extensions/unpacked_installer.h" #include "chrome/browser/extensions/updater/extension_updater.h" +#include "chrome/browser/infobars/infobar.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" @@ -1313,7 +1314,8 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, AlwaysAuthorizePlugins) { ui_test_utils::NavigateToURL(browser(), url); // This should have triggered the dangerous plugin infobar. ASSERT_EQ(1u, infobar_service->infobar_count()); - EXPECT_TRUE(infobar_service->infobar_at(0)->AsConfirmInfoBarDelegate()); + EXPECT_TRUE( + infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()); // And the plugin isn't running. EXPECT_EQ(0, CountPlugins()); @@ -1876,9 +1878,9 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DISABLED_TranslateEnabled) { // Verify that the translate infobar showed up. ASSERT_EQ(1u, infobar_service->infobar_count()); - InfoBarDelegate* infobar = infobar_service->infobar_at(0); + InfoBar* infobar = infobar_service->infobar_at(0); TranslateInfoBarDelegate* translate_infobar_delegate = - infobar->AsTranslateInfoBarDelegate(); + infobar->delegate()->AsTranslateInfoBarDelegate(); ASSERT_TRUE(translate_infobar_delegate); EXPECT_EQ(TranslateInfoBarDelegate::BEFORE_TRANSLATE, translate_infobar_delegate->infobar_type()); diff --git a/chrome/browser/ssl/ssl_tab_helper.cc b/chrome/browser/ssl/ssl_tab_helper.cc index ece2ea6..1048e3c 100644 --- a/chrome/browser/ssl/ssl_tab_helper.cc +++ b/chrome/browser/ssl/ssl_tab_helper.cc @@ -42,18 +42,17 @@ namespace { class SSLCertResultInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an SSL cert result infobar delegate. If |previous_infobar| is + // Creates an SSL cert result infobar and delegate. If |previous_infobar| is // NULL, adds the infobar to |infobar_service|; otherwise, replaces // |previous_infobar|. Returns the new infobar if it was successfully added. // |cert| is valid iff cert addition was successful. - static InfoBarDelegate* Create(InfoBarService* infobar_service, - InfoBarDelegate* previous_infobar, - const string16& message, - net::X509Certificate* cert); + static InfoBar* Create(InfoBarService* infobar_service, + InfoBar* previous_infobar, + const string16& message, + net::X509Certificate* cert); private: - SSLCertResultInfoBarDelegate(InfoBarService* infobar_service, - const string16& message, + SSLCertResultInfoBarDelegate(const string16& message, net::X509Certificate* cert); virtual ~SSLCertResultInfoBarDelegate(); @@ -72,23 +71,22 @@ class SSLCertResultInfoBarDelegate : public ConfirmInfoBarDelegate { }; // static -InfoBarDelegate* SSLCertResultInfoBarDelegate::Create( - InfoBarService* infobar_service, - InfoBarDelegate* previous_infobar, - const string16& message, - net::X509Certificate* cert) { - scoped_ptr<InfoBarDelegate> infobar( - new SSLCertResultInfoBarDelegate(infobar_service, message, cert)); +InfoBar* SSLCertResultInfoBarDelegate::Create(InfoBarService* infobar_service, + InfoBar* previous_infobar, + const string16& message, + net::X509Certificate* cert) { + scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new SSLCertResultInfoBarDelegate(message, cert)))); return previous_infobar ? infobar_service->ReplaceInfoBar(previous_infobar, infobar.Pass()) : infobar_service->AddInfoBar(infobar.Pass()); } SSLCertResultInfoBarDelegate::SSLCertResultInfoBarDelegate( - InfoBarService* infobar_service, const string16& message, net::X509Certificate* cert) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), message_(message), cert_(cert) { } @@ -147,7 +145,7 @@ class SSLTabHelper::SSLAddCertData const content::NotificationDetails& details) OVERRIDE; InfoBarService* infobar_service_; - InfoBarDelegate* infobar_; + InfoBar* infobar_; content::NotificationRegistrar registrar_; DISALLOW_COPY_AND_ASSIGN(SSLAddCertData); diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc index b28c930..8d6ad2d 100644 --- a/chrome/browser/task_manager/task_manager_browsertest.cc +++ b/chrome/browser/task_manager/task_manager_browsertest.cc @@ -14,6 +14,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/notifications/notification.h" @@ -399,7 +400,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, browser()->tab_strip_model()->GetActiveWebContents()); ASSERT_EQ(1U, infobar_service->infobar_count()); ConfirmInfoBarDelegate* delegate = - infobar_service->infobar_at(0)->AsConfirmInfoBarDelegate(); + infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate); delegate->Accept(); TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); diff --git a/chrome/browser/three_d_api_observer.cc b/chrome/browser/three_d_api_observer.cc index 5efe5cd..9fcb039 100644 --- a/chrome/browser/three_d_api_observer.cc +++ b/chrome/browser/three_d_api_observer.cc @@ -6,6 +6,7 @@ #include "base/metrics/histogram.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/tab_contents/tab_util.h" #include "content/public/browser/gpu_data_manager.h" @@ -17,7 +18,8 @@ class ThreeDAPIInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a 3D API infobar delegate and adds it to |infobar_service|. + // Creates a 3D API infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, const GURL& url, content::ThreeDAPIType requester); @@ -30,9 +32,7 @@ class ThreeDAPIInfoBarDelegate : public ConfirmInfoBarDelegate { DISMISSAL_MAX }; - ThreeDAPIInfoBarDelegate(InfoBarService* owner, - const GURL& url, - content::ThreeDAPIType requester); + ThreeDAPIInfoBarDelegate(const GURL& url, content::ThreeDAPIType requester); virtual ~ThreeDAPIInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -61,15 +61,15 @@ void ThreeDAPIInfoBarDelegate::Create(InfoBarService* infobar_service, content::ThreeDAPIType requester) { if (!infobar_service) return; // NULL for apps. - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ThreeDAPIInfoBarDelegate(infobar_service, url, requester))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new ThreeDAPIInfoBarDelegate(url, requester)))); } ThreeDAPIInfoBarDelegate::ThreeDAPIInfoBarDelegate( - InfoBarService* owner, const GURL& url, content::ThreeDAPIType requester) - : ConfirmInfoBarDelegate(owner), + : ConfirmInfoBarDelegate(), url_(url), requester_(requester), message_text_queried_(false), diff --git a/chrome/browser/translate/options_menu_model.cc b/chrome/browser/translate/options_menu_model.cc index 86a1cfc0..10b8db5 100644 --- a/chrome/browser/translate/options_menu_model.cc +++ b/chrome/browser/translate/options_menu_model.cc @@ -25,6 +25,9 @@ OptionsMenuModel::OptionsMenuModel( TranslateInfoBarDelegate* translate_delegate) : ui::SimpleMenuModel(this), translate_infobar_delegate_(translate_delegate) { + // |translate_delegate| must already be owned. + DCHECK(translate_infobar_delegate_->web_contents()); + string16 original_language = translate_delegate->language_name_at( translate_delegate->original_language_index()); string16 target_language = translate_delegate->language_name_at( diff --git a/chrome/browser/translate/translate_browsertest.cc b/chrome/browser/translate/translate_browsertest.cc index c7fa412..6b59537 100644 --- a/chrome/browser/translate/translate_browsertest.cc +++ b/chrome/browser/translate/translate_browsertest.cc @@ -7,6 +7,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/chrome_notification_types.h" +#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_script.h" @@ -90,13 +91,13 @@ class TranslateBrowserTest : public InProcessBrowserTest { // |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)->AsConfirmInfoBarDelegate(); + ConfirmInfoBarDelegate* confirm = infobar_service_->infobar_at(i)-> + delegate()->AsConfirmInfoBarDelegate(); if (confirm) continue; - TranslateInfoBarDelegate* translate = - infobar_service_->infobar_at(i)->AsTranslateInfoBarDelegate(); + TranslateInfoBarDelegate* translate = infobar_service_->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 578cf33..76fd37a 100644 --- a/chrome/browser/translate/translate_infobar_delegate.cc +++ b/chrome/browser/translate/translate_infobar_delegate.cc @@ -10,6 +10,7 @@ #include "base/metrics/histogram.h" #include "base/prefs/pref_service.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/translate/translate_accept_languages.h" @@ -60,16 +61,18 @@ void TranslateInfoBarDelegate::Create( TranslateTabHelper* translate_tab_helper = TranslateTabHelper::FromWebContents(web_contents); if (!translate_tab_helper || - translate_tab_helper->language_state().InTranslateNavigation()) + translate_tab_helper->language_state().InTranslateNavigation()) return; } // Find any existing translate infobar delegate. + InfoBar* old_infobar = NULL; InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); TranslateInfoBarDelegate* old_delegate = NULL; for (size_t i = 0; i < infobar_service->infobar_count(); ++i) { - old_delegate = infobar_service->infobar_at(i)->AsTranslateInfoBarDelegate(); + old_infobar = infobar_service->infobar_at(i); + old_delegate = old_infobar->delegate()->AsTranslateInfoBarDelegate(); if (old_delegate) { if (!replace_existing_infobar) return; @@ -78,12 +81,12 @@ void TranslateInfoBarDelegate::Create( } // Add the new delegate. - scoped_ptr<InfoBarDelegate> infobar( - new TranslateInfoBarDelegate(infobar_service, infobar_type, old_delegate, - original_language, target_language, - error_type, prefs, shortcut_config)); + scoped_ptr<InfoBar> infobar(CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate>(new TranslateInfoBarDelegate( + infobar_type, old_delegate, original_language, target_language, + error_type, prefs, shortcut_config)))); if (old_delegate) - infobar_service->ReplaceInfoBar(old_delegate, infobar.Pass()); + infobar_service->ReplaceInfoBar(old_infobar, infobar.Pass()); else infobar_service->AddInfoBar(infobar.Pass()); } @@ -127,7 +130,7 @@ void TranslateInfoBarDelegate::RevertTranslation() { TranslateManager::GetInstance()->RevertTranslation(web_contents()); UMA_HISTOGRAM_BOOLEAN(TranslateBrowserMetrics::GetMetricsName( TranslateBrowserMetrics::UMA_REVERT_TRANSLATION), true); - RemoveSelf(); + infobar()->RemoveSelf(); } void TranslateInfoBarDelegate::ReportLanguageDetectionError() { @@ -170,7 +173,7 @@ void TranslateInfoBarDelegate::ToggleTranslatableLanguageByPrefs() { TranslateTabHelper::FromWebContents(web_contents()); DCHECK(translate_tab_helper); translate_tab_helper->language_state().SetTranslateEnabled(false); - RemoveSelf(); + infobar()->RemoveSelf(); } UMA_HISTOGRAM_BOOLEAN(TranslateBrowserMetrics::GetMetricsName( @@ -195,7 +198,7 @@ void TranslateInfoBarDelegate::ToggleSiteBlacklist() { TranslateTabHelper::FromWebContents(web_contents()); DCHECK(translate_tab_helper); translate_tab_helper->language_state().SetTranslateEnabled(false); - RemoveSelf(); + infobar()->RemoveSelf(); } UMA_HISTOGRAM_BOOLEAN(TranslateBrowserMetrics::GetMetricsName( @@ -239,7 +242,7 @@ void TranslateInfoBarDelegate::NeverTranslatePageLanguage() { UMA_HISTOGRAM_BOOLEAN(TranslateBrowserMetrics::GetMetricsName( TranslateBrowserMetrics::UMA_NEVER_TRANSLATE_LANG), true); - RemoveSelf(); + infobar()->RemoveSelf(); } string16 TranslateInfoBarDelegate::GetMessageInfoBarText() { @@ -361,7 +364,6 @@ void TranslateInfoBarDelegate::GetAfterTranslateStrings( } TranslateInfoBarDelegate::TranslateInfoBarDelegate( - InfoBarService* infobar_service, Type infobar_type, TranslateInfoBarDelegate* old_delegate, const std::string& original_language, @@ -369,7 +371,7 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate( TranslateErrors::Type error_type, PrefService* prefs, ShortcutConfiguration shortcut_config) - : InfoBarDelegate(infobar_service), + : InfoBarDelegate(), infobar_type_(infobar_type), background_animation_(NONE), original_language_index_(kNoIndex), @@ -396,6 +398,9 @@ TranslateInfoBarDelegate::TranslateInfoBarDelegate( } } +// TranslateInfoBarDelegate::CreateInfoBar() is implemented in platform-specific +// files. + void TranslateInfoBarDelegate::InfoBarDismissed() { if (infobar_type_ != BEFORE_TRANSLATE) return; diff --git a/chrome/browser/translate/translate_infobar_delegate.h b/chrome/browser/translate/translate_infobar_delegate.h index 17f9236..a4cb05a 100644 --- a/chrome/browser/translate/translate_infobar_delegate.h +++ b/chrome/browser/translate/translate_infobar_delegate.h @@ -9,8 +9,8 @@ #include <utility> #include <vector> -#include "base/compiler_specific.h" #include "base/logging.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/infobars/infobar_delegate.h" #include "chrome/browser/translate/translate_prefs.h" #include "chrome/common/translate/translate_errors.h" @@ -180,8 +180,7 @@ class TranslateInfoBarDelegate : public InfoBarDelegate { bool autodetermined_source_language); protected: - TranslateInfoBarDelegate(InfoBarService* infobar_service, - Type infobar_type, + TranslateInfoBarDelegate(Type infobar_type, TranslateInfoBarDelegate* old_delegate, const std::string& original_language, const std::string& target_language, @@ -190,10 +189,14 @@ class TranslateInfoBarDelegate : public InfoBarDelegate { ShortcutConfiguration shortcut_config); private: + friend class TranslationInfoBarTest; typedef std::pair<std::string, string16> LanguageNamePair; + // Returns a translate infobar that owns |delegate|. + static scoped_ptr<InfoBar> CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); + // InfoBarDelegate: - virtual InfoBar* CreateInfoBar(InfoBarService* infobar_service) OVERRIDE; virtual void InfoBarDismissed() OVERRIDE; virtual int GetIconID() const OVERRIDE; virtual InfoBarDelegate::Type GetInfoBarType() const OVERRIDE; diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index 0f63e5e..cc6bad2 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -153,7 +153,8 @@ class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness, // infobar. TranslateInfoBarDelegate* GetTranslateInfoBar() { return (infobar_service()->infobar_count() == 1) ? - infobar_service()->infobar_at(0)->AsTranslateInfoBarDelegate() : NULL; + infobar_service()->infobar_at(0)->delegate()-> + AsTranslateInfoBarDelegate() : NULL; } // If there is 1 infobar and it is a translate infobar, closes it and returns @@ -163,7 +164,7 @@ class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness, if (!infobar) return false; infobar->InfoBarDismissed(); // Simulates closing the infobar. - infobar_service()->RemoveInfoBar(infobar); + infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); return true; } @@ -186,7 +187,7 @@ class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness, if (!infobar) return false; infobar->TranslationDeclined(); - infobar_service()->RemoveInfoBar(infobar); + infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); return true; } @@ -213,7 +214,7 @@ class TranslateManagerBrowserTest : public ChromeRenderViewHostTestHarness, const content::NotificationDetails& details) { DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); removed_infobars_.insert( - content::Details<InfoBar::RemovedDetails>(details)->first); + content::Details<InfoBar::RemovedDetails>(details)->first->delegate()); } MOCK_METHOD1(OnPreferenceChanged, void(const std::string&)); 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 6b76433..d5fbaf6 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 @@ -6,6 +6,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_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/blocked_content/popup_blocker_tab_helper.h" @@ -18,16 +19,17 @@ // static void PopupBlockedInfoBarDelegate::Create(InfoBarService* infobar_service, int num_popups) { - scoped_ptr<InfoBarDelegate> infobar( - new PopupBlockedInfoBarDelegate(infobar_service, num_popups)); + scoped_ptr<InfoBar> infobar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new PopupBlockedInfoBarDelegate(num_popups)))); // 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) { - InfoBarDelegate* existing_infobar = infobar_service->infobar_at(i); - if (existing_infobar->AsPopupBlockedInfoBarDelegate()) { + InfoBar* existing_infobar = infobar_service->infobar_at(i); + if (existing_infobar->delegate()->AsPopupBlockedInfoBarDelegate()) { infobar_service->ReplaceInfoBar(existing_infobar, infobar.Pass()); return; } @@ -48,10 +50,8 @@ PopupBlockedInfoBarDelegate* return this; } -PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate( - InfoBarService* infobar_service, - int num_popups) - : ConfirmInfoBarDelegate(infobar_service), +PopupBlockedInfoBarDelegate::PopupBlockedInfoBarDelegate(int num_popups) + : ConfirmInfoBarDelegate(), num_popups_(num_popups) { } @@ -71,17 +71,16 @@ string16 PopupBlockedInfoBarDelegate::GetButtonLabel( bool PopupBlockedInfoBarDelegate::Accept() { // Create exceptions. - content::WebContents* web_contents = owner()->web_contents(); - const GURL& url = web_contents->GetURL(); + const GURL& url = web_contents()->GetURL(); Profile* profile = Profile::FromBrowserContext( - web_contents->GetBrowserContext()); + web_contents()->GetBrowserContext()); profile->GetHostContentSettingsMap()->AddExceptionForURL( url, url, CONTENT_SETTINGS_TYPE_POPUPS, std::string(), CONTENT_SETTING_ALLOW); // Launch popups. PopupBlockerTabHelper* popup_blocker_helper = - PopupBlockerTabHelper::FromWebContents(web_contents); + PopupBlockerTabHelper::FromWebContents(web_contents()); DCHECK(popup_blocker_helper); PopupBlockerTabHelper::PopupIdMap blocked_popups = popup_blocker_helper->GetBlockedPopupRequests(); diff --git a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h index 8f21fae..1bbbb79 100644 --- a/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h +++ b/chrome/browser/ui/android/content_settings/popup_blocked_infobar_delegate.h @@ -11,13 +11,14 @@ class InfoBarService; class PopupBlockedInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a popup blocked infobar delegate and adds it to |infobar_service|. + // Creates a popup blocked infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, int num_popups); virtual ~PopupBlockedInfoBarDelegate(); private: - PopupBlockedInfoBarDelegate(InfoBarService* infobar_service, int num_popups); + explicit PopupBlockedInfoBarDelegate(int num_popups); // ConfirmInfoBarDelegate: virtual int GetIconID() const OVERRIDE; 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 6fa9b55..5651d01 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 @@ -8,6 +8,7 @@ #include "base/android/jni_helper.h" #include "base/android/jni_string.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar.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" @@ -21,10 +22,9 @@ using base::android::ScopedJavaLocalRef; AutoLoginInfoBarDelegateAndroid::AutoLoginInfoBarDelegateAndroid( - InfoBarService* owner, const Params& params, Profile* profile) - : AutoLoginInfoBarDelegate(owner, params, profile), + : AutoLoginInfoBarDelegate(params, profile), params_(params) { } @@ -83,37 +83,36 @@ bool AutoLoginInfoBarDelegateAndroid::Cancel() { void AutoLoginInfoBarDelegateAndroid::LoginSuccess(JNIEnv* env, jobject obj, jstring result) { - if (!owner()) + if (!infobar()->owner()) return; // We're closing; don't call anything, it might access the owner. // TODO(miguelg): Test whether the Stop() and RemoveInfoBar() calls here are // necessary, or whether OpenURL() will do this for us. - content::WebContents* web_contents = owner()->web_contents(); - web_contents->Stop(); - owner()->RemoveInfoBar(this); + content::WebContents* contents = web_contents(); + contents->Stop(); + infobar()->RemoveSelf(); // WARNING: |this| may be deleted at this point! Do not access any members! - web_contents->OpenURL(content::OpenURLParams( + contents->OpenURL(content::OpenURLParams( GURL(base::android::ConvertJavaStringToUTF8(env, result)), content::Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_AUTO_BOOKMARK, false)); } void AutoLoginInfoBarDelegateAndroid::LoginFailed(JNIEnv* env, jobject obj) { - if (!owner()) + if (!infobar()->owner()) return; // We're closing; don't call anything, it might access the owner. // TODO(miguelg): Using SimpleAlertInfoBarDelegate::Create() animates in a new // infobar while we animate the current one closed. It would be better to use // ReplaceInfoBar(). SimpleAlertInfoBarDelegate::Create( - owner(), IDR_INFOBAR_WARNING, + infobar()->owner(), IDR_INFOBAR_WARNING, l10n_util::GetStringUTF16(IDS_AUTO_LOGIN_FAILED), false); - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } void AutoLoginInfoBarDelegateAndroid::LoginDismiss(JNIEnv* env, jobject obj) { - if (owner()) - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } bool AutoLoginInfoBarDelegateAndroid::Register(JNIEnv* env) { diff --git a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h index bec32cd..8d97b01 100644 --- a/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h +++ b/chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android.h @@ -11,9 +11,7 @@ class AutoLoginInfoBarDelegateAndroid : public AutoLoginInfoBarDelegate { public: - AutoLoginInfoBarDelegateAndroid(InfoBarService* owner, - const Params& params, - Profile* profile); + AutoLoginInfoBarDelegateAndroid(const Params& params, Profile* profile); virtual ~AutoLoginInfoBarDelegateAndroid(); // AutoLoginInfoBarDelegate: diff --git a/chrome/browser/ui/android/infobars/confirm_infobar.cc b/chrome/browser/ui/android/infobars/confirm_infobar.cc index 59e6bff..48a3f14 100644 --- a/chrome/browser/ui/android/infobars/confirm_infobar.cc +++ b/chrome/browser/ui/android/infobars/confirm_infobar.cc @@ -15,15 +15,16 @@ // ConfirmInfoBarDelegate ----------------------------------------------------- // static -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ConfirmInfoBar(owner, this); +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ConfirmInfoBar(delegate.Pass())); } // ConfirmInfoBar ------------------------------------------------------------- -ConfirmInfoBar::ConfirmInfoBar(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBarAndroid(owner, delegate), +ConfirmInfoBar::ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate) + : InfoBarAndroid(delegate.PassAs<InfoBarDelegate>()), java_confirm_delegate_() { } diff --git a/chrome/browser/ui/android/infobars/confirm_infobar.h b/chrome/browser/ui/android/infobars/confirm_infobar.h index f8e47b7..1156a02 100644 --- a/chrome/browser/ui/android/infobars/confirm_infobar.h +++ b/chrome/browser/ui/android/infobars/confirm_infobar.h @@ -12,7 +12,7 @@ class ConfirmInfoBar : public InfoBarAndroid { public: - ConfirmInfoBar(InfoBarService* owner, InfoBarDelegate* delegate); + explicit ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate); virtual ~ConfirmInfoBar(); private: diff --git a/chrome/browser/ui/android/infobars/infobar_android.cc b/chrome/browser/ui/android/infobars/infobar_android.cc index f21841d..7b2f4b2 100644 --- a/chrome/browser/ui/android/infobars/infobar_android.cc +++ b/chrome/browser/ui/android/infobars/infobar_android.cc @@ -28,8 +28,8 @@ const int InfoBar::kDefaultBarTargetHeight = 36; // InfoBarAndroid ------------------------------------------------------------- -InfoBarAndroid::InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate) { +InfoBarAndroid::InfoBarAndroid(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()) { } InfoBarAndroid::~InfoBarAndroid() { diff --git a/chrome/browser/ui/android/infobars/infobar_android.h b/chrome/browser/ui/android/infobars/infobar_android.h index 2359c51..95a7d09 100644 --- a/chrome/browser/ui/android/infobars/infobar_android.h +++ b/chrome/browser/ui/android/infobars/infobar_android.h @@ -31,7 +31,7 @@ class InfoBarAndroid : public InfoBar { ACTION_TRANSLATE_SHOW_ORIGINAL = 4, }; - InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarAndroid(scoped_ptr<InfoBarDelegate> delegate); virtual ~InfoBarAndroid(); // InfoBar: diff --git a/chrome/browser/ui/android/infobars/infobar_container_android.cc b/chrome/browser/ui/android/infobars/infobar_container_android.cc index b81c1a2..4012bb4 100644 --- a/chrome/browser/ui/android/infobars/infobar_container_android.cc +++ b/chrome/browser/ui/android/infobars/infobar_container_android.cc @@ -79,7 +79,6 @@ void InfoBarContainerAndroid::PlatformSpecificReplaceInfoBar( void InfoBarContainerAndroid::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { InfoBarAndroid* android_infobar = static_cast<InfoBarAndroid*>(infobar); android_infobar->CloseJavaInfoBar(); - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); } diff --git a/chrome/browser/ui/android/infobars/translate_infobar.cc b/chrome/browser/ui/android/infobars/translate_infobar.cc index dcc6c70..258bf8a 100644 --- a/chrome/browser/ui/android/infobars/translate_infobar.cc +++ b/chrome/browser/ui/android/infobars/translate_infobar.cc @@ -16,16 +16,17 @@ // TranslateInfoBarDelegate --------------------------------------------------- // static -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new TranslateInfoBar(owner, this); +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new TranslateInfoBar(delegate.Pass())); } // TranslateInfoBar ----------------------------------------------------------- -TranslateInfoBar::TranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : InfoBarAndroid(owner, delegate), +TranslateInfoBar::TranslateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) + : InfoBarAndroid(delegate.PassAs<InfoBarDelegate>()), java_translate_delegate_() { } diff --git a/chrome/browser/ui/android/infobars/translate_infobar.h b/chrome/browser/ui/android/infobars/translate_infobar.h index 96899f0..548b10a 100644 --- a/chrome/browser/ui/android/infobars/translate_infobar.h +++ b/chrome/browser/ui/android/infobars/translate_infobar.h @@ -12,7 +12,7 @@ class TranslateInfoBar : public InfoBarAndroid { public: - TranslateInfoBar(InfoBarService* owner, TranslateInfoBarDelegate* delegate); + explicit TranslateInfoBar(scoped_ptr<TranslateInfoBarDelegate> delegate); virtual ~TranslateInfoBar(); // JNI methods specific to translate. diff --git a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc index 46dbfba..9ade4ad 100644 --- a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc +++ b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.cc @@ -9,6 +9,8 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/apps/app_launch_for_metro_restart_win.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/infobars/infobar.h" +#include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/lifetime/application_lifetime.h" #include "chrome/browser/metro_utils/metro_chrome_win.h" #include "chrome/browser/profiles/profile.h" @@ -43,10 +45,9 @@ void AppMetroInfoBarDelegateWin::Create( content::Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); content::WebContents* web_contents = displayer.browser()->OpenURL(params); - InfoBarService* info_bar_service = - InfoBarService::FromWebContents(web_contents); - info_bar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new AppMetroInfoBarDelegateWin(info_bar_service, mode, extension_id))); + InfoBarService::FromWebContents(web_contents)->AddInfoBar( + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( + new AppMetroInfoBarDelegateWin(mode, extension_id)))); // Use PostTask because we can get here in a COM SendMessage, and // ActivateApplication can not be sent nested (returns error @@ -56,10 +57,9 @@ void AppMetroInfoBarDelegateWin::Create( } AppMetroInfoBarDelegateWin::AppMetroInfoBarDelegateWin( - InfoBarService* info_bar_service, Mode mode, const std::string& extension_id) - : ConfirmInfoBarDelegate(info_bar_service), + : ConfirmInfoBarDelegate(), mode_(mode), extension_id_(extension_id) { DCHECK_EQ(mode_ == SHOW_APP_LIST, extension_id_.empty()); diff --git a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h index 920654e..03a384f 100644 --- a/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h +++ b/chrome/browser/ui/apps/app_metro_infobar_delegate_win.h @@ -22,16 +22,14 @@ class AppMetroInfoBarDelegateWin : public ConfirmInfoBarDelegate { LAUNCH_PACKAGED_APP }; - // Creates an app metro infobar delegate, adds it to a new browser tab, then - // activates Metro mode. + // Creates an app metro infobar and delegate, adds the infobar to a new + // browser tab, then activates Metro mode. static void Create(Profile* profile, Mode mode, const std::string& extension_id); private: - AppMetroInfoBarDelegateWin(InfoBarService* infobar_service, - Mode mode, - const std::string& extension_id); + AppMetroInfoBarDelegateWin(Mode mode, const std::string& extension_id); virtual ~AppMetroInfoBarDelegateWin(); // ConfirmInfoBarDelegate overrides: diff --git a/chrome/browser/ui/auto_login_infobar_delegate.cc b/chrome/browser/ui/auto_login_infobar_delegate.cc index 72c38af..4c4076a 100644 --- a/chrome/browser/ui/auto_login_infobar_delegate.cc +++ b/chrome/browser/ui/auto_login_infobar_delegate.cc @@ -13,6 +13,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/google/google_util.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/signin/ubertoken_fetcher.h" @@ -136,20 +137,18 @@ bool AutoLoginInfoBarDelegate::Create(content::WebContents* web_contents, Profile* profile = Profile::FromBrowserContext(web_contents->GetBrowserContext()); - return infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( #if defined(OS_ANDROID) - new AutoLoginInfoBarDelegateAndroid(infobar_service, params, profile) + typedef AutoLoginInfoBarDelegateAndroid Delegate; #else - new AutoLoginInfoBarDelegate(infobar_service, params, profile) + typedef AutoLoginInfoBarDelegate Delegate; #endif - )) != NULL; + return !!infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new Delegate(params, profile)))); } -AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate( - InfoBarService* owner, - const Params& params, - Profile* profile) - : ConfirmInfoBarDelegate(owner), +AutoLoginInfoBarDelegate::AutoLoginInfoBarDelegate(const Params& params, + Profile* profile) + : ConfirmInfoBarDelegate(), params_(params), button_pressed_(false) { RecordHistogramAction(SHOWN); @@ -213,10 +212,7 @@ void AutoLoginInfoBarDelegate::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, type); - // owner() can be NULL when InfoBarService removes us. See - // |InfoBarDelegate::clear_owner|. - if (owner()) - owner()->RemoveInfoBar(this); + infobar()->RemoveSelf(); } void AutoLoginInfoBarDelegate::RecordHistogramAction(Actions action) { diff --git a/chrome/browser/ui/auto_login_infobar_delegate.h b/chrome/browser/ui/auto_login_infobar_delegate.h index 85ebfde..db47dae 100644 --- a/chrome/browser/ui/auto_login_infobar_delegate.h +++ b/chrome/browser/ui/auto_login_infobar_delegate.h @@ -32,14 +32,13 @@ class AutoLoginInfoBarDelegate : public ConfirmInfoBarDelegate, std::string username; }; - // Creates an autologin infobar delegate and adds it to the infobar service - // for |web_contents|. Returns whether the infobar was successfully created. + // Creates an autologin infobar and delegate and adds the infobar to the + // infobar service for |web_contents|. Returns whether the infobar was + // successfully added. static bool Create(content::WebContents* web_contents, const Params& params); protected: - AutoLoginInfoBarDelegate(InfoBarService* owner, - const Params& params, - Profile* profile); + AutoLoginInfoBarDelegate(const Params& params, Profile* profile); virtual ~AutoLoginInfoBarDelegate(); private: diff --git a/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm index 9d64080b..3d0be70 100644 --- a/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/alternate_nav_infobar_controller.mm @@ -57,10 +57,13 @@ @end -InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); +// static +scoped_ptr<InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<AlternateNavInfoBarController> controller( [[AlternateNavInfoBarController alloc] initWithInfoBar:infobar.get()]); infobar->set_controller(controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } diff --git a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm index b237083..99c34bb 100644 --- a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.mm @@ -137,10 +137,13 @@ @end -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); +// static +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<ConfirmInfoBarController> controller( [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); infobar->set_controller(controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } 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 f7cdcee..e7eb9d4 100644 --- a/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/confirm_infobar_controller_unittest.mm @@ -89,14 +89,15 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest, CocoaProfileTest::SetUp(); web_contents_.reset( WebContents::Create(WebContents::CreateParams(profile()))); - InfoBarService::CreateForWebContents(web_contents_.get()); + InfoBarService::CreateForWebContents(web_contents_.get()); - delegate_ = new MockConfirmInfoBarDelegate(this); - infobar_.reset(new InfoBarCocoa( - InfoBarService::FromWebContents(web_contents_.get()), delegate_)); + scoped_ptr<InfoBarDelegate> delegate( + new MockConfirmInfoBarDelegate(this)); + infobar_ = new InfoBarCocoa(delegate.Pass()); + infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); controller_.reset([[TestConfirmInfoBarController alloc] - initWithInfoBar:infobar_.get()]); + initWithInfoBar:infobar_]); infobar_->set_controller(controller_); container_.reset( @@ -106,20 +107,22 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest, closed_delegate_ok_clicked_ = false; closed_delegate_cancel_clicked_ = false; closed_delegate_link_clicked_ = false; + delegate_closed_ = false; } virtual void TearDown() OVERRIDE { [controller_ removeSelf]; - if (delegate_) - delete delegate_; CocoaProfileTest::TearDown(); } protected: - // Hopefully-obvious: If this returns true, you must not deref |delegate_|! - bool delegate_closed() const { return delegate_ == NULL; } + // True if delegate is closed. + bool delegate_closed() const { return delegate_closed_; } + + MockConfirmInfoBarDelegate* delegate() const { + return static_cast<MockConfirmInfoBarDelegate*>(infobar_->delegate()); + } - MockConfirmInfoBarDelegate* delegate_; // Owns itself. base::scoped_nsobject<id> container_; base::scoped_nsobject<ConfirmInfoBarController> controller_; bool closed_delegate_ok_clicked_; @@ -128,14 +131,16 @@ class ConfirmInfoBarControllerTest : public CocoaProfileTest, private: virtual void OnInfoBarDelegateClosed() OVERRIDE { - closed_delegate_ok_clicked_ = delegate_->ok_clicked(); - closed_delegate_cancel_clicked_ = delegate_->cancel_clicked(); - closed_delegate_link_clicked_ = delegate_->link_clicked(); - delegate_ = NULL; + closed_delegate_ok_clicked_ = delegate()->ok_clicked(); + closed_delegate_cancel_clicked_ = delegate()->cancel_clicked(); + closed_delegate_link_clicked_ = delegate()->link_clicked(); + delegate_closed_ = true; + controller_.reset(); } scoped_ptr<WebContents> web_contents_; - scoped_ptr<InfoBarCocoa> infobar_; + InfoBarCocoa* infobar_; // Weak, will delete itself. + bool delegate_closed_; }; @@ -143,9 +148,9 @@ TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { // Make sure someone looked at the message, link, and icon. - EXPECT_TRUE(delegate_->message_text_accessed()); - EXPECT_TRUE(delegate_->link_text_accessed()); - EXPECT_TRUE(delegate_->icon_accessed()); + EXPECT_TRUE(delegate()->message_text_accessed()); + EXPECT_TRUE(delegate()->link_text_accessed()); + EXPECT_TRUE(delegate()->icon_accessed()); // Check to make sure the infobar message was set properly. EXPECT_EQ(MockConfirmInfoBarDelegate::kMessage, @@ -170,15 +175,15 @@ TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) { } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOKWithoutClosing) { - delegate_->set_dont_close_on_action(); + delegate()->set_dont_close_on_action(); // Check that clicking the OK button calls Accept() but does not close // the infobar. [controller_ ok:nil]; ASSERT_FALSE(delegate_closed()); - EXPECT_TRUE(delegate_->ok_clicked()); - EXPECT_FALSE(delegate_->cancel_clicked()); - EXPECT_FALSE(delegate_->link_clicked()); + EXPECT_TRUE(delegate()->ok_clicked()); + EXPECT_FALSE(delegate()->cancel_clicked()); + EXPECT_FALSE(delegate()->link_clicked()); } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { @@ -192,15 +197,15 @@ TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) { } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancelWithoutClosing) { - delegate_->set_dont_close_on_action(); + delegate()->set_dont_close_on_action(); // Check that clicking the cancel button calls Cancel() but does not close // the infobar. [controller_ cancel:nil]; ASSERT_FALSE(delegate_closed()); - EXPECT_FALSE(delegate_->ok_clicked()); - EXPECT_TRUE(delegate_->cancel_clicked()); - EXPECT_FALSE(delegate_->link_clicked()); + EXPECT_FALSE(delegate()->ok_clicked()); + EXPECT_TRUE(delegate()->cancel_clicked()); + EXPECT_FALSE(delegate()->link_clicked()); } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) { @@ -214,15 +219,15 @@ TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) { } TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { - delegate_->set_dont_close_on_action(); + delegate()->set_dont_close_on_action(); // Check that clicking on the link calls LinkClicked() on the // delegate. It should not close the infobar. [controller_ linkClicked]; ASSERT_FALSE(delegate_closed()); - EXPECT_FALSE(delegate_->ok_clicked()); - EXPECT_FALSE(delegate_->cancel_clicked()); - EXPECT_TRUE(delegate_->link_clicked()); + EXPECT_FALSE(delegate()->ok_clicked()); + EXPECT_FALSE(delegate()->cancel_clicked()); + EXPECT_TRUE(delegate()->link_clicked()); } TEST_F(ConfirmInfoBarControllerTest, ResizeView) { diff --git a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h index 3f35f94..aea7693 100644 --- a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h +++ b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.h @@ -20,9 +20,6 @@ class InfobarBridge; // The native extension view retrieved from the extension host. Weak. NSView* extensionView_; - // The window containing this InfoBar. Weak. - NSWindow* window_; - // The InfoBar's button with the Extension's icon that launches the context // menu. base::scoped_nsobject<MenuButton> dropdownButton_; diff --git a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm index 97568c5..cba2222 100644 --- a/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/extension_infobar_controller.mm @@ -52,21 +52,15 @@ const CGFloat kToolbarMaxHeightPx = 72.0; // A helper class to bridge the asynchronous Skia bitmap loading mechanism to // the extension's button. -class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { +class InfobarBridge { public: explicit InfobarBridge(ExtensionInfoBarController* owner) : owner_(owner), delegate_([owner delegate]->AsExtensionInfoBarDelegate()), weak_ptr_factory_(this) { - delegate_->set_observer(this); LoadIcon(); } - virtual ~InfobarBridge() { - if (delegate_) - delegate_->set_observer(NULL); - } - // Load the Extension's icon image. void LoadIcon() { const extensions::Extension* extension = delegate_->extension_view_host()-> @@ -119,11 +113,6 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { canvas->ExtractImageRep().sk_bitmap())]; } - // Overridden from ExtensionInfoBarDelegate::DelegateObserver: - virtual void OnDelegateDeleted() OVERRIDE { - delegate_ = NULL; - } - private: // Weak. Owns us. ExtensionInfoBarController* owner_; @@ -139,22 +128,11 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { @implementation ExtensionInfoBarController -- (id)initWithInfoBar:(InfoBarCocoa*)infobar - window:(NSWindow*)window { +- (id)initWithInfoBar:(InfoBarCocoa*)infobar { if ((self = [super initWithInfoBar:infobar])) { - window_ = window; dropdownButton_.reset([[MenuButton alloc] init]); [dropdownButton_ setOpenMenuOnClick:YES]; - extensions::ExtensionViewHost* extensionViewHost = - [self delegate]->AsExtensionInfoBarDelegate()->extension_view_host(); - Browser* browser = chrome::FindBrowserWithWebContents( - [self infobar]->OwnerCocoa()->web_contents()); - contextMenuController_.reset([[ExtensionActionContextMenuController alloc] - initWithExtension:extensionViewHost->extension() - browser:browser - extensionAction:NULL]); - base::scoped_nsobject<NSMenu> contextMenu( [[NSMenu alloc] initWithTitle:@""]); [contextMenu setDelegate:self]; @@ -224,8 +202,13 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adjustExtensionViewSize) - name:NSWindowDidResizeNotification - object:window_]; + name:NSViewFrameDidChangeNotification + object:[self view]]; +} + +- (void)infobarWillHide { + [[dropdownButton_ menu] cancelTracking]; + [super infobarWillHide]; } - (void)infobarWillClose { @@ -246,7 +229,7 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { - (void)adjustExtensionViewSize { [extensionView_ setPostsFrameChangedNotifications:NO]; NSSize extensionViewSize = [extensionView_ frame].size; - extensionViewSize.width = NSWidth([window_ frame]); + extensionViewSize.width = NSWidth([[self view] frame]); extensionViewSize.height = [self clampedExtensionViewHeight]; [extensionView_ setFrameSize:extensionViewSize]; [extensionView_ setPostsFrameChangedNotifications:YES]; @@ -257,20 +240,32 @@ class InfobarBridge : public ExtensionInfoBarDelegate::DelegateObserver { } - (void)menuNeedsUpdate:(NSMenu*)menu { + DCHECK([self isOwned]); + + if (!contextMenuController_) { + extensions::ExtensionViewHost* extensionViewHost = + [self delegate]->AsExtensionInfoBarDelegate()->extension_view_host(); + Browser* browser = chrome::FindBrowserWithWebContents( + [self infobar]->OwnerCocoa()->web_contents()); + contextMenuController_.reset([[ExtensionActionContextMenuController alloc] + initWithExtension:extensionViewHost->extension() + browser:browser + extensionAction:NULL]); + } + [menu removeAllItems]; [contextMenuController_ populateMenu:menu]; } @end -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); - NSWindow* window = - [(NSView*)owner->web_contents()->GetView()->GetContentNativeView() - window]; +// static +scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<ExtensionInfoBarController> controller( - [[ExtensionInfoBarController alloc] initWithInfoBar:infobar.get() - window:window]); + [[ExtensionInfoBarController alloc] initWithInfoBar:infobar.get()]); infobar->set_controller(controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } diff --git a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h index 7419f31..b48c6a4 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.h @@ -15,7 +15,7 @@ // actually in InfoBarController. class InfoBarCocoa : public InfoBar { public: - InfoBarCocoa(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarCocoa(scoped_ptr<InfoBarDelegate> delegate); virtual ~InfoBarCocoa(); @@ -26,7 +26,6 @@ class InfoBarCocoa : public InfoBar { } // These functions allow access to protected InfoBar functions. - void RemoveSelfCocoa(); InfoBarService* 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 398cd5f..b49579c 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_cocoa.mm @@ -4,6 +4,8 @@ #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" +#import "chrome/browser/ui/cocoa/infobars/infobar_controller.h" + const int InfoBar::kSeparatorLineHeight = 1; const int InfoBar::kDefaultArrowTargetHeight = 11; const int InfoBar::kMaximumArrowTargetHeight = 24; @@ -11,16 +13,14 @@ const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; const int InfoBar::kMaximumArrowTargetHalfWidth = 14; const int InfoBar::kDefaultBarTargetHeight = 36; -InfoBarCocoa::InfoBarCocoa(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate), +InfoBarCocoa::InfoBarCocoa(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()), weak_ptr_factory_(this) { } InfoBarCocoa::~InfoBarCocoa() { -} - -void InfoBarCocoa::RemoveSelfCocoa() { - RemoveSelf(); + if (controller()) + [controller() infobarWillClose]; } InfoBarService* InfoBarCocoa::OwnerCocoa() { diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm index ffaa38c..9d9df42 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller.mm @@ -6,7 +6,6 @@ #include "base/logging.h" #include "base/mac/mac_util.h" -#include "base/message_loop/message_loop.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_container.h" @@ -100,11 +99,8 @@ } - (void)removeInfoBar:(InfoBarCocoa*)infobar { - InfoBarController* controller = infobar->controller(); - [controller infobarWillClose]; - infobar->set_controller(nil); - [self removeController:controller]; - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); + [infobar->controller() infobarWillHide]; + [self removeController:infobar->controller()]; } - (void)positionInfoBarsAndRedraw:(BOOL)isAnimating { diff --git a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm index 15a83b6..52b2412 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm @@ -9,6 +9,7 @@ #include "base/mac/scoped_nsobject.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" +#import "chrome/browser/ui/cocoa/infobars/confirm_infobar_controller.h" #include "chrome/browser/ui/cocoa/infobars/infobar_cocoa.h" #include "chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h" #import "chrome/browser/ui/cocoa/view_resizer_pong.h" @@ -59,17 +60,16 @@ TEST_F(InfoBarContainerControllerTest, BWCPong) { TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { NSView* view = [controller_ view]; - // This delegate deletes itself when they're told their infobars have closed. - InfoBarDelegate* confirmDelegate = new MockConfirmInfoBarDelegate(NULL); - - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents_.get()); - scoped_ptr<InfoBarCocoa> infobar(static_cast<InfoBarCocoa*>( - confirmDelegate->CreateInfoBar(infobar_service))); + scoped_ptr<InfoBarDelegate> confirm_delegate( + new MockConfirmInfoBarDelegate(NULL)); + scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(confirm_delegate.Pass())); + base::scoped_nsobject<ConfirmInfoBarController> controller( + [[ConfirmInfoBarController alloc] initWithInfoBar:infobar.get()]); + infobar->set_controller(controller); [controller_ addInfoBar:infobar.get() position:0]; EXPECT_EQ(1U, [[view subviews] count]); - [controller_ removeInfoBar:infobar.release()]; + [controller_ removeInfoBar:infobar.get()]; EXPECT_EQ(0U, [[view subviews] count]); } diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.h b/chrome/browser/ui/cocoa/infobars/infobar_controller.h index 0699d37..7755dab 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.h @@ -72,6 +72,10 @@ class InfoBarService; - (void)addAdditionalControls; // Subclasses must override this method to perform cleanup just before the +// infobar hides. +- (void)infobarWillHide; + +// Subclasses must override this method to perform cleanup just before the // infobar closes. - (void)infobarWillClose; @@ -85,8 +89,8 @@ class InfoBarService; @end @interface InfoBarController (Protected) -// Closes and disables the provided menu. Subclasses should call this for each -// popup menu in -infobarWillClose. +// Disables the provided menu. Subclasses should call this for each popup menu +// in -infobarWillClose. - (void)disablePopUpMenu:(NSMenu*)menu; @end diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm index 1385f81..bccb2df 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm @@ -116,13 +116,16 @@ } - (void)removeSelf { - infobar_->RemoveSelfCocoa(); + infobar_->RemoveSelf(); } - (void)addAdditionalControls { // Default implementation does nothing. } +- (void)infobarWillHide { +} + - (void)infobarWillClose { } @@ -149,9 +152,6 @@ } - (void)disablePopUpMenu:(NSMenu*)menu { - // Remove the menu if visible. - [menu cancelTracking]; - // If the menu is re-opened, prevent queries to update items. [menu setDelegate:nil]; diff --git a/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc index da5f1a6..f772168 100644 --- a/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc +++ b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc @@ -9,7 +9,7 @@ const char MockConfirmInfoBarDelegate::kMessage[] = "MockConfirmInfoBarMessage"; MockConfirmInfoBarDelegate::MockConfirmInfoBarDelegate(Owner* owner) - : ConfirmInfoBarDelegate(NULL), + : ConfirmInfoBarDelegate(), owner_(owner), closes_on_action_(true), icon_accessed_(false), diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm index 3afe320..4f0d7ff 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_base.mm @@ -27,11 +27,13 @@ using InfoBarUtilities::VerifyControlOrderAndSpacing; using InfoBarUtilities::CreateLabel; using InfoBarUtilities::AddMenuItem; -// TranslateInfoBarDelegate views specific method: -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - scoped_ptr<InfoBarCocoa> infobar(new InfoBarCocoa(owner, this)); +// static +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + scoped_ptr<InfoBarCocoa> infobar( + new InfoBarCocoa(delegate.PassAs<InfoBarDelegate>())); base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller; - switch (infobar_type_) { + switch (infobar->delegate()->AsTranslateInfoBarDelegate()->infobar_type()) { case BEFORE_TRANSLATE: infobar_controller.reset([[BeforeTranslateInfobarController alloc] initWithInfoBar:infobar.get()]); @@ -49,7 +51,7 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { NOTREACHED(); } infobar->set_controller(infobar_controller); - return infobar.release(); + return infobar.PassAs<InfoBar>(); } @implementation TranslateInfoBarControllerBase (FrameChangeObserver) @@ -359,12 +361,17 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { [self updateState]; } +- (void)infobarWillHide { + [[fromLanguagePopUp_ menu] cancelTracking]; + [[toLanguagePopUp_ menu] cancelTracking]; + [[optionsPopUp_ menu] cancelTracking]; + [super infobarWillHide]; +} + - (void)infobarWillClose { [self disablePopUpMenu:[fromLanguagePopUp_ menu]]; [self disablePopUpMenu:[toLanguagePopUp_ menu]]; [self disablePopUpMenu:[optionsPopUp_ menu]]; - // [super infobarWillClose] clears the owner field which is relied on by the - // notification handler, so remove the handler first. [[NSNotificationCenter defaultCenter] removeObserver:self]; [super infobarWillClose]; } @@ -458,9 +465,6 @@ InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { } - (void)dealloc { - // Perhaps this was removed as an observer in -infobarWillClose, but there's - // no guarantee that that was the case. - [[NSNotificationCenter defaultCenter] removeObserver:self]; [showOriginalButton_ setTarget:nil]; [translateMessageButton_ setTarget:nil]; [super dealloc]; diff --git a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm index 3ecb8a24..45dce1e 100644 --- a/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm @@ -36,13 +36,11 @@ TranslateInfoBarDelegate::Type kTranslateToolbarStates[] = { class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { public: - MockTranslateInfoBarDelegate(InfoBarService* infobar_service, - TranslateInfoBarDelegate::Type type, + MockTranslateInfoBarDelegate(TranslateInfoBarDelegate::Type type, TranslateErrors::Type error, PrefService* prefs, ShortcutConfiguration config) - : TranslateInfoBarDelegate(infobar_service, type, NULL, "en", "es", error, - prefs, config) { + : TranslateInfoBarDelegate(type, NULL, "en", "es", error, prefs, config) { } MOCK_METHOD0(Translate, void()); @@ -58,8 +56,13 @@ class MockTranslateInfoBarDelegate : public TranslateInfoBarDelegate { MOCK_METHOD0(ToggleAlwaysTranslate, void()); }; +} // namespace + class TranslationInfoBarTest : public CocoaProfileTest { public: + TranslationInfoBarTest() : CocoaProfileTest(), infobar_(NULL) { + } + // Each test gets a single Mock translate delegate for the lifetime of // the test. virtual void SetUp() OVERRIDE { @@ -68,32 +71,37 @@ class TranslationInfoBarTest : public CocoaProfileTest { web_contents_.reset( WebContents::Create(WebContents::CreateParams(profile()))); InfoBarService::CreateForWebContents(web_contents_.get()); - CreateInfoBar(); } - void CreateInfoBar() { - CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); + virtual void TearDown() OVERRIDE { + if (infobar_) { + infobar_->CloseSoon(); + infobar_ = NULL; + } + CocoaProfileTest::TearDown(); } void CreateInfoBar(TranslateInfoBarDelegate::Type type) { TranslateErrors::Type error = TranslateErrors::NONE; if (type == TranslateInfoBarDelegate::TRANSLATION_ERROR) error = TranslateErrors::NETWORK; - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents_.get()); Profile* profile = Profile::FromBrowserContext(web_contents_->GetBrowserContext()); ShortcutConfiguration config; config.never_translate_min_count = 3; config.always_translate_min_count = 3; - infobar_delegate_.reset(new MockTranslateInfoBarDelegate( - infobar_service, type, error, profile->GetPrefs(), config)); [[infobar_controller_ view] removeFromSuperview]; - InfoBarDelegate* base = - static_cast<InfoBarDelegate*>(infobar_delegate_.get()); - infobar_.reset( - static_cast<InfoBarCocoa*>(base->CreateInfoBar(infobar_service))); + scoped_ptr<TranslateInfoBarDelegate> delegate( + new MockTranslateInfoBarDelegate(type, error, profile->GetPrefs(), + config)); + scoped_ptr<InfoBar> infobar( + TranslateInfoBarDelegate::CreateInfoBar(delegate.Pass())); + if (infobar_) + infobar_->CloseSoon(); + infobar_ = static_cast<InfoBarCocoa*>(infobar.release()); + infobar_->SetOwner(InfoBarService::FromWebContents(web_contents_.get())); + infobar_controller_.reset([static_cast<TranslateInfoBarControllerBase*>( infobar_->controller()) retain]); @@ -104,23 +112,26 @@ class TranslationInfoBarTest : public CocoaProfileTest { [[test_window() contentView] addSubview:[infobar_controller_ view]]; } + MockTranslateInfoBarDelegate* infobar_delegate() const { + return static_cast<MockTranslateInfoBarDelegate*>(infobar_->delegate()); + } + scoped_ptr<WebContents> web_contents_; - scoped_ptr<MockTranslateInfoBarDelegate> infobar_delegate_; - scoped_ptr<InfoBarCocoa> infobar_; + InfoBarCocoa* infobar_; // weak, deletes itself base::scoped_nsobject<TranslateInfoBarControllerBase> infobar_controller_; }; // Check that we can instantiate a Translate Infobar correctly. TEST_F(TranslationInfoBarTest, Instantiate) { - CreateInfoBar(); + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); ASSERT_TRUE(infobar_controller_.get()); } // Check that clicking the Translate button calls Translate(). TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) { - CreateInfoBar(); + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); - EXPECT_CALL(*infobar_delegate_, Translate()).Times(1); + EXPECT_CALL(*infobar_delegate(), Translate()).Times(1); [infobar_controller_ ok:nil]; } @@ -129,22 +140,23 @@ TEST_F(TranslationInfoBarTest, TranslateCalledOnButtonPress) { TEST_F(TranslationInfoBarTest, TranslateCalledInErrorMode) { CreateInfoBar(TranslateInfoBarDelegate::TRANSLATION_ERROR); - EXPECT_CALL(*infobar_delegate_, Translate()).Times(1); + EXPECT_CALL(*infobar_delegate(), Translate()).Times(1); [infobar_controller_ ok:nil]; } // Check that clicking the "Show Original button calls RevertTranslation(). TEST_F(TranslationInfoBarTest, RevertCalledOnButtonPress) { - CreateInfoBar(); + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); - EXPECT_CALL(*infobar_delegate_, RevertTranslation()).Times(1); + EXPECT_CALL(*infobar_delegate(), RevertTranslation()).Times(1); [infobar_controller_ showOriginal:nil]; } // Check that items in the options menu are hooked up correctly. TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { - EXPECT_CALL(*infobar_delegate_, Translate()) + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); + EXPECT_CALL(*infobar_delegate(), Translate()) .Times(0); [infobar_controller_ rebuildOptionsMenu:NO]; @@ -168,19 +180,19 @@ TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { NSMenuItem* aboutTranslateItem = [optionsMenuItems objectAtIndex:6]; { - EXPECT_CALL(*infobar_delegate_, ToggleAlwaysTranslate()) + EXPECT_CALL(*infobar_delegate(), ToggleAlwaysTranslate()) .Times(1); [infobar_controller_ optionsMenuChanged:alwaysTranslateLanguateItem]; } { - EXPECT_CALL(*infobar_delegate_, ToggleTranslatableLanguageByPrefs()) + EXPECT_CALL(*infobar_delegate(), ToggleTranslatableLanguageByPrefs()) .Times(1); [infobar_controller_ optionsMenuChanged:neverTranslateLanguateItem]; } { - EXPECT_CALL(*infobar_delegate_, ToggleSiteBlacklist()) + EXPECT_CALL(*infobar_delegate(), ToggleSiteBlacklist()) .Times(1); [infobar_controller_ optionsMenuChanged:neverTranslateSiteItem]; } @@ -198,13 +210,13 @@ TEST_F(TranslationInfoBarTest, OptionsMenuItemsHookedUp) { // translate" mode doesn't trigger a translation or change state. // http://crbug.com/36666 TEST_F(TranslationInfoBarTest, Bug36666) { - EXPECT_CALL(*infobar_delegate_, Translate()) + CreateInfoBar(TranslateInfoBarDelegate::BEFORE_TRANSLATE); + EXPECT_CALL(*infobar_delegate(), Translate()) .Times(0); - CreateInfoBar(); int arbitrary_index = 2; [infobar_controller_ sourceLanguageModified:arbitrary_index]; - EXPECT_CALL(*infobar_delegate_, Translate()) + EXPECT_CALL(*infobar_delegate(), Translate()) .Times(0); } @@ -212,11 +224,10 @@ TEST_F(TranslationInfoBarTest, Bug36666) { // each of the states. // http://crbug.com/36895 TEST_F(TranslationInfoBarTest, Bug36895) { - EXPECT_CALL(*infobar_delegate_, Translate()) - .Times(0); - for (size_t i = 0; i < arraysize(kTranslateToolbarStates); ++i) { CreateInfoBar(kTranslateToolbarStates[i]); + EXPECT_CALL(*infobar_delegate(), Translate()) + .Times(0); EXPECT_TRUE( [infobar_controller_ verifyLayout]) << "Layout wrong, for state #" << i; } @@ -251,5 +262,3 @@ TEST_F(TranslationInfoBarTest, TriggerShowNeverTranslateButton) { EXPECT_TRUE([[controller alwaysTranslateButton] superview] == nil); EXPECT_TRUE([[controller neverTranslateButton] superview] != nil); } - -} // namespace diff --git a/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm b/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm index 5f04437..b25ab67 100644 --- a/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm +++ b/chrome/browser/ui/cocoa/keystone_infobar_delegate.mm @@ -15,6 +15,7 @@ #include "base/prefs/pref_service.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #import "chrome/browser/mac/keystone_glue.h" #include "chrome/browser/profiles/profile.h" @@ -43,8 +44,7 @@ class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { static void Create(); private: - KeystonePromotionInfoBarDelegate(InfoBarService* infobar_service, - PrefService* prefs); + explicit KeystonePromotionInfoBarDelegate(PrefService* prefs); virtual ~KeystonePromotionInfoBarDelegate(); // Sets this info bar to be able to expire. Called a predetermined amount @@ -83,17 +83,15 @@ void KeystonePromotionInfoBarDelegate::Create() { return; InfoBarService* infobar_service = InfoBarService::FromWebContents(webContents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new KeystonePromotionInfoBarDelegate( - infobar_service, + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new KeystonePromotionInfoBarDelegate( Profile::FromBrowserContext( - webContents->GetBrowserContext())->GetPrefs()))); + webContents->GetBrowserContext())->GetPrefs())))); } KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( - InfoBarService* infobar_service, PrefService* prefs) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), prefs_(prefs), can_expire_(false), weak_ptr_factory_(this) { diff --git a/chrome/browser/ui/collected_cookies_infobar_delegate.cc b/chrome/browser/ui/collected_cookies_infobar_delegate.cc index b60761e..775b02e 100644 --- a/chrome/browser/ui/collected_cookies_infobar_delegate.cc +++ b/chrome/browser/ui/collected_cookies_infobar_delegate.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/collected_cookies_infobar_delegate.h" #include "base/logging.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" @@ -14,13 +15,13 @@ // static void CollectedCookiesInfoBarDelegate::Create(InfoBarService* infobar_service) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new CollectedCookiesInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new CollectedCookiesInfoBarDelegate()))); } -CollectedCookiesInfoBarDelegate::CollectedCookiesInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +CollectedCookiesInfoBarDelegate::CollectedCookiesInfoBarDelegate() + : ConfirmInfoBarDelegate() { } CollectedCookiesInfoBarDelegate::~CollectedCookiesInfoBarDelegate() { diff --git a/chrome/browser/ui/collected_cookies_infobar_delegate.h b/chrome/browser/ui/collected_cookies_infobar_delegate.h index 2023026..2fb053a 100644 --- a/chrome/browser/ui/collected_cookies_infobar_delegate.h +++ b/chrome/browser/ui/collected_cookies_infobar_delegate.h @@ -16,12 +16,12 @@ class InfoBarService; // the reload right from the infobar. class CollectedCookiesInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a collected cookies infobar delegate and adds it to + // Creates a collected cookies infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit CollectedCookiesInfoBarDelegate(InfoBarService* infobar_service); + CollectedCookiesInfoBarDelegate(); virtual ~CollectedCookiesInfoBarDelegate(); // ConfirmInfoBarDelegate: 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 8274edd..6e99a43 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 @@ -236,13 +236,9 @@ TEST_F(ContentSettingBubbleModelTest, BlockedMediastreamMicAndCamera) { CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string())); - // Removing an |InfoBarDelegate| from the |InfoBarService| does not delete - // it. Hence the |delegate| must be cleaned up after it was removed from the - // |infobar_service|. InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents()); - scoped_ptr<InfoBarDelegate> delegate(infobar_service->infobar_at(0)); - infobar_service->RemoveInfoBar(delegate.get()); + infobar_service->RemoveInfoBar(infobar_service->infobar_at(0)); } TEST_F(ContentSettingBubbleModelTest, MediastreamMic) { diff --git a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc index 8c1f841..7a93d5d 100644 --- a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc +++ b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h" #include "base/logging.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" @@ -14,13 +15,13 @@ // static void MediaSettingChangedInfoBarDelegate::Create( InfoBarService* infobar_service) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new MediaSettingChangedInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new MediaSettingChangedInfoBarDelegate()))); } -MediaSettingChangedInfoBarDelegate::MediaSettingChangedInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +MediaSettingChangedInfoBarDelegate::MediaSettingChangedInfoBarDelegate() + : ConfirmInfoBarDelegate() { } MediaSettingChangedInfoBarDelegate::~MediaSettingChangedInfoBarDelegate() { diff --git a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h index cbd459e..7fdbe86 100644 --- a/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h +++ b/chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h @@ -13,12 +13,12 @@ class InfoBarService; // settings, and allows a reload via a button on the infobar. class MediaSettingChangedInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a media setting changed infobar delegate and adds it to - // |infobar_service|. + // Creates a media setting changed infobar and delegate and adds the infobar + // to |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit MediaSettingChangedInfoBarDelegate(InfoBarService* infobar_service); + MediaSettingChangedInfoBarDelegate(); virtual ~MediaSettingChangedInfoBarDelegate(); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/ui/extensions/extension_install_ui_default.cc b/chrome/browser/ui/extensions/extension_install_ui_default.cc index 8ebb594..cec3a91 100644 --- a/chrome/browser/ui/extensions/extension_install_ui_default.cc +++ b/chrome/browser/ui/extensions/extension_install_ui_default.cc @@ -11,6 +11,7 @@ #include "chrome/browser/extensions/extension_install_prompt.h" #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" @@ -80,13 +81,13 @@ void ShowExtensionInstalledBubble(const extensions::Extension* extension, // Helper class to put up an infobar when installation fails. class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an error infobar delegate and adds it to |infobar_service|. + // Creates an error infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, const extensions::CrxInstallerError& error); private: - ErrorInfoBarDelegate(InfoBarService* infobar_service, - const extensions::CrxInstallerError& error); + explicit ErrorInfoBarDelegate(const extensions::CrxInstallerError& error); virtual ~ErrorInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -103,14 +104,13 @@ class ErrorInfoBarDelegate : public ConfirmInfoBarDelegate { // static void ErrorInfoBarDelegate::Create(InfoBarService* infobar_service, const extensions::CrxInstallerError& error) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ErrorInfoBarDelegate(infobar_service, error))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new ErrorInfoBarDelegate(error)))); } ErrorInfoBarDelegate::ErrorInfoBarDelegate( - InfoBarService* infobar_service, const extensions::CrxInstallerError& error) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), error_(error) { } diff --git a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc index bb68ff6..41c27e8 100644 --- a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.cc @@ -15,17 +15,16 @@ #include "ui/base/l10n/l10n_util.h" AfterTranslateInfoBar::AfterTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), weak_factory_(this) { } AfterTranslateInfoBar::~AfterTranslateInfoBar() { } -void AfterTranslateInfoBar::InitWidgets() { - TranslateInfoBarBase::InitWidgets(); +void AfterTranslateInfoBar::PlatformSpecificSetOwner() { + TranslateInfoBarBase::PlatformSpecificSetOwner(); bool swapped_language_combos = false; bool autodetermined_source_language = diff --git a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h index 8366119..000f2fd 100644 --- a/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/after_translate_infobar_gtk.h @@ -13,14 +13,13 @@ class TranslateInfoBarDelegate; class AfterTranslateInfoBar : public TranslateInfoBarBase { public: - AfterTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit AfterTranslateInfoBar(scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~AfterTranslateInfoBar(); // TranslateInfoBarBase: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual bool ShowOptionsMenuButton() const OVERRIDE; // These methods set the original/target language on the diff --git a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc index 68fbad9..a70d634 100644 --- a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.cc @@ -10,24 +10,25 @@ // AlternateNavInfoBarDelegate ------------------------------------------------- -InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new AlternateNavInfoBarGtk(owner, this); +// static +scoped_ptr<InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new AlternateNavInfoBarGtk(delegate.Pass())); } // AlternateNavInfoBarGtk ------------------------------------------------------ AlternateNavInfoBarGtk::AlternateNavInfoBarGtk( - InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate) { + scoped_ptr<AlternateNavInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()) { } AlternateNavInfoBarGtk::~AlternateNavInfoBarGtk() { } -void AlternateNavInfoBarGtk::InitWidgets() { - InfoBarGtk::InitWidgets(); +void AlternateNavInfoBarGtk::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); size_t link_offset; string16 display_text = GetDelegate()->GetMessageTextWithOffset(&link_offset); diff --git a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h index 9cf6a79..45f3e00 100644 --- a/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/alternate_nav_infobar_gtk.h @@ -5,7 +5,7 @@ #ifndef CHROME_BROWSER_UI_GTK_INFOBARS_ALTERNATE_NAV_INFOBAR_GTK_H_ #define CHROME_BROWSER_UI_GTK_INFOBARS_ALTERNATE_NAV_INFOBAR_GTK_H_ -#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" #include "ui/base/gtk/gtk_signal.h" @@ -14,14 +14,14 @@ class AlternateNavInfoBarDelegate; // An infobar that shows a string with an embedded link. class AlternateNavInfoBarGtk : public InfoBarGtk { public: - AlternateNavInfoBarGtk(InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate); + explicit AlternateNavInfoBarGtk( + scoped_ptr<AlternateNavInfoBarDelegate> delegate); private: virtual ~AlternateNavInfoBarGtk(); // InfoBarGtk: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; AlternateNavInfoBarDelegate* GetDelegate(); diff --git a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc index 86de96f..ee8e228 100644 --- a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.cc @@ -13,16 +13,15 @@ #include "ui/base/l10n/l10n_util.h" BeforeTranslateInfoBar::BeforeTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate) { + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()) { } BeforeTranslateInfoBar::~BeforeTranslateInfoBar() { } -void BeforeTranslateInfoBar::InitWidgets() { - TranslateInfoBarBase::InitWidgets(); +void BeforeTranslateInfoBar::PlatformSpecificSetOwner() { + TranslateInfoBarBase::PlatformSpecificSetOwner(); GtkWidget* new_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); gtk_util::CenterWidgetInHBox(hbox(), new_hbox, false, 0); diff --git a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h index 3e46456..25753be 100644 --- a/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/before_translate_infobar_gtk.h @@ -12,14 +12,14 @@ class TranslateInfoBarDelegate; class BeforeTranslateInfoBar : public TranslateInfoBarBase { public: - BeforeTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit BeforeTranslateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~BeforeTranslateInfoBar(); // TranslateInfoBarBase: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual bool ShowOptionsMenuButton() const OVERRIDE; CHROMEGTK_CALLBACK_0(BeforeTranslateInfoBar, void, OnLanguageModified); diff --git a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc index e5ca3cb..fbdfdb5 100644 --- a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.cc @@ -16,16 +16,18 @@ // ConfirmInfoBarDelegate ------------------------------------------------------ -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ConfirmInfoBarGtk(owner, this); +// static +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ConfirmInfoBarGtk(delegate.Pass())); } // ConfirmInfoBarGtk ----------------------------------------------------------- -ConfirmInfoBarGtk::ConfirmInfoBarGtk(InfoBarService* owner, - ConfirmInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate), +ConfirmInfoBarGtk::ConfirmInfoBarGtk( + scoped_ptr<ConfirmInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()), confirm_hbox_(NULL), size_group_(NULL) { } @@ -35,8 +37,8 @@ ConfirmInfoBarGtk::~ConfirmInfoBarGtk() { g_object_unref(size_group_); } -void ConfirmInfoBarGtk::InitWidgets() { - InfoBarGtk::InitWidgets(); +void ConfirmInfoBarGtk::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); confirm_hbox_ = gtk_chrome_shrinkable_hbox_new(FALSE, FALSE, kEndOfLabelSpacing); diff --git a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h index 3173efb..f670ca3 100644 --- a/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/confirm_infobar_gtk.h @@ -18,14 +18,13 @@ typedef struct _GtkWidget GtkWidget; // "Would you like to do X? [Yes] [No] _Learn More_ [x]" class ConfirmInfoBarGtk : public InfoBarGtk { public: - ConfirmInfoBarGtk(InfoBarService* owner, - ConfirmInfoBarDelegate* delegate); + explicit ConfirmInfoBarGtk(scoped_ptr<ConfirmInfoBarDelegate> delegate); private: virtual ~ConfirmInfoBarGtk(); // InfoBarGtk: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; ConfirmInfoBarDelegate* GetDelegate(); diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc index 9ddfe4d..8cc4366 100644 --- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc @@ -31,52 +31,32 @@ // ExtensionInfoBarDelegate --------------------------------------------------- -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ExtensionInfoBarGtk(owner, this); +// static +scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ExtensionInfoBarGtk(delegate.Pass())); } // ExtensionInfoBarGtk -------------------------------------------------------- -ExtensionInfoBarGtk::ExtensionInfoBarGtk(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate), - delegate_(delegate), +ExtensionInfoBarGtk::ExtensionInfoBarGtk( + scoped_ptr<ExtensionInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()), view_(NULL), button_(NULL), icon_(NULL), alignment_(NULL), weak_ptr_factory_(this) { - GetDelegate()->set_observer(this); - int height = GetDelegate()->height(); SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); } ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { - if (GetDelegate()) - GetDelegate()->set_observer(NULL); } -void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) { - DCHECK(view_); - DCHECK(alignment_); - gtk_util::RemoveAllChildren(alignment_); -} - -void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - // Extension infobars are always drawn with chrome-theme colors. - *r = *g = *b = 233.0 / 255.0; -} - -void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - *r = *g = *b = 218.0 / 255.0; -} - -void ExtensionInfoBarGtk::InitWidgets() { - InfoBarGtk::InitWidgets(); +void ExtensionInfoBarGtk::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); // Always render the close button as if we were doing chrome style widget // rendering. For extension infobars, we force chrome style rendering because @@ -142,15 +122,28 @@ void ExtensionInfoBarGtk::InitWidgets() { G_CALLBACK(&OnSizeAllocateThunk), this); } +void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) { + DCHECK(view_); + DCHECK(alignment_); + gtk_util::RemoveAllChildren(alignment_); +} + +void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + // Extension infobars are always drawn with chrome-theme colors. + *r = *g = *b = 233.0 / 255.0; +} + +void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + *r = *g = *b = 218.0 / 255.0; +} + void ExtensionInfoBarGtk::StoppedShowing() { if (button_) gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_)); } -void ExtensionInfoBarGtk::OnDelegateDeleted() { - delegate_ = NULL; -} - void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { DCHECK(icon_); @@ -188,7 +181,7 @@ void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { } ExtensionInfoBarDelegate* ExtensionInfoBarGtk::GetDelegate() { - return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; + return delegate()->AsExtensionInfoBarDelegate(); } Browser* ExtensionInfoBarGtk::GetBrowser() { diff --git a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h index 71c9c2a..af6a856 100644 --- a/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h @@ -16,30 +16,24 @@ class ExtensionContextMenuModel; class ExtensionViewGtk; class MenuGtk; -class ExtensionInfoBarGtk : public InfoBarGtk, - public MenuGtk::Delegate, - public ExtensionInfoBarDelegate::DelegateObserver { +class ExtensionInfoBarGtk : public InfoBarGtk, public MenuGtk::Delegate { public: - ExtensionInfoBarGtk(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate); + explicit ExtensionInfoBarGtk(scoped_ptr<ExtensionInfoBarDelegate> delegate); private: virtual ~ExtensionInfoBarGtk(); // InfoBarGtk: + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual void PlatformSpecificHide(bool animate) OVERRIDE; virtual void GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; virtual void GetBottomColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; - virtual void InitWidgets() OVERRIDE; // MenuGtk::Delegate: virtual void StoppedShowing() OVERRIDE; - // ExtensionInfoBarDelegate::DelegateObserver: - virtual void OnDelegateDeleted() OVERRIDE; - void OnImageLoaded(const gfx::Image& image); ExtensionInfoBarDelegate* GetDelegate(); @@ -61,11 +55,6 @@ class ExtensionInfoBarGtk : public InfoBarGtk, CHROMEGTK_CALLBACK_1(ExtensionInfoBarGtk, gboolean, OnExpose, GdkEventExpose*); - // TODO(pkasting): This shadows InfoBarView::delegate_. Get rid of this once - // InfoBars own their delegates (and thus we don't need the DelegateObserver - // functionality). For now, almost everyone should use GetDelegate() instead. - InfoBarDelegate* delegate_; - ExtensionViewGtk* view_; // The button that activates the extension popup menu. Non-NULL if the diff --git a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc index 6edd5d9..78f1116 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc @@ -8,7 +8,6 @@ #include <utility> -#include "base/message_loop/message_loop.h" #include "chrome/browser/infobars/infobar_delegate.h" #include "chrome/browser/platform_util.h" #include "chrome/browser/ui/browser_window.h" @@ -53,7 +52,6 @@ bool InfoBarContainerGtk::ContainsInfobars() const { void InfoBarContainerGtk::PlatformSpecificAddInfoBar(InfoBar* infobar, size_t position) { InfoBarGtk* infobar_gtk = static_cast<InfoBarGtk*>(infobar); - infobar_gtk->InitWidgets(); infobars_gtk_.insert(infobars_gtk_.begin() + position, infobar_gtk); if (infobars_gtk_.back() == infobar_gtk) { @@ -81,8 +79,6 @@ void InfoBarContainerGtk::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { std::find(infobars_gtk_.begin(), infobars_gtk_.end(), infobar); if (it != infobars_gtk_.end()) infobars_gtk_.erase(it); - - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); } void InfoBarContainerGtk::PlatformSpecificInfoBarStateChanged( diff --git a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc index ed157ec..514d9a7 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/infobar_gtk.cc @@ -52,8 +52,8 @@ const int InfoBar::kDefaultBarTargetHeight = 36; // static const int InfoBarGtk::kEndOfLabelSpacing = 6; -InfoBarGtk::InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate), +InfoBarGtk::InfoBarGtk(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()), bg_box_(NULL), hbox_(NULL), theme_service_(NULL), @@ -63,7 +63,32 @@ InfoBarGtk::InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate) InfoBarGtk::~InfoBarGtk() { } -void InfoBarGtk::InitWidgets() { +GdkColor InfoBarGtk::GetBorderColor() const { + DCHECK(theme_service_); + return theme_service_->GetBorderColor(); +} + +int InfoBarGtk::AnimatingHeight() const { + return animation().is_animating() ? bar_target_height() : 0; +} + +SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) { + double r, g, b; + (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b); + return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b); +} + +void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + GetBackgroundColor(InfoBar::GetTopColor(type), r, g, b); +} + +void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, + double* r, double* g, double* b) { + GetBackgroundColor(InfoBar::GetBottomColor(type), r, g, b); +} + +void InfoBarGtk::PlatformSpecificSetOwner() { DCHECK(owner()); DCHECK(!theme_service_); theme_service_ = GtkThemeService::GetFrom(Profile::FromBrowserContext( @@ -114,31 +139,6 @@ void InfoBarGtk::InitWidgets() { UpdateBorderColor(); } -GdkColor InfoBarGtk::GetBorderColor() const { - DCHECK(theme_service_); - return theme_service_->GetBorderColor(); -} - -int InfoBarGtk::AnimatingHeight() const { - return animation().is_animating() ? bar_target_height() : 0; -} - -SkColor InfoBarGtk::ConvertGetColor(ColorGetter getter) { - double r, g, b; - (this->*getter)(delegate()->GetInfoBarType(), &r, &g, &b); - return SkColorSetARGB(255, 255 * r, 255 * g, 255 * b); -} - -void InfoBarGtk::GetTopColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - GetBackgroundColor(InfoBar::GetTopColor(type), r, g, b); -} - -void InfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, - double* r, double* g, double* b) { - GetBackgroundColor(InfoBar::GetBottomColor(type), r, g, b); -} - void InfoBarGtk::PlatformSpecificShow(bool animate) { DCHECK(bg_box_); @@ -274,7 +274,7 @@ void InfoBarGtk::UpdateBorderColor() { void InfoBarGtk::OnCloseButton(GtkWidget* button) { // If we're not owned, we're already closing, so don't call // InfoBarDismissed(), since this can lead to us double-recording dismissals. - if (delegate() && owner()) + if (owner()) delegate()->InfoBarDismissed(); RemoveSelf(); } diff --git a/chrome/browser/ui/gtk/infobars/infobar_gtk.h b/chrome/browser/ui/gtk/infobars/infobar_gtk.h index 9b77635..e9e1d44 100644 --- a/chrome/browser/ui/gtk/infobars/infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/infobar_gtk.h @@ -33,21 +33,9 @@ class InfoBarGtk : public InfoBar, typedef void (InfoBarGtk::*ColorGetter)(InfoBarDelegate::Type, double* r, double* g, double* b); - InfoBarGtk(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarGtk(scoped_ptr<InfoBarDelegate> delegate); virtual ~InfoBarGtk(); - // Must be called before we try to show the infobar. Inits any widgets and - // related objects necessary. This must be called only once during the - // infobar's life. - // - // NOTE: Subclasses who need to init widgets should override this function and - // explicitly call their parent's implementation first, then continue with - // further work they need to do. Failing to call the parent implementation - // first (or at all), or setting up widgets in the constructor instead of - // here, will lead to bad side effects like crashing or having this function - // get called repeatedly. - virtual void InitWidgets(); - // Get the top level native GTK widget for this infobar. GtkWidget* widget() { return widget_.get(); } @@ -72,6 +60,16 @@ class InfoBarGtk : public InfoBar, static const int kEndOfLabelSpacing; // InfoBar: + + // Inits any widgets and related objects necessary. + // + // NOTE: Subclasses who need to init widgets should override this function and + // explicitly call their parent's implementation first, then continue with + // further work they need to do. Failing to call the parent implementation + // first (or at all), or setting up widgets in the constructor instead of + // here, will lead to bad side effects like crashing. + virtual void PlatformSpecificSetOwner() OVERRIDE; + virtual void PlatformSpecificShow(bool animate) OVERRIDE; virtual void PlatformSpecificOnCloseSoon() OVERRIDE; virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE; diff --git a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc index 686743c..a2489a6 100644 --- a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.cc @@ -21,24 +21,27 @@ // TranslateInfoBarDelegate --------------------------------------------------- -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - if (infobar_type_ == BEFORE_TRANSLATE) - return new BeforeTranslateInfoBar(owner, this); - if (infobar_type_ == AFTER_TRANSLATE) - return new AfterTranslateInfoBar(owner, this); - return new TranslateMessageInfoBar(owner, this); +// static +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + if (delegate->infobar_type() == BEFORE_TRANSLATE) + return scoped_ptr<InfoBar>(new BeforeTranslateInfoBar(delegate.Pass())); + if (delegate->infobar_type() == AFTER_TRANSLATE) + return scoped_ptr<InfoBar>(new AfterTranslateInfoBar(delegate.Pass())); + return scoped_ptr<InfoBar>(new TranslateMessageInfoBar(delegate.Pass())); } // TranslateInfoBarBase ------------------------------------------------------- -TranslateInfoBarBase::TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : InfoBarGtk(owner, delegate), +TranslateInfoBarBase::TranslateInfoBarBase( + scoped_ptr<TranslateInfoBarDelegate> delegate) + : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()), background_error_percent_(0) { - DCHECK(delegate); + TranslateInfoBarDelegate* translate_delegate = GetDelegate(); + DCHECK(translate_delegate); TranslateInfoBarDelegate::BackgroundAnimationType animation = - delegate->background_animation_type(); + translate_delegate->background_animation_type(); if (animation != TranslateInfoBarDelegate::NONE) { background_color_animation_.reset(new gfx::SlideAnimation(this)); background_color_animation_->SetTweenType(gfx::Tween::LINEAR); @@ -52,7 +55,7 @@ TranslateInfoBarBase::TranslateInfoBarBase(InfoBarService* owner, background_color_animation_->Hide(); } } else { - background_error_percent_ = delegate->is_error() ? 1 : 0; + background_error_percent_ = translate_delegate->is_error() ? 1 : 0; } } @@ -71,6 +74,22 @@ void TranslateInfoBarBase::AnimationProgressed( } } +void TranslateInfoBarBase::PlatformSpecificSetOwner() { + InfoBarGtk::PlatformSpecificSetOwner(); + + if (!ShowOptionsMenuButton()) + return; + + // The options button sits outside the translate_box so that it can be end + // packed in hbox(). + GtkWidget* options_menu_button = CreateMenuButton( + l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS)); + signals()->Connect(options_menu_button, "clicked", + G_CALLBACK(&OnOptionsClickedThunk), this); + gtk_widget_show_all(options_menu_button); + gtk_util::CenterWidgetInHBox(hbox(), options_menu_button, true, 0); +} + void TranslateInfoBarBase::GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double* b) { if (background_error_percent_ <= 0) { @@ -121,22 +140,6 @@ void TranslateInfoBarBase::GetBottomColor(InfoBarDelegate::Type type, } } -void TranslateInfoBarBase::InitWidgets() { - InfoBarGtk::InitWidgets(); - - if (!ShowOptionsMenuButton()) - return; - - // The options button sits outside the translate_box so that it can be end - // packed in hbox(). - GtkWidget* options_menu_button = CreateMenuButton( - l10n_util::GetStringUTF8(IDS_TRANSLATE_INFOBAR_OPTIONS)); - signals()->Connect(options_menu_button, "clicked", - G_CALLBACK(&OnOptionsClickedThunk), this); - gtk_widget_show_all(options_menu_button); - gtk_util::CenterWidgetInHBox(hbox(), options_menu_button, true, 0); -} - bool TranslateInfoBarBase::ShowOptionsMenuButton() const { return false; } diff --git a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h index 863c7eb..6892e66 100644 --- a/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h +++ b/chrome/browser/ui/gtk/infobars/translate_infobar_base_gtk.h @@ -15,17 +15,16 @@ class TranslateInfoBarDelegate; // use. class TranslateInfoBarBase : public InfoBarGtk { protected: - TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateInfoBarBase(scoped_ptr<TranslateInfoBarDelegate> delegate); virtual ~TranslateInfoBarBase(); // InfoBarGtk: virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; virtual void GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; virtual void GetBottomColor(InfoBarDelegate::Type type, double* r, double* g, double* b) OVERRIDE; - virtual void InitWidgets() OVERRIDE; // Sub-classes that want to have the options menu button showing should // override and return true. diff --git a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc index 08f7897..e7938cb 100644 --- a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.cc @@ -11,16 +11,15 @@ #include "ui/base/gtk/gtk_signal_registrar.h" TranslateMessageInfoBar::TranslateMessageInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate) { + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()) { } TranslateMessageInfoBar::~TranslateMessageInfoBar() { } -void TranslateMessageInfoBar::InitWidgets() { - TranslateInfoBarBase::InitWidgets(); +void TranslateMessageInfoBar::PlatformSpecificSetOwner() { + TranslateInfoBarBase::PlatformSpecificSetOwner(); GtkWidget* new_hbox = gtk_hbox_new(FALSE, ui::kControlSpacing); gtk_util::CenterWidgetInHBox(hbox(), new_hbox, false, 0); diff --git a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h index adb38ec..bd08697 100644 --- a/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobars/translate_message_infobar_gtk.h @@ -12,14 +12,14 @@ class TranslateInfoBarDelegate; class TranslateMessageInfoBar : public TranslateInfoBarBase { public: - TranslateMessageInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateMessageInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~TranslateMessageInfoBar(); // TranslateInfoBarBase: - virtual void InitWidgets() OVERRIDE; + virtual void PlatformSpecificSetOwner() OVERRIDE; CHROMEGTK_CALLBACK_0(TranslateMessageInfoBar, void, OnButtonPressed); diff --git a/chrome/browser/ui/hung_plugin_tab_helper.cc b/chrome/browser/ui/hung_plugin_tab_helper.cc index 0269aea..c4da8bd 100644 --- a/chrome/browser/ui/hung_plugin_tab_helper.cc +++ b/chrome/browser/ui/hung_plugin_tab_helper.cc @@ -130,16 +130,15 @@ void KillPluginOnIOThread(int child_id) { class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a hung plugin infobar delegate and adds it to |infobar_service|. - // Returns the delegate if it was successfully added. - static HungPluginInfoBarDelegate* Create(InfoBarService* infobar_service, - HungPluginTabHelper* helper, - int plugin_child_id, - const string16& plugin_name); + // Creates a hung plugin infobar and delegate and adds the infobar to + // |infobar_service|. Returns the infobar if it was successfully added. + static InfoBar* Create(InfoBarService* infobar_service, + HungPluginTabHelper* helper, + int plugin_child_id, + const string16& plugin_name); private: HungPluginInfoBarDelegate(HungPluginTabHelper* helper, - InfoBarService* infobar_service, int plugin_child_id, const string16& plugin_name); virtual ~HungPluginInfoBarDelegate(); @@ -159,22 +158,20 @@ class HungPluginInfoBarDelegate : public ConfirmInfoBarDelegate { }; // static -HungPluginInfoBarDelegate* HungPluginInfoBarDelegate::Create( - InfoBarService* infobar_service, - HungPluginTabHelper* helper, - int plugin_child_id, - const string16& plugin_name) { - return static_cast<HungPluginInfoBarDelegate*>(infobar_service->AddInfoBar( - scoped_ptr<InfoBarDelegate>(new HungPluginInfoBarDelegate( - helper, infobar_service, plugin_child_id, plugin_name)))); +InfoBar* HungPluginInfoBarDelegate::Create(InfoBarService* infobar_service, + HungPluginTabHelper* helper, + int plugin_child_id, + const string16& plugin_name) { + return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new HungPluginInfoBarDelegate( + helper, plugin_child_id, plugin_name)))); } HungPluginInfoBarDelegate::HungPluginInfoBarDelegate( HungPluginTabHelper* helper, - InfoBarService* infobar_service, int plugin_child_id, const string16& plugin_name) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), helper_(helper), plugin_child_id_(plugin_child_id), message_(l10n_util::GetStringFUTF16( @@ -223,7 +220,7 @@ struct HungPluginTabHelper::PluginState { string16 name; // Possibly-null if we're not showing an infobar right now. - InfoBarDelegate* infobar; + InfoBar* infobar; // Time to delay before re-showing the infobar for a hung plugin. This is // increased each time the user cancels it. @@ -327,14 +324,7 @@ void HungPluginTabHelper::Observe( const content::NotificationSource& source, const content::NotificationDetails& details) { DCHECK_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, type); - // Note: do not dereference. The InfoBarContainer will delete the object when - // it gets this notification, we only remove our tracking info, if we have - // any. - // - // TODO(pkasting): This comment will be incorrect and should be removed once - // InfoBars own their delegates. - InfoBarDelegate* infobar = - content::Details<InfoBar::RemovedDetails>(details)->first; + InfoBar* infobar = content::Details<InfoBar::RemovedDetails>(details)->first; for (PluginStateMap::iterator i = hung_plugins_.begin(); i != hung_plugins_.end(); ++i) { PluginState* state = i->second.get(); diff --git a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc index 47bd530..d1b5bc4 100644 --- a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc +++ b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.cc @@ -9,6 +9,7 @@ #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/shortcuts_backend.h" #include "chrome/browser/history/shortcuts_backend_factory.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "content/public/browser/web_contents.h" @@ -17,6 +18,9 @@ #include "ui/base/l10n/l10n_util.h" +AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { +} + // static void AlternateNavInfoBarDelegate::Create( content::WebContents* web_contents, @@ -25,20 +29,18 @@ void AlternateNavInfoBarDelegate::Create( const GURL& search_url) { InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new AlternateNavInfoBarDelegate( - infobar_service, + infobar_service->AddInfoBar(AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate>(new AlternateNavInfoBarDelegate( Profile::FromBrowserContext(web_contents->GetBrowserContext()), text, - match, search_url))); + match, search_url)))); } AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( - InfoBarService* owner, Profile* profile, const string16& text, const AutocompleteMatch& match, const GURL& search_url) - : InfoBarDelegate(owner), + : InfoBarDelegate(), profile_(profile), text_(text), match_(match), @@ -47,8 +49,8 @@ AlternateNavInfoBarDelegate::AlternateNavInfoBarDelegate( DCHECK(search_url_.is_valid()); } -AlternateNavInfoBarDelegate::~AlternateNavInfoBarDelegate() { -} +// AlternateNavInfoBarDelegate::CreateInfoBar() is implemented in +// platform-specific files. string16 AlternateNavInfoBarDelegate::GetMessageTextWithOffset( size_t* link_offset) const { diff --git a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h index 4eaba50..7c92901 100644 --- a/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h +++ b/chrome/browser/ui/omnibox/alternate_nav_infobar_delegate.h @@ -5,15 +5,16 @@ #ifndef CHROME_BROWSER_UI_OMNIBOX_ALTERNATE_NAV_INFOBAR_DELEGATE_H_ #define CHROME_BROWSER_UI_OMNIBOX_ALTERNATE_NAV_INFOBAR_DELEGATE_H_ -#include "base/basictypes.h" -#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/infobars/infobar_delegate.h" class AlternateNavInfoBarDelegate : public InfoBarDelegate { public: - // Creates an alternate nav infobar delegate and adds it to the infobar - // service for |web_contents|. + virtual ~AlternateNavInfoBarDelegate(); + + // Creates an alternate nav infobar and delegate and adds the infobar to the + // infobar service for |web_contents|. static void Create(content::WebContents* web_contents, const string16& text, const AutocompleteMatch& match, @@ -24,15 +25,16 @@ class AlternateNavInfoBarDelegate : public InfoBarDelegate { bool LinkClicked(WindowOpenDisposition disposition); private: - AlternateNavInfoBarDelegate(InfoBarService* owner, - Profile* profile, + AlternateNavInfoBarDelegate(Profile* profile, const string16& text, const AutocompleteMatch& match, const GURL& search_url); - virtual ~AlternateNavInfoBarDelegate(); + + // Returns an alternate nav infobar that owns |delegate|. + static scoped_ptr<InfoBar> CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate); // InfoBarDelegate: - virtual InfoBar* CreateInfoBar(InfoBarService* owner) OVERRIDE; virtual int GetIconID() const OVERRIDE; virtual Type GetInfoBarType() const OVERRIDE; diff --git a/chrome/browser/ui/startup/autolaunch_prompt_win.cc b/chrome/browser/ui/startup/autolaunch_prompt_win.cc index 4471fca..c10eab7 100644 --- a/chrome/browser/ui/startup/autolaunch_prompt_win.cc +++ b/chrome/browser/ui/startup/autolaunch_prompt_win.cc @@ -11,6 +11,7 @@ #include "chrome/browser/auto_launch_trial.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" @@ -36,12 +37,12 @@ namespace { // The delegate for the infobar shown when Chrome is auto-launched. class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an autolaunch infobar delegate and adds it to |infobar_service|. + // Creates an autolaunch infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service, Profile* profile); private: - AutolaunchInfoBarDelegate(InfoBarService* infobar_service, - Profile* profile); + explicit AutolaunchInfoBarDelegate(Profile* profile); virtual ~AutolaunchInfoBarDelegate(); void set_should_expire() { should_expire_ = true; } @@ -70,14 +71,14 @@ class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { // static void AutolaunchInfoBarDelegate::Create(InfoBarService* infobar_service, Profile* profile) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new AutolaunchInfoBarDelegate(infobar_service, profile))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new AutolaunchInfoBarDelegate(profile)))); } AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( - InfoBarService* infobar_service, Profile* profile) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), profile_(profile), should_expire_(false), weak_factory_(this) { diff --git a/chrome/browser/ui/startup/default_browser_prompt.cc b/chrome/browser/ui/startup/default_browser_prompt.cc index 786dcad..e24fe2c 100644 --- a/chrome/browser/ui/startup/default_browser_prompt.cc +++ b/chrome/browser/ui/startup/default_browser_prompt.cc @@ -13,6 +13,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/shell_integration.h" @@ -58,15 +59,14 @@ void SetChromeAsDefaultBrowser(bool interactive_flow, PrefService* prefs) { // The delegate for the infobar shown when Chrome is not the default browser. class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a default browser infobar delegate and adds it to + // Creates a default browser infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service, PrefService* prefs, bool interactive_flow_required); private: - DefaultBrowserInfoBarDelegate(InfoBarService* infobar_service, - PrefService* prefs, + DefaultBrowserInfoBarDelegate(PrefService* prefs, bool interactive_flow_required); virtual ~DefaultBrowserInfoBarDelegate(); @@ -105,16 +105,15 @@ class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service, PrefService* prefs, bool interactive_flow_required) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new DefaultBrowserInfoBarDelegate(infobar_service, prefs, - interactive_flow_required))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new DefaultBrowserInfoBarDelegate( + prefs, interactive_flow_required)))); } DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( - InfoBarService* infobar_service, PrefService* prefs, bool interactive_flow_required) - : ConfirmInfoBarDelegate(infobar_service), + : ConfirmInfoBarDelegate(), prefs_(prefs), action_taken_(false), should_expire_(false), diff --git a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc index 42f1d55..7db67d4 100644 --- a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc +++ b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/startup/google_api_keys_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "google_apis/google_api_keys.h" @@ -17,13 +18,12 @@ void GoogleApiKeysInfoBarDelegate::Create(InfoBarService* infobar_service) { if (google_apis::HasKeysConfigured()) return; - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new GoogleApiKeysInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new GoogleApiKeysInfoBarDelegate()))); } -GoogleApiKeysInfoBarDelegate::GoogleApiKeysInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +GoogleApiKeysInfoBarDelegate::GoogleApiKeysInfoBarDelegate() + : ConfirmInfoBarDelegate() { } GoogleApiKeysInfoBarDelegate::~GoogleApiKeysInfoBarDelegate() { diff --git a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h index dad3bf5..c949761 100644 --- a/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h +++ b/chrome/browser/ui/startup/google_api_keys_infobar_delegate.h @@ -16,11 +16,11 @@ class InfoBarService; class GoogleApiKeysInfoBarDelegate : public ConfirmInfoBarDelegate { public: // If Google API keys are missing, creates a missing Google API Keys infobar - // delegate and adds it to |infobar_service|. + // and delegate and adds the infobar to |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit GoogleApiKeysInfoBarDelegate(InfoBarService* infobar_service); + GoogleApiKeysInfoBarDelegate(); virtual ~GoogleApiKeysInfoBarDelegate(); virtual string16 GetMessageText() const OVERRIDE; diff --git a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc index 359e755..b2bbeaa 100644 --- a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc +++ b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/startup/obsolete_os_infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/chromium_strings.h" @@ -35,13 +36,12 @@ void ObsoleteOSInfoBarDelegate::Create(InfoBarService* infobar_service) { return; #endif - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new ObsoleteOSInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>(new ObsoleteOSInfoBarDelegate()))); } -ObsoleteOSInfoBarDelegate::ObsoleteOSInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +ObsoleteOSInfoBarDelegate::ObsoleteOSInfoBarDelegate() + : ConfirmInfoBarDelegate() { } ObsoleteOSInfoBarDelegate::~ObsoleteOSInfoBarDelegate() { diff --git a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h index 058ec48..3e0eec5 100644 --- a/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h +++ b/chrome/browser/ui/startup/obsolete_os_infobar_delegate.h @@ -16,11 +16,12 @@ class InfoBarService; // a "Learn More" link. class ObsoleteOSInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates an obsolete OS infobar delegate and adds it to |infobar_service|. + // Creates an obsolete OS infobar and delegate and adds the infobar to + // |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit ObsoleteOSInfoBarDelegate(InfoBarService* infobar_service); + ObsoleteOSInfoBarDelegate(); virtual ~ObsoleteOSInfoBarDelegate(); virtual string16 GetMessageText() const OVERRIDE; diff --git a/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc b/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc index d1d28cd..e49b81d 100644 --- a/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc +++ b/chrome/browser/ui/startup/session_crashed_infobar_delegate.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/startup/session_crashed_infobar_delegate.h" -#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/infobars/infobar.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search/search.h" @@ -14,7 +13,6 @@ #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/url_constants.h" #include "content/public/browser/dom_storage_context.h" -#include "content/public/browser/notification_service.h" #include "content/public/browser/storage_partition.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -34,31 +32,21 @@ void SessionCrashedInfoBarDelegate::Create(Browser* browser) { if (profile->IsOffTheRecord() || !web_contents) return; - InfoBarService* infobar_service = - InfoBarService::FromWebContents(web_contents); - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new SessionCrashedInfoBarDelegate(infobar_service, profile))); + InfoBarService::FromWebContents(web_contents)->AddInfoBar( + ConfirmInfoBarDelegate::CreateInfoBar(scoped_ptr<ConfirmInfoBarDelegate>( + new SessionCrashedInfoBarDelegate(profile)))); } -SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate( - InfoBarService* infobar_service, - Profile* profile) - : ConfirmInfoBarDelegate(infobar_service), +SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(Profile* profile) + : ConfirmInfoBarDelegate(), accepted_(false), - removed_notification_received_(false), profile_(profile) { - // TODO(pkasting,marja): Once InfoBars own they delegates, this is not needed - // any more. Then we can rely on delegates getting destroyed, and we can - // initiate the session storage scavenging only in the destructor. (Currently, - // info bars are leaked if they get closed while they're in background tabs.) - registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, - content::NotificationService::AllSources()); } SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() { // If the info bar wasn't accepted, it was either dismissed or expired. In // that case, session restore won't happen. - if (!accepted_ && !removed_notification_received_) { + if (!accepted_) { content::BrowserContext::GetDefaultStoragePartition(profile_)-> GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); } @@ -84,8 +72,7 @@ string16 SessionCrashedInfoBarDelegate::GetButtonLabel( bool SessionCrashedInfoBarDelegate::Accept() { uint32 behavior = 0; - Browser* browser = - chrome::FindBrowserWithWebContents(owner()->web_contents()); + Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); if (browser->tab_strip_model()->count() == 1) { const content::WebContents* active_tab = browser->tab_strip_model()->GetWebContentsAt(0); @@ -102,17 +89,3 @@ bool SessionCrashedInfoBarDelegate::Accept() { accepted_ = true; return true; } - -void SessionCrashedInfoBarDelegate::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); - if (content::Details<InfoBar::RemovedDetails>(details)->first != this) - return; - if (!accepted_) { - content::BrowserContext::GetDefaultStoragePartition(profile_)-> - GetDOMStorageContext()->StartScavengingUnusedSessionStorage(); - removed_notification_received_ = true; - } -} diff --git a/chrome/browser/ui/startup/session_crashed_infobar_delegate.h b/chrome/browser/ui/startup/session_crashed_infobar_delegate.h index e842d5d..260a320 100644 --- a/chrome/browser/ui/startup/session_crashed_infobar_delegate.h +++ b/chrome/browser/ui/startup/session_crashed_infobar_delegate.h @@ -5,32 +5,20 @@ #ifndef CHROME_BROWSER_UI_STARTUP_SESSION_CRASHED_INFOBAR_DELEGATE_H_ #define CHROME_BROWSER_UI_STARTUP_SESSION_CRASHED_INFOBAR_DELEGATE_H_ -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" #include "chrome/browser/infobars/confirm_infobar_delegate.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" class Browser; class Profile; // A delegate for the InfoBar shown when the previous session has crashed. -class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate, - public content::NotificationObserver { +class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // If |browser| is not incognito, creates a session crashed infobar delegate - // and adds it to the InfoBarService for |browser|. + // If |browser| is not incognito, creates a session crashed infobar and + // delegate and adds the infobar to the InfoBarService for |browser|. static void Create(Browser* browser); private: - FRIEND_TEST_ALL_PREFIXES(SessionCrashedInfoBarDelegateUnitTest, - DetachingTabWithCrashedInfoBar); -#if defined(UNIT_TEST) - friend struct base::DefaultDeleter<SessionCrashedInfoBarDelegate>; -#endif - - SessionCrashedInfoBarDelegate(InfoBarService* infobar_service, - Profile* profile); + explicit SessionCrashedInfoBarDelegate(Profile* profile); virtual ~SessionCrashedInfoBarDelegate(); // ConfirmInfoBarDelegate: @@ -40,14 +28,7 @@ class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate, virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; virtual bool Accept() OVERRIDE; - // content::NotificationObserver: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - - content::NotificationRegistrar registrar_; bool accepted_; - bool removed_notification_received_; Profile* profile_; DISALLOW_COPY_AND_ASSIGN(SessionCrashedInfoBarDelegate); 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 473928d..d43d425 100644 --- a/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc +++ b/chrome/browser/ui/startup/session_crashed_infobar_delegate_unittest.cc @@ -7,6 +7,7 @@ #include "base/prefs/pref_registry_simple.h" #include "base/prefs/testing_pref_service.h" #include "base/run_loop.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/sessions/session_service_factory.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" @@ -61,8 +62,8 @@ TEST_F(SessionCrashedInfoBarDelegateUnitTest, DetachingTabWithCrashedInfoBar) { InfoBarService* infobar_service = InfoBarService::FromWebContents(web_contents); EXPECT_EQ(1U, infobar_service->infobar_count()); - scoped_ptr<ConfirmInfoBarDelegate> infobar(InfoBarService::FromWebContents( - web_contents)->infobar_at(0)->AsConfirmInfoBarDelegate()); + ConfirmInfoBarDelegate* infobar = + infobar_service->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(infobar); // Open another browser. diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.cc b/chrome/browser/ui/views/infobars/after_translate_infobar.cc index 7620e15b..93c0bf4 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.cc @@ -16,9 +16,8 @@ #include "ui/views/controls/menu/menu_item_view.h" AfterTranslateInfoBar::AfterTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), label_1_(NULL), label_2_(NULL), label_3_(NULL), @@ -28,7 +27,8 @@ AfterTranslateInfoBar::AfterTranslateInfoBar( options_menu_button_(NULL), swapped_language_buttons_(false) { autodetermined_source_language_ = - delegate->original_language_index() == TranslateInfoBarDelegate::kNoIndex; + GetDelegate()->original_language_index() == + TranslateInfoBarDelegate::kNoIndex; } AfterTranslateInfoBar::~AfterTranslateInfoBar() { diff --git a/chrome/browser/ui/views/infobars/after_translate_infobar.h b/chrome/browser/ui/views/infobars/after_translate_infobar.h index 29e6acb..57fad6d 100644 --- a/chrome/browser/ui/views/infobars/after_translate_infobar.h +++ b/chrome/browser/ui/views/infobars/after_translate_infobar.h @@ -19,8 +19,7 @@ class MenuButton; class AfterTranslateInfoBar : public TranslateInfoBarBase, public views::MenuButtonListener { public: - AfterTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit AfterTranslateInfoBar(scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~AfterTranslateInfoBar(); diff --git a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc index 87ad887..700be5c 100644 --- a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc +++ b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.cc @@ -13,17 +13,18 @@ // AlternateNavInfoBarDelegate ------------------------------------------------- -InfoBar* AlternateNavInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new AlternateNavInfoBarView(owner, this); +// static +scoped_ptr<InfoBar> AlternateNavInfoBarDelegate::CreateInfoBar( + scoped_ptr<AlternateNavInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new AlternateNavInfoBarView(delegate.Pass())); } // AlternateNavInfoBarView ----------------------------------------------------- AlternateNavInfoBarView::AlternateNavInfoBarView( - InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate) - : InfoBarView(owner, delegate), + scoped_ptr<AlternateNavInfoBarDelegate> delegate) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), label_1_(NULL), link_(NULL), label_2_(NULL) { diff --git a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h index aba7c71..0d26a30 100644 --- a/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h +++ b/chrome/browser/ui/views/infobars/alternate_nav_infobar_view.h @@ -5,8 +5,7 @@ #ifndef CHROME_BROWSER_UI_VIEWS_INFOBARS_ALTERNATE_NAV_INFOBAR_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_INFOBARS_ALTERNATE_NAV_INFOBAR_VIEW_H_ -#include "base/basictypes.h" -#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "ui/views/controls/link_listener.h" @@ -16,8 +15,8 @@ class AlternateNavInfoBarDelegate; class AlternateNavInfoBarView : public InfoBarView, public views::LinkListener { public: - AlternateNavInfoBarView(InfoBarService* owner, - AlternateNavInfoBarDelegate* delegate); + explicit AlternateNavInfoBarView( + scoped_ptr<AlternateNavInfoBarDelegate> delegate); private: virtual ~AlternateNavInfoBarView(); diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.cc b/chrome/browser/ui/views/infobars/before_translate_infobar.cc index bc865b9..4820b41 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.cc +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.cc @@ -16,9 +16,8 @@ #include "ui/views/controls/menu/menu_item_view.h" BeforeTranslateInfoBar::BeforeTranslateInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), label_1_(NULL), label_2_(NULL), language_menu_button_(NULL), diff --git a/chrome/browser/ui/views/infobars/before_translate_infobar.h b/chrome/browser/ui/views/infobars/before_translate_infobar.h index 3f368f2..855da51 100644 --- a/chrome/browser/ui/views/infobars/before_translate_infobar.h +++ b/chrome/browser/ui/views/infobars/before_translate_infobar.h @@ -19,8 +19,8 @@ class MenuButton; class BeforeTranslateInfoBar : public TranslateInfoBarBase, public views::MenuButtonListener { public: - BeforeTranslateInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit BeforeTranslateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~BeforeTranslateInfoBar(); diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.cc b/chrome/browser/ui/views/infobars/confirm_infobar.cc index 82da528..34cd4f8 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.cc +++ b/chrome/browser/ui/views/infobars/confirm_infobar.cc @@ -14,16 +14,17 @@ // ConfirmInfoBarDelegate ----------------------------------------------------- -InfoBar* ConfirmInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ConfirmInfoBar(owner, this); +// static +scoped_ptr<InfoBar> ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate> delegate) { + return scoped_ptr<InfoBar>(new ConfirmInfoBar(delegate.Pass())); } // ConfirmInfoBar ------------------------------------------------------------- -ConfirmInfoBar::ConfirmInfoBar(InfoBarService* owner, - ConfirmInfoBarDelegate* delegate) - : InfoBarView(owner, delegate), +ConfirmInfoBar::ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), label_(NULL), ok_button_(NULL), cancel_button_(NULL), diff --git a/chrome/browser/ui/views/infobars/confirm_infobar.h b/chrome/browser/ui/views/infobars/confirm_infobar.h index ccde806..fd257d1 100644 --- a/chrome/browser/ui/views/infobars/confirm_infobar.h +++ b/chrome/browser/ui/views/infobars/confirm_infobar.h @@ -22,7 +22,7 @@ class Label; class ConfirmInfoBar : public InfoBarView, public views::LinkListener { public: - ConfirmInfoBar(InfoBarService* owner, ConfirmInfoBarDelegate* delegate); + explicit ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate); private: virtual ~ConfirmInfoBar(); diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc index 937cc9e..aa9393e 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.cc +++ b/chrome/browser/ui/views/infobars/extension_infobar.cc @@ -29,8 +29,11 @@ // ExtensionInfoBarDelegate ---------------------------------------------------- -InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - return new ExtensionInfoBar(owner, this, browser_); +// static +scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate) { + Browser* browser = delegate->browser_; + return scoped_ptr<InfoBar>(new ExtensionInfoBar(delegate.Pass(), browser)); } @@ -78,25 +81,20 @@ class MenuImageSource: public gfx::CanvasImageSource { } // namespace -ExtensionInfoBar::ExtensionInfoBar(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate, - Browser* browser) - : InfoBarView(owner, delegate), - delegate_(delegate), +ExtensionInfoBar::ExtensionInfoBar( + scoped_ptr<ExtensionInfoBarDelegate> delegate, + Browser* browser) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), browser_(browser), infobar_icon_(NULL), icon_as_menu_(NULL), icon_as_image_(NULL), weak_ptr_factory_(this) { - GetDelegate()->set_observer(this); - int height = GetDelegate()->height(); SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); } ExtensionInfoBar::~ExtensionInfoBar() { - if (GetDelegate()) - GetDelegate()->set_observer(NULL); } void ExtensionInfoBar::Layout() { @@ -166,10 +164,6 @@ int ExtensionInfoBar::ContentMinimumWidth() const { } -void ExtensionInfoBar::OnDelegateDeleted() { - delegate_ = NULL; -} - void ExtensionInfoBar::OnMenuButtonClicked(views::View* source, const gfx::Point& point) { if (!owner()) @@ -215,5 +209,5 @@ void ExtensionInfoBar::OnImageLoaded(const gfx::Image& image) { } ExtensionInfoBarDelegate* ExtensionInfoBar::GetDelegate() { - return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; + return delegate()->AsExtensionInfoBarDelegate(); } diff --git a/chrome/browser/ui/views/infobars/extension_infobar.h b/chrome/browser/ui/views/infobars/extension_infobar.h index 459b9c3..953d390 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.h +++ b/chrome/browser/ui/views/infobars/extension_infobar.h @@ -6,11 +6,11 @@ #define CHROME_BROWSER_UI_VIEWS_INFOBARS_EXTENSION_INFOBAR_H_ #include "base/compiler_specific.h" -#include "chrome/browser/extensions/extension_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "ui/views/controls/button/menu_button_listener.h" class Browser; +class ExtensionInfoBarDelegate; namespace views { class ImageView; @@ -18,11 +18,9 @@ class MenuButton; } class ExtensionInfoBar : public InfoBarView, - public ExtensionInfoBarDelegate::DelegateObserver, public views::MenuButtonListener { public: - ExtensionInfoBar(InfoBarService* owner, - ExtensionInfoBarDelegate* delegate, + ExtensionInfoBar(scoped_ptr<ExtensionInfoBarDelegate> delegate, Browser* browser); private: @@ -34,9 +32,6 @@ class ExtensionInfoBar : public InfoBarView, const ViewHierarchyChangedDetails& details) OVERRIDE; virtual int ContentMinimumWidth() const OVERRIDE; - // ExtensionInfoBarDelegate::DelegateObserver: - virtual void OnDelegateDeleted() OVERRIDE; - // views::MenuButtonListener: virtual void OnMenuButtonClicked(views::View* source, const gfx::Point& point) OVERRIDE; @@ -45,11 +40,6 @@ class ExtensionInfoBar : public InfoBarView, ExtensionInfoBarDelegate* GetDelegate(); - // TODO(pkasting): This shadows InfoBarView::delegate_. Get rid of this once - // InfoBars own their delegates (and thus we don't need the DelegateObserver - // functionality). For now, almost everyone should use GetDelegate() instead. - InfoBarDelegate* delegate_; - Browser* browser_; // The infobar icon used for the extension infobar. The icon can be either a diff --git a/chrome/browser/ui/views/infobars/infobar_container_view.cc b/chrome/browser/ui/views/infobars/infobar_container_view.cc index bcb9ca53..193330a 100644 --- a/chrome/browser/ui/views/infobars/infobar_container_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_container_view.cc @@ -4,7 +4,6 @@ #include "chrome/browser/ui/views/infobars/infobar_container_view.h" -#include "base/message_loop/message_loop.h" #include "chrome/browser/ui/view_ids.h" #include "chrome/browser/ui/views/infobars/infobar_view.h" #include "grit/generated_resources.h" @@ -60,5 +59,4 @@ void InfoBarContainerView::PlatformSpecificAddInfoBar(InfoBar* infobar, void InfoBarContainerView::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { RemoveChildView(static_cast<InfoBarView*>(infobar)); - base::MessageLoop::current()->DeleteSoon(FROM_HERE, infobar); } diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index c89d2b3..105b037 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -54,8 +54,8 @@ const int InfoBarView::kButtonButtonSpacing = 10; const int InfoBarView::kEndOfLabelSpacing = 16; const int InfoBarView::kHorizontalPadding = 6; -InfoBarView::InfoBarView(InfoBarService* owner, InfoBarDelegate* delegate) - : InfoBar(owner, delegate), +InfoBarView::InfoBarView(scoped_ptr<InfoBarDelegate> delegate) + : InfoBar(delegate.Pass()), views::ExternalFocusTracker(this, NULL), icon_(NULL), close_button_(NULL) { @@ -376,11 +376,9 @@ void InfoBarView::PlatformSpecificOnHeightsRecalculated() { } void InfoBarView::GetAccessibleState(ui::AccessibleViewState* state) { - if (delegate()) { - state->name = l10n_util::GetStringUTF16( - (delegate()->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ? - IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION); - } + state->name = l10n_util::GetStringUTF16( + (delegate()->GetInfoBarType() == InfoBarDelegate::WARNING_TYPE) ? + IDS_ACCNAME_INFOBAR_WARNING : IDS_ACCNAME_INFOBAR_PAGE_ACTION); state->role = ui::AccessibilityTypes::ROLE_ALERT; } diff --git a/chrome/browser/ui/views/infobars/infobar_view.h b/chrome/browser/ui/views/infobars/infobar_view.h index 5797ec7..8914c17 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.h +++ b/chrome/browser/ui/views/infobars/infobar_view.h @@ -35,7 +35,7 @@ class InfoBarView : public InfoBar, public views::ButtonListener, public views::ExternalFocusTracker { public: - InfoBarView(InfoBarService* owner, InfoBarDelegate* delegate); + explicit InfoBarView(scoped_ptr<InfoBarDelegate> delegate); const SkPath& fill_path() const { return fill_path_; } const SkPath& stroke_path() const { return stroke_path_; } diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.cc b/chrome/browser/ui/views/infobars/translate_infobar_base.cc index 896ac97..0c914e3 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.cc +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.cc @@ -5,6 +5,7 @@ #include "chrome/browser/ui/views/infobars/translate_infobar_base.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/translate/translate_infobar_delegate.h" #include "chrome/browser/ui/views/infobars/after_translate_infobar.h" #include "chrome/browser/ui/views/infobars/before_translate_infobar.h" @@ -19,12 +20,14 @@ // TranslateInfoBarDelegate --------------------------------------------------- -InfoBar* TranslateInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { - if (infobar_type_ == BEFORE_TRANSLATE) - return new BeforeTranslateInfoBar(owner, this); - if (infobar_type_ == AFTER_TRANSLATE) - return new AfterTranslateInfoBar(owner, this); - return new TranslateMessageInfoBar(owner, this); +// static +scoped_ptr<InfoBar> TranslateInfoBarDelegate::CreateInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate) { + if (delegate->infobar_type() == BEFORE_TRANSLATE) + return scoped_ptr<InfoBar>(new BeforeTranslateInfoBar(delegate.Pass())); + if (delegate->infobar_type() == AFTER_TRANSLATE) + return scoped_ptr<InfoBar>(new AfterTranslateInfoBar(delegate.Pass())); + return scoped_ptr<InfoBar>(new TranslateMessageInfoBar(delegate.Pass())); } @@ -42,9 +45,9 @@ void TranslateInfoBarBase::UpdateLanguageButtonText(views::MenuButton* button, SchedulePaint(); } -TranslateInfoBarBase::TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : InfoBarView(owner, delegate), +TranslateInfoBarBase::TranslateInfoBarBase( + scoped_ptr<TranslateInfoBarDelegate> delegate) + : InfoBarView(delegate.PassAs<InfoBarDelegate>()), error_background_(InfoBarDelegate::WARNING_TYPE) { } diff --git a/chrome/browser/ui/views/infobars/translate_infobar_base.h b/chrome/browser/ui/views/infobars/translate_infobar_base.h index 971bf3f..2c7440f 100644 --- a/chrome/browser/ui/views/infobars/translate_infobar_base.h +++ b/chrome/browser/ui/views/infobars/translate_infobar_base.h @@ -24,8 +24,7 @@ class TranslateInfoBarBase : public InfoBarView { const string16& text); protected: - TranslateInfoBarBase(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateInfoBarBase(scoped_ptr<TranslateInfoBarDelegate> delegate); virtual ~TranslateInfoBarBase(); // InfoBarView: diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.cc b/chrome/browser/ui/views/infobars/translate_message_infobar.cc index b54e04e..d84a389 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.cc +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.cc @@ -9,9 +9,8 @@ #include "ui/views/controls/label.h" TranslateMessageInfoBar::TranslateMessageInfoBar( - InfoBarService* owner, - TranslateInfoBarDelegate* delegate) - : TranslateInfoBarBase(owner, delegate), + scoped_ptr<TranslateInfoBarDelegate> delegate) + : TranslateInfoBarBase(delegate.Pass()), label_(NULL), button_(NULL) { } diff --git a/chrome/browser/ui/views/infobars/translate_message_infobar.h b/chrome/browser/ui/views/infobars/translate_message_infobar.h index 0452b95..1eda310 100644 --- a/chrome/browser/ui/views/infobars/translate_message_infobar.h +++ b/chrome/browser/ui/views/infobars/translate_message_infobar.h @@ -9,8 +9,8 @@ class TranslateMessageInfoBar : public TranslateInfoBarBase { public: - TranslateMessageInfoBar(InfoBarService* owner, - TranslateInfoBarDelegate* delegate); + explicit TranslateMessageInfoBar( + scoped_ptr<TranslateInfoBarDelegate> delegate); private: virtual ~TranslateMessageInfoBar(); diff --git a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc index f51f741..c995827 100644 --- a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc +++ b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "content/public/browser/web_contents.h" #include "grit/generated_resources.h" @@ -15,13 +16,13 @@ // static void WebsiteSettingsInfoBarDelegate::Create(InfoBarService* infobar_service) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new WebsiteSettingsInfoBarDelegate(infobar_service))); + infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( + scoped_ptr<ConfirmInfoBarDelegate>( + new WebsiteSettingsInfoBarDelegate()))); } -WebsiteSettingsInfoBarDelegate::WebsiteSettingsInfoBarDelegate( - InfoBarService* infobar_service) - : ConfirmInfoBarDelegate(infobar_service) { +WebsiteSettingsInfoBarDelegate::WebsiteSettingsInfoBarDelegate() + : ConfirmInfoBarDelegate() { } WebsiteSettingsInfoBarDelegate::~WebsiteSettingsInfoBarDelegate() { diff --git a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h index 19fffa0..be68757 100644 --- a/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h +++ b/chrome/browser/ui/website_settings/website_settings_infobar_delegate.h @@ -16,12 +16,12 @@ class InfoBarService; // the reload right from the infobar. class WebsiteSettingsInfoBarDelegate : public ConfirmInfoBarDelegate { public: - // Creates a website settings infobar delegate and adds it to + // Creates a website settings infobar and delegate and adds the infobar to // |infobar_service|. static void Create(InfoBarService* infobar_service); private: - explicit WebsiteSettingsInfoBarDelegate(InfoBarService* infobar_service); + WebsiteSettingsInfoBarDelegate(); virtual ~WebsiteSettingsInfoBarDelegate(); // ConfirmInfoBarDelegate: diff --git a/chrome/browser/ui/website_settings/website_settings_unittest.cc b/chrome/browser/ui/website_settings/website_settings_unittest.cc index ab5cba0..20519ab 100644 --- a/chrome/browser/ui/website_settings/website_settings_unittest.cc +++ b/chrome/browser/ui/website_settings/website_settings_unittest.cc @@ -12,7 +12,7 @@ #include "chrome/browser/content_settings/content_settings_utils.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/content_settings/tab_specific_content_settings.h" -#include "chrome/browser/infobars/infobar_delegate.h" +#include "chrome/browser/infobars/infobar.h" #include "chrome/browser/infobars/infobar_service.h" #include "chrome/browser/ui/website_settings/website_settings_ui.h" #include "chrome/common/content_settings.h" @@ -391,9 +391,5 @@ TEST_F(WebsiteSettingsTest, ShowInfoBar) { website_settings()->OnUIClosing(); ASSERT_EQ(1u, infobar_service()->infobar_count()); - // Removing an |InfoBarDelegate| from the |InfoBarService| does not delete - // it. Hence the |delegate| must be cleaned up after it was removed from the - // |infobar_service|. - scoped_ptr<InfoBarDelegate> delegate(infobar_service()->infobar_at(0)); - infobar_service()->RemoveInfoBar(delegate.get()); + infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); } diff --git a/chrome/test/gpu/webgl_infobar_browsertest.cc b/chrome/test/gpu/webgl_infobar_browsertest.cc index 3cd6767..f790e2a 100644 --- a/chrome/test/gpu/webgl_infobar_browsertest.cc +++ b/chrome/test/gpu/webgl_infobar_browsertest.cc @@ -7,6 +7,7 @@ #include "base/strings/utf_string_conversions.h" #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_service.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" @@ -136,7 +137,7 @@ IN_PROC_BROWSER_TEST_F(WebGLInfoBarTest, MAYBE_ContextLossInfoBarReload) { InfoBarService* infobar_service = InfoBarService::FromWebContents( browser()->tab_strip_model()->GetActiveWebContents()); ASSERT_EQ(1u, infobar_service->infobar_count()); - InfoBarDelegate* delegate = infobar_service->infobar_at(0); + InfoBarDelegate* delegate = infobar_service->infobar_at(0)->delegate(); ASSERT_TRUE(delegate->AsThreeDAPIInfoBarDelegate()); delegate->AsConfirmInfoBarDelegate()->Cancel(); diff --git a/chrome/test/ppapi/ppapi_test.cc b/chrome/test/ppapi/ppapi_test.cc index 66b9bba..783ae0e 100644 --- a/chrome/test/ppapi/ppapi_test.cc +++ b/chrome/test/ppapi/ppapi_test.cc @@ -107,8 +107,9 @@ void PPAPITestBase::InfoBarObserver::VerifyInfoBarState() { return; expecting_infobar_ = false; - InfoBarDelegate* infobar = infobar_service->infobar_at(0); - ConfirmInfoBarDelegate* delegate = infobar->AsConfirmInfoBarDelegate(); + InfoBar* infobar = infobar_service->infobar_at(0); + ConfirmInfoBarDelegate* delegate = + infobar->delegate()->AsConfirmInfoBarDelegate(); ASSERT_TRUE(delegate != NULL); if (should_accept_) delegate->Accept(); diff --git a/tools/valgrind/memcheck/suppressions.txt b/tools/valgrind/memcheck/suppressions.txt index 4866fbc..ff4c2eb 100644 --- a/tools/valgrind/memcheck/suppressions.txt +++ b/tools/valgrind/memcheck/suppressions.txt @@ -2479,13 +2479,6 @@ fun:_ZN3net13CookieMonster17CookieMonsterTask14InvokeCallbackEN4base8CallbackIFvvEEE } { - bug_96365 - Memcheck:Leak - fun:_Znw* - fun:_ZN27PasswordManagerDelegateImpl33AddSavePasswordInfoBarIfPermittedEP19PasswordFormManager - fun:_ZN15PasswordManager23OnPasswordFormsRenderedERKSt6vectorIN6webkit5forms12PasswordFormESaIS3_EE -} -{ bug_96369 Memcheck:Leak fun:malloc @@ -4219,15 +4212,6 @@ fun:_ZN7content18ResourceDispatcher17OnRequestCompleteEiRKN3net16URLRequestStatusERKSsRKN4base9TimeTicksE } { - bug_145698 - Memcheck:Leak - fun:_Znw* - fun:_ZN6chrome24ShowSessionCrashedPromptEP7Browser - fun:_ZN25StartupBrowserCreatorImpl22AddInfoBarsIfNecessaryEP7BrowserN6chrome7startup16IsProcessStartupE - fun:_ZN25StartupBrowserCreatorImpl17ProcessLaunchURLsEbRKSt6vectorI4GURLSaIS1_EE - fun:_ZN25StartupBrowserCreatorImpl6LaunchEP7ProfileRKSt6vectorI4GURLSaIS3_EEb -} -{ bug_145699 Memcheck:Leak fun:_Znw* @@ -4295,16 +4279,6 @@ fun:_ZN10extensions13ExtensionHost9OnRequestERK31ExtensionHostMsg_Request_Params } { - bug_145733 - Memcheck:Leak - fun:_Znw* - fun:_ZN25ExtensionInstallUIDefault35GetNewThemeInstalledInfoBarDelegateEP11TabContentsPKN10extensions9ExtensionERKSsb - fun:_ZN25ExtensionInstallUIDefault16ShowThemeInfoBarERKSsbPKN10extensions9ExtensionEP7Profile - fun:_ZN25ExtensionInstallUIDefault16OnInstallSuccessEPKN10extensions9ExtensionEP8SkBitmap - fun:_ZN22ExtensionInstallPrompt16OnInstallSuccessEPKN10extensions9ExtensionEP8SkBitmap - fun:_ZN10extensions12CrxInstaller25ReportSuccessFromUIThreadEv -} -{ bug_145735 Memcheck:Leak fun:_Znw* @@ -4315,24 +4289,6 @@ fun:_ZN4base5files12_GLOBAL__N_121InotifyReaderCallbackEPNS1_13InotifyReaderEii } { - bug_145747a - Memcheck:Leak - fun:_Znw* - fun:_ZN24TranslateInfoBarDelegate19CreateErrorDelegateEN15TranslateErrors4TypeEP14InfoBarServiceP11PrefServiceRKSsS7_ - fun:_ZN16TranslateManager14PageTranslatedEPN7content11WebContentsEP21PageTranslatedDetails - fun:_ZN16TranslateManager7ObserveEiRKN7content18NotificationSourceERKNS0_19NotificationDetailsE - fun:_ZN23NotificationServiceImpl6NotifyEiRKN7content18NotificationSourceERKNS0_19NotificationDetailsE - fun:_ZN18TranslateTabHelper16OnPageTranslatedEiRKSsS1_N15TranslateErrors4TypeE -} -{ - bug_145747b - Memcheck:Leak - fun:_Znw* - fun:_ZN24TranslateInfoBarDelegate19CreateErrorDelegateEN15TranslateErrors4TypeEP14InfoBarServiceP11PrefServiceRKSsS7_ - fun:_ZN16TranslateManager18OnURLFetchCompleteEPKN3net10URLFetcherE - fun:_ZN20TranslateManagerTest31SimulateTranslateScriptURLFetchEb -} -{ bug_146464 Memcheck:Leak fun:realloc |