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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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 | Annotate | Revision Log
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_service.h" 19 #include "chrome/browser/infobars/infobar_service.h"
19 #import "chrome/browser/mac/keystone_glue.h" 20 #import "chrome/browser/mac/keystone_glue.h"
20 #include "chrome/browser/profiles/profile.h" 21 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/browser.h" 22 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 23 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
26 #include "content/public/browser/navigation_details.h" 27 #include "content/public/browser/navigation_details.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "grit/chromium_strings.h" 29 #include "grit/chromium_strings.h"
29 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
30 #include "grit/theme_resources.h" 31 #include "grit/theme_resources.h"
31 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
32 33
33 class SkBitmap; 34 class SkBitmap;
34 35
35 namespace { 36 namespace {
36 37
37 // KeystonePromotionInfoBarDelegate ------------------------------------------- 38 // KeystonePromotionInfoBarDelegate -------------------------------------------
38 39
39 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { 40 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate {
40 public: 41 public:
41 // If there's an active tab, creates a keystone promotion delegate and adds it 42 // If there's an active tab, creates a keystone promotion delegate and adds it
42 // to the InfoBarService associated with that tab. 43 // to the InfoBarService associated with that tab.
43 static void Create(); 44 static void Create();
44 45
45 private: 46 private:
46 KeystonePromotionInfoBarDelegate(InfoBarService* infobar_service, 47 explicit KeystonePromotionInfoBarDelegate(PrefService* prefs);
47 PrefService* prefs);
48 virtual ~KeystonePromotionInfoBarDelegate(); 48 virtual ~KeystonePromotionInfoBarDelegate();
49 49
50 // 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
51 // of time after this object is created. 51 // of time after this object is created.
52 void SetCanExpire() { can_expire_ = true; } 52 void SetCanExpire() { can_expire_ = true; }
53 53
54 // ConfirmInfoBarDelegate 54 // ConfirmInfoBarDelegate
55 virtual int GetIconID() const OVERRIDE; 55 virtual int GetIconID() const OVERRIDE;
56 virtual string16 GetMessageText() const OVERRIDE; 56 virtual string16 GetMessageText() const OVERRIDE;
57 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 57 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
(...skipping 18 matching lines...) Expand all
76 void KeystonePromotionInfoBarDelegate::Create() { 76 void KeystonePromotionInfoBarDelegate::Create() {
77 Browser* browser = chrome::GetLastActiveBrowser(); 77 Browser* browser = chrome::GetLastActiveBrowser();
78 if (!browser) 78 if (!browser)
79 return; 79 return;
80 content::WebContents* webContents = 80 content::WebContents* webContents =
81 browser->tab_strip_model()->GetActiveWebContents(); 81 browser->tab_strip_model()->GetActiveWebContents();
82 if (!webContents) 82 if (!webContents)
83 return; 83 return;
84 InfoBarService* infobar_service = 84 InfoBarService* infobar_service =
85 InfoBarService::FromWebContents(webContents); 85 InfoBarService::FromWebContents(webContents);
86 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( 86 infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
87 new KeystonePromotionInfoBarDelegate( 87 scoped_ptr<ConfirmInfoBarDelegate>(new KeystonePromotionInfoBarDelegate(
88 infobar_service,
89 Profile::FromBrowserContext( 88 Profile::FromBrowserContext(
90 webContents->GetBrowserContext())->GetPrefs()))); 89 webContents->GetBrowserContext())->GetPrefs()))));
91 } 90 }
92 91
93 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( 92 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate(
94 InfoBarService* infobar_service,
95 PrefService* prefs) 93 PrefService* prefs)
96 : ConfirmInfoBarDelegate(infobar_service), 94 : ConfirmInfoBarDelegate(),
97 prefs_(prefs), 95 prefs_(prefs),
98 can_expire_(false), 96 can_expire_(false),
99 weak_ptr_factory_(this) { 97 weak_ptr_factory_(this) {
100 const base::TimeDelta kCanExpireOnNavigationAfterDelay = 98 const base::TimeDelta kCanExpireOnNavigationAfterDelay =
101 base::TimeDelta::FromSeconds(8); 99 base::TimeDelta::FromSeconds(8);
102 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 100 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
103 base::Bind(&KeystonePromotionInfoBarDelegate::SetCanExpire, 101 base::Bind(&KeystonePromotionInfoBarDelegate::SetCanExpire,
104 weak_ptr_factory_.GetWeakPtr()), 102 weak_ptr_factory_.GetWeakPtr()),
105 kCanExpireOnNavigationAfterDelay); 103 kCanExpireOnNavigationAfterDelay);
106 } 104 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 219
222 @end // @implementation KeystonePromotionInfoBar 220 @end // @implementation KeystonePromotionInfoBar
223 221
224 // static 222 // static
225 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { 223 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) {
226 KeystonePromotionInfoBar* promotionInfoBar = 224 KeystonePromotionInfoBar* promotionInfoBar =
227 [[[KeystonePromotionInfoBar alloc] init] autorelease]; 225 [[[KeystonePromotionInfoBar alloc] init] autorelease];
228 226
229 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; 227 [promotionInfoBar checkAndShowInfoBarForProfile:profile];
230 } 228 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/infobars/translate_infobar_unittest.mm ('k') | chrome/browser/ui/collected_cookies_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698