Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 2764963002: Move ProgID methods from BrowserDistribution into install_static. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // registry). 81 // registry).
82 CONFIRM_SHELL_REGISTRATION_IN_HKLM, 82 CONFIRM_SHELL_REGISTRATION_IN_HKLM,
83 }; 83 };
84 84
85 const wchar_t kReinstallCommand[] = L"ReinstallCommand"; 85 const wchar_t kReinstallCommand[] = L"ReinstallCommand";
86 86
87 // Returns the current (or installed) browser's ProgId (e.g. 87 // Returns the current (or installed) browser's ProgId (e.g.
88 // "ChromeHTML|suffix|"). 88 // "ChromeHTML|suffix|").
89 // |suffix| can be the empty string. 89 // |suffix| can be the empty string.
90 base::string16 GetBrowserProgId(const base::string16& suffix) { 90 base::string16 GetBrowserProgId(const base::string16& suffix) {
91 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 91 base::string16 chrome_html(install_static::GetProgIdPrefix());
92 base::string16 chrome_html(dist->GetBrowserProgIdPrefix());
93 chrome_html.append(suffix); 92 chrome_html.append(suffix);
94 93
95 // ProgIds cannot be longer than 39 characters. 94 // ProgIds cannot be longer than 39 characters.
96 // Ref: http://msdn.microsoft.com/en-us/library/aa911706.aspx. 95 // Ref: http://msdn.microsoft.com/en-us/library/aa911706.aspx.
97 // Make all new registrations comply with this requirement (existing 96 // Make all new registrations comply with this requirement (existing
98 // registrations must be preserved). 97 // registrations must be preserved).
99 base::string16 new_style_suffix; 98 base::string16 new_style_suffix;
100 if (ShellUtil::GetUserSpecificRegistrySuffix(&new_style_suffix) && 99 if (ShellUtil::GetUserSpecificRegistrySuffix(&new_style_suffix) &&
101 suffix == new_style_suffix && chrome_html.length() > 39) { 100 suffix == new_style_suffix && chrome_html.length() > 39) {
102 NOTREACHED(); 101 NOTREACHED();
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 342 }
344 } 343 }
345 344
346 // This method returns a list of all the registry entries that are needed to 345 // This method returns a list of all the registry entries that are needed to
347 // register this installation's ProgId and AppId. These entries need to be 346 // register this installation's ProgId and AppId. These entries need to be
348 // registered in HKLM prior to Win8. 347 // registered in HKLM prior to Win8.
349 void GetChromeProgIdEntries(BrowserDistribution* dist, 348 void GetChromeProgIdEntries(BrowserDistribution* dist,
350 const base::FilePath& chrome_exe, 349 const base::FilePath& chrome_exe,
351 const base::string16& suffix, 350 const base::string16& suffix,
352 ScopedVector<RegistryEntry>* entries) { 351 ScopedVector<RegistryEntry>* entries) {
352 DCHECK_EQ(BrowserDistribution::GetDistribution(), dist);
huangs 2017/03/21 15:35:48 Pointer comparison! Also, if we can get BrowserDis
grt (UTC plus 2) 2017/03/22 08:03:36 Done.
353 int chrome_icon_index = dist->GetIconIndex(); 353 int chrome_icon_index = dist->GetIconIndex();
354 354
355 ApplicationInfo app_info; 355 ApplicationInfo app_info;
356 app_info.prog_id = GetBrowserProgId(suffix); 356 app_info.prog_id = GetBrowserProgId(suffix);
357 app_info.file_type_name = dist->GetBrowserProgIdDesc(); 357 app_info.file_type_name = install_static::GetProgIdDescription();
358 // File types associated with Chrome are just given the Chrome icon. 358 // File types associated with Chrome are just given the Chrome icon.
359 app_info.file_type_icon_path = chrome_exe; 359 app_info.file_type_icon_path = chrome_exe;
360 app_info.file_type_icon_index = chrome_icon_index; 360 app_info.file_type_icon_index = chrome_icon_index;
361 app_info.command_line = ShellUtil::GetChromeShellOpenCmd(chrome_exe); 361 app_info.command_line = ShellUtil::GetChromeShellOpenCmd(chrome_exe);
362 // For user-level installs: entries for the app id will be in HKCU; thus we 362 // For user-level installs: entries for the app id will be in HKCU; thus we
363 // do not need a suffix on those entries. 363 // do not need a suffix on those entries.
364 DCHECK_EQ(BrowserDistribution::GetDistribution(), dist);
365 app_info.app_id = 364 app_info.app_id =
366 ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall()); 365 ShellUtil::GetBrowserModelId(InstallUtil::IsPerUserInstall());
367 366
368 // TODO(grt): http://crbug.com/75152 Write a reference to a localized 367 // TODO(grt): http://crbug.com/75152 Write a reference to a localized
369 // resource for name, description, and company. 368 // resource for name, description, and company.
370 app_info.application_name = dist->GetDisplayName(); 369 app_info.application_name = dist->GetDisplayName();
371 app_info.application_icon_path = chrome_exe; 370 app_info.application_icon_path = chrome_exe;
372 app_info.application_icon_index = chrome_icon_index; 371 app_info.application_icon_index = chrome_icon_index;
373 app_info.application_description = dist->GetAppDescription(); 372 app_info.application_description = dist->GetAppDescription();
374 app_info.publisher_name = dist->GetPublisherName(); 373 app_info.publisher_name = dist->GetPublisherName();
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 // where we used to not suffix user-level installs if they were the first to 787 // where we used to not suffix user-level installs if they were the first to
789 // request the non-suffixed registry entries on the machine). 788 // request the non-suffixed registry entries on the machine).
790 // NOTE: This a quick check that only validates that a single registry entry 789 // NOTE: This a quick check that only validates that a single registry entry
791 // points to |chrome_exe|. This should only be used at run-time to determine 790 // points to |chrome_exe|. This should only be used at run-time to determine
792 // how Chrome is registered, not to know whether the registration is complete 791 // how Chrome is registered, not to know whether the registration is complete
793 // at install-time (IsChromeRegistered() can be used for that). 792 // at install-time (IsChromeRegistered() can be used for that).
794 bool QuickIsChromeRegistered(BrowserDistribution* dist, 793 bool QuickIsChromeRegistered(BrowserDistribution* dist,
795 const base::FilePath& chrome_exe, 794 const base::FilePath& chrome_exe,
796 const base::string16& suffix, 795 const base::string16& suffix,
797 RegistrationConfirmationLevel confirmation_level) { 796 RegistrationConfirmationLevel confirmation_level) {
797 DCHECK_EQ(BrowserDistribution::GetDistribution(), dist);
huangs 2017/03/21 15:35:48 Same as above.
grt (UTC plus 2) 2017/03/22 08:03:36 Done.
798 // Get the appropriate key to look for based on the level desired. 798 // Get the appropriate key to look for based on the level desired.
799 base::string16 reg_key; 799 base::string16 reg_key;
800 switch (confirmation_level) { 800 switch (confirmation_level) {
801 case CONFIRM_PROGID_REGISTRATION: 801 case CONFIRM_PROGID_REGISTRATION:
802 // Software\Classes\ChromeHTML|suffix| 802 // Software\Classes\ChromeHTML|suffix|
803 reg_key = ShellUtil::kRegClasses; 803 reg_key = ShellUtil::kRegClasses;
804 reg_key.push_back(base::FilePath::kSeparators[0]); 804 reg_key.push_back(base::FilePath::kSeparators[0]);
805 reg_key.append(dist->GetBrowserProgIdPrefix()); 805 reg_key.append(install_static::GetProgIdPrefix());
806 reg_key.append(suffix); 806 reg_key.append(suffix);
807 break; 807 break;
808 case CONFIRM_SHELL_REGISTRATION: 808 case CONFIRM_SHELL_REGISTRATION:
809 case CONFIRM_SHELL_REGISTRATION_IN_HKLM: 809 case CONFIRM_SHELL_REGISTRATION_IN_HKLM:
810 // Software\Clients\StartMenuInternet\Google Chrome|suffix| 810 // Software\Clients\StartMenuInternet\Google Chrome|suffix|
811 reg_key = GetBrowserClientKey(dist, suffix); 811 reg_key = GetBrowserClientKey(dist, suffix);
812 break; 812 break;
813 default: 813 default:
814 NOTREACHED(); 814 NOTREACHED();
815 break; 815 break;
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 ShellUtil::DefaultState ProbeCurrentDefaultHandlers( 1029 ShellUtil::DefaultState ProbeCurrentDefaultHandlers(
1030 const base::FilePath& chrome_exe, 1030 const base::FilePath& chrome_exe,
1031 const wchar_t* const* protocols, 1031 const wchar_t* const* protocols,
1032 size_t num_protocols) { 1032 size_t num_protocols) {
1033 base::win::ScopedComPtr<IApplicationAssociationRegistration> registration; 1033 base::win::ScopedComPtr<IApplicationAssociationRegistration> registration;
1034 HRESULT hr = registration.CreateInstance( 1034 HRESULT hr = registration.CreateInstance(
1035 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC); 1035 CLSID_ApplicationAssociationRegistration, NULL, CLSCTX_INPROC);
1036 if (FAILED(hr)) 1036 if (FAILED(hr))
1037 return ShellUtil::UNKNOWN_DEFAULT; 1037 return ShellUtil::UNKNOWN_DEFAULT;
1038 1038
1039 base::string16 prog_id(install_static::GetProgIdPrefix());
huangs 2017/03/21 15:35:48 Note: These 3 lines can be combined, depending on
grt (UTC plus 2) 2017/03/22 08:03:36 Acknowledged.
1039 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); 1040 BrowserDistribution* dist = BrowserDistribution::GetDistribution();
1040 base::string16 prog_id(dist->GetBrowserProgIdPrefix());
1041 prog_id += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe); 1041 prog_id += ShellUtil::GetCurrentInstallationSuffix(dist, chrome_exe);
1042 1042
1043 for (size_t i = 0; i < num_protocols; ++i) { 1043 for (size_t i = 0; i < num_protocols; ++i) {
1044 base::win::ScopedCoMem<wchar_t> current_app; 1044 base::win::ScopedCoMem<wchar_t> current_app;
1045 hr = registration->QueryCurrentDefault(protocols[i], AT_URLPROTOCOL, 1045 hr = registration->QueryCurrentDefault(protocols[i], AT_URLPROTOCOL,
1046 AL_EFFECTIVE, &current_app); 1046 AL_EFFECTIVE, &current_app);
1047 if (FAILED(hr) || prog_id.compare(current_app) != 0) 1047 if (FAILED(hr) || prog_id.compare(current_app) != 0)
1048 return ShellUtil::NOT_DEFAULT; 1048 return ShellUtil::NOT_DEFAULT;
1049 } 1049 }
1050 1050
(...skipping 1283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2334 itr != entries.end(); ++itr) 2334 itr != entries.end(); ++itr)
2335 (*itr)->AddToWorkItemList(root, items.get()); 2335 (*itr)->AddToWorkItemList(root, items.get());
2336 2336
2337 // Apply all the registry changes and if there is a problem, rollback 2337 // Apply all the registry changes and if there is a problem, rollback
2338 if (!items->Do()) { 2338 if (!items->Do()) {
2339 items->Rollback(); 2339 items->Rollback();
2340 return false; 2340 return false;
2341 } 2341 }
2342 return true; 2342 return true;
2343 } 2343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698