| 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 dialog for picking the application to | 592 // Launches the Windows 7 and Windows 8 dialog for picking the application to |
| 615 // handle the given protocol. Most importantly, this is used to set the default | 593 // handle the given protocol. Most importantly, this is used to set the default |
| 616 // handler for http (and, implicitly with it, https). In that case it is also | 594 // handler for http (and, implicitly with it, https). In that case it is also |
| 617 // known as the 'how do you want to open webpages' dialog. | 595 // known as the 'how do you want to open webpages' dialog. |
| 618 // It is required that Chrome be already *registered* for the given protocol. | 596 // It is required that Chrome be already *registered* for the given protocol. |
| 619 bool LaunchSelectDefaultProtocolHandlerDialog(const wchar_t* protocol) { | 597 bool LaunchSelectDefaultProtocolHandlerDialog(const wchar_t* protocol) { |
| 620 DCHECK(protocol); | 598 DCHECK(protocol); |
| 621 OPENASINFO open_as_info = {}; | 599 OPENASINFO open_as_info = {}; |
| 622 open_as_info.pcszFile = protocol; | 600 open_as_info.pcszFile = protocol; |
| 623 open_as_info.oaifInFlags = | 601 open_as_info.oaifInFlags = |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 // should be removed after a reasonable time, say 2012-08-01. Anyone on Win8 | 635 // should be removed after a reasonable time, say 2012-08-01. Anyone on Win8 |
| 658 // dev channel who hasn't been autoupdated or manually updated by then will have | 636 // dev channel who hasn't been autoupdated or manually updated by then will have |
| 659 // to uninstall and reinstall Chrome to repair. See http://crbug.com/124666 and | 637 // to uninstall and reinstall Chrome to repair. See http://crbug.com/124666 and |
| 660 // http://crbug.com/123994 for gory details. | 638 // http://crbug.com/123994 for gory details. |
| 661 // This function is also used to remove DelegateExecute verb handler | 639 // This function is also used to remove DelegateExecute verb handler |
| 662 // registrations on builds for which Metro is no longer supported. This will | 640 // registrations on builds for which Metro is no longer supported. This will |
| 663 // also become irrelevant sometime after Windows 8 RC (thus the aforementioned | 641 // also become irrelevant sometime after Windows 8 RC (thus the aforementioned |
| 664 // removal date remains correct). | 642 // removal date remains correct). |
| 665 void RemoveBadWindows8RegistrationIfNeeded( | 643 void RemoveBadWindows8RegistrationIfNeeded( |
| 666 BrowserDistribution* dist, | 644 BrowserDistribution* dist, |
| 667 const string16& chrome_exe, | 645 const string16& chrome_exe) { |
| 668 const string16& suffix) { | |
| 669 string16 handler_guid; | 646 string16 handler_guid; |
| 670 | 647 |
| 671 if (dist->GetDelegateExecuteHandlerData(&handler_guid, NULL, NULL, NULL) && | 648 if (dist->GetDelegateExecuteHandlerData(&handler_guid, NULL, NULL, NULL) && |
| 672 (!InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe) || | 649 (!InstallUtil::HasDelegateExecuteHandler(dist, chrome_exe) || |
| 673 !IsChromeMetroSupported())) { | 650 !IsChromeMetroSupported())) { |
| 674 // There's no need to rollback, so forgo the usual work item lists and just | 651 // There's no need to rollback, so forgo the usual work item lists and just |
| 675 // remove the values from the registry. | 652 // remove the values from the registry. |
| 676 const HKEY root_key = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 653 const HKEY root_key = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? |
| 677 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 654 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
| 655 // Use the current installation's suffix, not the about-to-be-installed |
| 656 // suffix. |
| 657 const string16 installation_suffix( |
| 658 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe)); |
| 678 const string16 app_id(dist->GetBrowserAppId()); | 659 const string16 app_id(dist->GetBrowserAppId()); |
| 679 | 660 |
| 680 // <root hkey>\Software\Classes\<app_id> | 661 // <root hkey>\Software\Classes\<app_id> |
| 681 string16 key(ShellUtil::kRegClasses); | 662 string16 key(ShellUtil::kRegClasses); |
| 682 key.push_back(FilePath::kSeparators[0]); | 663 key.push_back(FilePath::kSeparators[0]); |
| 683 key.append(app_id); | 664 key.append(app_id); |
| 684 InstallUtil::DeleteRegistryKey(root_key, key); | 665 InstallUtil::DeleteRegistryKey(root_key, key); |
| 685 | 666 |
| 686 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command | 667 // <root hkey>\Software\Classes\ChromiumHTML[.user]\shell\open\command |
| 687 key = ShellUtil::kRegClasses; | 668 key = ShellUtil::kRegClasses; |
| 688 key.push_back(FilePath::kSeparators[0]); | 669 key.push_back(FilePath::kSeparators[0]); |
| 689 key.append(ShellUtil::kChromeHTMLProgId); | 670 key.append(ShellUtil::kChromeHTMLProgId); |
| 690 key.append(suffix); | 671 key.append(installation_suffix); |
| 691 key.append(ShellUtil::kRegShellOpen); | 672 key.append(ShellUtil::kRegShellOpen); |
| 692 InstallUtil::DeleteRegistryValue(root_key, key, | 673 InstallUtil::DeleteRegistryValue(root_key, key, |
| 693 ShellUtil::kRegDelegateExecute); | 674 ShellUtil::kRegDelegateExecute); |
| 694 } | 675 } |
| 695 } | 676 } |
| 696 | 677 |
| 678 // Returns true if the current install's |chrome_exe| has been registered with |
| 679 // |suffix|. |
| 680 // |confirmation_level| is the level of verification desired as described in |
| 681 // the RegistrationConfirmationLevel enum above. |
| 682 // |suffix| can be the empty string (this is used to support old installs |
| 683 // where we used to not suffix user-level installs if they were the first to |
| 684 // request the non-suffixed registry entries on the machine). |
| 685 // NOTE: This a quick check that only validates that a single registry entry |
| 686 // points to |chrome_exe|. This should only be used at run-time to determine |
| 687 // how Chrome is registered, not to know whether the registration is complete |
| 688 // at install-time (IsChromeRegistered() can be used for that). |
| 689 bool QuickIsChromeRegistered(BrowserDistribution* dist, |
| 690 const string16& chrome_exe, |
| 691 const string16& suffix, |
| 692 RegistrationConfirmationLevel confirmation_level) { |
| 693 // Get the appropriate key to look for based on the level desired. |
| 694 string16 reg_key; |
| 695 switch (confirmation_level) { |
| 696 case CONFIRM_PROGID_REGISTRATION: |
| 697 // Software\Classes\ChromeHTML|suffix| |
| 698 reg_key = ShellUtil::kRegClasses; |
| 699 reg_key.push_back(FilePath::kSeparators[0]); |
| 700 reg_key.append(ShellUtil::kChromeHTMLProgId); |
| 701 reg_key.append(suffix); |
| 702 break; |
| 703 case CONFIRM_SYSTEM_REGISTRATION: |
| 704 case CONFIRM_SYSTEM_REGISTRATION_IN_HKLM: |
| 705 // Software\Clients\StartMenuInternet\Google Chrome|suffix| |
| 706 reg_key = RegistryEntry::GetBrowserClientKey(dist, suffix); |
| 707 break; |
| 708 default: |
| 709 NOTREACHED(); |
| 710 break; |
| 711 } |
| 712 reg_key.append(ShellUtil::kRegShellOpen); |
| 713 |
| 714 // ProgId registrations are allowed to reside in HKCU for user-level installs |
| 715 // (and values there have priority over values in HKLM). The same is true for |
| 716 // system entries as of Windows 8. |
| 717 if (confirmation_level == CONFIRM_PROGID_REGISTRATION || |
| 718 (confirmation_level == CONFIRM_SYSTEM_REGISTRATION && |
| 719 base::win::GetVersion() >= base::win::VERSION_WIN8)) { |
| 720 const RegKey key_hkcu(HKEY_CURRENT_USER, reg_key.c_str(), KEY_QUERY_VALUE); |
| 721 string16 hkcu_value; |
| 722 // If |reg_key| is present in HKCU, assert that it points to |chrome_exe|. |
| 723 // Otherwise, fall back on an HKLM lookup below. |
| 724 if (key_hkcu.ReadValue(L"", &hkcu_value) == ERROR_SUCCESS) { |
| 725 return InstallUtil::ProgramCompare( |
| 726 FilePath(chrome_exe)).Evaluate(hkcu_value); |
| 727 } |
| 728 } |
| 729 |
| 730 // Assert that |reg_key| points to |chrome_exe| in HKLM. |
| 731 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); |
| 732 string16 hklm_value; |
| 733 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) { |
| 734 return InstallUtil::ProgramCompare( |
| 735 FilePath(chrome_exe)).Evaluate(hklm_value); |
| 736 } |
| 737 return false; |
| 738 } |
| 739 |
| 740 // Sets |suffix| to this user's username preceded by a dot. This suffix is then |
| 741 // meant to be added to all registration that may conflict with another |
| 742 // user-level Chrome install. |
| 743 // Returns true unless the OS call to retrieve the username fails. |
| 744 bool GetUserSpecificRegistrySuffix(string16* suffix) { |
| 745 wchar_t user_name[256]; |
| 746 DWORD size = arraysize(user_name); |
| 747 if (::GetUserName(user_name, &size) == 0 || size < 1) { |
| 748 PLOG(DFATAL) << "GetUserName failed"; |
| 749 return false; |
| 750 } |
| 751 suffix->reserve(size); |
| 752 suffix->assign(1, L'.'); |
| 753 suffix->append(user_name, size - 1); |
| 754 return true; |
| 755 } |
| 756 |
| 757 // Sets |suffix| to the current user's username, preceded by a dot, on |
| 758 // user-level installs. |
| 759 // To support old-style user-level installs however, |suffix| is cleared if |
| 760 // the user currently owns the non-suffixed HKLM registrations. |
| 761 // |suffix| is also cleared on system-level installs. |
| 762 // |suffix| should then be appended to all Chrome properties that may conflict |
| 763 // with other Chrome user-level installs. |
| 764 // Returns true unless one of the underlying calls fails. |
| 765 bool GetInstallationSpecificSuffix(BrowserDistribution* dist, |
| 766 const string16& chrome_exe, |
| 767 string16* suffix) { |
| 768 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 769 QuickIsChromeRegistered(dist, chrome_exe, string16(), |
| 770 CONFIRM_SYSTEM_REGISTRATION)) { |
| 771 // No suffix on system-level installs and user-level installs already |
| 772 // registered with no suffix. |
| 773 suffix->clear(); |
| 774 return true; |
| 775 } else { |
| 776 return GetUserSpecificRegistrySuffix(suffix); |
| 777 } |
| 778 } |
| 779 |
| 697 } // namespace | 780 } // namespace |
| 698 | 781 |
| 699 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; | 782 const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon"; |
| 700 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; | 783 const wchar_t* ShellUtil::kRegShellPath = L"\\shell"; |
| 701 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; | 784 const wchar_t* ShellUtil::kRegShellOpen = L"\\shell\\open\\command"; |
| 702 const wchar_t* ShellUtil::kRegStartMenuInternet = | 785 const wchar_t* ShellUtil::kRegStartMenuInternet = |
| 703 L"Software\\Clients\\StartMenuInternet"; | 786 L"Software\\Clients\\StartMenuInternet"; |
| 704 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; | 787 const wchar_t* ShellUtil::kRegClasses = L"Software\\Classes"; |
| 705 const wchar_t* ShellUtil::kRegRegisteredApplications = | 788 const wchar_t* ShellUtil::kRegRegisteredApplications = |
| 706 L"Software\\RegisteredApplications"; | 789 L"Software\\RegisteredApplications"; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 733 L"ApplicationDescription"; | 816 L"ApplicationDescription"; |
| 734 const wchar_t* ShellUtil::kRegApplicationName = L"ApplicationName"; | 817 const wchar_t* ShellUtil::kRegApplicationName = L"ApplicationName"; |
| 735 const wchar_t* ShellUtil::kRegApplicationIcon = L"ApplicationIcon"; | 818 const wchar_t* ShellUtil::kRegApplicationIcon = L"ApplicationIcon"; |
| 736 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; | 819 const wchar_t* ShellUtil::kRegApplicationCompany = L"ApplicationCompany"; |
| 737 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; | 820 const wchar_t* ShellUtil::kRegExePath = L"\\.exe"; |
| 738 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; | 821 const wchar_t* ShellUtil::kRegVerbOpen = L"open"; |
| 739 const wchar_t* ShellUtil::kRegVerbRun = L"run"; | 822 const wchar_t* ShellUtil::kRegVerbRun = L"run"; |
| 740 const wchar_t* ShellUtil::kRegCommand = L"command"; | 823 const wchar_t* ShellUtil::kRegCommand = L"command"; |
| 741 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; | 824 const wchar_t* ShellUtil::kRegDelegateExecute = L"DelegateExecute"; |
| 742 | 825 |
| 826 bool ShellUtil::QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
| 827 const string16& chrome_exe, |
| 828 const string16& suffix) { |
| 829 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
| 830 CONFIRM_SYSTEM_REGISTRATION_IN_HKLM); |
| 831 } |
| 832 |
| 743 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, | 833 bool ShellUtil::CreateChromeDesktopShortcut(BrowserDistribution* dist, |
| 744 const string16& chrome_exe, | 834 const string16& chrome_exe, |
| 745 const string16& description, | 835 const string16& description, |
| 746 const string16& appended_name, | 836 const string16& appended_name, |
| 747 const string16& arguments, | 837 const string16& arguments, |
| 748 const string16& icon_path, | 838 const string16& icon_path, |
| 749 int icon_index, | 839 int icon_index, |
| 750 ShellChange shell_change, | 840 ShellChange shell_change, |
| 751 uint32 options) { | 841 uint32 options) { |
| 752 string16 shortcut_name; | 842 string16 shortcut_name; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 KEY_QUERY_VALUE) != ERROR_SUCCESS || | 1023 KEY_QUERY_VALUE) != ERROR_SUCCESS || |
| 934 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) { | 1024 key.ReadValue(kReinstallCommand, &command) != ERROR_SUCCESS) { |
| 935 continue; | 1025 continue; |
| 936 } | 1026 } |
| 937 if (!name.empty() && !command.empty() && | 1027 if (!name.empty() && !command.empty() && |
| 938 name.find(dist->GetApplicationName()) == string16::npos) | 1028 name.find(dist->GetApplicationName()) == string16::npos) |
| 939 (*browsers)[name] = command; | 1029 (*browsers)[name] = command; |
| 940 } | 1030 } |
| 941 } | 1031 } |
| 942 | 1032 |
| 943 bool ShellUtil::GetUserSpecificDefaultBrowserSuffix(BrowserDistribution* dist, | 1033 string16 ShellUtil::GetCurrentInstallationSuffix(BrowserDistribution* dist, |
| 944 string16* entry) { | 1034 const string16& chrome_exe) { |
| 945 wchar_t user_name[256]; | 1035 string16 tested_suffix; |
| 946 DWORD size = arraysize(user_name); | 1036 if (!InstallUtil::IsPerUserInstall(chrome_exe.c_str()) || |
| 947 if (::GetUserName(user_name, &size) == 0 || size < 1) | 1037 !GetUserSpecificRegistrySuffix(&tested_suffix) || |
| 948 return false; | 1038 !QuickIsChromeRegistered(dist, chrome_exe, tested_suffix, |
| 949 entry->reserve(size); | 1039 CONFIRM_PROGID_REGISTRATION)) { |
| 950 entry->assign(1, L'.'); | 1040 return string16(); |
| 951 entry->append(user_name, size - 1); | 1041 } |
| 952 | 1042 return tested_suffix; |
| 953 return RegKey(HKEY_LOCAL_MACHINE, | |
| 954 RegistryEntry::GetBrowserClientKey(dist, *entry).c_str(), | |
| 955 KEY_READ).Valid(); | |
| 956 } | 1043 } |
| 957 | 1044 |
| 958 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, | 1045 bool ShellUtil::MakeChromeDefault(BrowserDistribution* dist, |
| 959 int shell_change, | 1046 int shell_change, |
| 960 const string16& chrome_exe, | 1047 const string16& chrome_exe, |
| 961 bool elevate_if_not_admin) { | 1048 bool elevate_if_not_admin) { |
| 962 if (!dist->CanSetAsDefault()) | 1049 if (!dist->CanSetAsDefault()) |
| 963 return false; | 1050 return false; |
| 964 | 1051 |
| 965 // Windows 8 does not permit making a browser default just like that. | 1052 // Windows 8 does not permit making a browser default just like that. |
| 966 // This process needs to be routed through the system's UI. Use | 1053 // This process needs to be routed through the system's UI. Use |
| 967 // ShowMakeChromeDefaultSystemUI instead (below). | 1054 // ShowMakeChromeDefaultSystemUI instead (below). |
| 968 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { | 1055 if (base::win::GetVersion() >= base::win::VERSION_WIN8) { |
| 969 NOTREACHED(); | 1056 NOTREACHED(); |
| 970 return false; | 1057 return false; |
| 971 } | 1058 } |
| 972 | 1059 |
| 973 ShellUtil::RegisterChromeBrowser(dist, chrome_exe, L"", elevate_if_not_admin); | 1060 if (!ShellUtil::RegisterChromeBrowser( |
| 1061 dist, chrome_exe, string16(), elevate_if_not_admin)) { |
| 1062 return false; |
| 1063 } |
| 974 | 1064 |
| 975 bool ret = true; | 1065 bool ret = true; |
| 976 // First use the new "recommended" way on Vista to make Chrome default | 1066 // First use the new "recommended" way on Vista to make Chrome default |
| 977 // browser. | 1067 // browser. |
| 978 string16 app_name = dist->GetApplicationName(); | 1068 string16 app_name = dist->GetApplicationName(); |
| 979 string16 app_suffix; | 1069 const string16 app_suffix( |
| 980 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &app_suffix)) | 1070 ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe)); |
| 981 app_name += app_suffix; | 1071 app_name += app_suffix; |
| 982 | 1072 |
| 983 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1073 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 984 // On Windows Vista and Win7 we still can set ourselves via the | 1074 // On Windows Vista and Win7 we still can set ourselves via the |
| 985 // the IApplicationAssociationRegistration interface. | 1075 // the IApplicationAssociationRegistration interface. |
| 986 VLOG(1) << "Registering Chrome as default browser on Vista."; | 1076 VLOG(1) << "Registering Chrome as default browser on Vista."; |
| 987 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1077 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 988 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1078 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 989 NULL, CLSCTX_INPROC); | 1079 NULL, CLSCTX_INPROC); |
| 990 if (SUCCEEDED(hr)) { | 1080 if (SUCCEEDED(hr)) { |
| 991 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { | 1081 for (int i = 0; ShellUtil::kBrowserProtocolAssociations[i] != NULL; i++) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1011 } | 1101 } |
| 1012 } | 1102 } |
| 1013 | 1103 |
| 1014 // Now use the old way to associate Chrome with supported protocols and file | 1104 // Now use the old way to associate Chrome with supported protocols and file |
| 1015 // associations. This should not be required on Vista but since some | 1105 // associations. This should not be required on Vista but since some |
| 1016 // applications still read Software\Classes\http key directly, we have to do | 1106 // applications still read Software\Classes\http key directly, we have to do |
| 1017 // this on Vista also. | 1107 // this on Vista also. |
| 1018 | 1108 |
| 1019 std::list<RegistryEntry*> entries; | 1109 std::list<RegistryEntry*> entries; |
| 1020 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1110 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 1021 string16 suffix; | 1111 RegistryEntry::GetUserEntries(dist, chrome_exe, app_suffix, &entries); |
| 1022 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | |
| 1023 suffix = L""; | |
| 1024 RegistryEntry::GetUserEntries(dist, chrome_exe, suffix, &entries); | |
| 1025 // Change the default browser for current user. | 1112 // Change the default browser for current user. |
| 1026 if ((shell_change & ShellUtil::CURRENT_USER) && | 1113 if ((shell_change & ShellUtil::CURRENT_USER) && |
| 1027 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 1114 !AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
| 1028 ret = false; | 1115 ret = false; |
| 1029 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; | 1116 LOG(ERROR) << "Could not make Chrome default browser (XP/current user)."; |
| 1030 } | 1117 } |
| 1031 | 1118 |
| 1032 // Chrome as default browser at system level. | 1119 // Chrome as default browser at system level. |
| 1033 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && | 1120 if ((shell_change & ShellUtil::SYSTEM_LEVEL) && |
| 1034 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { | 1121 !AddRegistryEntries(HKEY_LOCAL_MACHINE, entries)) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 // First use the new "recommended" way on Vista to make Chrome default | 1159 // First use the new "recommended" way on Vista to make Chrome default |
| 1073 // protocol handler. | 1160 // protocol handler. |
| 1074 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 1161 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
| 1075 VLOG(1) << "Registering Chrome as default handler for " << protocol | 1162 VLOG(1) << "Registering Chrome as default handler for " << protocol |
| 1076 << " on Vista."; | 1163 << " on Vista."; |
| 1077 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; | 1164 base::win::ScopedComPtr<IApplicationAssociationRegistration> pAAR; |
| 1078 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, | 1165 HRESULT hr = pAAR.CreateInstance(CLSID_ApplicationAssociationRegistration, |
| 1079 NULL, CLSCTX_INPROC); | 1166 NULL, CLSCTX_INPROC); |
| 1080 if (SUCCEEDED(hr)) { | 1167 if (SUCCEEDED(hr)) { |
| 1081 string16 app_name = dist->GetApplicationName(); | 1168 string16 app_name = dist->GetApplicationName(); |
| 1082 string16 suffix; | 1169 app_name += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe); |
| 1083 if (ShellUtil::GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | |
| 1084 app_name += suffix; | |
| 1085 | 1170 |
| 1086 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), | 1171 hr = pAAR->SetAppAsDefault(app_name.c_str(), protocol.c_str(), |
| 1087 AT_URLPROTOCOL); | 1172 AT_URLPROTOCOL); |
| 1088 } | 1173 } |
| 1089 if (!SUCCEEDED(hr)) { | 1174 if (!SUCCEEDED(hr)) { |
| 1090 ret = false; | 1175 ret = false; |
| 1091 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" | 1176 LOG(ERROR) << "Could not make Chrome default protocol client (Vista):" |
| 1092 << " HRESULT=" << hr << "."; | 1177 << " HRESULT=" << hr << "."; |
| 1093 } | 1178 } |
| 1094 } | 1179 } |
| 1095 | 1180 |
| 1096 // Now use the old way to associate Chrome with the desired protocol. This | 1181 // Now use the old way to associate Chrome with the desired protocol. This |
| 1097 // should not be required on Vista but since some applications still read | 1182 // should not be required on Vista but since some applications still read |
| 1098 // Software\Classes\http key directly, we have to do this on Vista also. | 1183 // Software\Classes\http key directly, we have to do this on Vista also. |
| 1099 | 1184 |
| 1100 std::list<RegistryEntry*> entries; | 1185 std::list<RegistryEntry*> entries; |
| 1101 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1186 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 1102 string16 suffix; | 1187 const string16 suffix(GetCurrentInstallationSuffix(dist, chrome_exe)); |
| 1103 if (!GetUserSpecificDefaultBrowserSuffix(dist, &suffix)) | 1188 const string16 chrome_open(ShellUtil::GetChromeShellOpenCmd(chrome_exe)); |
| 1104 suffix = L""; | 1189 const string16 chrome_icon(ShellUtil::GetChromeIcon(dist, chrome_exe)); |
| 1105 string16 chrome_open = ShellUtil::GetChromeShellOpenCmd(chrome_exe); | |
| 1106 string16 chrome_icon = ShellUtil::GetChromeIcon(dist, chrome_exe); | |
| 1107 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, | 1190 RegistryEntry::GetUserProtocolEntries(protocol, chrome_icon, chrome_open, |
| 1108 &entries); | 1191 &entries); |
| 1109 // Change the default protocol handler for current user. | 1192 // Change the default protocol handler for current user. |
| 1110 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { | 1193 if (!AddRegistryEntries(HKEY_CURRENT_USER, entries)) { |
| 1111 ret = false; | 1194 ret = false; |
| 1112 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; | 1195 LOG(ERROR) << "Could not make Chrome default protocol client (XP)."; |
| 1113 } | 1196 } |
| 1114 | 1197 |
| 1115 return ret; | 1198 return ret; |
| 1116 } | 1199 } |
| 1117 | 1200 |
| 1118 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, | 1201 bool ShellUtil::RegisterChromeBrowser(BrowserDistribution* dist, |
| 1119 const string16& chrome_exe, | 1202 const string16& chrome_exe, |
| 1120 const string16& unique_suffix, | 1203 const string16& unique_suffix, |
| 1121 bool elevate_if_not_admin) { | 1204 bool elevate_if_not_admin) { |
| 1122 if (!dist->CanSetAsDefault()) | 1205 if (!dist->CanSetAsDefault()) |
| 1123 return false; | 1206 return false; |
| 1124 | 1207 |
| 1125 // First figure out we need to append a suffix to the registry entries to | |
| 1126 // make them unique. | |
| 1127 string16 suffix; | 1208 string16 suffix; |
| 1128 if (!unique_suffix.empty()) { | 1209 if (!unique_suffix.empty()) { |
| 1129 suffix = unique_suffix; | 1210 suffix = unique_suffix; |
| 1130 } else if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && | 1211 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { |
| 1131 !GetUserSpecificDefaultBrowserSuffix(dist, &suffix) && | 1212 return false; |
| 1132 !AnotherUserHasDefaultBrowser(dist, chrome_exe)) { | |
| 1133 suffix = L""; | |
| 1134 } | 1213 } |
| 1135 | 1214 |
| 1136 // TODO(grt): remove this on or after 2012-08-01; see impl for details. | 1215 // TODO(grt): remove this on or after 2012-08-01; see impl for details. |
| 1137 RemoveBadWindows8RegistrationIfNeeded(dist, chrome_exe, suffix); | 1216 RemoveBadWindows8RegistrationIfNeeded(dist, chrome_exe); |
| 1138 | 1217 |
| 1139 // Check if Chromium is already registered with this suffix. | 1218 // Check if Chromium is already registered with this suffix. |
| 1140 if (IsChromeRegistered(dist, chrome_exe, suffix)) | 1219 if (IsChromeRegistered(dist, chrome_exe, suffix)) |
| 1141 return true; | 1220 return true; |
| 1142 | 1221 |
| 1143 // If user is an admin try to register and return the status. | 1222 // If user is an admin try to register and return the status. |
| 1144 if (IsUserAnAdmin()) { | 1223 if (IsUserAnAdmin()) { |
| 1145 std::list<RegistryEntry*> progids; | 1224 std::list<RegistryEntry*> progids; |
| 1146 STLElementDeleter<std::list<RegistryEntry*> > progids_deleter(&progids); | 1225 STLElementDeleter<std::list<RegistryEntry*> > progids_deleter(&progids); |
| 1147 std::list<RegistryEntry*> sys_entries; | 1226 std::list<RegistryEntry*> sys_entries; |
| 1148 STLElementDeleter<std::list<RegistryEntry*> > sys_deleter(&sys_entries); | 1227 STLElementDeleter<std::list<RegistryEntry*> > sys_deleter(&sys_entries); |
| 1149 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &progids); | 1228 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &progids); |
| 1150 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &sys_entries); | 1229 RegistryEntry::GetSystemEntries(dist, chrome_exe, suffix, &sys_entries); |
| 1151 return AddRegistryEntries( | 1230 return AddRegistryEntries( |
| 1152 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 1231 InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? |
| 1153 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, | 1232 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, |
| 1154 progids) && | 1233 progids) && |
| 1155 AddRegistryEntries(HKEY_LOCAL_MACHINE, sys_entries); | 1234 AddRegistryEntries(HKEY_LOCAL_MACHINE, sys_entries); |
| 1156 } | 1235 } |
| 1157 | 1236 |
| 1158 // If user is not an admin and OS is Vista, try to elevate and register. | 1237 // If user is not an admin and OS is Vista, try to elevate and register. |
| 1159 if (elevate_if_not_admin && | 1238 if (elevate_if_not_admin && |
| 1160 base::win::GetVersion() >= base::win::VERSION_VISTA && | 1239 base::win::GetVersion() >= base::win::VERSION_VISTA && |
| 1161 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) | 1240 ElevateAndRegisterChrome(dist, chrome_exe, suffix, L"")) |
| 1162 return true; | 1241 return true; |
| 1163 | 1242 |
| 1164 // If we got to this point then all we can do is create ProgIds under HKCU | 1243 // If we got to this point then all we can do is create ProgIds under HKCU. |
| 1165 // on XP as well as Vista. | |
| 1166 std::list<RegistryEntry*> entries; | 1244 std::list<RegistryEntry*> entries; |
| 1167 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); | 1245 STLElementDeleter<std::list<RegistryEntry*> > entries_deleter(&entries); |
| 1168 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); | 1246 RegistryEntry::GetProgIdEntries(dist, chrome_exe, L"", &entries); |
| 1169 return AddRegistryEntries(HKEY_CURRENT_USER, entries); | 1247 // Prefer to use |suffix|; unless Chrome's ProgIds are already registered with |
| 1248 // no suffix (as per the old registration style): in which case some other |
| 1249 // registry entries could refer to them and since we were not able to set our |
| 1250 // HKLM entries above, we are better off not altering these here. |
| 1251 if (!AreEntriesRegistered(entries, RegistryEntry::LOOK_IN_HKCU)) { |
| 1252 if (!suffix.empty()) { |
| 1253 STLDeleteElements(&entries); |
| 1254 RegistryEntry::GetProgIdEntries(dist, chrome_exe, suffix, &entries); |
| 1255 } |
| 1256 return AddRegistryEntries(HKEY_CURRENT_USER, entries); |
| 1257 } |
| 1258 return true; |
| 1170 } | 1259 } |
| 1171 | 1260 |
| 1172 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, | 1261 bool ShellUtil::RegisterChromeForProtocol(BrowserDistribution* dist, |
| 1173 const string16& chrome_exe, | 1262 const string16& chrome_exe, |
| 1174 const string16& unique_suffix, | 1263 const string16& unique_suffix, |
| 1175 const string16& protocol, | 1264 const string16& protocol, |
| 1176 bool elevate_if_not_admin) { | 1265 bool elevate_if_not_admin) { |
| 1177 if (!dist->CanSetAsDefault()) | 1266 if (!dist->CanSetAsDefault()) |
| 1178 return false; | 1267 return false; |
| 1179 | 1268 |
| 1180 // Figure out we need to append a suffix to the registry entries to | |
| 1181 // make them unique. | |
| 1182 string16 suffix; | 1269 string16 suffix; |
| 1183 if (!unique_suffix.empty()) { | 1270 if (!unique_suffix.empty()) { |
| 1184 suffix = unique_suffix; | 1271 suffix = unique_suffix; |
| 1185 } else if (InstallUtil::IsPerUserInstall(chrome_exe.c_str()) && | 1272 } else if (!GetInstallationSpecificSuffix(dist, chrome_exe, &suffix)) { |
| 1186 !GetUserSpecificDefaultBrowserSuffix(dist, &suffix) && | 1273 return false; |
| 1187 !AnotherUserHasDefaultBrowser(dist, chrome_exe)) { | |
| 1188 suffix = L""; | |
| 1189 } | 1274 } |
| 1190 | 1275 |
| 1191 // Check if Chromium is already registered with this suffix. | 1276 // Check if Chromium is already registered with this suffix. |
| 1192 if (IsChromeRegisteredForProtocol(dist, suffix, protocol)) | 1277 if (IsChromeRegisteredForProtocol(dist, suffix, protocol)) |
| 1193 return true; | 1278 return true; |
| 1194 | 1279 |
| 1195 if (IsUserAnAdmin()) { | 1280 if (IsUserAnAdmin()) { |
| 1196 // We can do this operation directly. | 1281 // We can do this operation directly. |
| 1197 // If we're not registered at all, try to register. If that fails | 1282 // If we're not registered at all, try to register. If that fails |
| 1198 // we should give up. | 1283 // we should give up. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 chrome_exe.c_str(), | 1409 chrome_exe.c_str(), |
| 1325 shortcut.c_str(), | 1410 shortcut.c_str(), |
| 1326 chrome_path.c_str(), | 1411 chrome_path.c_str(), |
| 1327 arguments.c_str(), | 1412 arguments.c_str(), |
| 1328 description.c_str(), | 1413 description.c_str(), |
| 1329 icon_path.c_str(), | 1414 icon_path.c_str(), |
| 1330 icon_index, | 1415 icon_index, |
| 1331 dist->GetBrowserAppId().c_str(), | 1416 dist->GetBrowserAppId().c_str(), |
| 1332 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1417 ConvertShellUtilShortcutOptionsToFileUtil(options)); |
| 1333 } | 1418 } |
| OLD | NEW |