Index: chrome/browser/ui/cocoa/keystone_infobar.mm |
=================================================================== |
--- chrome/browser/ui/cocoa/keystone_infobar.mm (revision 72158) |
+++ chrome/browser/ui/cocoa/keystone_infobar.mm (working copy) |
@@ -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. |
@@ -32,89 +32,102 @@ |
namespace { |
+// KeystonePromotionInfoBarDelegate ------------------------------------------- |
+ |
class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { |
public: |
- KeystonePromotionInfoBarDelegate(TabContents* tab_contents) |
- : ConfirmInfoBarDelegate(tab_contents), |
- profile_(tab_contents->profile()), |
- can_expire_(false), |
- ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
- const int kCanExpireOnNavigationAfterMilliseconds = 8 * 1000; |
- MessageLoop::current()->PostDelayedTask( |
- FROM_HERE, |
- method_factory_.NewRunnableMethod( |
- &KeystonePromotionInfoBarDelegate::SetCanExpire), |
- kCanExpireOnNavigationAfterMilliseconds); |
- } |
+ explicit KeystonePromotionInfoBarDelegate(TabContents* tab_contents); |
- virtual ~KeystonePromotionInfoBarDelegate() {} |
+ private: |
+ virtual ~KeystonePromotionInfoBarDelegate(); |
- // Inherited from InfoBarDelegate and overridden. |
+ // Sets this info bar to be able to expire. Called a predetermined amount |
+ // of time after this object is created. |
+ void SetCanExpire() { can_expire_ = true; } |
+ // ConfirmInfoBarDelegate |
virtual bool ShouldExpire( |
- const NavigationController::LoadCommittedDetails& details) { |
- return can_expire_; |
- } |
+ const NavigationController::LoadCommittedDetails& details) const; |
+ 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(); |
- virtual void InfoBarClosed() { |
- delete this; |
- } |
+ // The TabContents' profile. |
+ Profile* profile_; // weak |
- // Inherited from AlertInfoBarDelegate and overridden. |
+ // Whether the info bar should be dismissed on the next navigation. |
+ bool can_expire_; |
- virtual string16 GetMessageText() const { |
- return l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, |
- l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
- } |
+ // Used to delay the expiration of the info bar. |
+ ScopedRunnableMethodFactory<KeystonePromotionInfoBarDelegate> method_factory_; |
- virtual SkBitmap* GetIcon() const { |
- return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
- IDR_PRODUCT_ICON_32); |
- } |
+ DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); |
+}; |
- // Inherited from ConfirmInfoBarDelegate and overridden. |
+KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( |
+ TabContents* tab_contents) |
+ : ConfirmInfoBarDelegate(tab_contents), |
+ profile_(tab_contents->profile()), |
+ can_expire_(false), |
+ ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
+ const int kCanExpireOnNavigationAfterMilliseconds = 8 * 1000; |
+ MessageLoop::current()->PostDelayedTask(FROM_HERE, |
+ method_factory_.NewRunnableMethod( |
+ &KeystonePromotionInfoBarDelegate::SetCanExpire), |
+ kCanExpireOnNavigationAfterMilliseconds); |
+} |
- virtual int GetButtons() const { |
- return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT; |
- } |
+KeystonePromotionInfoBarDelegate::~KeystonePromotionInfoBarDelegate() { |
+} |
- virtual string16 GetButtonLabel(InfoBarButton button) const { |
- return button == BUTTON_OK ? |
- l10n_util::GetStringUTF16(IDS_PROMOTE_INFOBAR_PROMOTE_BUTTON) : |
- l10n_util::GetStringUTF16(IDS_PROMOTE_INFOBAR_DONT_ASK_BUTTON); |
- } |
+bool KeystonePromotionInfoBarDelegate::ShouldExpire( |
+ const NavigationController::LoadCommittedDetails& details) const { |
+ return can_expire_; |
+} |
- virtual bool Accept() { |
- [[KeystoneGlue defaultKeystoneGlue] promoteTicket]; |
- return true; |
- } |
+void KeystonePromotionInfoBarDelegate::InfoBarClosed() { |
+ delete this; |
+} |
- virtual bool Cancel() { |
- profile_->GetPrefs()->SetBoolean(prefs::kShowUpdatePromotionInfoBar, false); |
- return true; |
- } |
+SkBitmap* KeystonePromotionInfoBarDelegate::GetIcon() const { |
+ return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
+ IDR_PRODUCT_ICON_32); |
+} |
- private: |
- // Sets this info bar to be able to expire. Called a predetermined amount |
- // of time after this object is created. |
- void SetCanExpire() { |
- can_expire_ = true; |
- } |
+string16 KeystonePromotionInfoBarDelegate::GetMessageText() const { |
+ return l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, |
+ l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
+} |
- // The TabContents' profile. |
- Profile* profile_; // weak |
+int KeystonePromotionInfoBarDelegate::GetButtons() const { |
+ return BUTTON_OK | BUTTON_CANCEL; |
+} |
- // Whether the info bar should be dismissed on the next navigation. |
- bool can_expire_; |
+string16 KeystonePromotionInfoBarDelegate::GetButtonLabel( |
+ InfoBarButton button) const { |
+ return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
+ IDS_PROMOTE_INFOBAR_PROMOTE_BUTTON : IDS_PROMOTE_INFOBAR_DONT_ASK_BUTTON); |
+} |
- // Used to delay the expiration of the info bar. |
- ScopedRunnableMethodFactory<KeystonePromotionInfoBarDelegate> method_factory_; |
+bool KeystonePromotionInfoBarDelegate::Accept() { |
+ [[KeystoneGlue defaultKeystoneGlue] promoteTicket]; |
+ return true; |
+} |
- DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); |
-}; |
+bool KeystonePromotionInfoBarDelegate::Cancel() { |
+ profile_->GetPrefs()->SetBoolean(prefs::kShowUpdatePromotionInfoBar, false); |
+ return true; |
+} |
} // namespace |
+ |
+// KeystonePromotionInfoBar --------------------------------------------------- |
+ |
@interface KeystonePromotionInfoBar : NSObject |
- (void)checkAndShowInfoBarForProfile:(Profile*)profile; |
- (void)updateStatus:(NSNotification*)notification; |