| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_delegate.h" | 5 #include "chrome/browser/ui/cocoa/keystone_infobar_delegate.h" |
| 6 | 6 |
| 7 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "ui/base/resource/resource_bundle.h" | 31 #include "ui/base/resource/resource_bundle.h" |
| 32 | 32 |
| 33 class SkBitmap; | 33 class SkBitmap; |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // KeystonePromotionInfoBarDelegate ------------------------------------------- | 37 // KeystonePromotionInfoBarDelegate ------------------------------------------- |
| 38 | 38 |
| 39 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { | 39 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 40 public: | 40 public: |
| 41 // If there's an active tab, creates a keystone promotion delegate and adds it |
| 42 // to the InfoBarService associated with that tab. |
| 43 static void Create(); |
| 44 |
| 45 private: |
| 41 KeystonePromotionInfoBarDelegate(InfoBarService* infobar_service, | 46 KeystonePromotionInfoBarDelegate(InfoBarService* infobar_service, |
| 42 PrefService* prefs); | 47 PrefService* prefs); |
| 43 | |
| 44 private: | |
| 45 virtual ~KeystonePromotionInfoBarDelegate(); | 48 virtual ~KeystonePromotionInfoBarDelegate(); |
| 46 | 49 |
| 47 // Sets this info bar to be able to expire. Called a predetermined amount | 50 // Sets this info bar to be able to expire. Called a predetermined amount |
| 48 // of time after this object is created. | 51 // of time after this object is created. |
| 49 void SetCanExpire() { can_expire_ = true; } | 52 void SetCanExpire() { can_expire_ = true; } |
| 50 | 53 |
| 51 // ConfirmInfoBarDelegate | 54 // ConfirmInfoBarDelegate |
| 52 virtual gfx::Image* GetIcon() const OVERRIDE; | 55 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 53 virtual string16 GetMessageText() const OVERRIDE; | 56 virtual string16 GetMessageText() const OVERRIDE; |
| 54 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 57 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 55 virtual bool Accept() OVERRIDE; | 58 virtual bool Accept() OVERRIDE; |
| 56 virtual bool Cancel() OVERRIDE; | 59 virtual bool Cancel() OVERRIDE; |
| 57 virtual bool ShouldExpireInternal( | 60 virtual bool ShouldExpireInternal( |
| 58 const content::LoadCommittedDetails& details) const OVERRIDE; | 61 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 59 | 62 |
| 60 // The prefs to use. | 63 // The prefs to use. |
| 61 PrefService* prefs_; // weak | 64 PrefService* prefs_; // weak |
| 62 | 65 |
| 63 // Whether the info bar should be dismissed on the next navigation. | 66 // Whether the info bar should be dismissed on the next navigation. |
| 64 bool can_expire_; | 67 bool can_expire_; |
| 65 | 68 |
| 66 // Used to delay the expiration of the info bar. | 69 // Used to delay the expiration of the info bar. |
| 67 base::WeakPtrFactory<KeystonePromotionInfoBarDelegate> weak_ptr_factory_; | 70 base::WeakPtrFactory<KeystonePromotionInfoBarDelegate> weak_ptr_factory_; |
| 68 | 71 |
| 69 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); | 72 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); |
| 70 }; | 73 }; |
| 71 | 74 |
| 75 // static |
| 76 void KeystonePromotionInfoBarDelegate::Create() { |
| 77 Browser* browser = chrome::GetLastActiveBrowser(); |
| 78 if (browser) { |
| 79 content::WebContents* webContents = chrome::GetActiveWebContents(browser); |
| 80 |
| 81 if (webContents) { |
| 82 InfoBarService* infobar_service = |
| 83 InfoBarService::FromWebContents(webContents); |
| 84 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 85 new KeystonePromotionInfoBarDelegate( |
| 86 infobar_service, |
| 87 Profile::FromBrowserContext( |
| 88 webContents->GetBrowserContext())->GetPrefs()))); |
| 89 } |
| 90 } |
| 91 } |
| 92 |
| 72 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( | 93 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( |
| 73 InfoBarService* infobar_service, | 94 InfoBarService* infobar_service, |
| 74 PrefService* prefs) | 95 PrefService* prefs) |
| 75 : ConfirmInfoBarDelegate(infobar_service), | 96 : ConfirmInfoBarDelegate(infobar_service), |
| 76 prefs_(prefs), | 97 prefs_(prefs), |
| 77 can_expire_(false), | 98 can_expire_(false), |
| 78 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 99 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 79 const base::TimeDelta kCanExpireOnNavigationAfterDelay = | 100 const base::TimeDelta kCanExpireOnNavigationAfterDelay = |
| 80 base::TimeDelta::FromSeconds(8); | 101 base::TimeDelta::FromSeconds(8); |
| 81 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 102 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 [[dictionary objectForKey:kAutoupdateStatusStatus] intValue]); | 203 [[dictionary objectForKey:kAutoupdateStatusStatus] intValue]); |
| 183 | 204 |
| 184 if (status == kAutoupdateNone || status == kAutoupdateRegistering) { | 205 if (status == kAutoupdateNone || status == kAutoupdateRegistering) { |
| 185 return; | 206 return; |
| 186 } | 207 } |
| 187 | 208 |
| 188 [self removeObserver]; | 209 [self removeObserver]; |
| 189 | 210 |
| 190 if (status != kAutoupdateRegisterFailed && | 211 if (status != kAutoupdateRegisterFailed && |
| 191 [[KeystoneGlue defaultKeystoneGlue] needsPromotion]) { | 212 [[KeystoneGlue defaultKeystoneGlue] needsPromotion]) { |
| 192 Browser* browser = chrome::GetLastActiveBrowser(); | 213 KeystonePromotionInfoBarDelegate::Create(); |
| 193 if (browser) { | |
| 194 content::WebContents* webContents = chrome::GetActiveWebContents(browser); | |
| 195 | |
| 196 // Only show if no other info bars are showing, because that's how the | |
| 197 // default browser info bar works. | |
| 198 if (webContents) { | |
| 199 InfoBarService* infobarService = | |
| 200 InfoBarService::FromWebContents(webContents); | |
| 201 if (infobarService->GetInfoBarCount() == 0) { | |
| 202 infobarService->AddInfoBar( | |
| 203 new KeystonePromotionInfoBarDelegate( | |
| 204 infobarService, | |
| 205 Profile::FromBrowserContext( | |
| 206 webContents->GetBrowserContext())->GetPrefs())); | |
| 207 } | |
| 208 } | |
| 209 } | |
| 210 } | 214 } |
| 211 | 215 |
| 212 [self release]; | 216 [self release]; |
| 213 } | 217 } |
| 214 | 218 |
| 215 - (void)removeObserver { | 219 - (void)removeObserver { |
| 216 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 220 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 217 } | 221 } |
| 218 | 222 |
| 219 @end // @implementation KeystonePromotionInfoBar | 223 @end // @implementation KeystonePromotionInfoBar |
| 220 | 224 |
| 221 // static | 225 // static |
| 222 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { | 226 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { |
| 223 KeystonePromotionInfoBar* promotionInfoBar = | 227 KeystonePromotionInfoBar* promotionInfoBar = |
| 224 [[[KeystonePromotionInfoBar alloc] init] autorelease]; | 228 [[[KeystonePromotionInfoBar alloc] init] autorelease]; |
| 225 | 229 |
| 226 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; | 230 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; |
| 227 } | 231 } |
| OLD | NEW |