OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 7 #include <windows.h> |
8 #include <shobjidl.h> | 8 #include <shobjidl.h> |
9 #include <propkey.h> | 9 #include <propkey.h> |
10 #include <propvarutil.h> | 10 #include <propvarutil.h> |
(...skipping 13 matching lines...) Expand all Loading... | |
24 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_paths_internal.h" | 25 #include "chrome/common/chrome_paths_internal.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/installer/util/browser_distribution.h" | 27 #include "chrome/installer/util/browser_distribution.h" |
28 #include "chrome/installer/util/create_reg_key_work_item.h" | 28 #include "chrome/installer/util/create_reg_key_work_item.h" |
29 #include "chrome/installer/util/set_reg_value_work_item.h" | 29 #include "chrome/installer/util/set_reg_value_work_item.h" |
30 #include "chrome/installer/util/shell_util.h" | 30 #include "chrome/installer/util/shell_util.h" |
31 #include "chrome/installer/util/util_constants.h" | 31 #include "chrome/installer/util/util_constants.h" |
32 #include "chrome/installer/util/work_item.h" | 32 #include "chrome/installer/util/work_item.h" |
33 #include "chrome/installer/util/work_item_list.h" | 33 #include "chrome/installer/util/work_item_list.h" |
34 #include "chrome/installer/setup/setup_util.h" | |
grt (UTC plus 2)
2011/05/25 14:35:45
this goes above the installer/util includes
benwells
2011/05/26 00:23:04
Done.
| |
34 #include "content/browser/browser_thread.h" | 35 #include "content/browser/browser_thread.h" |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 // Helper function for ShellIntegration::GetAppId to generates profile id | 39 // Helper function for ShellIntegration::GetAppId to generates profile id |
39 // from profile path. "profile_id" is composed of sanitized basenames of | 40 // from profile path. "profile_id" is composed of sanitized basenames of |
40 // user data dir and profile dir joined by a ".". | 41 // user data dir and profile dir joined by a ".". |
41 std::wstring GetProfileIdFromPath(const FilePath& profile_path) { | 42 std::wstring GetProfileIdFromPath(const FilePath& profile_path) { |
42 // Return empty string if profile_path is empty | 43 // Return empty string if profile_path is empty |
43 if (profile_path.empty()) | 44 if (profile_path.empty()) |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 if (!ShellUtil::MakeChromeDefault(dist, ShellUtil::CURRENT_USER, | 281 if (!ShellUtil::MakeChromeDefault(dist, ShellUtil::CURRENT_USER, |
281 chrome_exe.value(), true)) { | 282 chrome_exe.value(), true)) { |
282 LOG(ERROR) << "Chrome could not be set as default browser."; | 283 LOG(ERROR) << "Chrome could not be set as default browser."; |
283 return false; | 284 return false; |
284 } | 285 } |
285 | 286 |
286 VLOG(1) << "Chrome registered as default browser."; | 287 VLOG(1) << "Chrome registered as default browser."; |
287 return true; | 288 return true; |
288 } | 289 } |
289 | 290 |
290 ShellIntegration::DefaultBrowserState ShellIntegration::IsDefaultBrowser() { | 291 bool ShellIntegration::SetAsDefaultProtocolClient(const std::string& protocol) { |
292 if (protocol.empty()) | |
293 return false; | |
294 | |
295 FilePath chrome_exe; | |
296 if (!PathService::Get(base::FILE_EXE, &chrome_exe)) { | |
297 LOG(ERROR) << "Error getting app exe path"; | |
298 return false; | |
299 } | |
300 | |
301 std::wstring wprotocol = UTF8ToWide(protocol); | |
302 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
303 if (!ShellUtil::MakeChromeDefaultProtocolClient(dist, chrome_exe.value(), | |
304 wprotocol)) { | |
305 LOG(ERROR) << "Chrome could not be set as default handler for " | |
306 << protocol << "."; | |
307 return false; | |
308 } | |
309 | |
310 VLOG(1) << "Chrome registered as default handler for " << protocol << "."; | |
311 return true; | |
312 } | |
313 | |
314 ShellIntegration::DefaultWebClientState ShellIntegration::IsDefaultBrowser() { | |
291 // First determine the app path. If we can't determine what that is, we have | 315 // First determine the app path. If we can't determine what that is, we have |
292 // bigger fish to fry... | 316 // bigger fish to fry... |
293 FilePath app_path; | 317 FilePath app_path; |
294 if (!PathService::Get(base::FILE_EXE, &app_path)) { | 318 if (!PathService::Get(base::FILE_EXE, &app_path)) { |
295 LOG(ERROR) << "Error getting app exe path"; | 319 LOG(ERROR) << "Error getting app exe path"; |
296 return UNKNOWN_DEFAULT_BROWSER; | 320 return UNKNOWN_DEFAULT_WEB_CLIENT; |
297 } | 321 } |
298 // When we check for default browser we don't necessarily want to count file | 322 // When we check for default browser we don't necessarily want to count file |
299 // type handlers and icons as having changed the default browser status, | 323 // type handlers and icons as having changed the default browser status, |
300 // since the user may have changed their shell settings to cause HTML files | 324 // since the user may have changed their shell settings to cause HTML files |
301 // to open with a text editor for example. We also don't want to aggressively | 325 // to open with a text editor for example. We also don't want to aggressively |
302 // claim FTP, since the user may have a separate FTP client. It is an open | 326 // claim FTP, since the user may have a separate FTP client. It is an open |
303 // question as to how to "heal" these settings. Perhaps the user should just | 327 // question as to how to "heal" these settings. Perhaps the user should just |
304 // re-run the installer or run with the --set-default-browser command line | 328 // re-run the installer or run with the --set-default-browser command line |
305 // flag. There is doubtless some other key we can hook into to cause "Repair" | 329 // flag. There is doubtless some other key we can hook into to cause "Repair" |
306 // to show up in Add/Remove programs for us. | 330 // to show up in Add/Remove programs for us. |
307 const std::wstring kChromeProtocols[] = {L"http", L"https"}; | 331 const std::wstring kChromeProtocols[] = {L"http", L"https"}; |
308 | 332 |
309 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 333 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
310 IApplicationAssociationRegistration* pAAR; | 334 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
311 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, | 335 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, |
grt (UTC plus 2)
2011/05/25 14:35:45
pAAR.CreateInstance(CLSID_ApplicationAssociationRe
benwells
2011/05/26 00:23:04
Done.
| |
312 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), | 336 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), |
313 (void**)&pAAR); | 337 (void**)&pAAR); |
314 if (!SUCCEEDED(hr)) | 338 if (!SUCCEEDED(hr)) |
315 return NOT_DEFAULT_BROWSER; | 339 return NOT_DEFAULT_WEB_CLIENT; |
316 | 340 |
317 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 341 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
318 std::wstring app_name = dist->GetApplicationName(); | 342 std::wstring app_name = dist->GetApplicationName(); |
319 // If a user specific default browser entry exists, we check for that | 343 // If a user specific default browser entry exists, we check for that |
320 // app name being default. If not, then default browser is just called | 344 // app name being default. If not, then default browser is just called |
321 // Google Chrome or Chromium so we do not append suffix to app name. | 345 // Google Chrome or Chromium so we do not append suffix to app name. |
322 std::wstring suffix; | 346 std::wstring suffix; |
323 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | 347 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) |
324 app_name += suffix; | 348 app_name += suffix; |
325 | 349 |
326 for (int i = 0; i < _countof(kChromeProtocols); i++) { | 350 for (int i = 0; i < _countof(kChromeProtocols); i++) { |
327 BOOL result = TRUE; | 351 BOOL result = TRUE; |
328 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, | 352 hr = pAAR->QueryAppIsDefault(kChromeProtocols[i].c_str(), AT_URLPROTOCOL, |
329 AL_EFFECTIVE, app_name.c_str(), &result); | 353 AL_EFFECTIVE, app_name.c_str(), &result); |
330 if (!SUCCEEDED(hr) || result == FALSE) { | 354 if (!SUCCEEDED(hr) || result == FALSE) { |
331 pAAR->Release(); | 355 return NOT_DEFAULT_WEB_CLIENT; |
332 return NOT_DEFAULT_BROWSER; | |
333 } | 356 } |
334 } | 357 } |
335 pAAR->Release(); | |
336 } else { | 358 } else { |
337 std::wstring short_app_path; | 359 std::wstring short_app_path; |
338 GetShortPathName(app_path.value().c_str(), | 360 GetShortPathName(app_path.value().c_str(), |
339 WriteInto(&short_app_path, MAX_PATH), | 361 WriteInto(&short_app_path, MAX_PATH), |
340 MAX_PATH); | 362 MAX_PATH); |
341 | 363 |
342 // open command for protocol associations | 364 // open command for protocol associations |
343 for (int i = 0; i < _countof(kChromeProtocols); i++) { | 365 for (int i = 0; i < _countof(kChromeProtocols); i++) { |
344 // Check in HKEY_CLASSES_ROOT that is the result of merge between | 366 // Check in HKEY_CLASSES_ROOT that is the result of merge between |
345 // HKLM and HKCU | 367 // HKLM and HKCU |
346 HKEY root_key = HKEY_CLASSES_ROOT; | 368 HKEY root_key = HKEY_CLASSES_ROOT; |
347 // Check <protocol>\shell\open\command | 369 // Check <protocol>\shell\open\command |
348 std::wstring key_path(kChromeProtocols[i] + ShellUtil::kRegShellOpen); | 370 std::wstring key_path(kChromeProtocols[i] + ShellUtil::kRegShellOpen); |
349 base::win::RegKey key(root_key, key_path.c_str(), KEY_READ); | 371 base::win::RegKey key(root_key, key_path.c_str(), KEY_READ); |
350 std::wstring value; | 372 std::wstring value; |
351 if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS)) | 373 if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS)) |
352 return NOT_DEFAULT_BROWSER; | 374 return NOT_DEFAULT_WEB_CLIENT; |
353 // Need to normalize path in case it's been munged. | 375 // Need to normalize path in case it's been munged. |
354 CommandLine command_line = CommandLine::FromString(value); | 376 CommandLine command_line = CommandLine::FromString(value); |
355 std::wstring short_path; | 377 std::wstring short_path; |
356 GetShortPathName(command_line.GetProgram().value().c_str(), | 378 GetShortPathName(command_line.GetProgram().value().c_str(), |
357 WriteInto(&short_path, MAX_PATH), MAX_PATH); | 379 WriteInto(&short_path, MAX_PATH), MAX_PATH); |
358 if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path)) | 380 if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path)) |
359 return NOT_DEFAULT_BROWSER; | 381 return NOT_DEFAULT_WEB_CLIENT; |
360 } | 382 } |
361 } | 383 } |
362 return IS_DEFAULT_BROWSER; | 384 return IS_DEFAULT_WEB_CLIENT; |
385 } | |
386 | |
387 ShellIntegration::DefaultWebClientState | |
388 ShellIntegration::IsDefaultProtocolClient(const std::string& protocol) { | |
389 if (protocol.empty()) | |
390 return UNKNOWN_DEFAULT_WEB_CLIENT; | |
391 | |
392 // Determine the app path. If we can't determine what that is, we have | |
393 // bigger fish to fry... | |
394 FilePath app_path; | |
395 if (!PathService::Get(base::FILE_EXE, &app_path)) { | |
396 LOG(ERROR) << "Error getting app exe path"; | |
397 return UNKNOWN_DEFAULT_WEB_CLIENT; | |
398 } | |
399 | |
400 std::wstring wprotocol = UTF8ToWide(protocol); | |
401 | |
402 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | |
403 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | |
404 HRESULT hr = CoCreateInstance(CLSID_ApplicationAssociationRegistration, | |
grt (UTC plus 2)
2011/05/25 14:35:45
pAAR.CreateInstance(CLSID_ApplicationAssociationRe
benwells
2011/05/26 00:23:04
Done.
| |
405 NULL, CLSCTX_INPROC, __uuidof(IApplicationAssociationRegistration), | |
406 (void**)&pAAR); | |
407 if (!SUCCEEDED(hr)) | |
408 return NOT_DEFAULT_WEB_CLIENT; | |
409 | |
410 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | |
411 std::wstring app_name = dist->GetApplicationName(); | |
412 // If a user specific default browser entry exists, we check for that | |
413 // app name being default. If not, then default browser is just called | |
414 // Google Chrome or Chromium so we do not append suffix to app name. | |
415 std::wstring suffix; | |
416 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | |
417 app_name += suffix; | |
418 | |
419 BOOL result = TRUE; | |
420 hr = pAAR->QueryAppIsDefault(wprotocol.c_str(), AT_URLPROTOCOL, | |
421 AL_EFFECTIVE, app_name.c_str(), &result); | |
422 if (!SUCCEEDED(hr) || result == FALSE) { | |
423 return NOT_DEFAULT_WEB_CLIENT; | |
424 } | |
425 } else { | |
426 std::wstring short_app_path; | |
427 GetShortPathName(app_path.value().c_str(), | |
428 WriteInto(&short_app_path, MAX_PATH), | |
429 MAX_PATH); | |
430 | |
431 // open command for protocol associations | |
432 // Check in HKEY_CLASSES_ROOT that is the result of merge between | |
433 // HKLM and HKCU | |
434 HKEY root_key = HKEY_CLASSES_ROOT; | |
435 // Check <protocol>\shell\open\command | |
436 std::wstring key_path(wprotocol + ShellUtil::kRegShellOpen); | |
437 base::win::RegKey key(root_key, key_path.c_str(), KEY_READ); | |
438 std::wstring value; | |
439 if (!key.Valid() || (key.ReadValue(L"", &value) != ERROR_SUCCESS)) | |
440 return NOT_DEFAULT_WEB_CLIENT; | |
441 // Need to normalize path in case it's been munged. | |
442 CommandLine command_line = CommandLine::FromString(value); | |
443 std::wstring short_path; | |
444 GetShortPathName(command_line.GetProgram().value().c_str(), | |
445 WriteInto(&short_path, MAX_PATH), MAX_PATH); | |
446 if (!FilePath::CompareEqualIgnoreCase(short_path, short_app_path)) | |
447 return NOT_DEFAULT_WEB_CLIENT; | |
448 } | |
449 return IS_DEFAULT_WEB_CLIENT; | |
363 } | 450 } |
364 | 451 |
365 // There is no reliable way to say which browser is default on a machine (each | 452 // There is no reliable way to say which browser is default on a machine (each |
366 // browser can have some of the protocols/shortcuts). So we look for only HTTP | 453 // browser can have some of the protocols/shortcuts). So we look for only HTTP |
367 // protocol handler. Even this handler is located at different places in | 454 // protocol handler. Even this handler is located at different places in |
368 // registry on XP and Vista: | 455 // registry on XP and Vista: |
369 // - HKCR\http\shell\open\command (XP) | 456 // - HKCR\http\shell\open\command (XP) |
370 // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ | 457 // - HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\ |
371 // http\UserChoice (Vista) | 458 // http\UserChoice (Vista) |
372 // This method checks if Firefox is defualt browser by checking these | 459 // This method checks if Firefox is defualt browser by checking these |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 profile_path); | 501 profile_path); |
415 } | 502 } |
416 | 503 |
417 void ShellIntegration::MigrateChromiumShortcuts() { | 504 void ShellIntegration::MigrateChromiumShortcuts() { |
418 if (base::win::GetVersion() < base::win::VERSION_WIN7) | 505 if (base::win::GetVersion() < base::win::VERSION_WIN7) |
419 return; | 506 return; |
420 | 507 |
421 BrowserThread::PostTask( | 508 BrowserThread::PostTask( |
422 BrowserThread::FILE, FROM_HERE, new MigrateChromiumShortcutsTask()); | 509 BrowserThread::FILE, FROM_HERE, new MigrateChromiumShortcutsTask()); |
423 } | 510 } |
OLD | NEW |