OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/cocoa/keystone_infobar.h" | 5 #include "chrome/browser/ui/cocoa/keystone_infobar.h" |
6 | 6 |
7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
(...skipping 13 matching lines...) Expand all Loading... |
25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
26 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
28 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
30 | 30 |
31 class SkBitmap; | 31 class SkBitmap; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
| 35 // KeystonePromotionInfoBarDelegate ------------------------------------------- |
| 36 |
35 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { | 37 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { |
36 public: | 38 public: |
37 KeystonePromotionInfoBarDelegate(TabContents* tab_contents) | 39 explicit KeystonePromotionInfoBarDelegate(TabContents* tab_contents); |
38 : ConfirmInfoBarDelegate(tab_contents), | |
39 profile_(tab_contents->profile()), | |
40 can_expire_(false), | |
41 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | |
42 const int kCanExpireOnNavigationAfterMilliseconds = 8 * 1000; | |
43 MessageLoop::current()->PostDelayedTask( | |
44 FROM_HERE, | |
45 method_factory_.NewRunnableMethod( | |
46 &KeystonePromotionInfoBarDelegate::SetCanExpire), | |
47 kCanExpireOnNavigationAfterMilliseconds); | |
48 } | |
49 | |
50 virtual ~KeystonePromotionInfoBarDelegate() {} | |
51 | |
52 // Inherited from InfoBarDelegate and overridden. | |
53 | |
54 virtual bool ShouldExpire( | |
55 const NavigationController::LoadCommittedDetails& details) { | |
56 return can_expire_; | |
57 } | |
58 | |
59 virtual void InfoBarClosed() { | |
60 delete this; | |
61 } | |
62 | |
63 // Inherited from AlertInfoBarDelegate and overridden. | |
64 | |
65 virtual string16 GetMessageText() const { | |
66 return l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, | |
67 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); | |
68 } | |
69 | |
70 virtual SkBitmap* GetIcon() const { | |
71 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
72 IDR_PRODUCT_ICON_32); | |
73 } | |
74 | |
75 // Inherited from ConfirmInfoBarDelegate and overridden. | |
76 | |
77 virtual int GetButtons() const { | |
78 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT; | |
79 } | |
80 | |
81 virtual string16 GetButtonLabel(InfoBarButton button) const { | |
82 return button == BUTTON_OK ? | |
83 l10n_util::GetStringUTF16(IDS_PROMOTE_INFOBAR_PROMOTE_BUTTON) : | |
84 l10n_util::GetStringUTF16(IDS_PROMOTE_INFOBAR_DONT_ASK_BUTTON); | |
85 } | |
86 | |
87 virtual bool Accept() { | |
88 [[KeystoneGlue defaultKeystoneGlue] promoteTicket]; | |
89 return true; | |
90 } | |
91 | |
92 virtual bool Cancel() { | |
93 profile_->GetPrefs()->SetBoolean(prefs::kShowUpdatePromotionInfoBar, false); | |
94 return true; | |
95 } | |
96 | 40 |
97 private: | 41 private: |
| 42 virtual ~KeystonePromotionInfoBarDelegate(); |
| 43 |
98 // Sets this info bar to be able to expire. Called a predetermined amount | 44 // Sets this info bar to be able to expire. Called a predetermined amount |
99 // of time after this object is created. | 45 // of time after this object is created. |
100 void SetCanExpire() { | 46 void SetCanExpire() { can_expire_ = true; } |
101 can_expire_ = true; | 47 |
102 } | 48 // ConfirmInfoBarDelegate |
| 49 virtual bool ShouldExpire( |
| 50 const NavigationController::LoadCommittedDetails& details) const; |
| 51 virtual void InfoBarClosed(); |
| 52 virtual SkBitmap* GetIcon() const; |
| 53 virtual string16 GetMessageText() const; |
| 54 virtual int GetButtons() const; |
| 55 virtual string16 GetButtonLabel(InfoBarButton button) const; |
| 56 virtual bool Accept(); |
| 57 virtual bool Cancel(); |
103 | 58 |
104 // The TabContents' profile. | 59 // The TabContents' profile. |
105 Profile* profile_; // weak | 60 Profile* profile_; // weak |
106 | 61 |
107 // Whether the info bar should be dismissed on the next navigation. | 62 // Whether the info bar should be dismissed on the next navigation. |
108 bool can_expire_; | 63 bool can_expire_; |
109 | 64 |
110 // Used to delay the expiration of the info bar. | 65 // Used to delay the expiration of the info bar. |
111 ScopedRunnableMethodFactory<KeystonePromotionInfoBarDelegate> method_factory_; | 66 ScopedRunnableMethodFactory<KeystonePromotionInfoBarDelegate> method_factory_; |
112 | 67 |
113 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); | 68 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); |
114 }; | 69 }; |
115 | 70 |
| 71 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( |
| 72 TabContents* tab_contents) |
| 73 : ConfirmInfoBarDelegate(tab_contents), |
| 74 profile_(tab_contents->profile()), |
| 75 can_expire_(false), |
| 76 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 77 const int kCanExpireOnNavigationAfterMilliseconds = 8 * 1000; |
| 78 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 79 method_factory_.NewRunnableMethod( |
| 80 &KeystonePromotionInfoBarDelegate::SetCanExpire), |
| 81 kCanExpireOnNavigationAfterMilliseconds); |
| 82 } |
| 83 |
| 84 KeystonePromotionInfoBarDelegate::~KeystonePromotionInfoBarDelegate() { |
| 85 } |
| 86 |
| 87 bool KeystonePromotionInfoBarDelegate::ShouldExpire( |
| 88 const NavigationController::LoadCommittedDetails& details) const { |
| 89 return can_expire_; |
| 90 } |
| 91 |
| 92 void KeystonePromotionInfoBarDelegate::InfoBarClosed() { |
| 93 delete this; |
| 94 } |
| 95 |
| 96 SkBitmap* KeystonePromotionInfoBarDelegate::GetIcon() const { |
| 97 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 98 IDR_PRODUCT_ICON_32); |
| 99 } |
| 100 |
| 101 string16 KeystonePromotionInfoBarDelegate::GetMessageText() const { |
| 102 return l10n_util::GetStringFUTF16(IDS_PROMOTE_INFOBAR_TEXT, |
| 103 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); |
| 104 } |
| 105 |
| 106 int KeystonePromotionInfoBarDelegate::GetButtons() const { |
| 107 return BUTTON_OK | BUTTON_CANCEL; |
| 108 } |
| 109 |
| 110 string16 KeystonePromotionInfoBarDelegate::GetButtonLabel( |
| 111 InfoBarButton button) const { |
| 112 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 113 IDS_PROMOTE_INFOBAR_PROMOTE_BUTTON : IDS_PROMOTE_INFOBAR_DONT_ASK_BUTTON); |
| 114 } |
| 115 |
| 116 bool KeystonePromotionInfoBarDelegate::Accept() { |
| 117 [[KeystoneGlue defaultKeystoneGlue] promoteTicket]; |
| 118 return true; |
| 119 } |
| 120 |
| 121 bool KeystonePromotionInfoBarDelegate::Cancel() { |
| 122 profile_->GetPrefs()->SetBoolean(prefs::kShowUpdatePromotionInfoBar, false); |
| 123 return true; |
| 124 } |
| 125 |
116 } // namespace | 126 } // namespace |
117 | 127 |
| 128 |
| 129 // KeystonePromotionInfoBar --------------------------------------------------- |
| 130 |
118 @interface KeystonePromotionInfoBar : NSObject | 131 @interface KeystonePromotionInfoBar : NSObject |
119 - (void)checkAndShowInfoBarForProfile:(Profile*)profile; | 132 - (void)checkAndShowInfoBarForProfile:(Profile*)profile; |
120 - (void)updateStatus:(NSNotification*)notification; | 133 - (void)updateStatus:(NSNotification*)notification; |
121 - (void)removeObserver; | 134 - (void)removeObserver; |
122 @end // @interface KeystonePromotionInfoBar | 135 @end // @interface KeystonePromotionInfoBar |
123 | 136 |
124 @implementation KeystonePromotionInfoBar | 137 @implementation KeystonePromotionInfoBar |
125 | 138 |
126 - (void)dealloc { | 139 - (void)dealloc { |
127 [self removeObserver]; | 140 [self removeObserver]; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 216 |
204 @end // @implementation KeystonePromotionInfoBar | 217 @end // @implementation KeystonePromotionInfoBar |
205 | 218 |
206 // static | 219 // static |
207 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { | 220 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { |
208 KeystonePromotionInfoBar* promotionInfoBar = | 221 KeystonePromotionInfoBar* promotionInfoBar = |
209 [[[KeystonePromotionInfoBar alloc] init] autorelease]; | 222 [[[KeystonePromotionInfoBar alloc] init] autorelease]; |
210 | 223 |
211 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; | 224 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; |
212 } | 225 } |
OLD | NEW |