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) | |
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(); |
50 | |
51 // Set as default asynchronous is not supported for all protocols. | |
grt (UTC plus 2)
2015/09/24 18:24:11
suggestion:
"not supported for all protocols" -> "
Patrick Monette
2015/09/25 20:06:24
Done.
| |
52 if (permission == SET_DEFAULT_ASYNCHRONOUS) | |
53 permission = SET_DEFAULT_INTERACTIVE; | |
grt (UTC plus 2)
2015/09/24 18:24:11
nit:
if (blah)
return SET_DEFAULT_INTERACTIV
Patrick Monette
2015/09/25 20:06:24
Done.
| |
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), set_as_default_completed_(true) {} |
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 set_as_default_completed_ = false; | |
grt (UTC plus 2)
2015/09/24 18:24:11
should this handle the case where a previous Start
Patrick Monette
2015/09/25 20:06:24
Calling FinalizeSetAsDefault is better imo because
| |
169 bool interactive_permitted = false; | 186 bool interactive_permitted = false; |
170 if (observer_) { | 187 if (observer_) { |
171 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); | 188 observer_->SetDefaultWebClientUIState(STATE_PROCESSING); |
172 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); | 189 interactive_permitted = observer_->IsInteractiveSetDefaultPermitted(); |
190 | |
191 InitializeSetAsDefault(); | |
173 } | 192 } |
174 BrowserThread::PostTask( | 193 |
175 BrowserThread::FILE, FROM_HERE, | 194 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
176 base::Bind(&DefaultWebClientWorker::ExecuteSetAsDefault, this, | 195 base::Bind(&DefaultWebClientWorker::SetAsDefault, |
177 interactive_permitted)); | 196 this, interactive_permitted)); |
178 } | 197 } |
179 | 198 |
180 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { | 199 void ShellIntegration::DefaultWebClientWorker::ObserverDestroyed() { |
181 // Our associated view has gone away, so we shouldn't call back to it if | 200 // 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. | 201 // our worker thread returns after the view is dead. |
183 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 202 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
184 observer_ = NULL; | 203 observer_ = NULL; |
204 // If set as default is currently running, CompleteSetAsDefault is invoked as | |
205 // the result will no longer be posted to any observers and we want to clear | |
206 // up ressources. | |
grt (UTC plus 2)
2015/09/24 18:24:11
nit: resources
Patrick Monette
2015/09/25 20:06:24
Done.
| |
207 if (!set_as_default_completed_) | |
208 CompleteSetAsDefault(false); | |
185 } | 209 } |
186 | 210 |
187 /////////////////////////////////////////////////////////////////////////////// | 211 /////////////////////////////////////////////////////////////////////////////// |
188 // DefaultWebClientWorker, private: | 212 // DefaultWebClientWorker, private: |
189 | 213 |
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( | 214 void ShellIntegration::DefaultWebClientWorker::CompleteCheckIsDefault( |
200 DefaultWebClientState state) { | 215 DefaultWebClientState state) { |
201 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
202 UpdateUI(state); | 217 UpdateUI(state); |
203 // The worker has finished everything it needs to do, so free the observer | 218 // The worker has finished everything it needs to do, so free the observer |
204 // if we own it. | 219 // if we own it. |
205 if (observer_ && observer_->IsOwnedByWorker()) { | 220 if (observer_ && observer_->IsOwnedByWorker()) { |
206 delete observer_; | 221 delete observer_; |
207 observer_ = NULL; | 222 observer_ = NULL; |
208 } | 223 } |
209 } | 224 } |
210 | 225 |
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( | 226 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( |
222 bool succeeded) { | 227 bool succeeded) { |
223 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 228 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
224 // First tell the observer what the SetAsDefault call has returned. | 229 if (!set_as_default_completed_) { |
grt (UTC plus 2)
2015/09/24 18:24:11
wdyt of set_as_default_in_progress_ instead of set
Patrick Monette
2015/09/25 20:06:24
Done.
| |
225 if (observer_) | 230 FinalizeSetAsDefault(succeeded); |
226 observer_->OnSetAsDefaultConcluded(succeeded); | 231 if (observer_) |
227 // Set as default completed, check again to make sure it stuck... | 232 observer_->OnSetAsDefaultConcluded(succeeded); |
228 StartCheckIsDefault(); | 233 // Set as default completed, check again to make sure it stuck... |
234 StartCheckIsDefault(); | |
235 } | |
236 set_as_default_completed_ = true; | |
grt (UTC plus 2)
2015/09/24 18:24:11
nit: move this up into the body of the if()
Patrick Monette
2015/09/25 20:06:24
Done.
| |
229 } | 237 } |
230 | 238 |
231 void ShellIntegration::DefaultWebClientWorker::UpdateUI( | 239 void ShellIntegration::DefaultWebClientWorker::UpdateUI( |
232 DefaultWebClientState state) { | 240 DefaultWebClientState state) { |
233 if (observer_) { | 241 if (observer_) { |
234 switch (state) { | 242 switch (state) { |
235 case NOT_DEFAULT: | 243 case NOT_DEFAULT: |
236 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); | 244 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); |
237 break; | 245 break; |
238 case IS_DEFAULT: | 246 case IS_DEFAULT: |
(...skipping 13 matching lines...) Expand all Loading... | |
252 // | 260 // |
253 | 261 |
254 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( | 262 ShellIntegration::DefaultBrowserWorker::DefaultBrowserWorker( |
255 DefaultWebClientObserver* observer) | 263 DefaultWebClientObserver* observer) |
256 : DefaultWebClientWorker(observer) { | 264 : DefaultWebClientWorker(observer) { |
257 } | 265 } |
258 | 266 |
259 /////////////////////////////////////////////////////////////////////////////// | 267 /////////////////////////////////////////////////////////////////////////////// |
260 // DefaultBrowserWorker, private: | 268 // DefaultBrowserWorker, private: |
261 | 269 |
262 ShellIntegration::DefaultWebClientState | 270 void ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { |
263 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { | 271 DefaultWebClientState state = ShellIntegration::GetDefaultBrowser(); |
264 return ShellIntegration::GetDefaultBrowser(); | 272 BrowserThread::PostTask( |
273 BrowserThread::UI, FROM_HERE, | |
274 base::Bind(&DefaultBrowserWorker::CompleteCheckIsDefault, this, state)); | |
265 } | 275 } |
266 | 276 |
267 bool ShellIntegration::DefaultBrowserWorker::SetAsDefault( | 277 void ShellIntegration::DefaultBrowserWorker::SetAsDefault( |
268 bool interactive_permitted) { | 278 bool interactive_permitted) { |
269 bool result = false; | 279 bool result = false; |
270 switch (ShellIntegration::CanSetAsDefaultBrowser()) { | 280 switch (ShellIntegration::CanSetAsDefaultBrowser()) { |
281 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: | |
282 NOTREACHED(); | |
283 break; | |
271 case ShellIntegration::SET_DEFAULT_UNATTENDED: | 284 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
272 result = ShellIntegration::SetAsDefaultBrowser(); | 285 result = ShellIntegration::SetAsDefaultBrowser(); |
273 break; | 286 break; |
274 case ShellIntegration::SET_DEFAULT_INTERACTIVE: | 287 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
275 if (interactive_permitted) | 288 if (interactive_permitted) { |
grt (UTC plus 2)
2015/09/24 18:24:11
nit: omit braces
Patrick Monette
2015/09/25 20:06:24
Done.
| |
276 result = ShellIntegration::SetAsDefaultBrowserInteractive(); | 289 result = ShellIntegration::SetAsDefaultBrowserInteractive(); |
290 } | |
277 break; | 291 break; |
278 default: | 292 case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS: |
279 NOTREACHED(); | 293 if (interactive_permitted) { |
294 // This function will cause CompleteSetAsDefault to be called | |
295 // asynchronously through a filter in startup_browser_creator.h. | |
grt (UTC plus 2)
2015/09/24 18:24:11
suggestion:
// asynchronously via a filter
Patrick Monette
2015/09/25 20:06:24
Done.
| |
296 ShellIntegration::SetAsDefaultBrowserAsynchronous(); | |
297 return; | |
298 } | |
299 break; | |
280 } | 300 } |
301 BrowserThread::PostTask( | |
302 BrowserThread::UI, FROM_HERE, | |
303 base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this, result)); | |
304 } | |
281 | 305 |
282 return result; | 306 #if !defined(OS_WIN) |
283 } | 307 void ShellIntegration::DefaultBrowserWorker::InitializeSetAsDefault() {} |
308 | |
309 void ShellIntegration::DefaultBrowserWorker::FinalizeSetAsDefault( | |
310 bool succeeded) {} | |
311 #endif // !defined(OS_WIN) | |
284 | 312 |
285 /////////////////////////////////////////////////////////////////////////////// | 313 /////////////////////////////////////////////////////////////////////////////// |
286 // ShellIntegration::DefaultProtocolClientWorker | 314 // ShellIntegration::DefaultProtocolClientWorker |
287 // | 315 // |
288 | 316 |
289 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 317 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
290 DefaultWebClientObserver* observer, const std::string& protocol) | 318 DefaultWebClientObserver* observer, const std::string& protocol) |
291 : DefaultWebClientWorker(observer), | 319 : DefaultWebClientWorker(observer), |
292 protocol_(protocol) { | 320 protocol_(protocol) { |
293 } | 321 } |
294 | 322 |
295 /////////////////////////////////////////////////////////////////////////////// | 323 /////////////////////////////////////////////////////////////////////////////// |
296 // DefaultProtocolClientWorker, private: | 324 // DefaultProtocolClientWorker, private: |
297 | 325 |
298 ShellIntegration::DefaultWebClientState | 326 void ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { |
299 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { | 327 DefaultWebClientState state = |
300 return ShellIntegration::IsDefaultProtocolClient(protocol_); | 328 ShellIntegration::IsDefaultProtocolClient(protocol_); |
329 BrowserThread::PostTask( | |
330 BrowserThread::UI, FROM_HERE, | |
331 base::Bind(&DefaultProtocolClientWorker::CompleteCheckIsDefault, this, | |
332 state)); | |
301 } | 333 } |
302 | 334 |
303 bool ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( | 335 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( |
304 bool interactive_permitted) { | 336 bool interactive_permitted) { |
305 bool result = false; | 337 bool result = false; |
306 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { | 338 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { |
307 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: | 339 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: |
308 result = false; | 340 BrowserThread::PostTask( |
341 BrowserThread::UI, FROM_HERE, | |
342 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, | |
343 false)); | |
309 break; | 344 break; |
310 case ShellIntegration::SET_DEFAULT_UNATTENDED: | 345 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
311 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); | 346 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); |
347 BrowserThread::PostTask( | |
348 BrowserThread::UI, FROM_HERE, | |
349 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, | |
350 result)); | |
312 break; | 351 break; |
313 case ShellIntegration::SET_DEFAULT_INTERACTIVE: | 352 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
314 if (interactive_permitted) { | 353 if (interactive_permitted) { |
315 result = ShellIntegration::SetAsDefaultProtocolClientInteractive( | 354 result = |
316 protocol_); | 355 ShellIntegration::SetAsDefaultProtocolClientInteractive(protocol_); |
356 BrowserThread::PostTask( | |
357 BrowserThread::UI, FROM_HERE, | |
358 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, | |
359 result)); | |
317 } | 360 } |
318 break; | 361 break; |
362 case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS: | |
363 NOTREACHED(); | |
364 break; | |
319 } | 365 } |
320 | |
321 return result; | |
322 } | 366 } |
OLD | NEW |