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 13 matching lines...) Expand all Loading... | |
24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
26 #include "grit/theme_resources_standard.h" | 26 #include "grit/theme_resources_standard.h" |
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 // Calls the appropriate function for setting Chrome as the default browser. | |
35 // This requires IO access (registry) and may result in interaction with a | |
36 // modal system UI. | |
37 void SetChromeAsDefaultBrowser(bool interactive_flow) { | |
38 if (interactive_flow) { | |
39 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUI", 1); | |
40 if (!ShellIntegration::SetAsDefaultBrowserInteractive()) | |
41 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefaultUIFailed", 1); | |
grt (UTC plus 2)
2012/06/01 14:36:39
please make sure that the description for this in
motek.
2012/06/01 20:50:17
Ack.
| |
42 } else { | |
43 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); | |
44 ShellIntegration::SetAsDefaultBrowser(); | |
45 } | |
46 } | |
47 | |
34 // The delegate for the infobar shown when Chrome is not the default browser. | 48 // The delegate for the infobar shown when Chrome is not the default browser. |
35 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { | 49 class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { |
36 public: | 50 public: |
37 explicit DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, | 51 DefaultBrowserInfoBarDelegate(InfoBarTabHelper* infobar_helper, |
38 PrefService* prefs); | 52 PrefService* prefs, |
53 bool interactive_flow_required); | |
39 | 54 |
40 private: | 55 private: |
41 virtual ~DefaultBrowserInfoBarDelegate(); | 56 virtual ~DefaultBrowserInfoBarDelegate(); |
42 | 57 |
43 void AllowExpiry() { should_expire_ = true; } | 58 void AllowExpiry() { should_expire_ = true; } |
44 | 59 |
45 // ConfirmInfoBarDelegate: | 60 // ConfirmInfoBarDelegate: |
46 virtual bool ShouldExpire( | 61 virtual bool ShouldExpire( |
47 const content::LoadCommittedDetails& details) const OVERRIDE; | 62 const content::LoadCommittedDetails& details) const OVERRIDE; |
48 virtual gfx::Image* GetIcon() const OVERRIDE; | 63 virtual gfx::Image* GetIcon() const OVERRIDE; |
49 virtual string16 GetMessageText() const OVERRIDE; | 64 virtual string16 GetMessageText() const OVERRIDE; |
50 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; | 65 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; |
51 virtual bool NeedElevation(InfoBarButton button) const OVERRIDE; | 66 virtual bool NeedElevation(InfoBarButton button) const OVERRIDE; |
52 virtual bool Accept() OVERRIDE; | 67 virtual bool Accept() OVERRIDE; |
53 virtual bool Cancel() OVERRIDE; | 68 virtual bool Cancel() OVERRIDE; |
54 | 69 |
55 // The prefs to use. | 70 // The prefs to use. |
56 PrefService* prefs_; | 71 PrefService* prefs_; |
57 | 72 |
58 // Whether the user clicked one of the buttons. | 73 // Whether the user clicked one of the buttons. |
59 bool action_taken_; | 74 bool action_taken_; |
60 | 75 |
61 // Whether the info-bar should be dismissed on the next navigation. | 76 // Whether the info-bar should be dismissed on the next navigation. |
62 bool should_expire_; | 77 bool should_expire_; |
63 | 78 |
79 // Whether changing the default application will require entering the | |
80 // modal-UI flow. | |
81 bool interactive_flow_required_; | |
82 | |
64 // Used to delay the expiration of the info-bar. | 83 // Used to delay the expiration of the info-bar. |
65 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; | 84 base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_; |
66 | 85 |
67 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); | 86 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); |
68 }; | 87 }; |
69 | 88 |
70 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( | 89 DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate( |
71 InfoBarTabHelper* infobar_helper, | 90 InfoBarTabHelper* infobar_helper, |
72 PrefService* prefs) | 91 PrefService* prefs, |
92 bool interactive_flow_required) | |
73 : ConfirmInfoBarDelegate(infobar_helper), | 93 : ConfirmInfoBarDelegate(infobar_helper), |
74 prefs_(prefs), | 94 prefs_(prefs), |
75 action_taken_(false), | 95 action_taken_(false), |
76 should_expire_(false), | 96 should_expire_(false), |
97 interactive_flow_required_(interactive_flow_required), | |
77 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 98 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
78 // We want the info-bar to stick-around for few seconds and then be hidden | 99 // We want the info-bar to stick-around for few seconds and then be hidden |
79 // on the next navigation after that. | 100 // on the next navigation after that. |
80 MessageLoop::current()->PostDelayedTask( | 101 MessageLoop::current()->PostDelayedTask( |
81 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, | 102 FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry, |
82 weak_factory_.GetWeakPtr()), | 103 weak_factory_.GetWeakPtr()), |
83 base::TimeDelta::FromSeconds(8)); | 104 base::TimeDelta::FromSeconds(8)); |
84 } | 105 } |
85 | 106 |
86 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { | 107 DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() { |
(...skipping 21 matching lines...) Expand all Loading... | |
108 IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL : | 129 IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL : |
109 IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL); | 130 IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL); |
110 } | 131 } |
111 | 132 |
112 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { | 133 bool DefaultBrowserInfoBarDelegate::NeedElevation(InfoBarButton button) const { |
113 return button == BUTTON_OK; | 134 return button == BUTTON_OK; |
114 } | 135 } |
115 | 136 |
116 bool DefaultBrowserInfoBarDelegate::Accept() { | 137 bool DefaultBrowserInfoBarDelegate::Accept() { |
117 action_taken_ = true; | 138 action_taken_ = true; |
118 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); | |
119 BrowserThread::PostTask( | 139 BrowserThread::PostTask( |
120 BrowserThread::FILE, | 140 BrowserThread::FILE, |
121 FROM_HERE, | 141 FROM_HERE, |
122 base::Bind(base::IgnoreResult(&ShellIntegration::SetAsDefaultBrowser))); | 142 base::Bind(&SetChromeAsDefaultBrowser, interactive_flow_required_)); |
143 | |
123 return true; | 144 return true; |
124 } | 145 } |
125 | 146 |
126 bool DefaultBrowserInfoBarDelegate::Cancel() { | 147 bool DefaultBrowserInfoBarDelegate::Cancel() { |
127 action_taken_ = true; | 148 action_taken_ = true; |
128 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); | 149 UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); |
129 // User clicked "Don't ask me again", remember that. | 150 // User clicked "Don't ask me again", remember that. |
130 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); | 151 prefs_->SetBoolean(prefs::kCheckDefaultBrowser, false); |
131 return true; | 152 return true; |
132 } | 153 } |
133 | 154 |
134 void CheckDefaultBrowserCallback() { | 155 void CheckDefaultBrowserCallback() { |
135 if (ShellIntegration::IsDefaultBrowser() || | 156 if (!ShellIntegration::IsDefaultBrowser()) { |
136 !ShellIntegration::CanSetAsDefaultBrowser()) { | 157 ShellIntegration::DefaultSettingsChangePermission default_change_mode = |
137 return; | 158 ShellIntegration::CanSetAsDefaultBrowser(); |
159 | |
160 if (default_change_mode != ShellIntegration::CHANGE_DEFAULT_NOT_ALLOWED) { | |
161 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
162 base::Bind(&browser::internal::NotifyNotDefaultBrowserCallback)); | |
163 } | |
138 } | 164 } |
139 BrowserThread::PostTask( | |
140 BrowserThread::UI, | |
141 FROM_HERE, | |
142 base::Bind(&browser::internal::NotifyNotDefaultBrowserCallback)); | |
143 } | 165 } |
144 | 166 |
145 } // namespace | 167 } // namespace |
146 | 168 |
147 namespace browser { | 169 namespace browser { |
148 | 170 |
149 void ShowDefaultBrowserPrompt(Profile* profile) { | 171 void ShowDefaultBrowserPrompt(Profile* profile) { |
150 // We do not check if we are the default browser if: | 172 // We do not check if we are the default browser if: |
151 // - the user said "don't ask me again" on the infobar earlier. | 173 // - the user said "don't ask me again" on the infobar earlier. |
152 // - this is the first launch after the first run flow. | 174 // - this is the first launch after the first run flow. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 // called during shutdown and |tab| can be NULL. | 207 // called during shutdown and |tab| can be NULL. |
186 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); | 208 TabContentsWrapper* tab = browser->GetSelectedTabContentsWrapper(); |
187 if (!tab) | 209 if (!tab) |
188 return; | 210 return; |
189 | 211 |
190 // Don't show the info-bar if there are already info-bars showing. | 212 // Don't show the info-bar if there are already info-bars showing. |
191 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); | 213 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
192 if (infobar_helper->infobar_count() > 0) | 214 if (infobar_helper->infobar_count() > 0) |
193 return; | 215 return; |
194 | 216 |
217 bool interactive_flow = ShellIntegration::CanSetAsDefaultBrowser() == | |
218 ShellIntegration::CHANGE_DEFAULT_INTERACTIVE; | |
195 infobar_helper->AddInfoBar( | 219 infobar_helper->AddInfoBar( |
196 new DefaultBrowserInfoBarDelegate(infobar_helper, | 220 new DefaultBrowserInfoBarDelegate(infobar_helper, |
197 tab->profile()->GetPrefs())); | 221 tab->profile()->GetPrefs(), |
222 interactive_flow)); | |
198 } | 223 } |
199 | 224 |
200 } // namespace internal | 225 } // namespace internal |
201 } // namespace browser | 226 } // namespace browser |
OLD | NEW |