Chromium Code Reviews| 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/default_browser_prompt.h" | 5 #include "chrome/browser/ui/startup/default_browser_prompt.h" |
| 6 | 6 |
| 7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 | 29 |
| 30 using content::BrowserThread; | 30 using content::BrowserThread; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // The delegate for the infobar shown when Chrome is not the default browser. | 34 // The delegate for the infobar shown when Chrome is not the default browser. |
| 35 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 35 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 36 public: | 36 public: |
| 37 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 37 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
|
grt (UTC plus 2)
2012/05/25 20:27:38
remove "explicit" since there's more than one arg.
motek.
2012/05/28 17:40:33
Good point. Haven't noticed that.
| |
| 38 PrefService* prefs); | 38 PrefService* prefs, |
| 39 bool interactive_flow_required); | |
| 39 | 40 |
| 40 private: | 41 private: |
| 41 virtual ~DefaultBrowserInfoBarDelegate(); | 42 virtual ~DefaultBrowserInfoBarDelegate(); |
| 42 | 43 |
| 43 void AllowExpiry() { should_expire_ = true; } | 44 void AllowExpiry() { should_expire_ = true; } |
| 44 | 45 |
| 45 // ConfirmInfoBarDelegate: | 46 // ConfirmInfoBarDelegate: |
| 46 virtual bool ShouldExpire( | 47 virtual bool ShouldExpire( |
| 47 const content::LoadCommittedDetails& details) const OVERRIDE; | 48 const content::LoadCommittedDetails& details) const OVERRIDE; |
| 48 virtual gfx::Image* GetIcon() const OVERRIDE; | 49 virtual gfx::Image* GetIcon() const OVERRIDE; |
| 49 virtual string16 GetMessageText() const OVERRIDE; | 50 virtual string16 GetMessageText() const OVERRIDE; |
| 50 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 51 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
| 51 virtual bool NeedElevation(InfoBarButton button) const OVERRIDE; | 52 virtual bool NeedElevation(InfoBarButton button) const OVERRIDE; |
| 52 virtual bool Accept() OVERRIDE; | 53 virtual bool Accept() OVERRIDE; |
| 53 virtual bool Cancel() OVERRIDE; | 54 virtual bool Cancel() OVERRIDE; |
| 55 static void SetChromeAsDefaultBrowser(bool interactive_flow); | |
|
grt (UTC plus 2)
2012/05/25 20:27:38
please separate this from the ConfirmInfoBarDelega
motek.
2012/05/28 17:40:33
Done.
| |
| 54 | 56 |
| 55 // The prefs to use. | 57 // The prefs to use. |
| 56 PrefService* prefs_; | 58 PrefService* prefs_; |
| 57 | 59 |
| 58 // Whether the user clicked one of the buttons. | 60 // Whether the user clicked one of the buttons. |
| 59 bool action_taken_; | 61 bool action_taken_; |
| 60 | 62 |
| 61 // Whether the info-bar should be dismissed on the next navigation. | 63 // Whether the info-bar should be dismissed on the next navigation. |
| 62 bool should_expire_; | 64 bool should_expire_; |
| 63 | 65 |
| 66 // Whether changing the default application will require entering the | |
| 67 // modal-UI flow. | |
| 68 bool interactive_flow_required_; | |
| 69 | |
| 64 // Used to delay the expiration of the info-bar. | 70 // Used to delay the expiration of the info-bar. |
| 65 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; | 71 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; |
| 66 | 72 |
| 67 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); | 73 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( | 76 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( |
| 71 InfoBarTabHelper* infobar_helper, | 77 InfoBarTabHelper* infobar_helper, |
| 72 PrefService* prefs) | 78 PrefService* prefs, |
| 79 bool interactive_flow_required) | |
| 73 : ConfirmInfoBarDelegate(infobar_helper), | 80 : ConfirmInfoBarDelegate(infobar_helper), |
| 74 prefs_(prefs), | 81 prefs_(prefs), |
| 75 action_taken_(false), | 82 action_taken_(false), |
| 76 should_expire_(false), | 83 should_expire_(false), |
| 84 interactive_flow_required_(interactive_flow_required), | |
| 77 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 85 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 78 // We want the info-bar to stick-around for few seconds and then be hidden | 86 // We want the info-bar to stick-around for few seconds and then be hidden |
| 79 // on the next navigation after that. | 87 // on the next navigation after that. |
| 80 MessageLoop::current()->PostDelayedTask( | 88 MessageLoop::current()->PostDelayedTask( |
| 81 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 89 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
| 82 weak_factory_.GetWeakPtr()), | 90 weak_factory_.GetWeakPtr()), |
| 83 base::TimeDelta::FromSeconds(8)); | 91 base::TimeDelta::FromSeconds(8)); |
| 84 } | 92 } |
| 85 | 93 |
| 86 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { | 94 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 108 IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL : | 116 IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL : |
| 109 IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL); | 117 IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL); |
| 110 } | 118 } |
| 111 | 119 |
| 112 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { | 120 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { |
| 113 return button == BUTTON_OK; | 121 return button == BUTTON_OK; |
| 114 } | 122 } |
| 115 | 123 |
| 116 bool DefaultBrowserInfoBarDelegate::Accept() { | 124 bool DefaultBrowserInfoBarDelegate::Accept() { |
| 117 action_taken_ = true; | 125 action_taken_ = true; |
| 118 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); | |
| 119 BrowserThread::PostTask( | 126 BrowserThread::PostTask( |
| 120 BrowserThread::FILE, | 127 BrowserThread::FILE, |
| 121 FROM_HERE, | 128 FROM_HERE, |
| 122 base::Bind(base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser))); | 129 base::Bind(&DefaultBrowserInfoBarDelegate::SetChromeAsDefaultBrowser, |
| 130 interactive_flow_required_)); | |
| 131 | |
| 123 return true; | 132 return true; |
| 124 } | 133 } |
| 125 | 134 |
| 135 void DefaultBrowserInfoBarDelegate::SetChromeAsDefaultBrowser( | |
| 136 bool interactive_flow) { | |
| 137 if (interactive_flow) { | |
| 138 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUI", 1); | |
| 139 if (!ShellIntegration::StartSetAsDefaultBrowserInteractive()) { | |
|
grt (UTC plus 2)
2012/05/25 20:27:38
remove braces
| |
| 140 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUIFailed", 1); | |
| 141 } | |
| 142 } else { | |
| 143 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); | |
| 144 ShellIntegration::SetAsDefaultBrowser(); | |
| 145 } | |
| 146 } | |
| 147 | |
| 126 bool DefaultBrowserInfoBarDelegate::Cancel() { | 148 bool DefaultBrowserInfoBarDelegate::Cancel() { |
| 127 action_taken_ = true; | 149 action_taken_ = true; |
| 128 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); | 150 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
| 129 // User clicked "Don't ask me again", remember that. | 151 // User clicked "Don't ask me again", remember that. |
| 130 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 152 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
| 131 return true; | 153 return true; |
| 132 } | 154 } |
| 133 | 155 |
| 134 void NotifyNotDefaultBrowserCallback() { | 156 void NotifyNotDefaultBrowserCallback( |
| 157 ShellIntegration::DefaultSettingsChangePermission operation_type) { | |
| 135 Browser* browser = BrowserList::GetLastActive(); | 158 Browser* browser = BrowserList::GetLastActive(); |
| 136 if (!browser) | 159 if (!browser) |
| 137 return; // Reached during ui tests. | 160 return; // Reached during ui tests. |
| 138 | 161 |
| 139 // In ChromeBot tests, there might be a race. This line appears to get | 162 // In ChromeBot tests, there might be a race. This line appears to get |
| 140 // called during shutdown and |tab| can be NULL. | 163 // called during shutdown and |tab| can be NULL. |
| 141 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); | 164 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); |
| 142 if (!tab) | 165 if (!tab) |
| 143 return; | 166 return; |
| 144 | 167 |
| 145 // Don't show the info-bar if there are already info-bars showing. | 168 // Don't show the info-bar if there are already info-bars showing. |
| 146 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); | 169 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
| 147 if (infobar_helper->infobar_count() > 0) | 170 if (infobar_helper->infobar_count() > 0) |
| 148 return; | 171 return; |
| 149 | 172 |
| 173 bool interactive_flow = operation_type == | |
| 174 ShellIntegration::CHANGE_DEFAULT_INTERACTIVE; | |
| 150 infobar_helper->AddInfoBar( | 175 infobar_helper->AddInfoBar( |
| 151 new DefaultBrowserInfoBarDelegate(infobar_helper, | 176 new DefaultBrowserInfoBarDelegate(infobar_helper, |
| 152 tab->profile()->GetPrefs())); | 177 tab->profile()->GetPrefs(), |
| 178 interactive_flow)); | |
| 153 } | 179 } |
| 154 | 180 |
| 155 void CheckDefaultBrowserCallback() { | 181 void CheckDefaultBrowserCallback() { |
| 156 if (ShellIntegration::IsDefaultBrowser() || | 182 if (!ShellIntegration::IsDefaultBrowser()) { |
| 157 !ShellIntegration::CanSetAsDefaultBrowser()) { | 183 ShellIntegration::DefaultSettingsChangePermission default_change_mode = |
| 158 return; | 184 ShellIntegration::CanSetAsDefaultBrowser(); |
| 159 } | 185 |
| 160 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 186 if (ShellIntegration::CHANGE_DEFAULT_NOT_ALLOWED == default_change_mode) |
|
grt (UTC plus 2)
2012/05/25 20:27:38
i think this looks better without the return:
if (
motek.
2012/05/28 17:40:33
Done.
| |
| 161 base::Bind(&NotifyNotDefaultBrowserCallback)); | 187 return; |
| 188 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 189 base::Bind(&NotifyNotDefaultBrowserCallback, | |
| 190 default_change_mode)); | |
| 191 } | |
| 162 } | 192 } |
| 163 | 193 |
| 164 } // namespace | 194 } // namespace |
| 165 | 195 |
| 166 namespace browser { | 196 namespace browser { |
| 167 | 197 |
| 168 void ShowDefaultBrowserPrompt(Profile* profile) { | 198 void ShowDefaultBrowserPrompt(Profile* profile) { |
| 169 // We do not check if we are the default browser if: | 199 // We do not check if we are the default browser if: |
| 170 // - the user said "don't ask me again" on the infobar earlier. | 200 // - the user said "don't ask me again" on the infobar earlier. |
| 171 // - this is the first launch after the first run flow. | 201 // - this is the first launch after the first run flow. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 187 // just prevent showing the infobar. | 217 // just prevent showing the infobar. |
| 188 } | 218 } |
| 189 return; | 219 return; |
| 190 } | 220 } |
| 191 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 221 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 192 base::Bind(&CheckDefaultBrowserCallback)); | 222 base::Bind(&CheckDefaultBrowserCallback)); |
| 193 | 223 |
| 194 } | 224 } |
| 195 | 225 |
| 196 } // namespace browser | 226 } // namespace browser |
| OLD | NEW |