| 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/startup/autolaunch_prompt.h" | 5 #include "chrome/browser/ui/startup/autolaunch_prompt.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const int kMaxInfobarShown = 5; | 34 const int kMaxInfobarShown = 5; |
| 35 | 35 |
| 36 // The delegate for the infobar shown when Chrome was auto-launched. | 36 // The delegate for the infobar shown when Chrome was auto-launched. |
| 37 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { | 37 class AutolaunchInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 38 public: | 38 public: |
| 39 // Creates an autolaunch delegate and adds it to |infobar_service|. |
| 40 static void Create(InfoBarService* infobar_service, |
| 41 PrefService* prefs, |
| 42 Profile* profile); |
| 43 |
| 44 private: |
| 39 AutolaunchInfoBarDelegate(InfoBarService* infobar_service, | 45 AutolaunchInfoBarDelegate(InfoBarService* infobar_service, |
| 40 PrefService* prefs, | 46 PrefService* prefs, |
| 41 Profile* profile); | 47 Profile* profile); |
| 42 virtual ~AutolaunchInfoBarDelegate(); | 48 virtual ~AutolaunchInfoBarDelegate(); |
| 43 | 49 |
| 44 private: | |
| 45 void AllowExpiry() { should_expire_ = true; } | 50 void AllowExpiry() { should_expire_ = true; } |
| 46 | 51 |
| 47 // ConfirmInfoBarDelegate: | 52 // ConfirmInfoBarDelegate: |
| 48 virtual gfx::Image* GetIcon() const OVERRIDE; | 53 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 49 virtual string16 GetMessageText() const OVERRIDE; | 54 virtual string16 GetMessageText() const OVERRIDE; |
| 50 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 55 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 51 virtual bool Accept() OVERRIDE; | 56 virtual bool Accept() OVERRIDE; |
| 52 virtual bool Cancel() OVERRIDE; | 57 virtual bool Cancel() OVERRIDE; |
| 53 virtual bool ShouldExpireInternal( | 58 virtual bool ShouldExpireInternal( |
| 54 const content::LoadCommittedDetails& details) const OVERRIDE; | 59 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 55 | 60 |
| 56 // The prefs to use. | 61 // The prefs to use. |
| 57 PrefService* prefs_; | 62 PrefService* prefs_; |
| 58 | 63 |
| 59 // Whether the user clicked one of the buttons. | 64 // Whether the user clicked one of the buttons. |
| 60 bool action_taken_; | 65 bool action_taken_; |
| 61 | 66 |
| 62 // Whether the info-bar should be dismissed on the next navigation. | 67 // Whether the info-bar should be dismissed on the next navigation. |
| 63 bool should_expire_; | 68 bool should_expire_; |
| 64 | 69 |
| 65 // Weak pointer to the profile, not owned by us. | 70 // Weak pointer to the profile, not owned by us. |
| 66 Profile* profile_; | 71 Profile* profile_; |
| 67 | 72 |
| 68 // Used to delay the expiration of the info-bar. | 73 // Used to delay the expiration of the info-bar. |
| 69 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_; | 74 base::WeakPtrFactory<AutolaunchInfoBarDelegate> weak_factory_; |
| 70 | 75 |
| 71 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); | 76 DISALLOW_COPY_AND_ASSIGN(AutolaunchInfoBarDelegate); |
| 72 }; | 77 }; |
| 73 | 78 |
| 79 // static |
| 80 void AutolaunchInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 81 PrefService* prefs, |
| 82 Profile* profile) { |
| 83 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 84 new AutolaunchInfoBarDelegate(infobar_service, prefs, profile))); |
| 85 } |
| 86 |
| 74 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( | 87 AutolaunchInfoBarDelegate::AutolaunchInfoBarDelegate( |
| 75 InfoBarService* infobar_service, | 88 InfoBarService* infobar_service, |
| 76 PrefService* prefs, | 89 PrefService* prefs, |
| 77 Profile* profile) | 90 Profile* profile) |
| 78 : ConfirmInfoBarDelegate(infobar_service), | 91 : ConfirmInfoBarDelegate(infobar_service), |
| 79 prefs_(prefs), | 92 prefs_(prefs), |
| 80 action_taken_(false), | 93 action_taken_(false), |
| 81 should_expire_(false), | 94 should_expire_(false), |
| 82 profile_(profile), | 95 profile_(profile), |
| 83 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 96 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 181 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 169 if (command_line.HasSwitch(switches::kChromeFrame)) | 182 if (command_line.HasSwitch(switches::kChromeFrame)) |
| 170 return false; | 183 return false; |
| 171 | 184 |
| 172 if (!command_line.HasSwitch(switches::kAutoLaunchAtStartup) && | 185 if (!command_line.HasSwitch(switches::kAutoLaunchAtStartup) && |
| 173 !first_run::IsChromeFirstRun()) { | 186 !first_run::IsChromeFirstRun()) { |
| 174 return false; | 187 return false; |
| 175 } | 188 } |
| 176 | 189 |
| 177 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); | 190 content::WebContents* web_contents = chrome::GetActiveWebContents(browser); |
| 178 | |
| 179 // Don't show the info-bar if there are already info-bars showing. | |
| 180 InfoBarService* infobar_service = | |
| 181 InfoBarService::FromWebContents(web_contents); | |
| 182 if (infobar_service->GetInfoBarCount() > 0) | |
| 183 return false; | |
| 184 | |
| 185 profile = Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 191 profile = Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 186 infobar_service->AddInfoBar(new AutolaunchInfoBarDelegate( | 192 AutolaunchInfoBarDelegate::Create( |
| 187 infobar_service, profile->GetPrefs(), profile)); | 193 InfoBarService::FromWebContents(web_contents), profile->GetPrefs(), |
| 188 | 194 profile); |
| 189 return true; | 195 return true; |
| 190 } | 196 } |
| 191 | 197 |
| 192 void RegisterAutolaunchUserPrefs(PrefServiceSyncable* prefs) { | 198 void RegisterAutolaunchUserPrefs(PrefServiceSyncable* prefs) { |
| 193 prefs->RegisterIntegerPref( | 199 prefs->RegisterIntegerPref( |
| 194 prefs::kShownAutoLaunchInfobar, 0, PrefServiceSyncable::UNSYNCABLE_PREF); | 200 prefs::kShownAutoLaunchInfobar, 0, PrefServiceSyncable::UNSYNCABLE_PREF); |
| 195 } | 201 } |
| 196 | 202 |
| 197 } // namespace chrome | 203 } // namespace chrome |
| OLD | NEW |