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

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

Issue 102163002: Revert 238283 "Infobar system refactor." (Closed) Base URL: svn://svn.chromium.org/chrome/
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"
19 #include "chrome/browser/infobars/infobar_service.h" 18 #include "chrome/browser/infobars/infobar_service.h"
20 #import "chrome/browser/mac/keystone_glue.h" 19 #import "chrome/browser/mac/keystone_glue.h"
21 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 22 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
27 #include "content/public/browser/navigation_details.h" 26 #include "content/public/browser/navigation_details.h"
28 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
29 #include "grit/chromium_strings.h" 28 #include "grit/chromium_strings.h"
30 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
31 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
32 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
33 32
34 class SkBitmap; 33 class SkBitmap;
35 34
36 namespace { 35 namespace {
37 36
38 // KeystonePromotionInfoBarDelegate ------------------------------------------- 37 // KeystonePromotionInfoBarDelegate -------------------------------------------
39 38
40 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate { 39 class KeystonePromotionInfoBarDelegate : public ConfirmInfoBarDelegate {
41 public: 40 public:
42 // If there's an active tab, creates a keystone promotion delegate and adds it 41 // If there's an active tab, creates a keystone promotion delegate and adds it
43 // to the InfoBarService associated with that tab. 42 // to the InfoBarService associated with that tab.
44 static void Create(); 43 static void Create();
45 44
46 private: 45 private:
47 explicit KeystonePromotionInfoBarDelegate(PrefService* prefs); 46 KeystonePromotionInfoBarDelegate(InfoBarService* infobar_service,
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(ConfirmInfoBarDelegate::CreateInfoBar( 86 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>(
87 scoped_ptr<ConfirmInfoBarDelegate>(new KeystonePromotionInfoBarDelegate( 87 new KeystonePromotionInfoBarDelegate(
88 infobar_service,
88 Profile::FromBrowserContext( 89 Profile::FromBrowserContext(
89 webContents->GetBrowserContext())->GetPrefs())))); 90 webContents->GetBrowserContext())->GetPrefs())));
90 } 91 }
91 92
92 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate( 93 KeystonePromotionInfoBarDelegate::KeystonePromotionInfoBarDelegate(
94 InfoBarService* infobar_service,
93 PrefService* prefs) 95 PrefService* prefs)
94 : ConfirmInfoBarDelegate(), 96 : ConfirmInfoBarDelegate(infobar_service),
95 prefs_(prefs), 97 prefs_(prefs),
96 can_expire_(false), 98 can_expire_(false),
97 weak_ptr_factory_(this) { 99 weak_ptr_factory_(this) {
98 const base::TimeDelta kCanExpireOnNavigationAfterDelay = 100 const base::TimeDelta kCanExpireOnNavigationAfterDelay =
99 base::TimeDelta::FromSeconds(8); 101 base::TimeDelta::FromSeconds(8);
100 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 102 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
101 base::Bind(&KeystonePromotionInfoBarDelegate::SetCanExpire, 103 base::Bind(&KeystonePromotionInfoBarDelegate::SetCanExpire,
102 weak_ptr_factory_.GetWeakPtr()), 104 weak_ptr_factory_.GetWeakPtr()),
103 kCanExpireOnNavigationAfterDelay); 105 kCanExpireOnNavigationAfterDelay);
104 } 106 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 221
220 @end // @implementation KeystonePromotionInfoBar 222 @end // @implementation KeystonePromotionInfoBar
221 223
222 // static 224 // static
223 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) { 225 void KeystoneInfoBar::PromotionInfoBar(Profile* profile) {
224 KeystonePromotionInfoBar* promotionInfoBar = 226 KeystonePromotionInfoBar* promotionInfoBar =
225 [[[KeystonePromotionInfoBar alloc] init] autorelease]; 227 [[[KeystonePromotionInfoBar alloc] init] autorelease];
226 228
227 [promotionInfoBar checkAndShowInfoBarForProfile:profile]; 229 [promotionInfoBar checkAndShowInfoBarForProfile:profile];
228 } 230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698