Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Side by Side Diff: chrome/browser/ui/cocoa/keystone_infobar_delegate.mm

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "chrome/browser/first_run/first_run.h" 16 #include "chrome/browser/first_run/first_run.h"
17 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 17 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
18 #include "chrome/browser/infobars/infobar.h" 18 #include "chrome/browser/infobars/infobar.h"
19 #include "chrome/browser/infobars/infobar_manager.h"
19 #include "chrome/browser/infobars/infobar_service.h" 20 #include "chrome/browser/infobars/infobar_service.h"
20 #import "chrome/browser/mac/keystone_glue.h" 21 #import "chrome/browser/mac/keystone_glue.h"
21 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 24 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "content/public/browser/navigation_details.h" 28 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
(...skipping 21 matching lines...) Expand all
50 // Sets this info bar to be able to expire. Called a predetermined amount 51 // Sets this info bar to be able to expire. Called a predetermined amount
51 // of time after this object is created. 52 // of time after this object is created.
52 void SetCanExpire() { can_expire_ = true; } 53 void SetCanExpire() { can_expire_ = true; }
53 54
54 // ConfirmInfoBarDelegate 55 // ConfirmInfoBarDelegate
55 virtual int GetIconID() const OVERRIDE; 56 virtual int GetIconID() const OVERRIDE;
56 virtual base::string16 GetMessageText() const OVERRIDE; 57 virtual base::string16 GetMessageText() const OVERRIDE;
57 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 58 virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
58 virtual bool Accept() OVERRIDE; 59 virtual bool Accept() OVERRIDE;
59 virtual bool Cancel() OVERRIDE; 60 virtual bool Cancel() OVERRIDE;
60 virtual bool ShouldExpireInternal( 61 virtual bool ShouldExpireInternal(const NavigationDetails& details) const
61 const content::LoadCommittedDetails& details) const OVERRIDE; 62 OVERRIDE;
62 63
63 // The prefs to use. 64 // The prefs to use.
64 PrefService* prefs_; // weak 65 PrefService* prefs_; // weak
65 66
66 // Whether the info bar should be dismissed on the next navigation. 67 // Whether the info bar should be dismissed on the next navigation.
67 bool can_expire_; 68 bool can_expire_;
68 69
69 // Used to delay the expiration of the info bar. 70 // Used to delay the expiration of the info bar.
70 base::WeakPtrFactory<KeystonePromotionInfoBarDelegate> weak_ptr_factory_; 71 base::WeakPtrFactory<KeystonePromotionInfoBarDelegate> weak_ptr_factory_;
71 72
72 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate); 73 DISALLOW_COPY_AND_ASSIGN(KeystonePromotionInfoBarDelegate);
73 }; 74 };
74 75
75 // static 76 // static
76 void KeystonePromotionInfoBarDelegate::Create() { 77 void KeystonePromotionInfoBarDelegate::Create() {
77 Browser* browser = chrome::GetLastActiveBrowser(); 78 Browser* browser = chrome::GetLastActiveBrowser();
78 if (!browser) 79 if (!browser)
79 return; 80 return;
80 content::WebContents* webContents = 81 content::WebContents* webContents =
81 browser->tab_strip_model()->GetActiveWebContents(); 82 browser->tab_strip_model()->GetActiveWebContents();
82 if (!webContents) 83 if (!webContents)
83 return; 84 return;
84 InfoBarService* infobar_service = 85 InfoBarService* infobar_service =
85 InfoBarService::FromWebContents(webContents); 86 InfoBarService::FromWebContents(webContents);
86 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( 87 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
87 scoped_ptr<ConfirmInfoBarDelegate>(new KeystonePromotionInfoBarDelegate( 88 scoped_ptr<ConfirmInfoBarDelegate>(new KeystonePromotionInfoBarDelegate(
88 Profile::FromBrowserContext( 89 Profile::FromBrowserContext(webContents->GetBrowserContext())
89 webContents->GetBrowserContext())->GetPrefs())))); 90 ->GetPrefs()))));
90 } 91 }
91 92
92 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( 93 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate(
93 PrefService* prefs) 94 PrefService* prefs)
94 : ConfirmInfoBarDelegate(), 95 : ConfirmInfoBarDelegate(),
95 prefs_(prefs), 96 prefs_(prefs),
96 can_expire_(false), 97 can_expire_(false),
97 weak_ptr_factory_(this) { 98 weak_ptr_factory_(this) {
98 const base::TimeDelta kCanExpireOnNavigationAfterDelay = 99 const base::TimeDelta kCanExpireOnNavigationAfterDelay =
99 base::TimeDelta::FromSeconds(8); 100 base::TimeDelta::FromSeconds(8);
(...skipping 25 matching lines...) Expand all
125 [[KeystoneGlue defaultKeystoneGlue] promoteTicket]; 126 [[KeystoneGlue defaultKeystoneGlue] promoteTicket];
126 return true; 127 return true;
127 } 128 }
128 129
129 bool KeystonePromotionInfoBarDelegate::Cancel() { 130 bool KeystonePromotionInfoBarDelegate::Cancel() {
130 prefs_->SetBoolean(prefs::kShowUpdatePromotionInfoBar, false); 131 prefs_->SetBoolean(prefs::kShowUpdatePromotionInfoBar, false);
131 return true; 132 return true;
132 } 133 }
133 134
134 bool KeystonePromotionInfoBarDelegate::ShouldExpireInternal( 135 bool KeystonePromotionInfoBarDelegate::ShouldExpireInternal(
135 const content::LoadCommittedDetails& details) const { 136 const NavigationDetails& details) const {
136 return can_expire_; 137 return can_expire_;
137 } 138 }
138 139
139 } // namespace 140 } // namespace
140 141
141 142
142 // KeystonePromotionInfoBar --------------------------------------------------- 143 // KeystonePromotionInfoBar ---------------------------------------------------
143 144
144 @interface KeystonePromotionInfoBar : NSObject 145 @interface KeystonePromotionInfoBar : NSObject
145 - (void)checkAndShowInfoBarForProfile:(Profile*)profile; 146 - (void)checkAndShowInfoBarForProfile:(Profile*)profile;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 220
220 @end // @implementation KeystonePromotionInfoBar 221 @end // @implementation KeystonePromotionInfoBar
221 222
222 // static 223 // static
223 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { 224 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) {
224 KeystonePromotionInfoBar* promotionInfoBar = 225 KeystonePromotionInfoBar* promotionInfoBar =
225 [[[KeystonePromotionInfoBar alloc] init] autorelease]; 226 [[[KeystonePromotionInfoBar alloc] init] autorelease];
226 227
227 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; 228 [promotionInfoBar checkAndShowInfoBarForProfile:profile];
228 } 229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698