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

Side by Side Diff: chrome/browser/shell_integration.cc

Issue 1349163008: Setting chrome as the default browser is now fixed on Windows 10 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months 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
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/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 11 matching lines...) Expand all
22 #endif 22 #endif
23 23
24 #if !defined(OS_WIN) 24 #if !defined(OS_WIN)
25 #include "chrome/common/channel_info.h" 25 #include "chrome/common/channel_info.h"
26 #include "chrome/grit/chromium_strings.h" 26 #include "chrome/grit/chromium_strings.h"
27 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
28 #endif 28 #endif
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 31
32 #if !defined(OS_WIN)
33 // static
34 bool ShellIntegration::IsSetAsDefaultAsynchronous() {
35 return false;
36 }
37
38 // static
39 void ShellIntegration::SetAsDefaultBrowserAsynchronous() {
40 NOTREACHED();
41 }
42 #endif // !defined(OS_WIN)
43
32 // static 44 // static
33 ShellIntegration::DefaultWebClientSetPermission 45 ShellIntegration::DefaultWebClientSetPermission
34 ShellIntegration::CanSetAsDefaultProtocolClient() { 46 ShellIntegration::CanSetAsDefaultProtocolClient() {
35 // Allowed as long as the browser can become the operating system default 47 // Allowed as long as the browser can become the operating system default
36 // browser. 48 // browser.
37 return CanSetAsDefaultBrowser(); 49 return CanSetAsDefaultBrowser();
38 } 50 }
39 51
40 static const struct ShellIntegration::AppModeInfo* gAppModeInfo = NULL; 52 static const struct ShellIntegration::AppModeInfo* gAppModeInfo = NULL;
41 53
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 bool ShellIntegration::SetAsDefaultProtocolClientInteractive( 140 bool ShellIntegration::SetAsDefaultProtocolClientInteractive(
129 const std::string& protocol) { 141 const std::string& protocol) {
130 return false; 142 return false;
131 } 143 }
132 144
133 // static 145 // static
134 bool ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient() { 146 bool ShellIntegration::IsElevationNeededForSettingDefaultProtocolClient() {
135 return false; 147 return false;
136 } 148 }
137 149
150 void ShellIntegration::DefaultBrowserWorker::InitializeSetAsDefault() {}
151
152 bool ShellIntegration::DefaultBrowserWorker::UninitializeSetAsDefault(
153 bool succeeded) {
154 return true;
155 }
156
138 #endif // !defined(OS_WIN) 157 #endif // !defined(OS_WIN)
139 158
140 bool ShellIntegration::DefaultWebClientObserver::IsOwnedByWorker() { 159 bool ShellIntegration::DefaultWebClientObserver::IsOwnedByWorker() {
141 return false; 160 return false;
142 } 161 }
143 162
144 bool ShellIntegration::DefaultWebClientObserver:: 163 bool ShellIntegration::DefaultWebClientObserver::
145 IsInteractiveSetDefaultPermitted() { 164 IsInteractiveSetDefaultPermitted() {
146 return false; 165 return false;
147 } 166 }
(...skipping 16 matching lines...) Expand all
164 &DefaultWebClientWorker::ExecuteCheckIsDefault, this)); 183 &DefaultWebClientWorker::ExecuteCheckIsDefault, this));
165 } 184 }
166 } 185 }
167 186
168 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { 187 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() {
169 bool interactive_permitted = false; 188 bool interactive_permitted = false;
170 if (observer_) { 189 if (observer_) {
171 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); 190 observer_->SetDefaultWebClientUIState(STATE_PROCESSING);
172 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); 191 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted();
173 } 192 }
193
194 InitializeSetAsDefault();
195
174 BrowserThread::PostTask( 196 BrowserThread::PostTask(
175 BrowserThread::FILE, FROM_HERE, 197 BrowserThread::FILE, FROM_HERE,
176 base::Bind(&DefaultWebClientWorker::ExecuteSetAsDefault, this, 198 base::Bind(&DefaultWebClientWorker::ExecuteSetAsDefault, this,
177 interactive_permitted)); 199 interactive_permitted));
178 } 200 }
179 201
180 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { 202 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() {
181 // Our associated view has gone away, so we shouldn't call back to it if 203 // Our associated view has gone away, so we shouldn't call back to it if
182 // our worker thread returns after the view is dead. 204 // our worker thread returns after the view is dead.
183 DCHECK_CURRENTLY_ON(BrowserThread::UI); 205 DCHECK_CURRENTLY_ON(BrowserThread::UI);
184 observer_ = NULL; 206 observer_ = NULL;
185 } 207 }
186 208
187 /////////////////////////////////////////////////////////////////////////////// 209 ///////////////////////////////////////////////////////////////////////////////
188 // DefaultWebClientWorker, private: 210 // DefaultWebClientWorker, private:
189 211
190 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() { 212 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() {
191 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 213 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
192 DefaultWebClientState state = CheckIsDefault(); 214 DefaultWebClientState state = CheckIsDefault();
193 BrowserThread::PostTask( 215 BrowserThread::PostTask(
194 BrowserThread::UI, FROM_HERE, 216 BrowserThread::UI, FROM_HERE,
195 base::Bind( 217 base::Bind(
196 &DefaultWebClientWorker::CompleteCheckIsDefault, this, state)); 218 &DefaultWebClientWorker::CompleteCheckIsDefault, this, state));
197 } 219 }
198 220
199 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault( 221 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault(
200 DefaultWebClientState state) { 222 DefaultWebClientState state) {
201 DCHECK_CURRENTLY_ON(BrowserThread::UI); 223 DCHECK_CURRENTLY_ON(BrowserThread::UI);
224
202 UpdateUI(state); 225 UpdateUI(state);
226
203 // The worker has finished everything it needs to do, so free the observer 227 // The worker has finished everything it needs to do, so free the observer
204 // if we own it. 228 // if we own it.
205 if (observer_ && observer_->IsOwnedByWorker()) { 229 if (observer_ && observer_->IsOwnedByWorker()) {
206 delete observer_; 230 delete observer_;
207 observer_ = NULL; 231 observer_ = NULL;
208 } 232 }
209 } 233 }
210 234
211 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault( 235 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault(
212 bool interactive_permitted) { 236 bool interactive_permitted) {
213 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 237 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
214 238
215 bool result = SetAsDefault(interactive_permitted); 239 SetAsDefault(interactive_permitted);
216 BrowserThread::PostTask(
217 BrowserThread::UI, FROM_HERE,
218 base::Bind(&DefaultWebClientWorker::CompleteSetAsDefault, this, result));
219 } 240 }
220 241
221 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( 242 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault(
222 bool succeeded) { 243 bool succeeded) {
223 DCHECK_CURRENTLY_ON(BrowserThread::UI); 244 DCHECK_CURRENTLY_ON(BrowserThread::UI);
224 // First tell the observer what the SetAsDefault call has returned. 245
225 if (observer_) 246 // Only notify observer is |UninitializeSetAsDefault| returns true. This is to
grt (UTC plus 2) 2015/09/22 18:21:47 is -> if
Patrick Monette 2015/09/23 22:40:44 Comment removed.
226 observer_->OnSetAsDefaultConcluded(succeeded); 247 // filter out multiple calls to |CompleteSetAsDefault| due to possible race
227 // Set as default completed, check again to make sure it stuck... 248 // conditions.
228 StartCheckIsDefault(); 249 if (UninitializeSetAsDefault(succeeded)) {
250 // First tell the observer what the SetAsDefault call has returned.
251 if (observer_)
252 observer_->OnSetAsDefaultConcluded(succeeded);
253 // Set as default completed, check again to make sure it stuck...
254 StartCheckIsDefault();
255 }
229 } 256 }
230 257
231 void ShellIntegration::DefaultWebClientWorker::UpdateUI( 258 void ShellIntegration::DefaultWebClientWorker::UpdateUI(
232 DefaultWebClientState state) { 259 DefaultWebClientState state) {
233 if (observer_) { 260 if (observer_) {
234 switch (state) { 261 switch (state) {
235 case NOT_DEFAULT: 262 case NOT_DEFAULT:
236 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); 263 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT);
237 break; 264 break;
238 case IS_DEFAULT: 265 case IS_DEFAULT:
(...skipping 18 matching lines...) Expand all
257 } 284 }
258 285
259 /////////////////////////////////////////////////////////////////////////////// 286 ///////////////////////////////////////////////////////////////////////////////
260 // DefaultBrowserWorker, private: 287 // DefaultBrowserWorker, private:
261 288
262 ShellIntegration::DefaultWebClientState 289 ShellIntegration::DefaultWebClientState
263 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { 290 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() {
264 return ShellIntegration::GetDefaultBrowser(); 291 return ShellIntegration::GetDefaultBrowser();
265 } 292 }
266 293
267 bool ShellIntegration::DefaultBrowserWorker::SetAsDefault( 294 void ShellIntegration::DefaultBrowserWorker::SetAsDefault(
268 bool interactive_permitted) { 295 bool interactive_permitted) {
269 bool result = false; 296 bool result = false;
270 switch (ShellIntegration::CanSetAsDefaultBrowser()) { 297 switch (ShellIntegration::CanSetAsDefaultBrowser()) {
271 case ShellIntegration::SET_DEFAULT_UNATTENDED: 298 case ShellIntegration::SET_DEFAULT_UNATTENDED:
272 result = ShellIntegration::SetAsDefaultBrowser(); 299 result = ShellIntegration::SetAsDefaultBrowser();
300 BrowserThread::PostTask(
301 BrowserThread::UI, FROM_HERE,
302 base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this,
303 result));
273 break; 304 break;
274 case ShellIntegration::SET_DEFAULT_INTERACTIVE: 305 case ShellIntegration::SET_DEFAULT_INTERACTIVE:
306 if (interactive_permitted) {
307 result = ShellIntegration::SetAsDefaultBrowserInteractive();
308 BrowserThread::PostTask(
309 BrowserThread::UI, FROM_HERE,
310 base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this,
311 result));
312 }
grt (UTC plus 2) 2015/09/22 18:21:47 this should run CompleteSetAsDefault with result=f
Patrick Monette 2015/09/23 22:40:44 CompleteSetAsDefault is not called at the end with
313 break;
314 case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS:
275 if (interactive_permitted) 315 if (interactive_permitted)
276 result = ShellIntegration::SetAsDefaultBrowserInteractive(); 316 ShellIntegration::SetAsDefaultBrowserAsynchronous();
277 break; 317 break;
278 default: 318 default:
grt (UTC plus 2) 2015/09/22 18:21:47 while you're here, please change this from "defaul
Patrick Monette 2015/09/23 22:40:44 Done. Moved the cases around so they are in the sa
279 NOTREACHED(); 319 NOTREACHED();
280 } 320 }
281
282 return result;
283 } 321 }
284 322
285 /////////////////////////////////////////////////////////////////////////////// 323 ///////////////////////////////////////////////////////////////////////////////
286 // ShellIntegration::DefaultProtocolClientWorker 324 // ShellIntegration::DefaultProtocolClientWorker
287 // 325 //
288 326
289 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( 327 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker(
290 DefaultWebClientObserver* observer, const std::string& protocol) 328 DefaultWebClientObserver* observer, const std::string& protocol)
291 : DefaultWebClientWorker(observer), 329 : DefaultWebClientWorker(observer),
292 protocol_(protocol) { 330 protocol_(protocol) {
293 } 331 }
294 332
295 /////////////////////////////////////////////////////////////////////////////// 333 ///////////////////////////////////////////////////////////////////////////////
296 // DefaultProtocolClientWorker, private: 334 // DefaultProtocolClientWorker, private:
297 335
298 ShellIntegration::DefaultWebClientState 336 ShellIntegration::DefaultWebClientState
299 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { 337 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() {
300 return ShellIntegration::IsDefaultProtocolClient(protocol_); 338 return ShellIntegration::IsDefaultProtocolClient(protocol_);
301 } 339 }
302 340
303 bool ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( 341 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault(
304 bool interactive_permitted) { 342 bool interactive_permitted) {
305 bool result = false; 343 bool result = false;
306 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { 344 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) {
307 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: 345 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED:
308 result = false; 346 BrowserThread::PostTask(
347 BrowserThread::UI, FROM_HERE,
348 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this,
349 false));
309 break; 350 break;
310 case ShellIntegration::SET_DEFAULT_UNATTENDED: 351 case ShellIntegration::SET_DEFAULT_UNATTENDED:
311 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); 352 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_);
353 BrowserThread::PostTask(
354 BrowserThread::UI, FROM_HERE,
355 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this,
356 result));
312 break; 357 break;
313 case ShellIntegration::SET_DEFAULT_INTERACTIVE: 358 case ShellIntegration::SET_DEFAULT_INTERACTIVE:
314 if (interactive_permitted) { 359 if (interactive_permitted) {
315 result = ShellIntegration::SetAsDefaultProtocolClientInteractive( 360 result =
316 protocol_); 361 ShellIntegration::SetAsDefaultProtocolClientInteractive(protocol_);
362 BrowserThread::PostTask(
363 BrowserThread::UI, FROM_HERE,
364 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this,
365 result));
317 } 366 }
318 break; 367 break;
319 } 368 }
320
321 return result;
322 } 369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698