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 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 Loading... |
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 Loading... |
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); |
(...skipping 21 matching lines...) Expand all Loading... |
205 if (observer_ && observer_->IsOwnedByWorker()) { | 227 if (observer_ && observer_->IsOwnedByWorker()) { |
206 delete observer_; | 228 delete observer_; |
207 observer_ = NULL; | 229 observer_ = NULL; |
208 } | 230 } |
209 } | 231 } |
210 | 232 |
211 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault( | 233 void ShellIntegration::DefaultWebClientWorker::ExecuteSetAsDefault( |
212 bool interactive_permitted) { | 234 bool interactive_permitted) { |
213 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 235 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
214 | 236 |
215 bool result = SetAsDefault(interactive_permitted); | 237 // This will call CompleteSetAsDefault asynchronously. |
216 BrowserThread::PostTask( | 238 SetAsDefault(interactive_permitted); |
217 BrowserThread::UI, FROM_HERE, | |
218 base::Bind(&DefaultWebClientWorker::CompleteSetAsDefault, this, result)); | |
219 } | 239 } |
220 | 240 |
221 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( | 241 void ShellIntegration::DefaultWebClientWorker::CompleteSetAsDefault( |
222 bool succeeded) { | 242 bool succeeded) { |
223 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 243 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
224 // First tell the observer what the SetAsDefault call has returned. | 244 |
225 if (observer_) | 245 // Only notify observer is |UninitializeSetAsDefault| returns true. This is to |
226 observer_->OnSetAsDefaultConcluded(succeeded); | 246 // filter out multiple calls to |CompleteSetAsDefault| due to possible race |
227 // Set as default completed, check again to make sure it stuck... | 247 // conditions. |
228 StartCheckIsDefault(); | 248 if (UninitializeSetAsDefault(succeeded)) { |
| 249 // First tell the observer what the SetAsDefault call has returned. |
| 250 if (observer_) |
| 251 observer_->OnSetAsDefaultConcluded(succeeded); |
| 252 // Set as default completed, check again to make sure it stuck... |
| 253 StartCheckIsDefault(); |
| 254 } |
229 } | 255 } |
230 | 256 |
231 void ShellIntegration::DefaultWebClientWorker::UpdateUI( | 257 void ShellIntegration::DefaultWebClientWorker::UpdateUI( |
232 DefaultWebClientState state) { | 258 DefaultWebClientState state) { |
233 if (observer_) { | 259 if (observer_) { |
234 switch (state) { | 260 switch (state) { |
235 case NOT_DEFAULT: | 261 case NOT_DEFAULT: |
236 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); | 262 observer_->SetDefaultWebClientUIState(STATE_NOT_DEFAULT); |
237 break; | 263 break; |
238 case IS_DEFAULT: | 264 case IS_DEFAULT: |
(...skipping 18 matching lines...) Expand all Loading... |
257 } | 283 } |
258 | 284 |
259 /////////////////////////////////////////////////////////////////////////////// | 285 /////////////////////////////////////////////////////////////////////////////// |
260 // DefaultBrowserWorker, private: | 286 // DefaultBrowserWorker, private: |
261 | 287 |
262 ShellIntegration::DefaultWebClientState | 288 ShellIntegration::DefaultWebClientState |
263 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { | 289 ShellIntegration::DefaultBrowserWorker::CheckIsDefault() { |
264 return ShellIntegration::GetDefaultBrowser(); | 290 return ShellIntegration::GetDefaultBrowser(); |
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()) { |
271 case ShellIntegration::SET_DEFAULT_UNATTENDED: | 297 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
272 result = ShellIntegration::SetAsDefaultBrowser(); | 298 result = ShellIntegration::SetAsDefaultBrowser(); |
| 299 BrowserThread::PostTask( |
| 300 BrowserThread::UI, FROM_HERE, |
| 301 base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this, |
| 302 result)); |
273 break; | 303 break; |
274 case ShellIntegration::SET_DEFAULT_INTERACTIVE: | 304 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
| 305 if (interactive_permitted) { |
| 306 result = ShellIntegration::SetAsDefaultBrowserInteractive(); |
| 307 BrowserThread::PostTask( |
| 308 BrowserThread::UI, FROM_HERE, |
| 309 base::Bind(&DefaultBrowserWorker::CompleteSetAsDefault, this, |
| 310 result)); |
| 311 } |
| 312 break; |
| 313 case ShellIntegration::SET_DEFAULT_ASYNCHRONOUS: |
275 if (interactive_permitted) | 314 if (interactive_permitted) |
276 result = ShellIntegration::SetAsDefaultBrowserInteractive(); | 315 ShellIntegration::SetAsDefaultBrowserAsynchronous(); |
277 break; | 316 break; |
278 default: | 317 default: |
279 NOTREACHED(); | 318 NOTREACHED(); |
280 } | 319 } |
281 | |
282 return result; | |
283 } | 320 } |
284 | 321 |
285 /////////////////////////////////////////////////////////////////////////////// | 322 /////////////////////////////////////////////////////////////////////////////// |
286 // ShellIntegration::DefaultProtocolClientWorker | 323 // ShellIntegration::DefaultProtocolClientWorker |
287 // | 324 // |
288 | 325 |
289 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( | 326 ShellIntegration::DefaultProtocolClientWorker::DefaultProtocolClientWorker( |
290 DefaultWebClientObserver* observer, const std::string& protocol) | 327 DefaultWebClientObserver* observer, const std::string& protocol) |
291 : DefaultWebClientWorker(observer), | 328 : DefaultWebClientWorker(observer), |
292 protocol_(protocol) { | 329 protocol_(protocol) { |
293 } | 330 } |
294 | 331 |
295 /////////////////////////////////////////////////////////////////////////////// | 332 /////////////////////////////////////////////////////////////////////////////// |
296 // DefaultProtocolClientWorker, private: | 333 // DefaultProtocolClientWorker, private: |
297 | 334 |
298 ShellIntegration::DefaultWebClientState | 335 ShellIntegration::DefaultWebClientState |
299 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { | 336 ShellIntegration::DefaultProtocolClientWorker::CheckIsDefault() { |
300 return ShellIntegration::IsDefaultProtocolClient(protocol_); | 337 return ShellIntegration::IsDefaultProtocolClient(protocol_); |
301 } | 338 } |
302 | 339 |
303 bool ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( | 340 void ShellIntegration::DefaultProtocolClientWorker::SetAsDefault( |
304 bool interactive_permitted) { | 341 bool interactive_permitted) { |
305 bool result = false; | 342 bool result = false; |
306 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { | 343 switch (ShellIntegration::CanSetAsDefaultProtocolClient()) { |
307 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: | 344 case ShellIntegration::SET_DEFAULT_NOT_ALLOWED: |
308 result = false; | 345 BrowserThread::PostTask( |
| 346 BrowserThread::UI, FROM_HERE, |
| 347 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, |
| 348 false)); |
309 break; | 349 break; |
310 case ShellIntegration::SET_DEFAULT_UNATTENDED: | 350 case ShellIntegration::SET_DEFAULT_UNATTENDED: |
311 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); | 351 result = ShellIntegration::SetAsDefaultProtocolClient(protocol_); |
| 352 BrowserThread::PostTask( |
| 353 BrowserThread::UI, FROM_HERE, |
| 354 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, |
| 355 result)); |
312 break; | 356 break; |
313 case ShellIntegration::SET_DEFAULT_INTERACTIVE: | 357 case ShellIntegration::SET_DEFAULT_INTERACTIVE: |
314 if (interactive_permitted) { | 358 if (interactive_permitted) { |
315 result = ShellIntegration::SetAsDefaultProtocolClientInteractive( | 359 result = |
316 protocol_); | 360 ShellIntegration::SetAsDefaultProtocolClientInteractive(protocol_); |
| 361 BrowserThread::PostTask( |
| 362 BrowserThread::UI, FROM_HERE, |
| 363 base::Bind(&DefaultProtocolClientWorker::CompleteSetAsDefault, this, |
| 364 result)); |
317 } | 365 } |
318 break; | 366 break; |
319 } | 367 } |
320 | |
321 return result; | |
322 } | 368 } |
OLD | NEW |