| 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 // This file defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
| 6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
| 7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
| 8 // this class. | 8 // this class. |
| 9 | 9 |
| 10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/installer/util/browser_distribution.h" | 34 #include "chrome/installer/util/browser_distribution.h" |
| 35 #include "chrome/installer/util/install_util.h" | 35 #include "chrome/installer/util/install_util.h" |
| 36 #include "chrome/installer/util/master_preferences.h" | 36 #include "chrome/installer/util/master_preferences.h" |
| 37 #include "chrome/installer/util/master_preferences_constants.h" | 37 #include "chrome/installer/util/master_preferences_constants.h" |
| 38 | 38 |
| 39 using base::win::RegKey; | 39 using base::win::RegKey; |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // An enum used to tell QuickIsChromeRegistered() which level of registration |
| 44 // the caller wants to confirm. |
| 45 enum RegistrationConfirmationLevel { |
| 46 // Only look for Chrome's ProgIds. |
| 47 // This is sufficient when we are trying to determine the suffix of the |
| 48 // currently running Chrome as system registrations might not be present. |
| 49 CONFIRM_PROGID_REGISTRATION = 0, |
| 50 // Confirm that Chrome is registered on the system (i.e. registered with |
| 51 // Defaut Programs). These registrations can be in HKCU as of Windows 8. |
| 52 CONFIRM_SYSTEM_REGISTRATION, |
| 53 // Same as CONFIRM_SYSTEM_REGISTRATION, but only look in HKLM (used when |
| 54 // uninstalling to know whether elevation is required to clean up the |
| 55 // registry). |
| 56 CONFIRM_SYSTEM_REGISTRATION_IN_HKLM, |
| 57 }; |
| 58 |
| 43 const wchar_t kReinstallCommand[] = L"ReinstallCommand"; | 59 const wchar_t kReinstallCommand[] = L"ReinstallCommand"; |
| 44 | 60 |
| 45 // Returns true if Chrome Metro is supported on this OS (Win 8 8370 or greater). | 61 // Returns true if Chrome Metro is supported on this OS (Win 8 8370 or greater). |
| 46 // TODO(gab): Change this to a simple check for Win 8 once old Win8 builds | 62 // TODO(gab): Change this to a simple check for Win 8 once old Win8 builds |
| 47 // become irrelevant. | 63 // become irrelevant. |
| 48 bool IsChromeMetroSupported() { | 64 bool IsChromeMetroSupported() { |
| 49 OSVERSIONINFOEX min_version_info = {}; | 65 OSVERSIONINFOEX min_version_info = {}; |
| 50 min_version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); | 66 min_version_info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
| 51 min_version_info.dwMajorVersion = 6; | 67 min_version_info.dwMajorVersion = 6; |
| 52 min_version_info.dwMinorVersion = 2; | 68 min_version_info.dwMinorVersion = 2; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 67 return VerifyVersionInfo(&min_version_info, type_mask, condition_mask) != 0; | 83 return VerifyVersionInfo(&min_version_info, type_mask, condition_mask) != 0; |
| 68 } | 84 } |
| 69 | 85 |
| 70 // This class represents a single registry entry. The objective is to | 86 // This class represents a single registry entry. The objective is to |
| 71 // encapsulate all the registry entries required for registering Chrome at one | 87 // encapsulate all the registry entries required for registering Chrome at one |
| 72 // place. This class can not be instantiated outside the class and the objects | 88 // place. This class can not be instantiated outside the class and the objects |
| 73 // of this class type can be obtained only by calling a static method of this | 89 // of this class type can be obtained only by calling a static method of this |
| 74 // class. | 90 // class. |
| 75 class RegistryEntry { | 91 class RegistryEntry { |
| 76 public: | 92 public: |
| 93 // A bit-field enum of places to look for this key in the Windows registry. |
| 94 enum LookForIn { |
| 95 LOOK_IN_HKCU = 1 << 0, |
| 96 LOOK_IN_HKLM = 1 << 1, |
| 97 LOOK_IN_HKCU_THEN_HKLM = LOOK_IN_HKCU | LOOK_IN_HKLM, |
| 98 }; |
| 99 |
| 77 // Returns the Windows browser client registration key for Chrome. For | 100 // Returns the Windows browser client registration key for Chrome. For |
| 78 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly | 101 // example: "Software\Clients\StartMenuInternet\Chromium[.user]". Strictly |
| 79 // speaking, we should use the name of the executable (e.g., "chrome.exe"), | 102 // speaking, we should use the name of the executable (e.g., "chrome.exe"), |
| 80 // but that ship has sailed. The cost of switching now is re-prompting users | 103 // but that ship has sailed. The cost of switching now is re-prompting users |
| 81 // to make Chrome their default browser, which isn't polite. |suffix| is the | 104 // to make Chrome their default browser, which isn't polite. |suffix| is the |
| 82 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix | 105 // user-specific registration suffix; see GetUserSpecificDefaultBrowserSuffix |
| 83 // in shell_util.h for details. | 106 // in shell_util.h for details. |
| 84 static string16 GetBrowserClientKey(BrowserDistribution* dist, | 107 static string16 GetBrowserClientKey(BrowserDistribution* dist, |
| 85 const string16& suffix) { | 108 const string16& suffix) { |
| 86 DCHECK(suffix.empty() || suffix[0] == L'.'); | 109 DCHECK(suffix.empty() || suffix[0] == L'.'); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // strings. | 266 // strings. |
| 244 entries->push_front(new RegistryEntry(install_info, kReinstallCommand, | 267 entries->push_front(new RegistryEntry(install_info, kReinstallCommand, |
| 245 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); | 268 quoted_exe_path + L" --" + ASCIIToWide(switches::kMakeDefaultBrowser))); |
| 246 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand", | 269 entries->push_front(new RegistryEntry(install_info, L"HideIconsCommand", |
| 247 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); | 270 quoted_exe_path + L" --" + ASCIIToWide(switches::kHideIcons))); |
| 248 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand", | 271 entries->push_front(new RegistryEntry(install_info, L"ShowIconsCommand", |
| 249 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); | 272 quoted_exe_path + L" --" + ASCIIToWide(switches::kShowIcons))); |
| 250 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1)); | 273 entries->push_front(new RegistryEntry(install_info, L"IconsVisible", 1)); |
| 251 | 274 |
| 252 // Register with Default Programs. | 275 // Register with Default Programs. |
| 253 string16 app_name(dist->GetApplicationName().append(suffix)); | 276 string16 reg_app_name(dist->GetApplicationName().append(suffix)); |
| 254 // Tell Windows where to find Chrome's Default Programs info. | 277 // Tell Windows where to find Chrome's Default Programs info. |
| 255 string16 capabilities(GetCapabilitiesKey(dist, suffix)); | 278 string16 capabilities(GetCapabilitiesKey(dist, suffix)); |
| 256 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications, | 279 entries->push_front(new RegistryEntry(ShellUtil::kRegRegisteredApplications, |
| 257 app_name, capabilities)); | 280 reg_app_name, capabilities)); |
| 258 // Write out Chrome's Default Programs info. | 281 // Write out Chrome's Default Programs info. |
| 259 // TODO(grt): http://crbug.com/75152 Write a reference to a localized | 282 // TODO(grt): http://crbug.com/75152 Write a reference to a localized |
| 260 // resource rather than this. | 283 // resource rather than this. |
| 261 entries->push_front(new RegistryEntry( | 284 entries->push_front(new RegistryEntry( |
| 262 capabilities, ShellUtil::kRegApplicationDescription, | 285 capabilities, ShellUtil::kRegApplicationDescription, |
| 263 dist->GetLongAppDescription())); | 286 dist->GetLongAppDescription())); |
| 264 entries->push_front(new RegistryEntry( | 287 entries->push_front(new RegistryEntry( |
| 265 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); | 288 capabilities, ShellUtil::kRegApplicationIcon, icon_path)); |
| 266 entries->push_front(new RegistryEntry( | 289 entries->push_front(new RegistryEntry( |
| 267 capabilities, ShellUtil::kRegApplicationName, app_name)); | 290 capabilities, ShellUtil::kRegApplicationName, |
| 291 dist->GetAppShortCutName())); |
| 268 | 292 |
| 269 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", | 293 entries->push_front(new RegistryEntry(capabilities + L"\\Startmenu", |
| 270 L"StartMenuInternet", app_name)); | 294 L"StartMenuInternet", reg_app_name)); |
| 271 | 295 |
| 272 string16 html_prog_id(ShellUtil::kChromeHTMLProgId); | 296 string16 html_prog_id(ShellUtil::kChromeHTMLProgId); |
| 273 html_prog_id.append(suffix); | 297 html_prog_id.append(suffix); |
| 274 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { | 298 for (int i = 0; ShellUtil::kFileAssociations[i] != NULL; i++) { |
| 275 entries->push_front(new RegistryEntry( | 299 entries->push_front(new RegistryEntry( |
| 276 capabilities + L"\\FileAssociations", | 300 capabilities + L"\\FileAssociations", |
| 277 ShellUtil::kFileAssociations[i], html_prog_id)); | 301 ShellUtil::kFileAssociations[i], html_prog_id)); |
| 278 } | 302 } |
| 279 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; | 303 for (int i = 0; ShellUtil::kPotentialProtocolAssociations[i] != NULL; |
| 280 i++) { | 304 i++) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 if (_is_string) { | 394 if (_is_string) { |
| 371 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); | 395 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); |
| 372 } else { | 396 } else { |
| 373 items->AddSetRegValueWorkItem(root, _key_path, _name, _int_value, true); | 397 items->AddSetRegValueWorkItem(root, _key_path, _name, _int_value, true); |
| 374 } | 398 } |
| 375 } | 399 } |
| 376 | 400 |
| 377 // Checks if the current registry entry exists in HKCU\|_key_path|\|_name| | 401 // Checks if the current registry entry exists in HKCU\|_key_path|\|_name| |
| 378 // and value is |_value|. If the key does NOT exist in HKCU, checks for | 402 // and value is |_value|. If the key does NOT exist in HKCU, checks for |
| 379 // the correct name and value in HKLM. | 403 // the correct name and value in HKLM. |
| 380 // This mimics Windows' behavior when searching in HKCR (HKCU takes precedence | 404 // |look_for_in| specifies roots (HKCU and/or HKLM) in which to look for the |
| 381 // over HKLM). For registrations outside of HKCR on versions of Windows up | 405 // key, unspecified roots are not looked into (i.e. the the key is assumed not |
| 382 // to Win7, Chrome's values go in HKLM. This function will make unnecessary | 406 // to exist in them). |
| 383 // (but harmless) queries into HKCU in that case. Starting with Windows 8, | 407 // |look_for_in| must at least specify one root to look into. |
| 384 // Chrome's values go in HKCU for user-level installs, which takes precedence | 408 // If |look_for_in| is LOOK_IN_HKCU_THEN_HKLM, this method mimics Windows' |
| 385 // over HKLM. | 409 // behavior when searching in HKCR (HKCU takes precedence over HKLM). For |
| 386 bool ExistsInRegistry() { | 410 // registrations outside of HKCR on versions of Windows prior to Win8, |
| 387 RegistryStatus hkcu_status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); | 411 // Chrome's values go in HKLM. This function will make unnecessary (but |
| 388 return (hkcu_status == SAME_VALUE || | 412 // harmless) queries into HKCU in that case. |
| 389 (hkcu_status == DOES_NOT_EXIST && | 413 bool ExistsInRegistry(uint32 look_for_in) const { |
| 390 StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE) == SAME_VALUE)); | 414 DCHECK(look_for_in); |
| 415 |
| 416 RegistryStatus status = DOES_NOT_EXIST; |
| 417 if (look_for_in & LOOK_IN_HKCU) |
| 418 status = StatusInRegistryUnderRoot(HKEY_CURRENT_USER); |
| 419 if (status == DOES_NOT_EXIST && (look_for_in & LOOK_IN_HKLM)) |
| 420 status = StatusInRegistryUnderRoot(HKEY_LOCAL_MACHINE); |
| 421 return status == SAME_VALUE; |
| 391 } | 422 } |
| 392 | 423 |
| 393 private: | 424 private: |
| 394 // States this RegistryKey can be in compared to the registry. | 425 // States this RegistryKey can be in compared to the registry. |
| 395 enum RegistryStatus { | 426 enum RegistryStatus { |
| 396 // |_name| does not exist in the registry | 427 // |_name| does not exist in the registry |
| 397 DOES_NOT_EXIST, | 428 DOES_NOT_EXIST, |
| 398 // |_name| exists, but its value != |_value| | 429 // |_name| exists, but its value != |_value| |
| 399 DIFFERENT_VALUE, | 430 DIFFERENT_VALUE, |
| 400 // |_name| exists and its value is |_value| | 431 // |_name| exists and its value is |_value| |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 | 495 |
| 465 // Apply all the registry changes and if there is a problem, rollback | 496 // Apply all the registry changes and if there is a problem, rollback |
| 466 if (!items->Do()) { | 497 if (!items->Do()) { |
| 467 items->Rollback(); | 498 items->Rollback(); |
| 468 return false; | 499 return false; |
| 469 } | 500 } |
| 470 return true; | 501 return true; |
| 471 } | 502 } |
| 472 | 503 |
| 473 // Checks that all |entries| are present on this computer. | 504 // Checks that all |entries| are present on this computer. |
| 474 bool AreEntriesRegistered(const std::list<RegistryEntry*>& entries) { | 505 // |look_for_in| is passed to RegistryEntry::ExistsInRegistry(). Documentation |
| 506 // for it can be found there. |
| 507 bool AreEntriesRegistered(const std::list<RegistryEntry*>& entries, |
| 508 uint32 look_for_in) { |
| 475 bool registered = true; | 509 bool registered = true; |
| 476 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); | 510 for (std::list<RegistryEntry*>::const_iterator itr = entries.begin(); |
| 477 registered && itr != entries.end(); ++itr) { | 511 registered && itr != entries.end(); ++itr) { |
| 478 // We do not need registered = registered && ... since the loop condition | 512 // We do not need registered = registered && ... since the loop condition |
| 479 // is set to exit early. | 513 // is set to exit early. |
| 480 registered = (*itr)->ExistsInRegistry(); | 514 registered = (*itr)->ExistsInRegistry(look_for_in); |
| 481 } | 515 } |
| 482 return registered; | 516 return registered; |
| 483 } | 517 } |
| 484 | 518 |
| 485 // Checks that all required registry entries for Chrome are already present | 519 // Checks that all required registry entries for Chrome are already present |
| 486 // on this computer. | 520 // on this computer. |
| 487 bool IsChromeRegistered(BrowserDistribution* dist, | 521 bool IsChromeRegistered(BrowserDistribution* dist, |
| 488 const string16& chrome_exe, | 522 const string16& chrome_exe, |
| 489 const string16& suffix) { | 523 const string16& suffix) { |
| 490 std::list<RegistryEntry*> entries; | 524 std::list<RegistryEntry*> entries; |
| 491 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 525 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 492 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); | 526 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
| 493 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &entries); | 527 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &entries); |
| 494 return AreEntriesRegistered(entries); | 528 return AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU_THEN_HKLM); |
| 495 } | 529 } |
| 496 | 530 |
| 497 // This method checks if Chrome is already registered on the local machine | 531 // This method checks if Chrome is already registered on the local machine |
| 498 // for the requested protocol. It just checks the one value required for this. | 532 // for the requested protocol. It just checks the one value required for this. |
| 499 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, | 533 bool IsChromeRegisteredForProtocol(BrowserDistribution* dist, |
| 500 const string16& suffix, | 534 const string16& suffix, |
| 501 const string16& protocol) { | 535 const string16& protocol) { |
| 502 std::list<RegistryEntry*> entries; | 536 std::list<RegistryEntry*> entries; |
| 503 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 537 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 504 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, &entries); | 538 RegistryEntry::GetProtocolCapabilityEntries(dist, suffix, protocol, &entries); |
| 505 return AreEntriesRegistered(entries); | 539 return AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU_THEN_HKLM); |
| 506 } | 540 } |
| 507 | 541 |
| 508 // This method registers Chrome on Vista by launching an elevated setup.exe. | 542 // This method registers Chrome on Vista by launching an elevated setup.exe. |
| 509 // That will show the user the standard Vista elevation prompt. If the user | 543 // That will show the user the standard Vista elevation prompt. If the user |
| 510 // accepts it the new process will make the necessary changes and return SUCCESS | 544 // accepts it the new process will make the necessary changes and return SUCCESS |
| 511 // that we capture and return. | 545 // that we capture and return. |
| 512 // If protocol is non-empty we will also register Chrome as being capable of | 546 // If protocol is non-empty we will also register Chrome as being capable of |
| 513 // handling the protocol. | 547 // handling the protocol. |
| 514 bool ElevateAndRegisterChrome(BrowserDistribution* dist, | 548 bool ElevateAndRegisterChrome(BrowserDistribution* dist, |
| 515 const string16& chrome_exe, | 549 const string16& chrome_exe, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 582 } |
| 549 | 583 |
| 550 DWORD ret_val = 0; | 584 DWORD ret_val = 0; |
| 551 InstallUtil::ExecuteExeAsAdmin(cmd, &ret_val); | 585 InstallUtil::ExecuteExeAsAdmin(cmd, &ret_val); |
| 552 if (ret_val == 0) | 586 if (ret_val == 0) |
| 553 return true; | 587 return true; |
| 554 } | 588 } |
| 555 return false; | 589 return false; |
| 556 } | 590 } |
| 557 | 591 |
| 558 // This method tries to figure out if another user has already registered her | |
| 559 // own copy of Chrome so that we can avoid overwriting it and append current | |
| 560 // user's login name to default browser registry entries. This function is | |
| 561 // not meant to detect all cases. It just tries to handle the most common case. | |
| 562 // All the conditions below have to be true for it to return true: | |
| 563 // - Software\Clients\StartMenuInternet\Chromium\"" key should have a valid | |
| 564 // value. | |
| 565 // - The value should not be same as given value in |chrome_exe| | |
| 566 // - Finally to handle the default install path (C:\Document and Settings\ | |
| 567 // <user>\Local Settings\Application Data\Chromium\Application) the value | |
| 568 // of the above key should differ from |chrome_exe| only in user name. | |
| 569 bool AnotherUserHasDefaultBrowser(BrowserDistribution* dist, | |
| 570 const string16& chrome_exe) { | |
| 571 const string16 reg_key( | |
| 572 RegistryEntry::GetBrowserClientKey(dist, string16()) | |
| 573 .append(ShellUtil::kRegShellOpen)); | |
| 574 RegKey key(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_READ); | |
| 575 string16 registry_chrome_exe; | |
| 576 if ((key.ReadValue(L"", ®istry_chrome_exe) != ERROR_SUCCESS) || | |
| 577 registry_chrome_exe.length() < 2) | |
| 578 return false; | |
| 579 | |
| 580 registry_chrome_exe = registry_chrome_exe.substr(1, | |
| 581 registry_chrome_exe.length() - 2); | |
| 582 if ((registry_chrome_exe.size() == chrome_exe.size()) && | |
| 583 (std::equal(chrome_exe.begin(), chrome_exe.end(), | |
| 584 registry_chrome_exe.begin(), | |
| 585 base::CaseInsensitiveCompare<wchar_t>()))) { | |
| 586 return false; | |
| 587 } | |
| 588 | |
| 589 std::vector<string16> v1, v2; | |
| 590 base::SplitString(registry_chrome_exe, L'\\', &v1); | |
| 591 base::SplitString(chrome_exe, L'\\', &v2); | |
| 592 if (v1.empty() || v2.empty() || v1.size() != v2.size()) | |
| 593 return false; | |
| 594 | |
| 595 // Now check that only one of the values within two '\' chars differ. | |
| 596 std::vector<string16>::iterator itr1 = v1.begin(); | |
| 597 std::vector<string16>::iterator itr2 = v2.begin(); | |
| 598 bool one_mismatch = false; | |
| 599 for ( ; itr1 < v1.end() && itr2 < v2.end(); ++itr1, ++itr2) { | |
| 600 string16 s1 = *itr1; | |
| 601 string16 s2 = *itr2; | |
| 602 if ((s1.size() != s2.size()) || | |
| 603 (!std::equal(s1.begin(), s1.end(), | |
| 604 s2.begin(), base::CaseInsensitiveCompare<wchar_t>()))) { | |
| 605 if (one_mismatch) | |
| 606 return false; | |
| 607 else | |
| 608 one_mismatch = true; | |
| 609 } | |
| 610 } | |
| 611 return true; | |
| 612 } | |
| 613 | |
| 614 // Launches the Windows 7 and Windows 8 application association dialog, which | 592 // Launches the Windows 7 and Windows 8 application association dialog, which |
| 615 // is the only documented way to make a browser the default browser on | 593 // is the only documented way to make a browser the default browser on |
| 616 // Windows 8. | 594 // Windows 8. |
| 617 bool LaunchApplicationAssociationDialog(const string16& app_id) { | 595 bool LaunchApplicationAssociationDialog(const string16& app_id) { |
| 618 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; | 596 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; |
| 619 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); | 597 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); |
| 620 if (FAILED(hr)) | 598 if (FAILED(hr)) |
| 621 return false; | 599 return false; |
| 622 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); | 600 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); |
| 623 return SUCCEEDED(hr); | 601 return SUCCEEDED(hr); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 640 // should be removed after a reasonable time, say 2012-08-01. Anyone on Win8 | 618 // should be removed after a reasonable time, say 2012-08-01. Anyone on Win8 |
| 641 // dev channel who hasn't been autoupdated or manually updated by then will have | 619 // dev channel who hasn't been autoupdated or manually updated by then will have |
| 642 // to uninstall and reinstall Chrome to repair. See http://crbug.com/124666 and | 620 // to uninstall and reinstall Chrome to repair. See http://crbug.com/124666 and |
| 643 // http://crbug.com/123994 for gory details. | 621 // http://crbug.com/123994 for gory details. |
| 644 // This function is also used to remove DelegateExecute verb handler | 622 // This function is also used to remove DelegateExecute verb handler |
| 645 // registrations on builds for which Metro is no longer supported. This will | 623 // registrations on builds for which Metro is no longer supported. This will |
| 646 // also become irrelevant sometime after Windows 8 RC (thus the aforementioned | 624 // also become irrelevant sometime after Windows 8 RC (thus the aforementioned |
| 647 // removal date remains correct). | 625 // removal date remains correct). |
| 648 void RemoveBadWindows8RegistrationIfNeeded( | 626 void RemoveBadWindows8RegistrationIfNeeded( |
| 649 BrowserDistribution* dist, | 627 BrowserDistribution* dist, |
| 650 const string16& chrome_exe, | 628 const string16& chrome_exe) { |
| 651 const string16& suffix) { | |
| 652 string16 handler_guid; | 629 string16 handler_guid; |
| 653 | 630 |
| 654 if (dist->GetDelegateExecuteHandlerData(&handler_guid, NULL, NULL, NULL) && | 631 if (dist->GetDelegateExecuteHandlerData(&handler_guid, NULL, NULL, NULL) && |
| 655 (!InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe) || | 632 (!InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe) || |
| 656 !IsChromeMetroSupported())) { | 633 !IsChromeMetroSupported())) { |
| 657 // There's no need to rollback, so forgo the usual work item lists and just | 634 // There's no need to rollback, so forgo the usual work item lists and just |
| 658 // remove the values from the registry. | 635 // remove the values from the registry. |
| 659 const HKEY root_key = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 636 const HKEY root_key = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? |
| 660 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 637 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 638 // Use the current installation's suffix, not the about-to-be-installed |
| 639 // suffix. |
| 640 const string16 installation_suffix( |
| 641 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe)); |
| 661 const string16 app_id(dist->GetBrowserAppId()); | 642 const string16 app_id(dist->GetBrowserAppId()); |
| 662 | 643 |
| 663 // <root hkey>\Software\Classes\<app_id> | 644 // <root hkey>\Software\Classes\<app_id> |
| 664 string16 key(ShellUtil::kRegClasses); | 645 string16 key(ShellUtil::kRegClasses); |
| 665 key.push_back(FilePath::kSeparators[0]); | 646 key.push_back(FilePath::kSeparators[0]); |
| 666 key.append(app_id); | 647 key.append(app_id); |
| 667 InstallUtil::DeleteRegistryKey(root_key, key); | 648 InstallUtil::DeleteRegistryKey(root_key, key); |
| 668 | 649 |
| 669 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command | 650 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command |
| 670 key = ShellUtil::kRegClasses; | 651 key = ShellUtil::kRegClasses; |
| 671 key.push_back(FilePath::kSeparators[0]); | 652 key.push_back(FilePath::kSeparators[0]); |
| 672 key.append(ShellUtil::kChromeHTMLProgId); | 653 key.append(ShellUtil::kChromeHTMLProgId); |
| 673 key.append(suffix); | 654 key.append(installation_suffix); |
| 674 key.append(ShellUtil::kRegShellOpen); | 655 key.append(ShellUtil::kRegShellOpen); |
| 675 InstallUtil::DeleteRegistryValue(root_key, key, | 656 InstallUtil::DeleteRegistryValue(root_key, key, |
| 676 ShellUtil::kRegDelegateExecute); | 657 ShellUtil::kRegDelegateExecute); |
| 677 } | 658 } |
| 678 } | 659 } |
| 679 | 660 |
| 661 // Returns true if the current install's |chrome_exe| has been registered with |
| 662 // |suffix|. |
| 663 // |confirmation_level| is the level of verification desired as described in |
| 664 // the RegistrationConfirmationLevel enum above. |
| 665 // |suffix| can be the empty string (this is used to support old installs |
| 666 // where we used to not suffix user-level installs if they were the first to |
| 667 // request the non-suffixed registry entries on the machine). |
| 668 // NOTE: This a quick check that only validates that a single registry entry |
| 669 // points to |chrome_exe|. This should only be used at run-time to determine |
| 670 // how Chrome is registered, not to know whether the registration is complete |
| 671 // at install-time (IsChromeRegistered() can be used for that). |
| 672 bool QuickIsChromeRegistered(BrowserDistribution* dist, |
| 673 const string16& chrome_exe, |
| 674 const string16& suffix, |
| 675 RegistrationConfirmationLevel confirmation_level) { |
| 676 // Get the appropriate key to look for based on the level desired. |
| 677 string16 reg_key; |
| 678 switch (confirmation_level) { |
| 679 case CONFIRM_PROGID_REGISTRATION: |
| 680 // Software\Classes\ChromeHTML|suffix| |
| 681 reg_key = ShellUtil::kRegClasses; |
| 682 reg_key.push_back(FilePath::kSeparators[0]); |
| 683 reg_key.append(ShellUtil::kChromeHTMLProgId); |
| 684 reg_key.append(suffix); |
| 685 break; |
| 686 case CONFIRM_SYSTEM_REGISTRATION: |
| 687 case CONFIRM_SYSTEM_REGISTRATION_IN_HKLM: |
| 688 // Software\Clients\StartMenuInternet\Google Chrome|suffix| |
| 689 reg_key = RegistryEntry::GetBrowserClientKey(dist, suffix); |
| 690 break; |
| 691 default: |
| 692 NOTREACHED(); |
| 693 break; |
| 694 } |
| 695 reg_key.append(ShellUtil::kRegShellOpen); |
| 696 |
| 697 // User-level installs ProgId registrations can be found in HKCU (and values |
| 698 // there have priority over HKLM). The same is true for system entries as |
| 699 // of Windows 8. |
| 700 if (confirmation_level == CONFIRM_PROGID_REGISTRATION || |
| 701 (confirmation_level == CONFIRM_SYSTEM_REGISTRATION && |
| 702 base::win::GetVersion() >= base::win::VERSION_WIN8)) { |
| 703 const RegKey key_hkcu(HKEY_CURRENT_USER, reg_key.c_str(), KEY_QUERY_VALUE); |
| 704 string16 hkcu_value; |
| 705 // If |reg_key| is present in HKCU, assert that it points to |chrome_exe|. |
| 706 // Otherwise, fall back on an HKLM lookup below. |
| 707 if (key_hkcu.ReadValue(L"", &hkcu_value) == ERROR_SUCCESS) { |
| 708 return InstallUtil::ProgramCompare( |
| 709 FilePath(chrome_exe)).Evaluate(hkcu_value); |
| 710 } |
| 711 } |
| 712 |
| 713 // Assert that |reg_key| points to |chrome_exe| in HKLM. |
| 714 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); |
| 715 string16 hklm_value; |
| 716 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) { |
| 717 return InstallUtil::ProgramCompare( |
| 718 FilePath(chrome_exe)).Evaluate(hklm_value); |
| 719 } |
| 720 return false; |
| 721 } |
| 722 |
| 723 // Sets |suffix| to this user's username preceded by a dot. This suffix is then |
| 724 // meant to be added to all registration that may conflict with another |
| 725 // user-level Chrome install. |
| 726 // Returns true unless the OS call to retrieve the username fails. |
| 727 bool GetUserSpecificRegistrySuffix(string16* suffix) { |
| 728 wchar_t user_name[256]; |
| 729 DWORD size = arraysize(user_name); |
| 730 if (::GetUserName(user_name, &size) == 0 || size < 1) { |
| 731 PLOG(DFATAL) << "GetUserName failed"; |
| 732 return false; |
| 733 } |
| 734 suffix->reserve(size); |
| 735 suffix->assign(1, L'.'); |
| 736 suffix->append(user_name, size - 1); |
| 737 return true; |
| 738 } |
| 739 |
| 740 // Sets |suffix| to the current user's username, preceded by a dot, on |
| 741 // user-level installs. |
| 742 // To support old-style user-level installs however, |suffix| is cleared if |
| 743 // the user currently owns the non-suffixed HKLM registrations. |
| 744 // |suffix| is also cleared on system-level installs. |
| 745 // |suffix| should then be appended to all Chrome properties that may conflict |
| 746 // with other Chrome user-level installs. |
| 747 // Returns true unless one of the underlying calls fails. |
| 748 bool GetInstallationSpecificSuffix(BrowserDistribution* dist, |
| 749 const string16& chrome_exe, |
| 750 string16* suffix) { |
| 751 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 752 QuickIsChromeRegistered(dist, chrome_exe, string16(), |
| 753 CONFIRM_SYSTEM_REGISTRATION)) { |
| 754 // No suffix on system-level installs and user-level installs already |
| 755 // registered with no suffix. |
| 756 suffix->clear(); |
| 757 return true; |
| 758 } else { |
| 759 return GetUserSpecificRegistrySuffix(suffix); |
| 760 } |
| 761 } |
| 762 |
| 680 } // namespace | 763 } // namespace |
| 681 | 764 |
| 682 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 765 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
| 683 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 766 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
| 684 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 767 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
| 685 const wchar_t* ShellUtil::kRegStartMenuInternet = | 768 const wchar_t* ShellUtil::kRegStartMenuInternet = |
| 686 L"Software\\Clients\\StartMenuInternet"; | 769 L"Software\\Clients\\StartMenuInternet"; |
| 687 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 770 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
| 688 const wchar_t* ShellUtil::kRegRegisteredApplications = | 771 const wchar_t* ShellUtil::kRegRegisteredApplications = |
| 689 L"Software\\RegisteredApplications"; | 772 L"Software\\RegisteredApplications"; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 716 L"ApplicationDescription"; | 799 L"ApplicationDescription"; |
| 717 const wchar_t* ShellUtil::kRegApplicationName = L"ApplicationName"; | 800 const wchar_t* ShellUtil::kRegApplicationName = L"ApplicationName"; |
| 718 const wchar_t* ShellUtil::kRegApplicationIcon = L"ApplicationIcon"; | 801 const wchar_t* ShellUtil::kRegApplicationIcon = L"ApplicationIcon"; |
| 719 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; | 802 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; |
| 720 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; | 803 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; |
| 721 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; | 804 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; |
| 722 const wchar_t* ShellUtil::kRegVerbRun = L"run"; | 805 const wchar_t* ShellUtil::kRegVerbRun = L"run"; |
| 723 const wchar_t* ShellUtil::kRegCommand = L"command"; | 806 const wchar_t* ShellUtil::kRegCommand = L"command"; |
| 724 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; | 807 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; |
| 725 | 808 |
| 809 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
| 810 const string16& chrome_exe, |
| 811 const string16& suffix) { |
| 812 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
| 813 CONFIRM_SYSTEM_REGISTRATION_IN_HKLM); |
| 814 } |
| 815 |
| 726 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, | 816 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, |
| 727 const string16& chrome_exe, | 817 const string16& chrome_exe, |
| 728 const string16& description, | 818 const string16& description, |
| 729 const string16& appended_name, | 819 const string16& appended_name, |
| 730 const string16& arguments, | 820 const string16& arguments, |
| 731 const string16& icon_path, | 821 const string16& icon_path, |
| 732 int icon_index, | 822 int icon_index, |
| 733 ShellChange shell_change, | 823 ShellChange shell_change, |
| 734 uint32 options) { | 824 uint32 options) { |
| 735 string16 shortcut_name; | 825 string16 shortcut_name; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 KEY_QUERY_VALUE) != ERROR_SUCCESS || | 1006 KEY_QUERY_VALUE) != ERROR_SUCCESS || |
| 917 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) { | 1007 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) { |
| 918 continue; | 1008 continue; |
| 919 } | 1009 } |
| 920 if (!name.empty() && !command.empty() && | 1010 if (!name.empty() && !command.empty() && |
| 921 name.find(dist->GetApplicationName()) == string16::npos) | 1011 name.find(dist->GetApplicationName()) == string16::npos) |
| 922 (*browsers)[name] = command; | 1012 (*browsers)[name] = command; |
| 923 } | 1013 } |
| 924 } | 1014 } |
| 925 | 1015 |
| 926 bool ShellUtil::GetUserSpecificDefaultBrowserSuffix(BrowserDistribution* dist, | 1016 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist, |
| 927 string16* entry) { | 1017 const string16& chrome_exe) { |
| 928 wchar_t user_name[256]; | 1018 string16 tested_suffix; |
| 929 DWORD size = arraysize(user_name); | 1019 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 930 if (::GetUserName(user_name, &size) == 0 || size < 1) | 1020 !GetUserSpecificRegistrySuffix(&tested_suffix) || |
| 931 return false; | 1021 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, |
| 932 entry->reserve(size); | 1022 CONFIRM_PROGID_REGISTRATION)) { |
| 933 entry->assign(1, L'.'); | 1023 return string16(); |
| 934 entry->append(user_name, size - 1); | 1024 } |
| 935 | 1025 return tested_suffix; |
| 936 return RegKey(HKEY_LOCAL_MACHINE, | |
| 937 RegistryEntry::GetBrowserClientKey(dist, *entry).c_str(), | |
| 938 KEY_READ).Valid(); | |
| 939 } | 1026 } |
| 940 | 1027 |
| 941 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, | 1028 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, |
| 942 int shell_change, | 1029 int shell_change, |
| 943 const string16& chrome_exe, | 1030 const string16& chrome_exe, |
| 944 bool elevate_if_not_admin) { | 1031 bool elevate_if_not_admin) { |
| 945 if (!dist->CanSetAsDefault()) | 1032 if (!dist->CanSetAsDefault()) |
| 946 return false; | 1033 return false; |
| 947 | 1034 |
| 948 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); | 1035 if (!ShellUtil::RegisterChromeBrowser( |
| 1036 dist, chrome_exe, string16(), elevate_if_not_admin)) { |
| 1037 return false; |
| 1038 } |
| 949 | 1039 |
| 950 bool ret = true; | 1040 bool ret = true; |
| 951 // First use the new "recommended" way on Vista to make Chrome default | 1041 // First use the new "recommended" way on Vista to make Chrome default |
| 952 // browser. | 1042 // browser. |
| 953 string16 app_name = dist->GetApplicationName(); | 1043 string16 app_name = dist->GetApplicationName(); |
| 954 string16 app_suffix; | 1044 const string16 app_suffix( |
| 955 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) | 1045 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe)); |
| 956 app_name += app_suffix; | 1046 app_name += app_suffix; |
| 957 | 1047 |
| 958 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 1048 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 959 // On Windows 8, you can't set yourself as the default handler | 1049 // On Windows 8, you can't set yourself as the default handler |
| 960 // programatically. In other words IApplicationAssociationRegistration | 1050 // programatically. In other words IApplicationAssociationRegistration |
| 961 // has been rendered useless. What you can do is to launch | 1051 // has been rendered useless. What you can do is to launch |
| 962 // "Set Program Associations" section of the "Default Programs" | 1052 // "Set Program Associations" section of the "Default Programs" |
| 963 // control panel. This action does not require elevation and we | 1053 // control panel. This action does not require elevation and we |
| 964 // don't get to control window activation. More info at: | 1054 // don't get to control window activation. More info at: |
| 965 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx | 1055 // http://msdn.microsoft.com/en-us/library/cc144154(VS.85).aspx |
| 966 return LaunchApplicationAssociationDialog(app_name.c_str()); | 1056 return LaunchApplicationAssociationDialog(app_name.c_str()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 996 } | 1086 } |
| 997 } | 1087 } |
| 998 | 1088 |
| 999 // Now use the old way to associate Chrome with supported protocols and file | 1089 // Now use the old way to associate Chrome with supported protocols and file |
| 1000 // associations. This should not be required on Vista but since some | 1090 // associations. This should not be required on Vista but since some |
| 1001 // applications still read Software\Classes\http key directly, we have to do | 1091 // applications still read Software\Classes\http key directly, we have to do |
| 1002 // this on Vista also. | 1092 // this on Vista also. |
| 1003 | 1093 |
| 1004 std::list<RegistryEntry*> entries; | 1094 std::list<RegistryEntry*> entries; |
| 1005 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1095 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 1006 string16 suffix; | 1096 RegistryEntry::GetUserEntries(dist, chrome_exe, app_suffix, &entries); |
| 1007 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | |
| 1008 suffix = L""; | |
| 1009 RegistryEntry::GetUserEntries(dist, chrome_exe, suffix, &entries); | |
| 1010 // Change the default browser for current user. | 1097 // Change the default browser for current user. |
| 1011 if ((shell_change & ShellUtil::CURRENT_USER) && | 1098 if ((shell_change & ShellUtil::CURRENT_USER) && |
| 1012 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 1099 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
| 1013 ret = false; | 1100 ret = false; |
| 1014 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; | 1101 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; |
| 1015 } | 1102 } |
| 1016 | 1103 |
| 1017 // Chrome as default browser at system level. | 1104 // Chrome as default browser at system level. |
| 1018 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && | 1105 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && |
| 1019 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { | 1106 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1039 // First use the new "recommended" way on Vista to make Chrome default | 1126 // First use the new "recommended" way on Vista to make Chrome default |
| 1040 // protocol handler. | 1127 // protocol handler. |
| 1041 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1128 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1042 VLOG(1) << "Registering Chrome as default handler for " << protocol | 1129 VLOG(1) << "Registering Chrome as default handler for " << protocol |
| 1043 << " on Vista."; | 1130 << " on Vista."; |
| 1044 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1131 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 1045 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1132 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 1046 NULL, CLSCTX_INPROC); | 1133 NULL, CLSCTX_INPROC); |
| 1047 if (SUCCEEDED(hr)) { | 1134 if (SUCCEEDED(hr)) { |
| 1048 string16 app_name = dist->GetApplicationName(); | 1135 string16 app_name = dist->GetApplicationName(); |
| 1049 string16 suffix; | 1136 app_name += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe); |
| 1050 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | |
| 1051 app_name += suffix; | |
| 1052 | 1137 |
| 1053 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), | 1138 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), |
| 1054 AT_URLPROTOCOL); | 1139 AT_URLPROTOCOL); |
| 1055 } | 1140 } |
| 1056 if (!SUCCEEDED(hr)) { | 1141 if (!SUCCEEDED(hr)) { |
| 1057 ret = false; | 1142 ret = false; |
| 1058 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 1143 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
| 1059 << " HRESULT=" << hr << "."; | 1144 << " HRESULT=" << hr << "."; |
| 1060 } | 1145 } |
| 1061 } | 1146 } |
| 1062 | 1147 |
| 1063 // Now use the old way to associate Chrome with the desired protocol. This | 1148 // Now use the old way to associate Chrome with the desired protocol. This |
| 1064 // should not be required on Vista but since some applications still read | 1149 // should not be required on Vista but since some applications still read |
| 1065 // Software\Classes\http key directly, we have to do this on Vista also. | 1150 // Software\Classes\http key directly, we have to do this on Vista also. |
| 1066 | 1151 |
| 1067 std::list<RegistryEntry*> entries; | 1152 std::list<RegistryEntry*> entries; |
| 1068 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1153 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 1069 string16 suffix; | 1154 const string16 suffix(GetCurrentInstallationSuffix(dist, chrome_exe)); |
| 1070 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | 1155 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
| 1071 suffix = L""; | 1156 const string16 chrome_icon(ShellUtil::GetChromeIcon(dist, chrome_exe)); |
| 1072 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | |
| 1073 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); | |
| 1074 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, | 1157 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, |
| 1075 &entries); | 1158 &entries); |
| 1076 // Change the default protocol handler for current user. | 1159 // Change the default protocol handler for current user. |
| 1077 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 1160 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
| 1078 ret = false; | 1161 ret = false; |
| 1079 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | 1162 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; |
| 1080 } | 1163 } |
| 1081 | 1164 |
| 1082 return ret; | 1165 return ret; |
| 1083 } | 1166 } |
| 1084 | 1167 |
| 1085 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, | 1168 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, |
| 1086 const string16& chrome_exe, | 1169 const string16& chrome_exe, |
| 1087 const string16& unique_suffix, | 1170 const string16& unique_suffix, |
| 1088 bool elevate_if_not_admin) { | 1171 bool elevate_if_not_admin) { |
| 1089 if (!dist->CanSetAsDefault()) | 1172 if (!dist->CanSetAsDefault()) |
| 1090 return false; | 1173 return false; |
| 1091 | 1174 |
| 1092 // First figure out we need to append a suffix to the registry entries to | |
| 1093 // make them unique. | |
| 1094 string16 suffix; | 1175 string16 suffix; |
| 1095 if (!unique_suffix.empty()) { | 1176 if (!unique_suffix.empty()) { |
| 1096 suffix = unique_suffix; | 1177 suffix = unique_suffix; |
| 1097 } else if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && | 1178 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { |
| 1098 !GetUserSpecificDefaultBrowserSuffix(dist, &suffix) && | 1179 return false; |
| 1099 !AnotherUserHasDefaultBrowser(dist, chrome_exe)) { | |
| 1100 suffix = L""; | |
| 1101 } | 1180 } |
| 1102 | 1181 |
| 1103 // TODO(grt): remove this on or after 2012-08-01; see impl for details. | 1182 // TODO(grt): remove this on or after 2012-08-01; see impl for details. |
| 1104 RemoveBadWindows8RegistrationIfNeeded(dist, chrome_exe, suffix); | 1183 RemoveBadWindows8RegistrationIfNeeded(dist, chrome_exe); |
| 1105 | 1184 |
| 1106 // Check if Chromium is already registered with this suffix. | 1185 // Check if Chromium is already registered with this suffix. |
| 1107 if (IsChromeRegistered(dist, chrome_exe, suffix)) | 1186 if (IsChromeRegistered(dist, chrome_exe, suffix)) |
| 1108 return true; | 1187 return true; |
| 1109 | 1188 |
| 1110 // If user is an admin try to register and return the status. | 1189 // If user is an admin try to register and return the status. |
| 1111 if (IsUserAnAdmin()) { | 1190 if (IsUserAnAdmin()) { |
| 1112 std::list<RegistryEntry*> progids; | 1191 std::list<RegistryEntry*> progids; |
| 1113 STLElementDeleter<std::list<RegistryEntry*> > progids_deleter(&progids); | 1192 STLElementDeleter<std::list<RegistryEntry*> > progids_deleter(&progids); |
| 1114 std::list<RegistryEntry*> sys_entries; | 1193 std::list<RegistryEntry*> sys_entries; |
| 1115 STLElementDeleter<std::list<RegistryEntry*> > sys_deleter(&sys_entries); | 1194 STLElementDeleter<std::list<RegistryEntry*> > sys_deleter(&sys_entries); |
| 1116 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &progids); | 1195 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &progids); |
| 1117 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &sys_entries); | 1196 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &sys_entries); |
| 1118 return AddRegistryEntries( | 1197 return AddRegistryEntries( |
| 1119 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 1198 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? |
| 1120 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, | 1199 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, |
| 1121 progids) && | 1200 progids) && |
| 1122 AddRegistryEntries(HKEY_LOCAL_MACHINE, sys_entries); | 1201 AddRegistryEntries(HKEY_LOCAL_MACHINE, sys_entries); |
| 1123 } | 1202 } |
| 1124 | 1203 |
| 1125 // If user is not an admin and OS is Vista, try to elevate and register. | 1204 // If user is not an admin and OS is Vista, try to elevate and register. |
| 1126 if (elevate_if_not_admin && | 1205 if (elevate_if_not_admin && |
| 1127 base::win::GetVersion() >= base::win::VERSION_VISTA && | 1206 base::win::GetVersion() >= base::win::VERSION_VISTA && |
| 1128 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) | 1207 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) |
| 1129 return true; | 1208 return true; |
| 1130 | 1209 |
| 1131 // If we got to this point then all we can do is create ProgIds under HKCU | 1210 // If we got to this point then all we can do is create ProgIds under HKCU. |
| 1132 // on XP as well as Vista. | |
| 1133 std::list<RegistryEntry*> entries; | 1211 std::list<RegistryEntry*> entries; |
| 1134 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1212 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 1135 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); | 1213 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); |
| 1136 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | 1214 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered with |
| 1215 // no suffix (as per the old registration style): in which case some other |
| 1216 // registry entries could refer to them and since we were not able to set our |
| 1217 // HKLM entries above, we are better off not altering these here. |
| 1218 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { |
| 1219 if (!suffix.empty()) { |
| 1220 STLDeleteElements(&entries); |
| 1221 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
| 1222 } |
| 1223 return AddRegistryEntries(HKEY_CURRENT_USER, entries); |
| 1224 } |
| 1225 return true; |
| 1137 } | 1226 } |
| 1138 | 1227 |
| 1139 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, | 1228 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, |
| 1140 const string16& chrome_exe, | 1229 const string16& chrome_exe, |
| 1141 const string16& unique_suffix, | 1230 const string16& unique_suffix, |
| 1142 const string16& protocol, | 1231 const string16& protocol, |
| 1143 bool elevate_if_not_admin) { | 1232 bool elevate_if_not_admin) { |
| 1144 if (!dist->CanSetAsDefault()) | 1233 if (!dist->CanSetAsDefault()) |
| 1145 return false; | 1234 return false; |
| 1146 | 1235 |
| 1147 // Figure out we need to append a suffix to the registry entries to | |
| 1148 // make them unique. | |
| 1149 string16 suffix; | 1236 string16 suffix; |
| 1150 if (!unique_suffix.empty()) { | 1237 if (!unique_suffix.empty()) { |
| 1151 suffix = unique_suffix; | 1238 suffix = unique_suffix; |
| 1152 } else if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && | 1239 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { |
| 1153 !GetUserSpecificDefaultBrowserSuffix(dist, &suffix) && | 1240 return false; |
| 1154 !AnotherUserHasDefaultBrowser(dist, chrome_exe)) { | |
| 1155 suffix = L""; | |
| 1156 } | 1241 } |
| 1157 | 1242 |
| 1158 // Check if Chromium is already registered with this suffix. | 1243 // Check if Chromium is already registered with this suffix. |
| 1159 if (IsChromeRegisteredForProtocol(dist, suffix, protocol)) | 1244 if (IsChromeRegisteredForProtocol(dist, suffix, protocol)) |
| 1160 return true; | 1245 return true; |
| 1161 | 1246 |
| 1162 if (IsUserAnAdmin()) { | 1247 if (IsUserAnAdmin()) { |
| 1163 // We can do this operation directly. | 1248 // We can do this operation directly. |
| 1164 // If we're not registered at all, try to register. If that fails | 1249 // If we're not registered at all, try to register. If that fails |
| 1165 // we should give up. | 1250 // we should give up. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 chrome_exe.c_str(), | 1376 chrome_exe.c_str(), |
| 1292 shortcut.c_str(), | 1377 shortcut.c_str(), |
| 1293 chrome_path.c_str(), | 1378 chrome_path.c_str(), |
| 1294 arguments.c_str(), | 1379 arguments.c_str(), |
| 1295 description.c_str(), | 1380 description.c_str(), |
| 1296 icon_path.c_str(), | 1381 icon_path.c_str(), |
| 1297 icon_index, | 1382 icon_index, |
| 1298 dist->GetBrowserAppId().c_str(), | 1383 dist->GetBrowserAppId().c_str(), |
| 1299 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1384 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
| 1300 } | 1385 } |
| OLD | NEW |