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/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 Loading... | |
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) | |
Peter Kasting
2015/09/25 20:52:26
Nit: Define these in the same place in the .cc fil
Patrick Monette
2015/09/28 23:46:36
Done.
| |
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 auto permission = CanSetAsDefaultBrowser(); |
Peter Kasting
2015/09/25 20:52:26
Nit: I think in this case using the real type is s
Patrick Monette
2015/09/28 23:46:36
Done.
| |
50 | |
51 // Set as default asynchronous is only supported for default web browser. | |
52 if (permission == SET_DEFAULT_ASYNCHRONOUS) | |
Peter Kasting
2015/09/25 20:52:25
Nit: Shorter:
return (permission == SET_DEFAULT
Patrick Monette
2015/09/28 23:46:36
Done.
| |
53 return SET_DEFAULT_INTERACTIVE; | |
54 | |
55 return permission; | |
38 } | 56 } |
39 | 57 |
40 static const struct ShellIntegration::AppModeInfo* gAppModeInfo = NULL; | 58 static const struct ShellIntegration::AppModeInfo* gAppModeInfo = NULL; |
41 | 59 |
42 // static | 60 // static |
43 void ShellIntegration::SetAppModeInfo(const struct AppModeInfo* info) { | 61 void ShellIntegration::SetAppModeInfo(const struct AppModeInfo* info) { |
44 gAppModeInfo = info; | 62 gAppModeInfo = info; |
45 } | 63 } |
46 | 64 |
47 // static | 65 // static |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 IsInteractiveSetDefaultPermitted() { | 163 IsInteractiveSetDefaultPermitted() { |
146 return false; | 164 return false; |
147 } | 165 } |
148 | 166 |
149 /////////////////////////////////////////////////////////////////////////////// | 167 /////////////////////////////////////////////////////////////////////////////// |
150 // ShellIntegration::DefaultWebClientWorker | 168 // ShellIntegration::DefaultWebClientWorker |
151 // | 169 // |
152 | 170 |
153 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( | 171 ShellIntegration::DefaultWebClientWorker::DefaultWebClientWorker( |
154 DefaultWebClientObserver* observer) | 172 DefaultWebClientObserver* observer) |
155 : observer_(observer) { | 173 : observer_(observer) {} |
156 } | |
157 | 174 |
158 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { | 175 void ShellIntegration::DefaultWebClientWorker::StartCheckIsDefault() { |
159 if (observer_) { | 176 if (observer_) { |
160 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); | 177 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
161 BrowserThread::PostTask( | 178 BrowserThread::PostTask( |
162 BrowserThread::FILE, FROM_HERE, | 179 BrowserThread::FILE, FROM_HERE, |
163 base::Bind( | 180 base::Bind(&DefaultWebClientWorker::CheckIsDefault, this)); |
164 &DefaultWebClientWorker::ExecuteCheckIsDefault, this)); | |
165 } | 181 } |
166 } | 182 } |
167 | 183 |
168 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { | 184 void ShellIntegration::DefaultWebClientWorker::StartSetAsDefault() { |
185 // Cancel the already running process if another start is requested. | |
186 if (set_as_default_in_progress_) | |
187 CompleteSetAsDefault(false); | |
188 | |
189 set_as_default_in_progress_ = true; | |
169 bool interactive_permitted = false; | 190 bool interactive_permitted = false; |
170 if (observer_) { | 191 if (observer_) { |
171 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); | 192 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
172 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); | 193 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); |
194 | |
195 InitializeSetAsDefault(); | |
173 } | 196 } |
174 BrowserThread::PostTask( | 197 |
175 BrowserThread::FILE, FROM_HERE, | 198 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
176 base::Bind(&DefaultWebClientWorker::ExecuteSetAsDefault, this, | 199 base::Bind(&DefaultWebClientWorker::SetAsDefault, |
177 interactive_permitted)); | 200 this, interactive_permitted)); |
178 } | 201 } |
179 | 202 |
180 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { | 203 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { |
181 // Our associated view has gone away, so we shouldn't call back to it if | 204 // 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. | 205 // our worker thread returns after the view is dead. |
183 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 206 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
184 observer_ = NULL; | 207 observer_ = NULL; |
208 // If set as default is currently running, CompleteSetAsDefault is invoked as | |
Peter Kasting
2015/09/25 20:52:26
Nit: Avoid passive voice ("If an attempt to set th
Patrick Monette
2015/09/28 23:46:36
Done.
| |
209 // the result will no longer be posted to any observers and resources must be | |
210 // cleared. | |
211 if (set_as_default_in_progress_) | |
212 CompleteSetAsDefault(false); | |
185 } | 213 } |
186 | 214 |
187 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
188 // DefaultWebClientWorker, private: | 216 // DefaultWebClientWorker, private: |
189 | 217 |
190 void ShellIntegration::DefaultWebClientWorker::ExecuteCheckIsDefault() { | |
191 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
192 DefaultWebClientState state = CheckIsDefault(); | |
193 BrowserThread::PostTask( | |
194 BrowserThread::UI, FROM_HERE, | |
195 base::Bind( | |
196 &DefaultWebClientWorker::CompleteCheckIsDefault, this, state)); | |
197 } | |
198 | |
199 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault( | 218 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault( |
200 DefaultWebClientState state) { | 219 DefaultWebClientState state) { |
201 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 220 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
202 UpdateUI(state); | 221 UpdateUI(state); |
203 // The worker has finished everything it needs to do, so free the observer | 222 // The worker has finished everything it needs to do, so free the observer |
204 // if we own it. | 223 // if we own it. |
205 if (observer_ && observer_->IsOwnedByWorker()) { | 224 if (observer_ && observer_->IsOwnedByWorker()) { |
206 delete observer_; | 225 delete observer_; |
207 observer_ = NULL; | 226 observer_ = NULL; |
208 } | 227 } |
209 } | 228 } |
210 | 229 |
211 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault( | |
212 bool interactive_permitted) { | |
213 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
214 | |
215 bool result = SetAsDefault(interactive_permitted); | |
216 BrowserThread::PostTask( | |
217 BrowserThread::UI, FROM_HERE, | |
218 base::Bind(&DefaultWebClientWorker::CompleteSetAsDefault, this, result)); | |
219 } | |
220 | |
221 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( | 230 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( |
222 bool succeeded) { | 231 bool succeeded) { |
223 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
224 // First tell the observer what the SetAsDefault call has returned. | 233 // Hold on to a reference because if this was called via the default browser |
225 if (observer_) | 234 // callback in StartupBrowserCreator, clearing the callback in |
226 observer_->OnSetAsDefaultConcluded(succeeded); | 235 // FinalizeSetAsDefault will remove the last reference and delete the worker |
Peter Kasting
2015/09/25 20:52:26
Nit: will -> would otherwise; the worker -> us
Patrick Monette
2015/09/28 23:46:36
Done.
| |
227 // Set as default completed, check again to make sure it stuck... | 236 // in the middle of the function. |
Peter Kasting
2015/09/25 20:52:26
Nit: the -> this
Patrick Monette
2015/09/28 23:46:36
Done.
| |
228 StartCheckIsDefault(); | 237 scoped_refptr<DefaultWebClientWorker> scoped_ref(this); |
238 | |
239 if (set_as_default_in_progress_) { | |
240 set_as_default_in_progress_ = false; | |
241 | |
242 FinalizeSetAsDefault(succeeded); | |
243 if (observer_) | |
244 observer_->OnSetAsDefaultConcluded(succeeded); | |
245 // Set as default completed, check again to make sure it stuck... | |
Peter Kasting
2015/09/25 20:52:25
Nit: Can you elaborate? When would the operation
Patrick Monette
2015/09/28 23:46:36
Done.
| |
246 StartCheckIsDefault(); | |
247 } | |
229 } | 248 } |
230 | 249 |
231 void ShellIntegration::DefaultWebClientWorker::UpdateUI( | 250 void ShellIntegration::DefaultWebClientWorker::UpdateUI( |
232 DefaultWebClientState state) { | 251 DefaultWebClientState state) { |
233 if (observer_) { | 252 if (observer_) { |
234 switch (state) { | 253 switch (state) { |
235 case NOT_DEFAULT: | 254 case NOT_DEFAULT: |
236 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); | 255 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); |
237 break; | 256 break; |
238 case IS_DEFAULT: | 257 case IS_DEFAULT: |
(...skipping 10 matching lines...) Expand all Loading... | |
249 | 268 |
250 /////////////////////////////////////////////////////////////////////////////// | 269 /////////////////////////////////////////////////////////////////////////////// |
251 // ShellIntegration::DefaultBrowserWorker | 270 // ShellIntegration::DefaultBrowserWorker |
252 // | 271 // |
253 | 272 |
254 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( | 273 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( |
255 DefaultWebClientObserver* observer) | 274 DefaultWebClientObserver* observer) |
256 : DefaultWebClientWorker(observer) { | 275 : DefaultWebClientWorker(observer) { |
257 } | 276 } |
258 | 277 |
278 ShellIntegration::DefaultBrowserWorker::~DefaultBrowserWorker() { | |
279 if (set_as_default_in_progress_) | |
280 CompleteSetAsDefault(false); | |
281 } | |
282 | |
259 /////////////////////////////////////////////////////////////////////////////// | 283 /////////////////////////////////////////////////////////////////////////////// |
260 // DefaultBrowserWorker, private: | 284 // DefaultBrowserWorker, private: |
261 | 285 |
262 ShellIntegration::DefaultWebClientState | 286 void ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { |
263 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { | 287 DefaultWebClientState state = ShellIntegration::GetDefaultBrowser(); |
264 return ShellIntegration::GetDefaultBrowser(); | 288 BrowserThread::PostTask( |
289 BrowserThread::UI, FROM_HERE, | |
290 base::Bind(&DefaultBrowserWorker::CompleteCheckIsDefault, this, state)); | |
265 } | 291 } |
266 | 292 |
267 bool ShellIntegration::DefaultBrowserWorker::SetAsDefault( | 293 void ShellIntegration::DefaultBrowserWorker::SetAsDefault( |
268 bool interactive_permitted) { | 294 bool interactive_permitted) { |
269 bool result = false; | 295 bool result = false; |
270 switch (ShellIntegration::CanSetAsDefaultBrowser()) { | 296 switch (ShellIntegration::CanSetAsDefaultBrowser()) { |
297 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: | |
298 NOTREACHED(); | |
299 break; | |
271 case ShellIntegration::SET_DEFAULT_UNATTENDED: | 300 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
272 result = ShellIntegration::SetAsDefaultBrowser(); | 301 result = ShellIntegration::SetAsDefaultBrowser(); |
273 break; | 302 break; |
274 case ShellIntegration::SET_DEFAULT_INTERACTIVE: | 303 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
275 if (interactive_permitted) | 304 if (interactive_permitted) |
276 result = ShellIntegration::SetAsDefaultBrowserInteractive(); | 305 result = ShellIntegration::SetAsDefaultBrowserInteractive(); |
277 break; | 306 break; |
278 default: | 307 case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS: |
279 NOTREACHED(); | 308 if (interactive_permitted) { |
Peter Kasting
2015/09/25 20:52:25
Nit: If you reverse this conditional, you can omit
Patrick Monette
2015/09/28 23:46:36
Done.
| |
309 // This function will cause CompleteSetAsDefault to be called | |
310 // asynchronously via a filter established in InitializeSetAsDefault(). | |
311 ShellIntegration::SetAsDefaultBrowserAsynchronous(); | |
312 return; | |
313 } | |
314 break; | |
280 } | 315 } |
316 BrowserThread::PostTask( | |
317 BrowserThread::UI, FROM_HERE, | |
318 base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this, result)); | |
319 } | |
281 | 320 |
282 return result; | 321 #if !defined(OS_WIN) |
283 } | 322 void ShellIntegration::DefaultBrowserWorker::InitializeSetAsDefault() {} |
323 | |
324 void ShellIntegration::DefaultBrowserWorker::FinalizeSetAsDefault( | |
325 bool succeeded) {} | |
326 #endif // !defined(OS_WIN) | |
284 | 327 |
285 /////////////////////////////////////////////////////////////////////////////// | 328 /////////////////////////////////////////////////////////////////////////////// |
286 // ShellIntegration::DefaultProtocolClientWorker | 329 // ShellIntegration::DefaultProtocolClientWorker |
287 // | 330 // |
288 | 331 |
289 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 332 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
290 DefaultWebClientObserver* observer, const std::string& protocol) | 333 DefaultWebClientObserver* observer, const std::string& protocol) |
291 : DefaultWebClientWorker(observer), | 334 : DefaultWebClientWorker(observer), |
292 protocol_(protocol) { | 335 protocol_(protocol) { |
293 } | 336 } |
294 | 337 |
295 /////////////////////////////////////////////////////////////////////////////// | 338 /////////////////////////////////////////////////////////////////////////////// |
296 // DefaultProtocolClientWorker, private: | 339 // DefaultProtocolClientWorker, private: |
297 | 340 |
298 ShellIntegration::DefaultWebClientState | 341 void ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { |
299 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { | 342 DefaultWebClientState state = |
300 return ShellIntegration::IsDefaultProtocolClient(protocol_); | 343 ShellIntegration::IsDefaultProtocolClient(protocol_); |
344 BrowserThread::PostTask( | |
345 BrowserThread::UI, FROM_HERE, | |
346 base::Bind(&DefaultProtocolClientWorker::CompleteCheckIsDefault, this, | |
347 state)); | |
301 } | 348 } |
302 | 349 |
303 bool ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( | 350 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( |
304 bool interactive_permitted) { | 351 bool interactive_permitted) { |
305 bool result = false; | 352 bool result = false; |
306 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { | 353 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { |
307 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: | 354 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: |
308 result = false; | 355 BrowserThread::PostTask( |
356 BrowserThread::UI, FROM_HERE, | |
357 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, | |
358 false)); | |
309 break; | 359 break; |
310 case ShellIntegration::SET_DEFAULT_UNATTENDED: | 360 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
311 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); | 361 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); |
362 BrowserThread::PostTask( | |
363 BrowserThread::UI, FROM_HERE, | |
364 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, | |
365 result)); | |
312 break; | 366 break; |
313 case ShellIntegration::SET_DEFAULT_INTERACTIVE: | 367 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
314 if (interactive_permitted) { | 368 if (interactive_permitted) { |
Peter Kasting
2015/09/25 20:52:26
Nit: If you reverse this conditional and return; i
Patrick Monette
2015/09/28 23:46:36
Done.
| |
315 result = ShellIntegration::SetAsDefaultProtocolClientInteractive( | 369 result = |
316 protocol_); | 370 ShellIntegration::SetAsDefaultProtocolClientInteractive(protocol_); |
371 BrowserThread::PostTask( | |
372 BrowserThread::UI, FROM_HERE, | |
373 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, | |
374 result)); | |
317 } | 375 } |
318 break; | 376 break; |
377 case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS: | |
378 NOTREACHED(); | |
379 break; | |
319 } | 380 } |
320 | |
321 return result; | |
322 } | 381 } |
OLD | NEW |