summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-05 02:12:10 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-05 02:12:10 +0000
commite3c31d27e49dd4b795fdca9c290fabee1b117b02 (patch)
treec5b4d960ae0237842d77324542b205e80d4dfcbf /chrome
parentf9486289464b51ffedba0541bf0fbeefc5d53f39 (diff)
downloadchromium_src-e3c31d27e49dd4b795fdca9c290fabee1b117b02.zip
chromium_src-e3c31d27e49dd4b795fdca9c290fabee1b117b02.tar.gz
chromium_src-e3c31d27e49dd4b795fdca9c290fabee1b117b02.tar.bz2
Replace the virtual InfoBarDelegate::InfoBarClosed() function with a non-virtual one. This is a step along the way to killing it entirely. This also adds a lot of OVERRIDE markers and does some other cleanup in a few places.
The original (stupid) design for the delegate class left subclasses great flexibility in how they mapped infobars to delegates. In practice, no one ever wanted multiple infobars driven off a single delegate, so the mapping was always one-to-one. As a result, it was always correct for InfoBarClosed() to "delete this", but because the base class did not do so, every subclass needed to. Most did; the others leaked memory and failed to run their destructors. This change forces the base class to delete itself. This fixes the delegate leaks in the couple subclasses that failed to do this. It also eliminates a lot of copy-and-pasted "delete this" implementations. Ultimately, we'll be moving to a model where the InfoBar "view" class owns the delegate and deletes it directly, which will eliminate InfoBarClosed() completely. BUG=62154 TEST=none Review URL: http://codereview.chromium.org/6926001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84195 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/alternate_nav_url_fetcher.cc4
-rw-r--r--chrome/browser/alternate_nav_url_fetcher.h15
-rw-r--r--chrome/browser/autofill/autofill_cc_infobar_delegate.cc9
-rw-r--r--chrome/browser/autofill/autofill_cc_infobar_delegate.h21
-rw-r--r--chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc4
-rw-r--r--chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h1
-rw-r--r--chrome/browser/download/download_request_infobar_delegate.cc4
-rw-r--r--chrome/browser/download/download_request_infobar_delegate.h9
-rw-r--r--chrome/browser/extensions/extension_disabled_infobar_delegate.cc15
-rw-r--r--chrome/browser/extensions/extension_infobar_delegate.cc4
-rw-r--r--chrome/browser/extensions/extension_infobar_delegate.h13
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.cc4
-rw-r--r--chrome/browser/extensions/theme_installed_infobar_delegate.h14
-rw-r--r--chrome/browser/geolocation/geolocation_permission_context.cc21
-rw-r--r--chrome/browser/google/google_url_tracker.cc6
-rw-r--r--chrome/browser/google/google_url_tracker.h9
-rw-r--r--chrome/browser/notifications/desktop_notification_service.cc18
-rw-r--r--chrome/browser/omnibox_search_hint.cc25
-rw-r--r--chrome/browser/password_manager_delegate_impl.cc17
-rw-r--r--chrome/browser/pdf_unsupported_feature.cc338
-rw-r--r--chrome/browser/plugin_installer_infobar_delegate.h17
-rw-r--r--chrome/browser/plugin_observer.cc51
-rw-r--r--chrome/browser/tab_contents/infobar_delegate.cc1
-rw-r--r--chrome/browser/tab_contents/infobar_delegate.h23
-rw-r--r--chrome/browser/tab_contents/simple_alert_infobar_delegate.cc4
-rw-r--r--chrome/browser/tab_contents/simple_alert_infobar_delegate.h1
-rw-r--r--chrome/browser/tab_contents/tab_contents_ssl_helper.cc18
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.cc4
-rw-r--r--chrome/browser/translate/translate_infobar_delegate.h11
-rw-r--r--chrome/browser/ui/browser_init.cc71
-rw-r--r--chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm37
-rw-r--r--chrome/browser/ui/cocoa/infobars/infobar_controller.mm2
-rw-r--r--chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm153
-rw-r--r--chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc12
-rw-r--r--chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h15
-rw-r--r--chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.cc12
-rw-r--r--chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h15
-rw-r--r--chrome/browser/ui/cocoa/keystone_infobar.mm17
-rw-r--r--chrome/browser/ui/collected_cookies_infobar_delegate.cc4
-rw-r--r--chrome/browser/ui/collected_cookies_infobar_delegate.h12
40 files changed, 486 insertions, 545 deletions
diff --git a/chrome/browser/alternate_nav_url_fetcher.cc b/chrome/browser/alternate_nav_url_fetcher.cc
index 58e99c7..6eb4ca6 100644
--- a/chrome/browser/alternate_nav_url_fetcher.cc
+++ b/chrome/browser/alternate_nav_url_fetcher.cc
@@ -131,10 +131,6 @@ bool AlternateNavURLFetcher::LinkClicked(WindowOpenDisposition disposition) {
return true;
}
-void AlternateNavURLFetcher::InfoBarClosed() {
- delete this;
-}
-
void AlternateNavURLFetcher::SetStatusFromURLFetch(
const GURL& url,
const net::URLRequestStatus& status,
diff --git a/chrome/browser/alternate_nav_url_fetcher.h b/chrome/browser/alternate_nav_url_fetcher.h
index 1f06b9a..c004826 100644
--- a/chrome/browser/alternate_nav_url_fetcher.h
+++ b/chrome/browser/alternate_nav_url_fetcher.h
@@ -47,7 +47,7 @@ class AlternateNavURLFetcher : public NotificationObserver,
// NotificationObserver
virtual void Observe(NotificationType type,
const NotificationSource& source,
- const NotificationDetails& details);
+ const NotificationDetails& details) OVERRIDE;
// URLFetcher::Delegate
virtual void OnURLFetchComplete(const URLFetcher* source,
@@ -55,15 +55,14 @@ class AlternateNavURLFetcher : public NotificationObserver,
const net::URLRequestStatus& status,
int response_code,
const ResponseCookies& cookies,
- const std::string& data);
+ const std::string& data) OVERRIDE;
// LinkInfoBarDelegate
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageTextWithOffset(size_t* link_offset) const;
- virtual string16 GetLinkText() const;
- virtual bool LinkClicked(WindowOpenDisposition disposition);
- virtual void InfoBarClosed();
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageTextWithOffset(size_t* link_offset) const OVERRIDE;
+ virtual string16 GetLinkText() const OVERRIDE;
+ virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
// Sets |state_| to either SUCCEEDED or FAILED depending on the result of the
// fetch.
diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc
index 2a2aff0..49d16ae 100644
--- a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc
+++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc
@@ -28,6 +28,8 @@ AutofillCCInfoBarDelegate::AutofillCCInfoBarDelegate(
}
AutofillCCInfoBarDelegate::~AutofillCCInfoBarDelegate() {
+ if (!had_user_interaction_)
+ LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
}
void AutofillCCInfoBarDelegate::LogUserAction(
@@ -46,13 +48,6 @@ bool AutofillCCInfoBarDelegate::ShouldExpire(
return false;
}
-void AutofillCCInfoBarDelegate::InfoBarClosed() {
- if (!had_user_interaction_)
- LogUserAction(AutofillMetrics::INFOBAR_IGNORED);
-
- delete this;
-}
-
void AutofillCCInfoBarDelegate::InfoBarDismissed() {
LogUserAction(AutofillMetrics::INFOBAR_DENIED);
}
diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.h b/chrome/browser/autofill/autofill_cc_infobar_delegate.h
index a686b93..91be6f8 100644
--- a/chrome/browser/autofill/autofill_cc_infobar_delegate.h
+++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.h
@@ -36,17 +36,16 @@ class AutofillCCInfoBarDelegate : public ConfirmInfoBarDelegate {
// ConfirmInfoBarDelegate:
virtual bool ShouldExpire(
- const NavigationController::LoadCommittedDetails& details) const;
- virtual void InfoBarClosed();
- virtual void InfoBarDismissed();
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual bool Cancel();
- virtual string16 GetLinkText();
- virtual bool LinkClicked(WindowOpenDisposition disposition);
+ const NavigationController::LoadCommittedDetails& details) const OVERRIDE;
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+ virtual string16 GetLinkText() OVERRIDE;
+ virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
// The credit card that should be saved if the user accepts the infobar.
scoped_ptr<const CreditCard> credit_card_;
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 d9d3b9c..56fcc04 100644
--- a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc
+++ b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.cc
@@ -27,10 +27,6 @@ bool RegisterProtocolHandlerInfoBarDelegate::ShouldExpire(
return false;
}
-void RegisterProtocolHandlerInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
InfoBarDelegate::Type
RegisterProtocolHandlerInfoBarDelegate::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
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 c6eaf21..f71f6aa 100644
--- a/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h
+++ b/chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h
@@ -25,7 +25,6 @@ class RegisterProtocolHandlerInfoBarDelegate : public ConfirmInfoBarDelegate {
// ConfirmInfoBarDelegate:
virtual bool ShouldExpire(const NavigationController::LoadCommittedDetails&
details) const OVERRIDE;
- virtual void InfoBarClosed() OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
virtual string16 GetMessageText() const OVERRIDE;
virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
diff --git a/chrome/browser/download/download_request_infobar_delegate.cc b/chrome/browser/download/download_request_infobar_delegate.cc
index 9200878..ff33efc 100644
--- a/chrome/browser/download/download_request_infobar_delegate.cc
+++ b/chrome/browser/download/download_request_infobar_delegate.cc
@@ -18,12 +18,8 @@ DownloadRequestInfoBarDelegate::DownloadRequestInfoBarDelegate(
}
DownloadRequestInfoBarDelegate::~DownloadRequestInfoBarDelegate() {
-}
-
-void DownloadRequestInfoBarDelegate::InfoBarClosed() {
if (host_)
host_->Cancel();
- delete this;
}
gfx::Image* DownloadRequestInfoBarDelegate::GetIcon() const {
diff --git a/chrome/browser/download/download_request_infobar_delegate.h b/chrome/browser/download/download_request_infobar_delegate.h
index 81a9898..23ca16a 100644
--- a/chrome/browser/download/download_request_infobar_delegate.h
+++ b/chrome/browser/download/download_request_infobar_delegate.h
@@ -30,11 +30,10 @@ class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~DownloadRequestInfoBarDelegate();
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
DownloadRequestLimiter::TabDownloadState* host_;
diff --git a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
index e334fd2..d423427 100644
--- a/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_disabled_infobar_delegate.cc
@@ -87,16 +87,15 @@ class ExtensionDisabledInfobarDelegate : public ConfirmInfoBarDelegate,
virtual ~ExtensionDisabledInfobarDelegate();
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed();
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual int GetButtons() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
// NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
- const NotificationDetails& details);
+ const NotificationDetails& details) OVERRIDE;
NotificationRegistrar registrar_;
TabContents* tab_contents_;
@@ -122,10 +121,6 @@ ExtensionDisabledInfobarDelegate::ExtensionDisabledInfobarDelegate(
ExtensionDisabledInfobarDelegate::~ExtensionDisabledInfobarDelegate() {
}
-void ExtensionDisabledInfobarDelegate::InfoBarClosed() {
- delete this;
-}
-
string16 ExtensionDisabledInfobarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(extension_->is_app() ?
IDS_APP_DISABLED_INFOBAR_LABEL : IDS_EXTENSION_DISABLED_INFOBAR_LABEL,
diff --git a/chrome/browser/extensions/extension_infobar_delegate.cc b/chrome/browser/extensions/extension_infobar_delegate.cc
index 0db3ae8..336f287 100644
--- a/chrome/browser/extensions/extension_infobar_delegate.cc
+++ b/chrome/browser/extensions/extension_infobar_delegate.cc
@@ -59,10 +59,6 @@ void ExtensionInfoBarDelegate::InfoBarDismissed() {
closing_ = true;
}
-void ExtensionInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
diff --git a/chrome/browser/extensions/extension_infobar_delegate.h b/chrome/browser/extensions/extension_infobar_delegate.h
index 884056e..9a3385d 100644
--- a/chrome/browser/extensions/extension_infobar_delegate.h
+++ b/chrome/browser/extensions/extension_infobar_delegate.h
@@ -43,17 +43,16 @@ class ExtensionInfoBarDelegate : public InfoBarDelegate,
virtual ~ExtensionInfoBarDelegate();
// InfoBarDelegate:
- virtual InfoBar* CreateInfoBar();
- virtual bool EqualsDelegate(InfoBarDelegate* delegate) const;
- virtual void InfoBarDismissed();
- virtual void InfoBarClosed();
- virtual Type GetInfoBarType() const;
- virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate();
+ virtual InfoBar* CreateInfoBar() OVERRIDE;
+ virtual bool EqualsDelegate(InfoBarDelegate* delegate) const OVERRIDE;
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate() OVERRIDE;
// NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
- const NotificationDetails& details);
+ const NotificationDetails& details) OVERRIDE;
// 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
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.cc b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
index 29e75ba..3f01810 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.cc
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.cc
@@ -69,10 +69,6 @@ bool ThemeInstalledInfoBarDelegate::Cancel() {
return true;
}
-void ThemeInstalledInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
gfx::Image* ThemeInstalledInfoBarDelegate::GetIcon() const {
// TODO(aa): Reply with the theme's icon, but this requires reading it
// asynchronously from disk.
diff --git a/chrome/browser/extensions/theme_installed_infobar_delegate.h b/chrome/browser/extensions/theme_installed_infobar_delegate.h
index bbde65c..f31b957 100644
--- a/chrome/browser/extensions/theme_installed_infobar_delegate.h
+++ b/chrome/browser/extensions/theme_installed_infobar_delegate.h
@@ -38,17 +38,17 @@ class ThemeInstalledInfoBarDelegate : public ConfirmInfoBarDelegate,
private:
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual ThemeInstalledInfoBarDelegate* AsThemePreviewInfobarDelegate();
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual ThemeInstalledInfoBarDelegate*
+ AsThemePreviewInfobarDelegate() OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual int GetButtons() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
// NotificationObserver:
virtual void Observe(NotificationType type,
const NotificationSource& source,
- const NotificationDetails& details);
+ const NotificationDetails& details) OVERRIDE;
Profile* profile_;
ThemeService* theme_service_;
diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc
index 71d03d6..200b3c3 100644
--- a/chrome/browser/geolocation/geolocation_permission_context.cc
+++ b/chrome/browser/geolocation/geolocation_permission_context.cc
@@ -125,15 +125,14 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~GeolocationConfirmInfoBarDelegate();
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual bool Cancel();
- virtual string16 GetLinkText();
- virtual bool LinkClicked(WindowOpenDisposition disposition);
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+ virtual string16 GetLinkText() OVERRIDE;
+ virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
TabContents* tab_contents_;
GeolocationInfoBarQueueController* controller_;
@@ -165,12 +164,8 @@ GeolocationConfirmInfoBarDelegate::GeolocationConfirmInfoBarDelegate(
}
GeolocationConfirmInfoBarDelegate::~GeolocationConfirmInfoBarDelegate() {
-}
-
-void GeolocationConfirmInfoBarDelegate::InfoBarClosed() {
controller_->OnInfoBarClosed(render_process_id_, render_view_id_,
bridge_id_);
- delete this;
}
gfx::Image* GeolocationConfirmInfoBarDelegate::GetIcon() const {
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc
index 22dd95c..66567bb 100644
--- a/chrome/browser/google/google_url_tracker.cc
+++ b/chrome/browser/google/google_url_tracker.cc
@@ -59,12 +59,8 @@ bool GoogleURLTrackerInfoBarDelegate::Cancel() {
return true;
}
-void GoogleURLTrackerInfoBarDelegate::InfoBarClosed() {
- google_url_tracker_->InfoBarClosed();
- delete this;
-}
-
GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
+ google_url_tracker_->InfoBarClosed();
}
string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h
index 2f67820..6de5002 100644
--- a/chrome/browser/google/google_url_tracker.h
+++ b/chrome/browser/google/google_url_tracker.h
@@ -168,9 +168,8 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
const GURL& new_google_url);
// ConfirmInfoBarDelegate:
- virtual bool Accept();
- virtual bool Cancel();
- virtual void InfoBarClosed();
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
protected:
virtual ~GoogleURLTrackerInfoBarDelegate();
@@ -180,8 +179,8 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
private:
// ConfirmInfoBarDelegate:
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate);
};
diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc
index bfd179d..0d2711f 100644
--- a/chrome/browser/notifications/desktop_notification_service.cc
+++ b/chrome/browser/notifications/desktop_notification_service.cc
@@ -102,13 +102,12 @@ class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~NotificationPermissionInfoBarDelegate();
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual bool Cancel();
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
// The origin we are asking for permissions on.
GURL origin_;
@@ -151,9 +150,6 @@ NotificationPermissionInfoBarDelegate::NotificationPermissionInfoBarDelegate(
NotificationPermissionInfoBarDelegate::
~NotificationPermissionInfoBarDelegate() {
-}
-
-void NotificationPermissionInfoBarDelegate::InfoBarClosed() {
if (!action_taken_)
UMA_HISTOGRAM_COUNTS("NotificationPermissionRequest.Ignored", 1);
@@ -162,8 +158,6 @@ void NotificationPermissionInfoBarDelegate::InfoBarClosed() {
host->Send(new DesktopNotificationMsg_PermissionRequestDone(
route_id_, callback_context_));
}
-
- delete this;
}
gfx::Image* NotificationPermissionInfoBarDelegate::GetIcon() const {
diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc
index 9053dd8..42f7de1 100644
--- a/chrome/browser/omnibox_search_hint.cc
+++ b/chrome/browser/omnibox_search_hint.cc
@@ -56,15 +56,14 @@ class HintInfoBar : public ConfirmInfoBarDelegate {
// ConfirmInfoBarDelegate:
virtual bool ShouldExpire(
- const NavigationController::LoadCommittedDetails& details) const;
- virtual void InfoBarDismissed();
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
+ const NavigationController::LoadCommittedDetails& details) const OVERRIDE;
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual int GetButtons() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
// The omnibox hint that shows us.
OmniboxSearchHint* omnibox_hint_;
@@ -95,6 +94,8 @@ HintInfoBar::HintInfoBar(OmniboxSearchHint* omnibox_hint)
}
HintInfoBar::~HintInfoBar() {
+ if (!action_taken_)
+ UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1);
}
bool HintInfoBar::ShouldExpire(
@@ -109,12 +110,6 @@ void HintInfoBar::InfoBarDismissed() {
omnibox_hint_->DisableHint();
}
-void HintInfoBar::InfoBarClosed() {
- if (!action_taken_)
- UMA_HISTOGRAM_COUNTS("OmniboxSearchHint.Ignored", 1);
- delete this;
-}
-
gfx::Image* HintInfoBar::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_INFOBAR_QUESTION_MARK);
diff --git a/chrome/browser/password_manager_delegate_impl.cc b/chrome/browser/password_manager_delegate_impl.cc
index 7a5a54d..1a518ba 100644
--- a/chrome/browser/password_manager_delegate_impl.cc
+++ b/chrome/browser/password_manager_delegate_impl.cc
@@ -41,13 +41,12 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~SavePasswordInfoBarDelegate();
// ConfirmInfoBarDelegate
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual bool Cancel();
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
// The PasswordFormManager managing the form we're asking the user about,
// and should update as per her decision.
@@ -68,12 +67,8 @@ SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate(
}
SavePasswordInfoBarDelegate::~SavePasswordInfoBarDelegate() {
-}
-
-void SavePasswordInfoBarDelegate::InfoBarClosed() {
UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
infobar_response_, NUM_RESPONSE_TYPES);
- delete this;
}
gfx::Image* SavePasswordInfoBarDelegate::GetIcon() const {
diff --git a/chrome/browser/pdf_unsupported_feature.cc b/chrome/browser/pdf_unsupported_feature.cc
index 7779560..3fd20fb 100644
--- a/chrome/browser/pdf_unsupported_feature.cc
+++ b/chrome/browser/pdf_unsupported_feature.cc
@@ -42,85 +42,81 @@ static const char kReaderUpdateUrl[] =
// The info bar delegate used to ask the user if they want to use Adobe Reader
// by default. We want the infobar to have [No][Yes], so we swap the text on
// the buttons, and the meaning of the delegate callbacks.
-class PDFEnableAdobeReaderConfirmInfoBarDelegate
- : public ConfirmInfoBarDelegate {
+class PDFEnableAdobeReaderInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- PDFEnableAdobeReaderConfirmInfoBarDelegate(
- TabContents* tab_contents)
- : ConfirmInfoBarDelegate(tab_contents),
- tab_contents_(tab_contents) {
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_EnableReaderInfoBarShown"));
- }
+ explicit PDFEnableAdobeReaderInfoBarDelegate(TabContents* tab_contents);
+ virtual ~PDFEnableAdobeReaderInfoBarDelegate();
// ConfirmInfoBarDelegate
- virtual void InfoBarClosed() {
- delete this;
- }
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
- virtual void InfoBarDismissed() {
- OnNo();
- }
+ private:
+ void OnYes();
+ void OnNo();
- virtual Type GetInfoBarType() const {
- return PAGE_ACTION_TYPE;
- }
+ TabContents* tab_contents_;
- virtual bool Accept() {
- tab_contents_->profile()->GetPrefs()->SetBoolean(
- prefs::kPluginsShowSetReaderDefaultInfobar, false);
- return OnNo();
- }
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderInfoBarDelegate);
+};
- virtual bool Cancel() {
- return OnYes();
- }
+PDFEnableAdobeReaderInfoBarDelegate::PDFEnableAdobeReaderInfoBarDelegate(
+ TabContents* tab_contents)
+ : ConfirmInfoBarDelegate(tab_contents),
+ tab_contents_(tab_contents) {
+ UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarShown"));
+}
- virtual int GetButtons() const {
- return BUTTON_OK | BUTTON_CANCEL;
- }
+PDFEnableAdobeReaderInfoBarDelegate::~PDFEnableAdobeReaderInfoBarDelegate() {
+}
- virtual string16 GetButtonLabel(InfoBarButton button) const {
- switch (button) {
- case BUTTON_OK:
- return l10n_util::GetStringUTF16(
- IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON);
- case BUTTON_CANCEL:
- return l10n_util::GetStringUTF16(
- IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
- default:
- // All buttons are labeled above.
- NOTREACHED() << "Bad button id " << button;
- return string16();
- }
- }
+void PDFEnableAdobeReaderInfoBarDelegate::InfoBarDismissed() {
+ OnNo();
+}
- virtual string16 GetMessageText() const {
- return l10n_util::GetStringUTF16(
- IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
- }
+InfoBarDelegate::Type
+ PDFEnableAdobeReaderInfoBarDelegate::GetInfoBarType() const {
+ return PAGE_ACTION_TYPE;
+}
- private:
- bool OnYes() {
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_EnableReaderInfoBarOK"));
- webkit::npapi::PluginList::Singleton()->EnableGroup(
- false, ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
- webkit::npapi::PluginList::Singleton()->EnableGroup(
- true, ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
- return true;
- }
+bool PDFEnableAdobeReaderInfoBarDelegate::Accept() {
+ tab_contents_->profile()->GetPrefs()->SetBoolean(
+ prefs::kPluginsShowSetReaderDefaultInfobar, false);
+ OnNo();
+ return true;
+}
- bool OnNo() {
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
- return true;
- }
+bool PDFEnableAdobeReaderInfoBarDelegate::Cancel() {
+ OnYes();
+ return true;
+}
- TabContents* tab_contents_;
+string16 PDFEnableAdobeReaderInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
+ IDS_PDF_INFOBAR_NEVER_USE_READER_BUTTON :
+ IDS_PDF_INFOBAR_ALWAYS_USE_READER_BUTTON);
+}
- DISALLOW_IMPLICIT_CONSTRUCTORS(PDFEnableAdobeReaderConfirmInfoBarDelegate);
-};
+string16 PDFEnableAdobeReaderInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetStringUTF16(IDS_PDF_INFOBAR_QUESTION_ALWAYS_USE_READER);
+}
+
+void PDFEnableAdobeReaderInfoBarDelegate::OnYes() {
+ UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarOK"));
+ webkit::npapi::PluginList::Singleton()->EnableGroup(false,
+ ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
+ webkit::npapi::PluginList::Singleton()->EnableGroup(true,
+ ASCIIToUTF16(webkit::npapi::PluginGroup::kAdobeReaderGroupName));
+}
+
+void PDFEnableAdobeReaderInfoBarDelegate::OnNo() {
+ UserMetrics::RecordAction(UserMetricsAction("PDF_EnableReaderInfoBarCancel"));
+}
// Launch the url to get the latest Adbobe Reader installer.
void OpenReaderUpdateURL(TabContents* tab) {
@@ -229,137 +225,128 @@ class PDFUnsupportedFeatureInterstitial : public ChromeInterstitialPage {
// The info bar delegate used to inform the user that we don't support a feature
// in the PDF. See the comment about how we swap buttons for
-// PDFEnableAdobeReaderConfirmInfoBarDelegate.
-class PDFUnsupportedFeatureConfirmInfoBarDelegate
- : public ConfirmInfoBarDelegate {
+// PDFEnableAdobeReaderInfoBarDelegate.
+class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- PDFUnsupportedFeatureConfirmInfoBarDelegate(
- TabContents* tab_contents,
- PluginGroup* reader_group) // NULL if Adobe Reader isn't installed.
- : ConfirmInfoBarDelegate(tab_contents),
- tab_contents_(tab_contents),
- reader_installed_(!!reader_group),
- reader_vulnerable_(false) {
- if (reader_installed_) {
- UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
- std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos();
- DCHECK_EQ(plugins.size(), 1u);
- reader_webplugininfo_ = plugins[0];
-
- reader_vulnerable_ = reader_group->IsVulnerable();
- if (!reader_vulnerable_) {
- scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
- reader_webplugininfo_.version));
- if (version.get()) {
- if (version->components()[0] < kMinReaderVersionToUse)
- reader_vulnerable_ = true;
- }
- }
- } else {
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_InstallReaderInfoBarShown"));
- }
- }
+ // |reader_group| is NULL if Adobe Reader isn't installed.
+ PDFUnsupportedFeatureInfoBarDelegate(TabContents* tab_contents,
+ PluginGroup* reader_group);
+ virtual ~PDFUnsupportedFeatureInfoBarDelegate();
// ConfirmInfoBarDelegate
- virtual void InfoBarClosed() {
- delete this;
- }
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
- virtual void InfoBarDismissed() {
- OnNo();
- }
+ private:
+ bool OnYes();
+ void OnNo();
- virtual Type GetInfoBarType() const {
- return PAGE_ACTION_TYPE;
- }
+ TabContents* tab_contents_;
+ bool reader_installed_;
+ bool reader_vulnerable_;
+ WebPluginInfo reader_webplugininfo_;
- virtual bool Accept() {
- return OnNo();
- }
+ DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate);
+};
- virtual bool Cancel() {
- return OnYes();
+PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate(
+ TabContents* tab_contents,
+ PluginGroup* reader_group)
+ : ConfirmInfoBarDelegate(tab_contents),
+ tab_contents_(tab_contents),
+ reader_installed_(!!reader_group),
+ reader_vulnerable_(false) {
+ if (!reader_installed_) {
+ UserMetrics::RecordAction(
+ UserMetricsAction("PDF_InstallReaderInfoBarShown"));
+ return;
}
- virtual int GetButtons() const {
- return BUTTON_OK | BUTTON_CANCEL;
+ UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarShown"));
+ std::vector<WebPluginInfo> plugins = reader_group->web_plugin_infos();
+ DCHECK_EQ(plugins.size(), 1u);
+ reader_webplugininfo_ = plugins[0];
+
+ reader_vulnerable_ = reader_group->IsVulnerable();
+ if (!reader_vulnerable_) {
+ scoped_ptr<Version> version(PluginGroup::CreateVersionFromString(
+ reader_webplugininfo_.version));
+ reader_vulnerable_ =
+ version.get() && (version->components()[0] < kMinReaderVersionToUse);
}
+}
- virtual string16 GetButtonLabel(InfoBarButton button) const {
- switch (button) {
- case BUTTON_OK:
- return l10n_util::GetStringUTF16(
- IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
- case BUTTON_CANCEL:
- return l10n_util::GetStringUTF16(
- IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
- default:
- // All buttons are labeled above.
- NOTREACHED() << "Bad button id " << button;
- return string16();
- }
- }
+PDFUnsupportedFeatureInfoBarDelegate::~PDFUnsupportedFeatureInfoBarDelegate() {
+}
- virtual string16 GetMessageText() const {
- return l10n_util::GetStringUTF16(reader_installed_ ?
- IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
- IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED);
- }
+void PDFUnsupportedFeatureInfoBarDelegate::InfoBarDismissed() {
+ OnNo();
+}
- private:
- bool OnYes() {
- if (!reader_installed_) {
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_InstallReaderInfoBarOK"));
- OpenReaderUpdateURL(tab_contents_);
- return true;
- }
+InfoBarDelegate::Type
+ PDFUnsupportedFeatureInfoBarDelegate::GetInfoBarType() const {
+ return PAGE_ACTION_TYPE;
+}
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_UseReaderInfoBarOK"));
-
- if (reader_vulnerable_) {
- PDFUnsupportedFeatureInterstitial* interstitial = new
- PDFUnsupportedFeatureInterstitial(
- tab_contents_, reader_webplugininfo_);
- interstitial->Show();
- return true;
- }
+bool PDFUnsupportedFeatureInfoBarDelegate::Accept() {
+ OnNo();
+ return true;
+}
- InfoBarDelegate* bar = NULL;
- if (tab_contents_->profile()->GetPrefs()->GetBoolean(
- prefs::kPluginsShowSetReaderDefaultInfobar)) {
- bar = new PDFEnableAdobeReaderConfirmInfoBarDelegate(tab_contents_);
- }
+bool PDFUnsupportedFeatureInfoBarDelegate::Cancel() {
+ return OnYes();
+}
- if (bar) {
- OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar);
- return false;
- } else {
- OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL);
- return true;
- }
+string16 PDFUnsupportedFeatureInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
+ IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL :
+ IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL);
+}
+
+string16 PDFUnsupportedFeatureInfoBarDelegate::GetMessageText() const {
+ return l10n_util::GetStringUTF16(reader_installed_ ?
+ IDS_PDF_INFOBAR_QUESTION_READER_INSTALLED :
+ IDS_PDF_INFOBAR_QUESTION_READER_NOT_INSTALLED);
+}
+
+bool PDFUnsupportedFeatureInfoBarDelegate::OnYes() {
+ if (!reader_installed_) {
+ UserMetrics::RecordAction(UserMetricsAction("PDF_InstallReaderInfoBarOK"));
+ OpenReaderUpdateURL(tab_contents_);
+ return true;
}
- bool OnNo() {
- if (reader_installed_) {
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_UseReaderInfoBarCancel"));
- } else {
- UserMetrics::RecordAction(
- UserMetricsAction("PDF_InstallReaderInfoBarCancel"));
- }
+ UserMetrics::RecordAction(UserMetricsAction("PDF_UseReaderInfoBarOK"));
+
+ if (reader_vulnerable_) {
+ PDFUnsupportedFeatureInterstitial* interstitial =
+ new PDFUnsupportedFeatureInterstitial(tab_contents_,
+ reader_webplugininfo_);
+ interstitial->Show();
return true;
}
- TabContents* tab_contents_;
- bool reader_installed_;
- bool reader_vulnerable_;
- WebPluginInfo reader_webplugininfo_;
+ if (tab_contents_->profile()->GetPrefs()->GetBoolean(
+ prefs::kPluginsShowSetReaderDefaultInfobar)) {
+ InfoBarDelegate* bar =
+ new PDFEnableAdobeReaderInfoBarDelegate(tab_contents_);
+ OpenUsingReader(tab_contents_, reader_webplugininfo_, this, bar);
+ return false;
+ }
- DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureConfirmInfoBarDelegate);
-};
+ OpenUsingReader(tab_contents_, reader_webplugininfo_, NULL, NULL);
+ return true;
+}
+
+void PDFUnsupportedFeatureInfoBarDelegate::OnNo() {
+ UserMetrics::RecordAction(UserMetricsAction(reader_installed_ ?
+ "PDF_UseReaderInfoBarCancel" : "PDF_InstallReaderInfoBarCancel"));
+}
} // namespace
@@ -386,6 +373,5 @@ void PDFHasUnsupportedFeature(TabContents* tab) {
}
}
- tab->AddInfoBar(new PDFUnsupportedFeatureConfirmInfoBarDelegate(
- tab, reader_group));
+ tab->AddInfoBar(new PDFUnsupportedFeatureInfoBarDelegate(tab, reader_group));
}
diff --git a/chrome/browser/plugin_installer_infobar_delegate.h b/chrome/browser/plugin_installer_infobar_delegate.h
index a04bcac..d4065d5 100644
--- a/chrome/browser/plugin_installer_infobar_delegate.h
+++ b/chrome/browser/plugin_installer_infobar_delegate.h
@@ -20,14 +20,15 @@ class PluginInstallerInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~PluginInstallerInfoBarDelegate();
// ConfirmInfoBarDelegate:
- virtual gfx::Image* GetIcon() const;
- virtual PluginInstallerInfoBarDelegate* AsPluginInstallerInfoBarDelegate();
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual string16 GetLinkText();
- virtual bool LinkClicked(WindowOpenDisposition disposition);
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual PluginInstallerInfoBarDelegate*
+ AsPluginInstallerInfoBarDelegate() OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual int GetButtons() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual string16 GetLinkText() OVERRIDE;
+ virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
// The containing TabContents
TabContents* tab_contents_;
diff --git a/chrome/browser/plugin_observer.cc b/chrome/browser/plugin_observer.cc
index 7e1d0a9..dabdac1 100644
--- a/chrome/browser/plugin_observer.cc
+++ b/chrome/browser/plugin_observer.cc
@@ -38,9 +38,8 @@ class PluginInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~PluginInfoBarDelegate();
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed();
- virtual bool Cancel();
- virtual bool LinkClicked(WindowOpenDisposition disposition);
+ virtual bool Cancel() OVERRIDE;
+ virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
virtual std::string GetLearnMoreURL() const = 0;
@@ -65,10 +64,6 @@ PluginInfoBarDelegate::PluginInfoBarDelegate(TabContents* tab_contents,
PluginInfoBarDelegate::~PluginInfoBarDelegate() {
}
-void PluginInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
bool PluginInfoBarDelegate::Cancel() {
tab_contents_->render_view_host()->Send(new ViewMsg_LoadBlockedPlugins(
tab_contents_->render_view_host()->routing_id()));
@@ -102,14 +97,13 @@ class BlockedPluginInfoBarDelegate : public PluginInfoBarDelegate {
virtual ~BlockedPluginInfoBarDelegate();
// PluginInfoBarDelegate:
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual bool Cancel();
- virtual void InfoBarClosed();
- virtual void InfoBarDismissed();
- virtual bool LinkClicked(WindowOpenDisposition disposition);
- virtual std::string GetLearnMoreURL() const;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
+ virtual std::string GetLearnMoreURL() const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBarDelegate);
};
@@ -135,6 +129,7 @@ BlockedPluginInfoBarDelegate::BlockedPluginInfoBarDelegate(
}
BlockedPluginInfoBarDelegate::~BlockedPluginInfoBarDelegate() {
+ UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed"));
}
std::string BlockedPluginInfoBarDelegate::GetLearnMoreURL() const {
@@ -171,11 +166,6 @@ void BlockedPluginInfoBarDelegate::InfoBarDismissed() {
UserMetricsAction("BlockedPluginInfobar.Dismissed"));
}
-void BlockedPluginInfoBarDelegate::InfoBarClosed() {
- UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed"));
- PluginInfoBarDelegate::InfoBarClosed();
-}
-
bool BlockedPluginInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
UserMetrics::RecordAction(
@@ -195,14 +185,13 @@ class OutdatedPluginInfoBarDelegate : public PluginInfoBarDelegate {
virtual ~OutdatedPluginInfoBarDelegate();
// PluginInfoBarDelegate:
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual bool Cancel();
- virtual void InfoBarClosed();
- virtual void InfoBarDismissed();
- virtual bool LinkClicked(WindowOpenDisposition disposition);
- virtual std::string GetLearnMoreURL() const;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
+ virtual std::string GetLearnMoreURL() const OVERRIDE;
GURL update_url_;
@@ -238,6 +227,7 @@ OutdatedPluginInfoBarDelegate::OutdatedPluginInfoBarDelegate(
}
OutdatedPluginInfoBarDelegate::~OutdatedPluginInfoBarDelegate() {
+ UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed"));
}
std::string OutdatedPluginInfoBarDelegate::GetLearnMoreURL() const {
@@ -272,11 +262,6 @@ void OutdatedPluginInfoBarDelegate::InfoBarDismissed() {
UserMetricsAction("OutdatedPluginInfobar.Dismissed"));
}
-void OutdatedPluginInfoBarDelegate::InfoBarClosed() {
- UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed"));
- PluginInfoBarDelegate::InfoBarClosed();
-}
-
bool OutdatedPluginInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
UserMetrics::RecordAction(
diff --git a/chrome/browser/tab_contents/infobar_delegate.cc b/chrome/browser/tab_contents/infobar_delegate.cc
index 7b4720e..d0b04b7 100644
--- a/chrome/browser/tab_contents/infobar_delegate.cc
+++ b/chrome/browser/tab_contents/infobar_delegate.cc
@@ -30,6 +30,7 @@ void InfoBarDelegate::InfoBarDismissed() {
}
void InfoBarDelegate::InfoBarClosed() {
+ delete this;
}
gfx::Image* InfoBarDelegate::GetIcon() const {
diff --git a/chrome/browser/tab_contents/infobar_delegate.h b/chrome/browser/tab_contents/infobar_delegate.h
index 4ee29c4..ea56a1e 100644
--- a/chrome/browser/tab_contents/infobar_delegate.h
+++ b/chrome/browser/tab_contents/infobar_delegate.h
@@ -28,23 +28,6 @@ class Image;
// does not map to a specific InfoBar type. Instead, you must implement either
// LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own
// delegate for your own InfoBar variety.
-//
-// --- WARNING ---
-// When creating your InfoBarDelegate subclass, it is recommended that you
-// design it such that you instantiate a brand new delegate for every call to
-// AddInfoBar, rather than re-using/sharing a delegate object. Otherwise,
-// you need to consider the fact that more than one InfoBar instance can exist
-// and reference the same delegate -- even though it is also true that we only
-// ever fully show one infobar (they don't stack). The dual-references occur
-// because a second InfoBar can be added while the first one is in the process
-// of closing (the animations). This can cause problems because when the first
-// one does finally fully close InfoBarDelegate::InfoBarClosed() is called,
-// and the delegate is free to clean itself up or reset state, which may have
-// fatal consequences for the InfoBar that was in the process of opening (or is
-// now fully opened) -- it is referencing a delegate that may not even exist
-// anymore.
-// As such, it is generally much safer to dedicate a delegate instance to
-// AddInfoBar!
class InfoBarDelegate {
public:
// The type of the infobar. It controls its appearance, such as its background
@@ -77,9 +60,9 @@ class InfoBarDelegate {
// Called when the user clicks on the close button to dismiss the infobar.
virtual void InfoBarDismissed();
- // Called after the InfoBar is closed. The delegate is free to delete itself
- // at this point.
- virtual void InfoBarClosed();
+ // Called after the InfoBar is closed. Deletes |this|.
+ // TODO(pkasting): Get rid of this and delete delegates directly.
+ void InfoBarClosed();
// Return the icon to be shown for this InfoBar. If the returned Image is
// NULL, no icon is shown.
diff --git a/chrome/browser/tab_contents/simple_alert_infobar_delegate.cc b/chrome/browser/tab_contents/simple_alert_infobar_delegate.cc
index 28220be..da52690 100644
--- a/chrome/browser/tab_contents/simple_alert_infobar_delegate.cc
+++ b/chrome/browser/tab_contents/simple_alert_infobar_delegate.cc
@@ -27,10 +27,6 @@ bool SimpleAlertInfoBarDelegate::ShouldExpire(
return auto_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details);
}
-void SimpleAlertInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
gfx::Image* SimpleAlertInfoBarDelegate::GetIcon() const {
return icon_;
}
diff --git a/chrome/browser/tab_contents/simple_alert_infobar_delegate.h b/chrome/browser/tab_contents/simple_alert_infobar_delegate.h
index 1ef2539..1e30125 100644
--- a/chrome/browser/tab_contents/simple_alert_infobar_delegate.h
+++ b/chrome/browser/tab_contents/simple_alert_infobar_delegate.h
@@ -27,7 +27,6 @@ class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate {
// ConfirmInfoBarDelegate:
virtual bool ShouldExpire(
const NavigationController::LoadCommittedDetails& details) const OVERRIDE;
- virtual void InfoBarClosed() OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual string16 GetMessageText() const OVERRIDE;
virtual int GetButtons() const OVERRIDE;
diff --git a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
index acf72478..bf05599 100644
--- a/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
+++ b/chrome/browser/tab_contents/tab_contents_ssl_helper.cc
@@ -42,13 +42,12 @@ class SSLCertAddedInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~SSLCertAddedInfoBarDelegate();
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual int GetButtons() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
TabContents* tab_contents_; // The TabContents we are attached to.
scoped_refptr<net::X509Certificate> cert_; // The cert we added.
@@ -65,11 +64,6 @@ SSLCertAddedInfoBarDelegate::SSLCertAddedInfoBarDelegate(
SSLCertAddedInfoBarDelegate::~SSLCertAddedInfoBarDelegate() {
}
-void SSLCertAddedInfoBarDelegate::InfoBarClosed() {
- // ConfirmInfoBarDelegate doesn't delete itself.
- delete this;
-}
-
gfx::Image* SSLCertAddedInfoBarDelegate::GetIcon() const {
return GetCertIcon();
}
diff --git a/chrome/browser/translate/translate_infobar_delegate.cc b/chrome/browser/translate/translate_infobar_delegate.cc
index 3e67c22..5537e83 100644
--- a/chrome/browser/translate/translate_infobar_delegate.cc
+++ b/chrome/browser/translate/translate_infobar_delegate.cc
@@ -359,10 +359,6 @@ void TranslateInfoBarDelegate::InfoBarDismissed() {
UMA_HISTOGRAM_COUNTS("Translate.DeclineTranslateCloseInfobar", 1);
}
-void TranslateInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
gfx::Image* TranslateInfoBarDelegate::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_INFOBAR_TRANSLATE);
diff --git a/chrome/browser/translate/translate_infobar_delegate.h b/chrome/browser/translate/translate_infobar_delegate.h
index 9d763089..03c196e 100644
--- a/chrome/browser/translate/translate_infobar_delegate.h
+++ b/chrome/browser/translate/translate_infobar_delegate.h
@@ -159,12 +159,11 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
typedef std::pair<std::string, string16> LanguageNamePair;
// InfoBarDelegate:
- virtual InfoBar* CreateInfoBar();
- virtual void InfoBarDismissed();
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual InfoBarDelegate::Type GetInfoBarType() const;
- virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate();
+ virtual InfoBar* CreateInfoBar() OVERRIDE;
+ virtual void InfoBarDismissed() OVERRIDE;
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual InfoBarDelegate::Type GetInfoBarType() const OVERRIDE;
+ virtual TranslateInfoBarDelegate* AsTranslateInfoBarDelegate() OVERRIDE;
// Gets the host of the page being translated, or an empty string if no URL is
// associated with the current page.
diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc
index 86bb2ec..6700377 100644
--- a/chrome/browser/ui/browser_init.cc
+++ b/chrome/browser/ui/browser_init.cc
@@ -144,7 +144,6 @@ class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
// ConfirmInfoBarDelegate:
virtual bool ShouldExpire(
const NavigationController::LoadCommittedDetails& details) const OVERRIDE;
- virtual void InfoBarClosed() OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual string16 GetMessageText() const OVERRIDE;
virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
@@ -182,6 +181,8 @@ DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(
}
DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() {
+ if (!action_taken_)
+ UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.Ignored", 1);
}
bool DefaultBrowserInfoBarDelegate::ShouldExpire(
@@ -189,12 +190,6 @@ bool DefaultBrowserInfoBarDelegate::ShouldExpire(
return should_expire_;
}
-void DefaultBrowserInfoBarDelegate::InfoBarClosed() {
- if (!action_taken_)
- UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.Ignored", 1);
- delete this;
-}
-
gfx::Image* DefaultBrowserInfoBarDelegate::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_PRODUCT_ICON_32);
@@ -305,7 +300,6 @@ class SessionCrashedInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual ~SessionCrashedInfoBarDelegate();
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed() OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual string16 GetMessageText() const OVERRIDE;
virtual int GetButtons() const OVERRIDE;
@@ -327,10 +321,6 @@ SessionCrashedInfoBarDelegate::SessionCrashedInfoBarDelegate(
SessionCrashedInfoBarDelegate::~SessionCrashedInfoBarDelegate() {
}
-void SessionCrashedInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
gfx::Image* SessionCrashedInfoBarDelegate::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_INFOBAR_RESTORE_SESSION);
@@ -1081,29 +1071,13 @@ void BrowserInit::LaunchWithProfile::AddBadFlagsInfoBarIfNecessary(
class DNSCertProvenanceCheckingInfoBar : public ConfirmInfoBarDelegate {
public:
- explicit DNSCertProvenanceCheckingInfoBar(TabContents* tab_contents)
- : ConfirmInfoBarDelegate(tab_contents),
- tab_contents_(tab_contents) {
- }
+ explicit DNSCertProvenanceCheckingInfoBar(TabContents* tab_contents);
+ virtual ~DNSCertProvenanceCheckingInfoBar();
- virtual string16 GetMessageText() const {
- return l10n_util::GetStringUTF16(
- IDS_DNS_CERT_PROVENANCE_CHECKING_WARNING_MESSAGE);
- }
-
- virtual int GetButtons() const {
- return BUTTON_OK;
- }
-
- virtual string16 GetButtonLabel(InfoBarButton button) const {
- return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
- }
-
- virtual bool Accept() {
- tab_contents_->OpenURL(GURL(kLearnMoreURL), GURL(), NEW_FOREGROUND_TAB,
- PageTransition::AUTO_BOOKMARK);
- return true;
- }
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual int GetButtons() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(DNSCertProvenanceCheckingInfoBar);
@@ -1112,6 +1086,35 @@ class DNSCertProvenanceCheckingInfoBar : public ConfirmInfoBarDelegate {
TabContents* const tab_contents_;
};
+DNSCertProvenanceCheckingInfoBar::DNSCertProvenanceCheckingInfoBar(
+ TabContents* tab_contents)
+ : ConfirmInfoBarDelegate(tab_contents),
+ tab_contents_(tab_contents) {
+}
+
+DNSCertProvenanceCheckingInfoBar::~DNSCertProvenanceCheckingInfoBar() {
+}
+
+string16 DNSCertProvenanceCheckingInfoBar::GetMessageText() const {
+ return l10n_util::GetStringUTF16(
+ IDS_DNS_CERT_PROVENANCE_CHECKING_WARNING_MESSAGE);
+}
+
+int DNSCertProvenanceCheckingInfoBar::GetButtons() const {
+ return BUTTON_OK;
+}
+
+string16 DNSCertProvenanceCheckingInfoBar::GetButtonLabel(
+ InfoBarButton button) const {
+ return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
+}
+
+bool DNSCertProvenanceCheckingInfoBar::Accept() {
+ tab_contents_->OpenURL(GURL(kLearnMoreURL), GURL(), NEW_FOREGROUND_TAB,
+ PageTransition::AUTO_BOOKMARK);
+ return true;
+}
+
// This is the page which provides information on DNS certificate provenance
// checking.
const char DNSCertProvenanceCheckingInfoBar::kLearnMoreURL[] =
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 c05a9ae..78e43e3 100644
--- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm
@@ -53,26 +53,31 @@ TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) {
// Add three infobars and then remove them.
// After each step check to make sure we have the correct number of
// infobar subviews.
- MockLinkInfoBarDelegate linkDelegate, linkDelegate2;
- MockConfirmInfoBarDelegate confirmDelegate;
- [controller_ addInfoBar:&linkDelegate animate:NO];
+ // These delegates delete themselves when they're told their infobars have
+ // closed.
+ MockLinkInfoBarDelegate* linkDelegate = new MockLinkInfoBarDelegate(NULL);
+ MockLinkInfoBarDelegate* linkDelegate2 = new MockLinkInfoBarDelegate(NULL);
+ MockConfirmInfoBarDelegate* confirmDelegate =
+ new MockConfirmInfoBarDelegate(NULL);
+
+ [controller_ addInfoBar:linkDelegate animate:NO];
EXPECT_EQ(1U, [[view subviews] count]);
- [controller_ addInfoBar:&confirmDelegate animate:NO];
+ [controller_ addInfoBar:confirmDelegate animate:NO];
EXPECT_EQ(2U, [[view subviews] count]);
- [controller_ addInfoBar:&linkDelegate2 animate:NO];
+ [controller_ addInfoBar:linkDelegate2 animate:NO];
EXPECT_EQ(3U, [[view subviews] count]);
// Just to mix things up, remove them in a different order.
- [controller_ closeInfoBarsForDelegate:&confirmDelegate animate:NO];
+ [controller_ closeInfoBarsForDelegate:confirmDelegate animate:NO];
EXPECT_EQ(2U, [[view subviews] count]);
- [controller_ closeInfoBarsForDelegate:&linkDelegate animate:NO];
+ [controller_ closeInfoBarsForDelegate:linkDelegate animate:NO];
EXPECT_EQ(1U, [[view subviews] count]);
- [controller_ closeInfoBarsForDelegate:&linkDelegate2 animate:NO];
+ [controller_ closeInfoBarsForDelegate:linkDelegate2 animate:NO];
EXPECT_EQ(0U, [[view subviews] count]);
}
@@ -80,12 +85,18 @@ TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) {
NSView* view = [controller_ view];
// Add three infobars and then remove them all.
- MockLinkInfoBarDelegate linkDelegate;
- MockConfirmInfoBarDelegate confirmDelegate, confirmDelegate2;
- [controller_ addInfoBar:&linkDelegate animate:NO];
- [controller_ addInfoBar:&confirmDelegate animate:NO];
- [controller_ addInfoBar:&confirmDelegate2 animate:NO];
+ // These delegates delete themselves when they're told their infobars have
+ // closed.
+ MockLinkInfoBarDelegate* linkDelegate = new MockLinkInfoBarDelegate(NULL);
+ MockConfirmInfoBarDelegate* confirmDelegate =
+ new MockConfirmInfoBarDelegate(NULL);
+ MockConfirmInfoBarDelegate* confirmDelegate2 =
+ new MockConfirmInfoBarDelegate(NULL);
+
+ [controller_ addInfoBar:linkDelegate animate:NO];
+ [controller_ addInfoBar:confirmDelegate animate:NO];
+ [controller_ addInfoBar:confirmDelegate2 animate:NO];
EXPECT_EQ(3U, [[view subviews] count]);
[controller_ removeAllInfoBars];
diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm
index d45447f..c2e6d50 100644
--- a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm
+++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm
@@ -266,7 +266,7 @@ const float kAnimateCloseDuration = 0.12;
if (!infoBarClosing_)
return;
- // Notify the delegate that the infobar was closed. The delegate may delete
+ // Notify the delegate that the infobar was closed. The delegate will delete
// itself as a result of InfoBarClosed(), so we null out its pointer.
if (delegate_) {
delegate_->InfoBarClosed();
diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm
index 011e38b..2dc43f9 100644
--- a/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm
@@ -70,42 +70,86 @@ namespace {
///////////////////////////////////////////////////////////////////////////
// Test fixtures
-class LinkInfoBarControllerTest : public CocoaTest {
+class LinkInfoBarControllerTest : public CocoaTest,
+ public MockLinkInfoBarDelegate::Owner {
public:
virtual void SetUp() {
CocoaTest::SetUp();
+ delegate_ = new MockLinkInfoBarDelegate(this);
controller_.reset(
- [[LinkInfoBarController alloc] initWithDelegate:&delegate_]);
+ [[LinkInfoBarController alloc] initWithDelegate:delegate_]);
container_.reset(
[[InfoBarContainerTest alloc] initWithController:controller_]);
[controller_ setContainerController:container_];
[[test_window() contentView] addSubview:[controller_ view]];
+ closed_delegate_link_clicked_ = false;
+ }
+
+ virtual void TearDown() {
+ if (delegate_)
+ delete delegate_;
+ CocoaTest::TearDown();
}
protected:
- MockLinkInfoBarDelegate delegate_;
+ // Hopefully-obvious: If this returns true, you must not deref |delegate_|!
+ bool delegate_closed() const { return delegate_ == NULL; }
+
+ MockLinkInfoBarDelegate* delegate_; // Owns itself.
scoped_nsobject<id> container_;
scoped_nsobject<LinkInfoBarController> controller_;
+ bool closed_delegate_link_clicked_;
+
+ private:
+ virtual void OnInfoBarDelegateClosed() {
+ closed_delegate_link_clicked_ = delegate_->link_clicked();
+ delegate_ = NULL;
+ }
};
-class ConfirmInfoBarControllerTest : public CocoaTest {
+class ConfirmInfoBarControllerTest : public CocoaTest,
+ public MockConfirmInfoBarDelegate::Owner {
public:
virtual void SetUp() {
CocoaTest::SetUp();
+ delegate_ = new MockConfirmInfoBarDelegate(this);
controller_.reset(
- [[ConfirmInfoBarController alloc] initWithDelegate:&delegate_]);
+ [[ConfirmInfoBarController alloc] initWithDelegate:delegate_]);
container_.reset(
[[InfoBarContainerTest alloc] initWithController:controller_]);
[controller_ setContainerController:container_];
[[test_window() contentView] addSubview:[controller_ view]];
+ closed_delegate_ok_clicked_ = false;
+ closed_delegate_cancel_clicked_ = false;
+ closed_delegate_link_clicked_ = false;
+ }
+
+ virtual void TearDown() {
+ if (delegate_)
+ delete delegate_;
+ CocoaTest::TearDown();
}
protected:
- MockConfirmInfoBarDelegate delegate_;
+ // Hopefully-obvious: If this returns true, you must not deref |delegate_|!
+ bool delegate_closed() const { return delegate_ == NULL; }
+
+ MockConfirmInfoBarDelegate* delegate_; // Owns itself.
scoped_nsobject<id> container_;
scoped_nsobject<ConfirmInfoBarController> controller_;
+ bool closed_delegate_ok_clicked_;
+ bool closed_delegate_cancel_clicked_;
+ bool closed_delegate_link_clicked_;
+
+ private:
+ virtual void OnInfoBarDelegateClosed() {
+ closed_delegate_ok_clicked_ = delegate_->ok_clicked();
+ closed_delegate_cancel_clicked_ = delegate_->cancel_clicked();
+ closed_delegate_link_clicked_ = delegate_->link_clicked();
+ delegate_ = NULL;
+ }
};
@@ -116,125 +160,124 @@ TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]);
TEST_F(LinkInfoBarControllerTest, 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 that dismissing the infobar calls InfoBarClosed() on the delegate.
+ // Check that dismissing the infobar deletes the delegate.
[controller_ dismiss:nil];
- EXPECT_FALSE(delegate_.link_clicked());
- EXPECT_TRUE(delegate_.closed());
+ ASSERT_TRUE(delegate_closed());
+ EXPECT_FALSE(closed_delegate_link_clicked_);
}
TEST_F(LinkInfoBarControllerTest, ShowAndClickLink) {
// Check that clicking on the link calls LinkClicked() on the
// delegate. It should also close the infobar.
[controller_ linkClicked];
- EXPECT_TRUE(delegate_.link_clicked());
- EXPECT_TRUE(delegate_.closed());
+ ASSERT_TRUE(delegate_closed());
+ EXPECT_TRUE(closed_delegate_link_clicked_);
}
TEST_F(LinkInfoBarControllerTest, 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];
- EXPECT_TRUE(delegate_.link_clicked());
- EXPECT_FALSE(delegate_.closed());
+ ASSERT_FALSE(delegate_closed());
+ EXPECT_TRUE(delegate_->link_clicked());
}
TEST_F(LinkInfoBarControllerTest, DeallocController) {
- // Test that dealloc'ing the controller does not send an
- // InfoBarClosed() message to the delegate.
+ // Test that dealloc'ing the controller does not delete the delegate.
controller_.reset(nil);
- EXPECT_FALSE(delegate_.closed());
+ ASSERT_FALSE(delegate_closed());
}
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,
base::SysNSStringToUTF8([controller_.get() labelString]));
- // Check that dismissing the infobar calls InfoBarClosed() on the delegate.
+ // Check that dismissing the infobar deletes the delegate.
[controller_ dismiss:nil];
- EXPECT_FALSE(delegate_.ok_clicked());
- EXPECT_FALSE(delegate_.cancel_clicked());
- EXPECT_FALSE(delegate_.link_clicked());
- EXPECT_TRUE(delegate_.closed());
+ ASSERT_TRUE(delegate_closed());
+ EXPECT_FALSE(closed_delegate_ok_clicked_);
+ EXPECT_FALSE(closed_delegate_cancel_clicked_);
+ EXPECT_FALSE(closed_delegate_link_clicked_);
}
TEST_F(ConfirmInfoBarControllerTest, ShowAndClickOK) {
// Check that clicking the OK button calls Accept() and then closes
// the infobar.
[controller_ ok:nil];
- EXPECT_TRUE(delegate_.ok_clicked());
- EXPECT_FALSE(delegate_.cancel_clicked());
- EXPECT_FALSE(delegate_.link_clicked());
- EXPECT_TRUE(delegate_.closed());
+ ASSERT_TRUE(delegate_closed());
+ EXPECT_TRUE(closed_delegate_ok_clicked_);
+ EXPECT_FALSE(closed_delegate_cancel_clicked_);
+ EXPECT_FALSE(closed_delegate_link_clicked_);
}
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];
- EXPECT_TRUE(delegate_.ok_clicked());
- EXPECT_FALSE(delegate_.cancel_clicked());
- EXPECT_FALSE(delegate_.link_clicked());
- EXPECT_FALSE(delegate_.closed());
+ ASSERT_FALSE(delegate_closed());
+ EXPECT_TRUE(delegate_->ok_clicked());
+ EXPECT_FALSE(delegate_->cancel_clicked());
+ EXPECT_FALSE(delegate_->link_clicked());
}
TEST_F(ConfirmInfoBarControllerTest, ShowAndClickCancel) {
// Check that clicking the cancel button calls Cancel() and closes
// the infobar.
[controller_ cancel:nil];
- EXPECT_FALSE(delegate_.ok_clicked());
- EXPECT_TRUE(delegate_.cancel_clicked());
- EXPECT_FALSE(delegate_.link_clicked());
- EXPECT_TRUE(delegate_.closed());
+ ASSERT_TRUE(delegate_closed());
+ EXPECT_FALSE(closed_delegate_ok_clicked_);
+ EXPECT_TRUE(closed_delegate_cancel_clicked_);
+ EXPECT_FALSE(closed_delegate_link_clicked_);
}
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];
- EXPECT_FALSE(delegate_.ok_clicked());
- EXPECT_TRUE(delegate_.cancel_clicked());
- EXPECT_FALSE(delegate_.link_clicked());
- EXPECT_FALSE(delegate_.closed());
+ ASSERT_FALSE(delegate_closed());
+ EXPECT_FALSE(delegate_->ok_clicked());
+ EXPECT_TRUE(delegate_->cancel_clicked());
+ EXPECT_FALSE(delegate_->link_clicked());
}
TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLink) {
// Check that clicking on the link calls LinkClicked() on the
// delegate. It should also close the infobar.
[controller_ linkClicked];
- EXPECT_FALSE(delegate_.ok_clicked());
- EXPECT_FALSE(delegate_.cancel_clicked());
- EXPECT_TRUE(delegate_.link_clicked());
- EXPECT_TRUE(delegate_.closed());
+ ASSERT_TRUE(delegate_closed());
+ EXPECT_FALSE(closed_delegate_ok_clicked_);
+ EXPECT_FALSE(closed_delegate_cancel_clicked_);
+ EXPECT_TRUE(closed_delegate_link_clicked_);
}
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];
- EXPECT_FALSE(delegate_.ok_clicked());
- EXPECT_FALSE(delegate_.cancel_clicked());
- EXPECT_TRUE(delegate_.link_clicked());
- EXPECT_FALSE(delegate_.closed());
+ ASSERT_FALSE(delegate_closed());
+ 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/mock_confirm_infobar_delegate.cc b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc
index 6cc13bf..25df444 100644
--- a/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc
+++ b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.cc
@@ -9,23 +9,21 @@
const char MockConfirmInfoBarDelegate::kMessage[] = "MockConfirmInfoBarMessage";
-MockConfirmInfoBarDelegate::MockConfirmInfoBarDelegate()
+MockConfirmInfoBarDelegate::MockConfirmInfoBarDelegate(Owner* owner)
: ConfirmInfoBarDelegate(NULL),
+ owner_(owner),
closes_on_action_(true),
icon_accessed_(false),
message_text_accessed_(false),
link_text_accessed_(false),
ok_clicked_(false),
cancel_clicked_(false),
- link_clicked_(false),
- closed_(false) {
+ link_clicked_(false) {
}
MockConfirmInfoBarDelegate::~MockConfirmInfoBarDelegate() {
-}
-
-void MockConfirmInfoBarDelegate::InfoBarClosed() {
- closed_ = true;
+ if (owner_)
+ owner_->OnInfoBarDelegateClosed();
}
gfx::Image* MockConfirmInfoBarDelegate::GetIcon() const {
diff --git a/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h
index 7a05597..f392b0c 100644
--- a/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h
+++ b/chrome/browser/ui/cocoa/infobars/mock_confirm_infobar_delegate.h
@@ -15,7 +15,16 @@ class SkBitmap;
class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
- MockConfirmInfoBarDelegate();
+ // Called when |this| is about to be destroyed.
+ class Owner {
+ public:
+ virtual void OnInfoBarDelegateClosed() = 0;
+
+ protected:
+ virtual ~Owner() {}
+ };
+
+ explicit MockConfirmInfoBarDelegate(Owner* owner);
virtual ~MockConfirmInfoBarDelegate();
void set_dont_close_on_action() { closes_on_action_ = false; }
@@ -25,13 +34,11 @@ class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
bool ok_clicked() const { return ok_clicked_; }
bool cancel_clicked() const { return cancel_clicked_; }
bool link_clicked() const { return link_clicked_; }
- bool closed() const { return closed_; }
static const char kMessage[];
private:
// ConfirmInfoBarDelegate:
- virtual void InfoBarClosed() OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual string16 GetMessageText() const OVERRIDE;
virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
@@ -40,6 +47,7 @@ class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
virtual string16 GetLinkText() OVERRIDE;
virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
+ Owner* owner_;
// Determines whether the infobar closes when an action is taken or not.
bool closes_on_action_;
mutable bool icon_accessed_;
@@ -48,7 +56,6 @@ class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate {
bool ok_clicked_;
bool cancel_clicked_;
bool link_clicked_;
- bool closed_;
DISALLOW_COPY_AND_ASSIGN(MockConfirmInfoBarDelegate);
};
diff --git a/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.cc b/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.cc
index 8c7d4f6..f0070d0 100644
--- a/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.cc
+++ b/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.cc
@@ -10,21 +10,19 @@
const char MockLinkInfoBarDelegate::kMessage[] = "MockLinkInfoBarMessage ";
const char MockLinkInfoBarDelegate::kLink[] = "http://dev.chromium.org";
-MockLinkInfoBarDelegate::MockLinkInfoBarDelegate()
+MockLinkInfoBarDelegate::MockLinkInfoBarDelegate(Owner* owner)
: LinkInfoBarDelegate(NULL),
+ owner_(owner),
closes_on_action_(true),
icon_accessed_(false),
message_text_accessed_(false),
link_text_accessed_(false),
- link_clicked_(false),
- closed_(false) {
+ link_clicked_(false) {
}
MockLinkInfoBarDelegate::~MockLinkInfoBarDelegate() {
-}
-
-void MockLinkInfoBarDelegate::InfoBarClosed() {
- closed_ = true;
+ if (owner_)
+ owner_->OnInfoBarDelegateClosed();
}
gfx::Image* MockLinkInfoBarDelegate::GetIcon() const {
diff --git a/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h b/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h
index a4f6ff7..477620b 100644
--- a/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h
+++ b/chrome/browser/ui/cocoa/infobars/mock_link_infobar_delegate.h
@@ -15,7 +15,16 @@ class SkBitmap;
class MockLinkInfoBarDelegate : public LinkInfoBarDelegate {
public:
- MockLinkInfoBarDelegate();
+ // Called when |this| is about to be destroyed.
+ class Owner {
+ public:
+ virtual void OnInfoBarDelegateClosed() = 0;
+
+ protected:
+ virtual ~Owner() {}
+ };
+
+ explicit MockLinkInfoBarDelegate(Owner* owner);
virtual ~MockLinkInfoBarDelegate();
void set_dont_close_on_action() { closes_on_action_ = false; }
@@ -23,26 +32,24 @@ class MockLinkInfoBarDelegate : public LinkInfoBarDelegate {
bool message_text_accessed() const { return message_text_accessed_; }
bool link_text_accessed() const { return link_text_accessed_; }
bool link_clicked() const { return link_clicked_; }
- bool closed() const { return closed_; }
static const char kMessage[];
static const char kLink[];
private:
// LinkInfoBarDelegate:
- virtual void InfoBarClosed() OVERRIDE;
virtual gfx::Image* GetIcon() const OVERRIDE;
virtual string16 GetMessageTextWithOffset(size_t* link_offset) const OVERRIDE;
virtual string16 GetLinkText() const OVERRIDE;
virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE;
+ Owner* owner_;
// Determines whether the infobar closes when an action is taken or not.
bool closes_on_action_;
mutable bool icon_accessed_;
mutable bool message_text_accessed_;
mutable bool link_text_accessed_;
bool link_clicked_;
- bool closed_;
DISALLOW_COPY_AND_ASSIGN(MockLinkInfoBarDelegate);
};
diff --git a/chrome/browser/ui/cocoa/keystone_infobar.mm b/chrome/browser/ui/cocoa/keystone_infobar.mm
index d218199..265d122 100644
--- a/chrome/browser/ui/cocoa/keystone_infobar.mm
+++ b/chrome/browser/ui/cocoa/keystone_infobar.mm
@@ -47,13 +47,12 @@ class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate {
// ConfirmInfoBarDelegate
virtual bool ShouldExpire(
- const NavigationController::LoadCommittedDetails& details) const;
- virtual void InfoBarClosed();
- virtual gfx::Image* GetIcon() const;
- virtual string16 GetMessageText() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
- virtual bool Cancel();
+ const NavigationController::LoadCommittedDetails& details) const OVERRIDE;
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
+ virtual bool Cancel() OVERRIDE;
// The TabContents' profile.
Profile* profile_; // weak
@@ -88,10 +87,6 @@ bool KeystonePromotionInfoBarDelegate::ShouldExpire(
return can_expire_;
}
-void KeystonePromotionInfoBarDelegate::InfoBarClosed() {
- delete this;
-}
-
gfx::Image* KeystonePromotionInfoBarDelegate::GetIcon() const {
return &ResourceBundle::GetSharedInstance().GetNativeImageNamed(
IDR_PRODUCT_ICON_32);
diff --git a/chrome/browser/ui/collected_cookies_infobar_delegate.cc b/chrome/browser/ui/collected_cookies_infobar_delegate.cc
index 9c503a7..5e97a7d 100644
--- a/chrome/browser/ui/collected_cookies_infobar_delegate.cc
+++ b/chrome/browser/ui/collected_cookies_infobar_delegate.cc
@@ -34,8 +34,8 @@ int CollectedCookiesInfoBarDelegate::GetButtons() const {
return BUTTON_OK;
}
-string16 CollectedCookiesInfoBarDelegate::GetButtonLabel(InfoBarButton button)
- const {
+string16 CollectedCookiesInfoBarDelegate::GetButtonLabel(
+ InfoBarButton button) const {
DCHECK_EQ(BUTTON_OK, button);
return l10n_util::GetStringUTF16(IDS_COLLECTED_COOKIES_INFOBAR_BUTTON);
}
diff --git a/chrome/browser/ui/collected_cookies_infobar_delegate.h b/chrome/browser/ui/collected_cookies_infobar_delegate.h
index b9be902..fd2bf8e 100644
--- a/chrome/browser/ui/collected_cookies_infobar_delegate.h
+++ b/chrome/browser/ui/collected_cookies_infobar_delegate.h
@@ -18,12 +18,12 @@ class CollectedCookiesInfoBarDelegate : public ConfirmInfoBarDelegate {
private:
// ConfirmInfoBarDelegate overrides.
- virtual gfx::Image* GetIcon() const;
- virtual Type GetInfoBarType() const;
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
- virtual bool Accept();
+ virtual gfx::Image* GetIcon() const OVERRIDE;
+ virtual Type GetInfoBarType() const OVERRIDE;
+ virtual string16 GetMessageText() const OVERRIDE;
+ virtual int GetButtons() const OVERRIDE;
+ virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
+ virtual bool Accept() OVERRIDE;
TabContents* tab_contents_;