diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 23:58:58 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-26 23:58:58 +0000 |
commit | 70b1f803bad74bc90a5586af96534c2b4f9a65cc (patch) | |
tree | 4e7753e6c9c0a4a9cdf583f4868b766fc1b453fd /chrome | |
parent | 13786dd536bb42858d03db754b0dfe39a749a47f (diff) | |
download | chromium_src-70b1f803bad74bc90a5586af96534c2b4f9a65cc.zip chromium_src-70b1f803bad74bc90a5586af96534c2b4f9a65cc.tar.gz chromium_src-70b1f803bad74bc90a5586af96534c2b4f9a65cc.tar.bz2 |
Cleanup:
* Remove AlertInfoBarDelegate. There are basically no users of this (the only one is in autofill which is really trying to make something like a confirm info bar).
* Change the default button set for a ConfirmInfoBarDelegate from 0 buttons to 2 to match how practically every caller uses it.
Note that this doesn't remove views' AlertInfoBar yet. AlertInfoBar is now only used as a base for ConfirmInfoBar, but actually moving that functionality into ConfirmInfoBar is to come in a subsequent patch.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6262018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
26 files changed, 74 insertions, 348 deletions
diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc index d143cfd..d531dc9 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_delegate.cc +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.cc @@ -51,10 +51,6 @@ string16 AutoFillCCInfoBarDelegate::GetMessageText() const { return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_INFOBAR_TEXT); } -int AutoFillCCInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 AutoFillCCInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_AUTOFILL_CC_INFOBAR_ACCEPT : IDS_AUTOFILL_CC_INFOBAR_DENY); diff --git a/chrome/browser/autofill/autofill_cc_infobar_delegate.h b/chrome/browser/autofill/autofill_cc_infobar_delegate.h index fae8167..4916335 100644 --- a/chrome/browser/autofill/autofill_cc_infobar_delegate.h +++ b/chrome/browser/autofill/autofill_cc_infobar_delegate.h @@ -27,7 +27,6 @@ class AutoFillCCInfoBarDelegate : public ConfirmInfoBarDelegate { virtual SkBitmap* GetIcon() const; virtual Type GetInfoBarType() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel( ConfirmInfoBarDelegate::InfoBarButton button) const; virtual bool Accept(); diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 987eee2..0f4bdc5 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -2153,11 +2153,6 @@ ListValue* TestingAutomationProvider::GetInfobarsInfo(TabContents* tc) { buttons_list->Append(button_label); } infobar_item->Set("buttons", buttons_list); - } else if (infobar->AsAlertInfoBarDelegate()) { - infobar_item->SetString("type", "alert_infobar"); - AlertInfoBarDelegate* alert_infobar = - infobar->AsAlertInfoBarDelegate(); - infobar_item->SetString("text", alert_infobar->GetMessageText()); } else if (infobar->AsLinkInfoBarDelegate()) { infobar_item->SetString("type", "link_infobar"); LinkInfoBarDelegate* link_infobar = infobar->AsLinkInfoBarDelegate(); diff --git a/chrome/browser/download/download_request_infobar_delegate.cc b/chrome/browser/download/download_request_infobar_delegate.cc index beb0d90..1601b9f 100644 --- a/chrome/browser/download/download_request_infobar_delegate.cc +++ b/chrome/browser/download/download_request_infobar_delegate.cc @@ -37,10 +37,6 @@ string16 DownloadRequestInfoBarDelegate::GetMessageText() const { return l10n_util::GetStringUTF16(IDS_MULTI_DOWNLOAD_WARNING); } -int DownloadRequestInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 DownloadRequestInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? diff --git a/chrome/browser/download/download_request_infobar_delegate.h b/chrome/browser/download/download_request_infobar_delegate.h index 9b1092c..60d2132 100644 --- a/chrome/browser/download/download_request_infobar_delegate.h +++ b/chrome/browser/download/download_request_infobar_delegate.h @@ -33,7 +33,6 @@ class DownloadRequestInfoBarDelegate : public ConfirmInfoBarDelegate { virtual void InfoBarClosed(); virtual SkBitmap* GetIcon() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); virtual bool Cancel(); diff --git a/chrome/browser/geolocation/geolocation_permission_context.cc b/chrome/browser/geolocation/geolocation_permission_context.cc index ff33fb7..5d52abb 100644 --- a/chrome/browser/geolocation/geolocation_permission_context.cc +++ b/chrome/browser/geolocation/geolocation_permission_context.cc @@ -135,7 +135,6 @@ class GeolocationConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { virtual SkBitmap* GetIcon() const; virtual Type GetInfoBarType() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); virtual bool Cancel(); @@ -195,10 +194,6 @@ string16 GeolocationConfirmInfoBarDelegate::GetMessageText() const { net::FormatUrl(requesting_frame_url_.GetOrigin(), display_languages_)); } -int GeolocationConfirmInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 GeolocationConfirmInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index 0c30969..5c0e05d 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -73,15 +73,11 @@ string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { UTF8ToUTF16(new_google_url_.spec())); } -int GoogleURLTrackerInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? - IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL : - IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); + IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL : + IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); } diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h index 7f58ab1..e12ee00 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -185,7 +185,6 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { private: // ConfirmInfoBarDelegate virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate); diff --git a/chrome/browser/notifications/desktop_notification_service.cc b/chrome/browser/notifications/desktop_notification_service.cc index 64e4efd..0f837f9 100644 --- a/chrome/browser/notifications/desktop_notification_service.cc +++ b/chrome/browser/notifications/desktop_notification_service.cc @@ -103,7 +103,6 @@ class NotificationPermissionInfoBarDelegate : public ConfirmInfoBarDelegate { virtual SkBitmap* GetIcon() const; virtual Type GetInfoBarType() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); virtual bool Cancel(); @@ -177,10 +176,6 @@ string16 NotificationPermissionInfoBarDelegate::GetMessageText() const { display_name_); } -int NotificationPermissionInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 NotificationPermissionInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? diff --git a/chrome/browser/omnibox_search_hint.cc b/chrome/browser/omnibox_search_hint.cc index 7b19d10..1df6d4f 100644 --- a/chrome/browser/omnibox_search_hint.cc +++ b/chrome/browser/omnibox_search_hint.cc @@ -132,6 +132,7 @@ int HintInfoBar::GetButtons() const { } string16 HintInfoBar::GetButtonLabel(InfoBarButton button) const { + DCHECK_EQ(BUTTON_OK, button); return l10n_util::GetStringUTF16( IDS_OMNIBOX_SEARCH_HINT_INFOBAR_BUTTON_LABEL); } diff --git a/chrome/browser/password_manager_delegate_impl.cc b/chrome/browser/password_manager_delegate_impl.cc index 8340f11..7a96746 100644 --- a/chrome/browser/password_manager_delegate_impl.cc +++ b/chrome/browser/password_manager_delegate_impl.cc @@ -45,7 +45,6 @@ class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { virtual SkBitmap* GetIcon() const; virtual Type GetInfoBarType() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); virtual bool Cancel(); @@ -90,10 +89,6 @@ string16 SavePasswordInfoBarDelegate::GetMessageText() const { return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); } -int SavePasswordInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 SavePasswordInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? diff --git a/chrome/browser/tab_contents/infobar_delegate.cc b/chrome/browser/tab_contents/infobar_delegate.cc index 0834b73..6a5eeae 100644 --- a/chrome/browser/tab_contents/infobar_delegate.cc +++ b/chrome/browser/tab_contents/infobar_delegate.cc @@ -42,16 +42,12 @@ InfoBarDelegate::Type InfoBarDelegate::GetInfoBarType() const { return WARNING_TYPE; } -AlertInfoBarDelegate* InfoBarDelegate::AsAlertInfoBarDelegate() { - return NULL; -} - ConfirmInfoBarDelegate* InfoBarDelegate::AsConfirmInfoBarDelegate() { return NULL; } CrashedExtensionInfoBarDelegate* -InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() { + InfoBarDelegate::AsCrashedExtensionInfoBarDelegate() { return NULL; } @@ -84,26 +80,6 @@ void InfoBarDelegate::StoreActiveEntryUniqueID(TabContents* contents) { } -// AlertInfoBarDelegate ------------------------------------------------------- - -bool AlertInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { - AlertInfoBarDelegate* alert_delegate = delegate->AsAlertInfoBarDelegate(); - return alert_delegate && - (alert_delegate->GetMessageText() == GetMessageText()); -} - -AlertInfoBarDelegate::AlertInfoBarDelegate(TabContents* contents) - : InfoBarDelegate(contents) { -} - -AlertInfoBarDelegate::~AlertInfoBarDelegate() { -} - -AlertInfoBarDelegate* AlertInfoBarDelegate::AsAlertInfoBarDelegate() { - return this; -} - - // LinkInfoBarDelegate -------------------------------------------------------- string16 LinkInfoBarDelegate::GetMessageTextWithOffset( @@ -131,7 +107,7 @@ LinkInfoBarDelegate* LinkInfoBarDelegate::AsLinkInfoBarDelegate() { // ConfirmInfoBarDelegate ----------------------------------------------------- int ConfirmInfoBarDelegate::GetButtons() const { - return BUTTON_NONE; + return BUTTON_OK | BUTTON_CANCEL; } string16 ConfirmInfoBarDelegate::GetButtonLabel(InfoBarButton button) const { @@ -159,12 +135,19 @@ bool ConfirmInfoBarDelegate::LinkClicked(WindowOpenDisposition disposition) { } ConfirmInfoBarDelegate::ConfirmInfoBarDelegate(TabContents* contents) - : AlertInfoBarDelegate(contents) { + : InfoBarDelegate(contents) { } ConfirmInfoBarDelegate::~ConfirmInfoBarDelegate() { } +bool ConfirmInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { + ConfirmInfoBarDelegate* confirm_delegate = + delegate->AsConfirmInfoBarDelegate(); + return confirm_delegate && + (confirm_delegate->GetMessageText() == GetMessageText()); +} + ConfirmInfoBarDelegate* ConfirmInfoBarDelegate::AsConfirmInfoBarDelegate() { return this; } @@ -177,7 +160,7 @@ SimpleAlertInfoBarDelegate::SimpleAlertInfoBarDelegate( SkBitmap* icon, const string16& message, bool auto_expire) - : AlertInfoBarDelegate(contents), + : ConfirmInfoBarDelegate(contents), icon_(icon), message_(message), auto_expire_(auto_expire) { @@ -188,7 +171,7 @@ SimpleAlertInfoBarDelegate::~SimpleAlertInfoBarDelegate() { bool SimpleAlertInfoBarDelegate::ShouldExpire( const NavigationController::LoadCommittedDetails& details) const { - return auto_expire_ && AlertInfoBarDelegate::ShouldExpire(details); + return auto_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details); } void SimpleAlertInfoBarDelegate::InfoBarClosed() { @@ -202,3 +185,7 @@ SkBitmap* SimpleAlertInfoBarDelegate::GetIcon() const { string16 SimpleAlertInfoBarDelegate::GetMessageText() const { return message_; } + +int SimpleAlertInfoBarDelegate::GetButtons() const { + return BUTTON_NONE; +} diff --git a/chrome/browser/tab_contents/infobar_delegate.h b/chrome/browser/tab_contents/infobar_delegate.h index ca7b497..889fbf4 100644 --- a/chrome/browser/tab_contents/infobar_delegate.h +++ b/chrome/browser/tab_contents/infobar_delegate.h @@ -11,7 +11,6 @@ #include "chrome/browser/tab_contents/navigation_controller.h" #include "webkit/glue/window_open_disposition.h" -class AlertInfoBarDelegate; class ConfirmInfoBarDelegate; class CrashedExtensionInfoBarDelegate; class ExtensionInfoBarDelegate; @@ -24,7 +23,7 @@ class TranslateInfoBarDelegate; // An interface implemented by objects wishing to control an InfoBar. // Implementing this interface is not sufficient to use an InfoBar, since it // does not map to a specific InfoBar type. Instead, you must implement either -// AlertInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own +// LinkInfoBarDelegate or ConfirmInfoBarDelegate, or override with your own // delegate for your own InfoBar variety. // // --- WARNING --- @@ -88,7 +87,6 @@ class InfoBarDelegate { virtual Type GetInfoBarType() const; // Type-checking downcast routines: - virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate(); virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); virtual CrashedExtensionInfoBarDelegate* AsCrashedExtensionInfoBarDelegate(); virtual ExtensionInfoBarDelegate* AsExtensionInfoBarDelegate(); @@ -116,27 +114,6 @@ class InfoBarDelegate { }; // An interface derived from InfoBarDelegate implemented by objects wishing to -// control an AlertInfoBar. -class AlertInfoBarDelegate : public InfoBarDelegate { - public: - // Returns the message string to be displayed for the InfoBar. - virtual string16 GetMessageText() const = 0; - - // InfoBarDelegate: - virtual InfoBar* CreateInfoBar(); - virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; - - protected: - explicit AlertInfoBarDelegate(TabContents* contents); - virtual ~AlertInfoBarDelegate(); - - private: - virtual AlertInfoBarDelegate* AsAlertInfoBarDelegate(); - - DISALLOW_COPY_AND_ASSIGN(AlertInfoBarDelegate); -}; - -// An interface derived from InfoBarDelegate implemented by objects wishing to // control a LinkInfoBar. class LinkInfoBarDelegate : public InfoBarDelegate { public: @@ -170,14 +147,17 @@ class LinkInfoBarDelegate : public InfoBarDelegate { // An interface derived from InfoBarDelegate implemented by objects wishing to // control a ConfirmInfoBar. -class ConfirmInfoBarDelegate : public AlertInfoBarDelegate { +class ConfirmInfoBarDelegate : public InfoBarDelegate { public: enum InfoBarButton { - BUTTON_NONE = 0, - BUTTON_OK = 1 << 0, - BUTTON_CANCEL = 1 << 1, + BUTTON_NONE = 0, + BUTTON_OK = 1 << 0, + BUTTON_CANCEL = 1 << 1, }; + // Returns the message string to be displayed for the InfoBar. + virtual string16 GetMessageText() const = 0; + // Return the buttons to be shown for this InfoBar. virtual int GetButtons() const; @@ -215,6 +195,7 @@ class ConfirmInfoBarDelegate : public AlertInfoBarDelegate { private: // InfoBarDelegate: virtual InfoBar* CreateInfoBar(); + virtual bool EqualsDelegate(InfoBarDelegate* delegate) const; virtual ConfirmInfoBarDelegate* AsConfirmInfoBarDelegate(); DISALLOW_COPY_AND_ASSIGN(ConfirmInfoBarDelegate); @@ -222,7 +203,7 @@ class ConfirmInfoBarDelegate : public AlertInfoBarDelegate { // Simple implementations for common use cases --------------------------------- -class SimpleAlertInfoBarDelegate : public AlertInfoBarDelegate { +class SimpleAlertInfoBarDelegate : public ConfirmInfoBarDelegate { public: SimpleAlertInfoBarDelegate(TabContents* contents, SkBitmap* icon, // May be NULL. @@ -232,12 +213,13 @@ class SimpleAlertInfoBarDelegate : public AlertInfoBarDelegate { private: virtual ~SimpleAlertInfoBarDelegate(); - // AlertInfoBarDelegate: + // ConfirmInfoBarDelegate: virtual bool ShouldExpire( const NavigationController::LoadCommittedDetails& details) const; virtual void InfoBarClosed(); virtual SkBitmap* GetIcon() const; virtual string16 GetMessageText() const; + virtual int GetButtons() const; SkBitmap* icon_; string16 message_; diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 370ff80e..4b1b340 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -265,7 +265,6 @@ class OutdatedPluginInfoBar : public ConfirmInfoBarDelegate { virtual void InfoBarClosed(); virtual SkBitmap* GetIcon() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); virtual bool Cancel(); @@ -305,10 +304,6 @@ string16 OutdatedPluginInfoBar::GetMessageText() const { return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); } -int OutdatedPluginInfoBar::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index 6d93a53..a0fb4b6 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -143,7 +143,6 @@ class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { virtual void InfoBarClosed(); virtual SkBitmap* GetIcon() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool NeedElevation(InfoBarButton button) const; virtual bool Accept(); @@ -202,15 +201,11 @@ string16 DefaultBrowserInfoBarDelegate::GetMessageText() const { return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT); } -int DefaultBrowserInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 DefaultBrowserInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { - return button == BUTTON_OK ? - l10n_util::GetStringUTF16(IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL) : - l10n_util::GetStringUTF16(IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL); + return l10n_util::GetStringUTF16((button == BUTTON_OK) ? + IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL : + IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL); } bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { 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 fd189c4..b39d48c 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_container_controller_unittest.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -49,30 +49,29 @@ TEST_F(InfoBarContainerControllerTest, BWCPong) { TEST_F(InfoBarContainerControllerTest, AddAndRemoveInfoBars) { NSView* view = [controller_ view]; - // Add three infobars, one of each type, and then remove them. + // Add three infobars and then remove them. // After each step check to make sure we have the correct number of // infobar subviews. - MockAlertInfoBarDelegate alertDelegate; - MockLinkInfoBarDelegate linkDelegate; + MockLinkInfoBarDelegate linkDelegate, linkDelegate2; MockConfirmInfoBarDelegate confirmDelegate; - [controller_ addInfoBar:&alertDelegate animate:NO]; + [controller_ addInfoBar:&linkDelegate animate:NO]; EXPECT_EQ(1U, [[view subviews] count]); - [controller_ addInfoBar:&linkDelegate animate:NO]; + [controller_ addInfoBar:&confirmDelegate animate:NO]; EXPECT_EQ(2U, [[view subviews] count]); - [controller_ addInfoBar:&confirmDelegate 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:&linkDelegate animate:NO]; + [controller_ closeInfoBarsForDelegate:&confirmDelegate animate:NO]; EXPECT_EQ(2U, [[view subviews] count]); - [controller_ closeInfoBarsForDelegate:&confirmDelegate animate:NO]; + [controller_ closeInfoBarsForDelegate:&linkDelegate animate:NO]; EXPECT_EQ(1U, [[view subviews] count]); - [controller_ closeInfoBarsForDelegate:&alertDelegate animate:NO]; + [controller_ closeInfoBarsForDelegate:&linkDelegate2 animate:NO]; EXPECT_EQ(0U, [[view subviews] count]); } @@ -80,13 +79,12 @@ TEST_F(InfoBarContainerControllerTest, RemoveAllInfoBars) { NSView* view = [controller_ view]; // Add three infobars and then remove them all. - MockAlertInfoBarDelegate alertDelegate; MockLinkInfoBarDelegate linkDelegate; - MockConfirmInfoBarDelegate confirmDelegate; + MockConfirmInfoBarDelegate confirmDelegate, confirmDelegate2; - [controller_ addInfoBar:&alertDelegate animate:NO]; [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.h b/chrome/browser/ui/cocoa/infobars/infobar_controller.h index f0b735e..6214a42 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.h @@ -91,10 +91,6 @@ class InfoBarDelegate; // subclass. Each of these subclasses overrides addAdditionalControls to // configure its view as necessary. -@interface AlertInfoBarController : InfoBarController -@end - - @interface LinkInfoBarController : InfoBarController // Called when there is a click on the link in the infobar. - (void)linkClicked; diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm index 63b1c08..4522821 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller.mm @@ -338,25 +338,6 @@ const float kAnimateCloseDuration = 0.12; ///////////////////////////////////////////////////////////////////////// -// AlertInfoBarController implementation - -@implementation AlertInfoBarController - -// Alert infobars have a text message. -- (void)addAdditionalControls { - // No buttons. - [self removeButtons]; - - // Insert the text. - AlertInfoBarDelegate* delegate = delegate_->AsAlertInfoBarDelegate(); - DCHECK(delegate); - [self setLabelToMessage:base::SysUTF16ToNSString(delegate->GetMessageText())]; -} - -@end - - -///////////////////////////////////////////////////////////////////////// // LinkInfoBarController implementation @implementation LinkInfoBarController @@ -518,12 +499,6 @@ const float kAnimateCloseDuration = 0.12; ////////////////////////////////////////////////////////////////////////// // CreateInfoBar() implementations -InfoBar* AlertInfoBarDelegate::CreateInfoBar() { - AlertInfoBarController* controller = - [[AlertInfoBarController alloc] initWithDelegate:this]; - return new InfoBar(controller); -} - InfoBar* LinkInfoBarDelegate::CreateInfoBar() { LinkInfoBarController* controller = [[LinkInfoBarController alloc] initWithDelegate:this]; diff --git a/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm b/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm index 1f980c4..4b19aff 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_controller_unittest.mm @@ -65,25 +65,6 @@ namespace { /////////////////////////////////////////////////////////////////////////// // Test fixtures -class AlertInfoBarControllerTest : public CocoaTest { - public: - virtual void SetUp() { - CocoaTest::SetUp(); - - controller_.reset( - [[AlertInfoBarController alloc] initWithDelegate:&delegate_]); - container_.reset( - [[InfoBarContainerTest alloc] initWithController:controller_]); - [controller_ setContainerController:container_]; - [[test_window() contentView] addSubview:[controller_ view]]; - } - - protected: - MockAlertInfoBarDelegate delegate_; - scoped_nsobject<id> container_; - scoped_nsobject<AlertInfoBarController> controller_; -}; - class LinkInfoBarControllerTest : public CocoaTest { public: virtual void SetUp() { @@ -126,43 +107,6 @@ class ConfirmInfoBarControllerTest : public CocoaTest { //////////////////////////////////////////////////////////////////////////// // Tests -TEST_VIEW(AlertInfoBarControllerTest, [controller_ view]); - -TEST_F(AlertInfoBarControllerTest, ShowAndDismiss) { - // Make sure someone looked at the message and icon. - EXPECT_TRUE(delegate_.message_text_accessed()); - EXPECT_TRUE(delegate_.icon_accessed()); - - // Check to make sure the infobar message was set properly. - EXPECT_EQ(MockAlertInfoBarDelegate::kMessage, - base::SysNSStringToUTF8([controller_.get() labelString])); - - // Check that dismissing the infobar calls InfoBarClosed() on the delegate. - [controller_ dismiss:nil]; - EXPECT_TRUE(delegate_.closed()); -} - -TEST_F(AlertInfoBarControllerTest, DeallocController) { - // Test that dealloc'ing the controller does not send an - // InfoBarClosed() message to the delegate. - controller_.reset(nil); - EXPECT_FALSE(delegate_.closed()); -} - -TEST_F(AlertInfoBarControllerTest, ResizeView) { - NSRect originalLabelFrame = [controller_ labelFrame]; - - // Expand the view by 20 pixels and make sure the label frame changes - // accordingly. - const CGFloat width = 20; - NSRect newViewFrame = [[controller_ view] frame]; - newViewFrame.size.width += width; - [[controller_ view] setFrame:newViewFrame]; - - NSRect newLabelFrame = [controller_ labelFrame]; - EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); -} - TEST_VIEW(LinkInfoBarControllerTest, [controller_ view]); TEST_F(LinkInfoBarControllerTest, ShowAndDismiss) { @@ -195,6 +139,13 @@ TEST_F(LinkInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { EXPECT_FALSE(delegate_.closed()); } +TEST_F(LinkInfoBarControllerTest, DeallocController) { + // Test that dealloc'ing the controller does not send an + // InfoBarClosed() message to the delegate. + controller_.reset(nil); + EXPECT_FALSE(delegate_.closed()); +} + TEST_VIEW(ConfirmInfoBarControllerTest, [controller_ view]); TEST_F(ConfirmInfoBarControllerTest, ShowAndDismiss) { @@ -281,4 +232,18 @@ TEST_F(ConfirmInfoBarControllerTest, ShowAndClickLinkWithoutClosing) { EXPECT_FALSE(delegate_.closed()); } +TEST_F(ConfirmInfoBarControllerTest, ResizeView) { + NSRect originalLabelFrame = [controller_ labelFrame]; + + // Expand the view by 20 pixels and make sure the label frame changes + // accordingly. + const CGFloat width = 20; + NSRect newViewFrame = [[controller_ view] frame]; + newViewFrame.size.width += width; + [[controller_ view] setFrame:newViewFrame]; + + NSRect newLabelFrame = [controller_ labelFrame]; + EXPECT_EQ(NSWidth(newLabelFrame), NSWidth(originalLabelFrame) + width); +} + } // namespace diff --git a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h index 7f8f497..e14e0dd 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h +++ b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.h @@ -9,33 +9,6 @@ #include "chrome/browser/tab_contents/infobar_delegate.h" -// MockAlertInfoBarDelegate --------------------------------------------------- - -class MockAlertInfoBarDelegate : public AlertInfoBarDelegate { - public: - MockAlertInfoBarDelegate(); - virtual ~MockAlertInfoBarDelegate(); - - bool icon_accessed() const { return icon_accessed_; } - bool message_text_accessed() const { return message_text_accessed_; } - bool closed() const { return closed_; } - - static const char kMessage[]; - - private: - // AlertInfoBarDelegate - virtual void InfoBarClosed(); - virtual SkBitmap* GetIcon() const; - virtual string16 GetMessageText() const; - - mutable bool icon_accessed_; - mutable bool message_text_accessed_; - bool closed_; - - DISALLOW_COPY_AND_ASSIGN(MockAlertInfoBarDelegate); -}; - - // MockLinkInfoBarDelegate ---------------------------------------------------- class MockLinkInfoBarDelegate : public LinkInfoBarDelegate { @@ -99,7 +72,6 @@ class MockConfirmInfoBarDelegate : public ConfirmInfoBarDelegate { virtual void InfoBarClosed(); virtual SkBitmap* GetIcon() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); virtual bool Cancel(); diff --git a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.mm b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.mm index b5881fb..f9b7c62 100644 --- a/chrome/browser/ui/cocoa/infobars/infobar_test_helper.mm +++ b/chrome/browser/ui/cocoa/infobars/infobar_test_helper.mm @@ -7,35 +7,6 @@ #include "base/utf_string_conversions.h" -// MockAlertInfoBarDelegate --------------------------------------------------- - -const char MockAlertInfoBarDelegate::kMessage[] = "MockAlertInfoBarMessage"; - -MockAlertInfoBarDelegate::MockAlertInfoBarDelegate() - : AlertInfoBarDelegate(NULL), - icon_accessed_(false), - message_text_accessed_(false), - closed_(false) { -} - -MockAlertInfoBarDelegate::~MockAlertInfoBarDelegate() { -} - -void MockAlertInfoBarDelegate::InfoBarClosed() { - closed_ = true; -} - -SkBitmap* MockAlertInfoBarDelegate::GetIcon() const { - icon_accessed_ = true; - return NULL; -} - -string16 MockAlertInfoBarDelegate::GetMessageText() const { - message_text_accessed_ = true; - return ASCIIToUTF16(kMessage); -} - - // MockLinkInfoBarDelegate ---------------------------------------------------- const char MockLinkInfoBarDelegate::kMessage[] = "MockLinkInfoBarMessage"; @@ -113,10 +84,6 @@ string16 MockConfirmInfoBarDelegate::GetMessageText() const { return ASCIIToUTF16(kMessage); } -int MockConfirmInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 MockConfirmInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { return ASCIIToUTF16((button == BUTTON_OK) ? "OK" : "Cancel"); diff --git a/chrome/browser/ui/cocoa/keystone_infobar.mm b/chrome/browser/ui/cocoa/keystone_infobar.mm index 39df317..ff910bd 100644 --- a/chrome/browser/ui/cocoa/keystone_infobar.mm +++ b/chrome/browser/ui/cocoa/keystone_infobar.mm @@ -51,7 +51,6 @@ class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { virtual void InfoBarClosed(); virtual SkBitmap* GetIcon() const; virtual string16 GetMessageText() const; - virtual int GetButtons() const; virtual string16 GetButtonLabel(InfoBarButton button) const; virtual bool Accept(); virtual bool Cancel(); @@ -103,10 +102,6 @@ string16 KeystonePromotionInfoBarDelegate::GetMessageText() const { l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); } -int KeystonePromotionInfoBarDelegate::GetButtons() const { - return BUTTON_OK | BUTTON_CANCEL; -} - string16 KeystonePromotionInfoBarDelegate::GetButtonLabel( InfoBarButton button) const { return l10n_util::GetStringUTF16((button == BUTTON_OK) ? diff --git a/chrome/browser/ui/gtk/infobar_gtk.cc b/chrome/browser/ui/gtk/infobar_gtk.cc index 28b6b2c..fb4b2b5 100644 --- a/chrome/browser/ui/gtk/infobar_gtk.cc +++ b/chrome/browser/ui/gtk/infobar_gtk.cc @@ -187,9 +187,9 @@ void InfoBar::AddLabelWithInlineLink(const string16& display_text, gtk_util::ForceFontSizePixels(initial_label, 13.4); gtk_util::ForceFontSizePixels(trailing_label, 13.4); - // TODO(joth): Unlike the AddLabelAndLink below, none of the label widgets - // are set as shrinkable here, meaning the text will run under the close - // button etc. when the width is restricted, rather than eliding. + // TODO(joth): None of the label widgets are set as shrinkable here, meaning + // the text will run under the close button etc. when the width is restricted, + // rather than eliding. gtk_widget_modify_fg(initial_label, GTK_STATE_NORMAL, >k_util::kGdkBlack); gtk_widget_modify_fg(trailing_label, GTK_STATE_NORMAL, >k_util::kGdkBlack); @@ -200,42 +200,6 @@ void InfoBar::AddLabelWithInlineLink(const string16& display_text, gtk_box_pack_start(GTK_BOX(hbox), trailing_label, FALSE, FALSE, 0); } -// TODO(joth): This method factors out some common functionality between the -// various derived infobar classes, however the class hierarchy itself could -// use refactoring to reduce this duplication. http://crbug.com/38924 -void InfoBar::AddLabelAndLink(const string16& display_text, - const string16& link_text, - GCallback callback) { - GtkWidget* link_button = NULL; - if (!link_text.empty()) { - // If we have some link text, create the link button. - link_button = gtk_chrome_link_button_new(UTF16ToUTF8(link_text).c_str()); - gtk_chrome_link_button_set_use_gtk_theme( - GTK_CHROME_LINK_BUTTON(link_button), FALSE); - DCHECK(callback); - g_signal_connect(link_button, "clicked", callback, this); - gtk_util::SetButtonTriggersNavigation(link_button); - } - - GtkWidget* hbox = gtk_hbox_new(FALSE, 0); - // We want the link to be horizontally shrinkable, so that the Chrome - // window can be resized freely even with a very long link. - gtk_widget_set_size_request(hbox, 0, -1); - gtk_box_pack_start(GTK_BOX(hbox_), hbox, TRUE, TRUE, 0); - - if (link_button) - gtk_box_pack_end(GTK_BOX(hbox), link_button, FALSE, FALSE, 0); - GtkWidget* label = gtk_label_new(UTF16ToUTF8(display_text).c_str()); - gtk_util::ForceFontSizePixels(label, 13.4); - // In order to avoid the link_button and the label overlapping with each - // other, we make the label shrinkable. - gtk_widget_set_size_request(label, 0, -1); - gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_END); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_widget_modify_fg(label, GTK_STATE_NORMAL, >k_util::kGdkBlack); - gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); -} - void InfoBar::GetTopColor(InfoBarDelegate::Type type, double* r, double* g, double *b) { // These constants are copied from corresponding skia constants from @@ -330,16 +294,6 @@ gboolean InfoBar::OnBackgroundExpose(GtkWidget* sender, return FALSE; } -// AlertInfoBar ---------------------------------------------------------------- - -class AlertInfoBar : public InfoBar { - public: - explicit AlertInfoBar(AlertInfoBarDelegate* delegate) - : InfoBar(delegate) { - AddLabelAndLink(delegate->GetMessageText(), string16(), NULL); - } -}; - // LinkInfoBar ----------------------------------------------------------------- class LinkInfoBar : public InfoBar { @@ -450,12 +404,10 @@ void ConfirmInfoBar::OnLinkClicked(GtkWidget* widget) { } } -InfoBar* AlertInfoBarDelegate::CreateInfoBar() { - return new AlertInfoBar(this); -} InfoBar* LinkInfoBarDelegate::CreateInfoBar() { return new LinkInfoBar(this); } + InfoBar* ConfirmInfoBarDelegate::CreateInfoBar() { return new ConfirmInfoBar(this); } diff --git a/chrome/browser/ui/gtk/infobar_gtk.h b/chrome/browser/ui/gtk/infobar_gtk.h index 98c6d72..b78f2da 100644 --- a/chrome/browser/ui/gtk/infobar_gtk.h +++ b/chrome/browser/ui/gtk/infobar_gtk.h @@ -100,11 +100,6 @@ class InfoBar : public SlideAnimatorGtk::Delegate, size_t link_offset, GCallback callback); - // Adds |display_text| to the infobar. If |link_text| is not empty, it is - // right aligned in the infobar. - void AddLabelAndLink(const string16& display_text, - const string16& link_text, - GCallback callback); // The top level widget of the infobar. scoped_ptr<SlideAnimatorGtk> slide_widget_; diff --git a/chrome/browser/ui/views/infobars/infobars.cc b/chrome/browser/ui/views/infobars/infobars.cc index 1014ed8..8129c273 100644 --- a/chrome/browser/ui/views/infobars/infobars.cc +++ b/chrome/browser/ui/views/infobars/infobars.cc @@ -316,7 +316,7 @@ void InfoBar::DeleteSelf() { // AlertInfoBar, public: ------------------------------------------------------- -AlertInfoBar::AlertInfoBar(AlertInfoBarDelegate* delegate) +AlertInfoBar::AlertInfoBar(ConfirmInfoBarDelegate* delegate) : InfoBar(delegate) { label_ = new views::Label( UTF16ToWideHack(delegate->GetMessageText()), @@ -353,12 +353,6 @@ void AlertInfoBar::Layout() { OffsetY(this, text_ps), text_width, text_ps.height()); } -// AlertInfoBar, private: ------------------------------------------------------ - -AlertInfoBarDelegate* AlertInfoBar::GetDelegate() { - return delegate()->AsAlertInfoBarDelegate(); -} - // LinkInfoBar, public: -------------------------------------------------------- LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate) @@ -598,12 +592,6 @@ void ConfirmInfoBar::Init() { AddChildView(link_); } -// AlertInfoBarDelegate, InfoBarDelegate overrides: ---------------------------- - -InfoBar* AlertInfoBarDelegate::CreateInfoBar() { - return new AlertInfoBar(this); -} - // LinkInfoBarDelegate, InfoBarDelegate overrides: ----------------------------- InfoBar* LinkInfoBarDelegate::CreateInfoBar() { diff --git a/chrome/browser/ui/views/infobars/infobars.h b/chrome/browser/ui/views/infobars/infobars.h index 4b8e6aa..ba5967b 100644 --- a/chrome/browser/ui/views/infobars/infobars.h +++ b/chrome/browser/ui/views/infobars/infobars.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -171,7 +171,7 @@ class InfoBar : public views::View, class AlertInfoBar : public InfoBar { public: - explicit AlertInfoBar(AlertInfoBarDelegate* delegate); + explicit AlertInfoBar(ConfirmInfoBarDelegate* delegate); virtual ~AlertInfoBar(); // Overridden from views::View: @@ -182,8 +182,6 @@ class AlertInfoBar : public InfoBar { views::ImageView* icon() const { return icon_; } private: - AlertInfoBarDelegate* GetDelegate(); - views::Label* label_; views::ImageView* icon_; |