| 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 declares methods that are useful for integrating Chrome in | 5 // This file declares methods that are useful for integrating Chrome in |
| 6 // Windows shell. These methods are all static and currently part of | 6 // Windows shell. These methods are all static and currently part of |
| 7 // ShellUtil class. | 7 // ShellUtil class. |
| 8 | 8 |
| 9 #ifndef CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 9 #ifndef CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
| 10 #define CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 10 #define CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // This is a utility class that provides common shell integration methods | 28 // This is a utility class that provides common shell integration methods |
| 29 // that can be used by installer as well as Chrome. | 29 // that can be used by installer as well as Chrome. |
| 30 class ShellUtil { | 30 class ShellUtil { |
| 31 public: | 31 public: |
| 32 // Input to any methods that make changes to OS shell. | 32 // Input to any methods that make changes to OS shell. |
| 33 enum ShellChange { | 33 enum ShellChange { |
| 34 CURRENT_USER = 0x1, // Make any shell changes only at the user level | 34 CURRENT_USER = 0x1, // Make any shell changes only at the user level |
| 35 SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level | 35 SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Input to CreateOrUpdateChromeShortcuts(). |
| 39 enum ChromeShortcutOptions { |
| 40 SHORTCUT_NO_OPTIONS = 0, |
| 41 // Set DualMode property for Windows 8 Metro-enabled shortcuts. |
| 42 SHORTCUT_DUAL_MODE = 1 << 0, |
| 43 // Create a new shortcut (overwriting if necessary). |
| 44 SHORTCUT_CREATE_ALWAYS = 1 << 1, |
| 45 // Use an alternate application name for the shortcut (e.g. "The Internet"). |
| 46 // This option is only applied to the Desktop shortcut. |
| 47 SHORTCUT_ALTERNATE = 1 << 2, |
| 48 // Operate on the system-level variant of this shortcut (e.g. for Desktop |
| 49 // shortcut C:\Users\Public\Desktop). |
| 50 SHORTCUT_SYSTEM_LEVEL = 1 << 3, |
| 51 // Pin this shortcut to the Win7+ taskbar. This option is only applied if |
| 52 // SHORTCUT_CREATE_ALWAYS is also set and the shortcut is successfully |
| 53 // created. |
| 54 SHORTCUT_PIN_TO_TASKBAR = 1 << 4, |
| 55 }; |
| 56 |
| 57 // Input to various ShellUtil shortcut methods. |
| 58 enum ShortcutLocation { |
| 59 SHORTCUT_DESKTOP = 0, |
| 60 SHORTCUT_QUICK_LAUNCH, |
| 61 SHORTCUT_START_MENU, |
| 62 SHORTCUT_START_MENU_UNINSTALL, |
| 63 }; |
| 64 |
| 38 enum VerifyShortcutStatus { | 65 enum VerifyShortcutStatus { |
| 39 VERIFY_SHORTCUT_SUCCESS = 0, | 66 VERIFY_SHORTCUT_SUCCESS = 0, |
| 40 VERIFY_SHORTCUT_FAILURE_UNEXPECTED, | 67 VERIFY_SHORTCUT_FAILURE_UNEXPECTED, |
| 41 VERIFY_SHORTCUT_FAILURE_PATH, | 68 VERIFY_SHORTCUT_FAILURE_PATH, |
| 42 VERIFY_SHORTCUT_FAILURE_DESCRIPTION, | 69 VERIFY_SHORTCUT_FAILURE_DESCRIPTION, |
| 43 VERIFY_SHORTCUT_FAILURE_ICON_INDEX, | 70 VERIFY_SHORTCUT_FAILURE_ICON_INDEX, |
| 44 }; | 71 }; |
| 45 | 72 |
| 46 // Relative path of the URL Protocol registry entry (prefixed with '\'). | 73 // Relative path of the URL Protocol registry entry (prefixed with '\'). |
| 47 static const wchar_t* kRegURLProtocol; | 74 static const wchar_t* kRegURLProtocol; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // Registry value name for the OpenWithProgids entry for file associations. | 162 // Registry value name for the OpenWithProgids entry for file associations. |
| 136 static const wchar_t* kRegOpenWithProgids; | 163 static const wchar_t* kRegOpenWithProgids; |
| 137 | 164 |
| 138 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. | 165 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. |
| 139 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and | 166 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and |
| 140 // doesn't otherwise validate a full Chrome install in HKLM. | 167 // doesn't otherwise validate a full Chrome install in HKLM. |
| 141 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 168 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
| 142 const string16& chrome_exe, | 169 const string16& chrome_exe, |
| 143 const string16& suffix); | 170 const string16& suffix); |
| 144 | 171 |
| 145 // Creates Chrome shortcut on the Desktop. | 172 // Sets |path| to the path for a shortcut at the |location| desired at |
| 173 // |system_level| or not. |
| 174 // Returns false on failure (in which case |path| shouldn't to be trusted). |
| 175 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, |
| 176 bool system_level, |
| 177 FilePath* path); |
| 178 |
| 179 // Returns the FilePath to be used, based on |options| (as per |options| in |
| 180 // CreateOrUpdateChromeShorcuts), when deciding between installing |
| 181 // |user_level_shortcut| or |system_level_shortcut|. |
| 182 static FilePath ShellUtil::DetermineShortcutPathToCreateFromOptions( |
| 183 const FilePath& user_level_shortcut, |
| 184 const FilePath& system_level_shortcut, |
| 185 uint32 options); |
| 186 |
| 187 // Updates Chrome shortcut in |location| (or creates it if |options| specify |
| 188 // SHORTCUT_CREATE_ALWAYS). |
| 146 // |dist| gives the type of browser distribution currently in use. | 189 // |dist| gives the type of browser distribution currently in use. |
| 147 // |chrome_exe| provides the target path information. | 190 // |exe_path| provides the target path information. |
| 148 // |description| provides the shortcut's "comment" property. | 191 // |description| provides the shortcut's "comment" property. |
| 149 // |appended_name| provides a string to be appended to the distribution name, | 192 // |appended_name| provides a string to be appended to the distribution name |
| 150 // and can be the empty string. | 193 // and can be the empty string. |
| 151 // |arguments| gives a set of arguments to be passed to the executable. | 194 // |arguments| gives a set of arguments to be passed to the executable. |
| 152 // |icon_path| provides the path to the icon file to use. | 195 // |icon_path| provides the path to the icon file to use. |
| 153 // |icon_index| provides the index of the icon within the provided icon file. | 196 // |icon_index| provides the index of the icon within the provided icon file. |
| 154 // If |shell_change| is CURRENT_USER, the shortcut is created in the | 197 // If |icon_path| is |exe_path| and |exe_path| points to chrome.exe: |
| 155 // Desktop folder of current user's profile. | 198 // |icon_index is overriden with the master preferences value. |
| 156 // If |shell_change| is SYSTEM_LEVEL, the shortcut is created in the | |
| 157 // Desktop folder of the "All Users" profile. | |
| 158 // |options|: bitfield for which the options come from ChromeShortcutOptions. | 199 // |options|: bitfield for which the options come from ChromeShortcutOptions. |
| 200 // If SHORTCUT_CREATE_ALWAYS is not set in |options|, only specified (non- |
| 201 // empty) properties on an existing shortcut will be modified. If the shortcut |
| 202 // does not exist, this method is a no-op and returns false. |
| 159 // Returns true iff the method causes a shortcut to be created / updated. | 203 // Returns true iff the method causes a shortcut to be created / updated. |
| 160 static bool CreateChromeDesktopShortcut(BrowserDistribution* dist, | 204 static bool CreateOrUpdateChromeShortcut(ShortcutLocation location, |
| 161 const string16& chrome_exe, | 205 BrowserDistribution* dist, |
| 162 const string16& description, | 206 const string16& chrome_exe, |
| 163 const string16& appended_name, | 207 const string16& description, |
| 164 const string16& arguments, | 208 const string16& appended_name, |
| 165 const string16& icon_path, | 209 const string16& arguments, |
| 166 int icon_index, | 210 const string16& icon_path, |
| 167 ShellChange shell_change, | 211 int icon_index, |
| 168 uint32 options); | 212 uint32 options); |
| 169 | |
| 170 // Create Chrome shortcut on Quick Launch Bar. | |
| 171 // If shell_change is CURRENT_USER, the shortcut is created in the | |
| 172 // Quick Launch folder of current user's profile. | |
| 173 // If shell_change is SYSTEM_LEVEL, the shortcut is created in the | |
| 174 // Quick Launch folder of "Default User" profile. This will make sure | |
| 175 // that this shortcut will be seen by all the new users logging into the | |
| 176 // system. | |
| 177 // |options|: bitfield for which the options come from ChromeShortcutOptions. | |
| 178 static bool CreateChromeQuickLaunchShortcut(BrowserDistribution* dist, | |
| 179 const string16& chrome_exe, | |
| 180 int shell_change, | |
| 181 uint32 options); | |
| 182 | 213 |
| 183 // This method appends the Chrome icon index inside chrome.exe to the | 214 // This method appends the Chrome icon index inside chrome.exe to the |
| 184 // chrome.exe path passed in as input, to generate the full path for | 215 // chrome.exe path passed in as input, to generate the full path for |
| 185 // Chrome icon that can be used as value for Windows registry keys. | 216 // Chrome icon that can be used as value for Windows registry keys. |
| 186 // |chrome_exe| full path to chrome.exe. | 217 // |chrome_exe| full path to chrome.exe. |
| 187 static string16 GetChromeIcon(BrowserDistribution* dist, | 218 static string16 GetChromeIcon(BrowserDistribution* dist, |
| 188 const string16& chrome_exe); | 219 const string16& chrome_exe); |
| 189 | 220 |
| 190 // This method returns the command to open URLs/files using chrome. Typically | 221 // This method returns the command to open URLs/files using chrome. Typically |
| 191 // this command is written to the registry under shell\open\command key. | 222 // this command is written to the registry under shell\open\command key. |
| 192 // |chrome_exe|: the full path to chrome.exe | 223 // |chrome_exe|: the full path to chrome.exe |
| 193 static string16 GetChromeShellOpenCmd(const string16& chrome_exe); | 224 static string16 GetChromeShellOpenCmd(const string16& chrome_exe); |
| 194 | 225 |
| 195 // This method returns the command to be called by the DelegateExecute verb | 226 // This method returns the command to be called by the DelegateExecute verb |
| 196 // handler to launch chrome on Windows 8. Typically this command is written to | 227 // handler to launch chrome on Windows 8. Typically this command is written to |
| 197 // the registry under the HKCR\Chrome\.exe\shell\(open|run)\command key. | 228 // the registry under the HKCR\Chrome\.exe\shell\(open|run)\command key. |
| 198 // |chrome_exe|: the full path to chrome.exe | 229 // |chrome_exe|: the full path to chrome.exe |
| 199 static string16 GetChromeDelegateCommand(const string16& chrome_exe); | 230 static string16 GetChromeDelegateCommand(const string16& chrome_exe); |
| 200 | 231 |
| 201 // Returns the localized name of Chrome shortcut in |shortcut|. If | 232 // Sets |shortcut| to the localized name of the Chrome shortcut at |location|. |
| 202 // |appended_name| is not empty, it is included in the shortcut name. If | 233 // If |appended_name| is not empty, it is included in the shortcut name. If |
| 203 // |alternate| is true, a second localized text that is better suited for | 234 // |alternate| is true, a second localized text that is better suited for |
| 204 // certain scenarios is used. | 235 // certain scenarios is used (this only applies if |location| is |
| 205 static bool GetChromeShortcutName(BrowserDistribution* dist, | 236 // SHORTCUT_DESKTOP). |
| 237 static bool GetChromeShortcutName(ShellUtil::ShortcutLocation location, |
| 238 BrowserDistribution* dist, |
| 206 bool alternate, | 239 bool alternate, |
| 207 const string16& appended_name, | 240 const string16& appended_name, |
| 208 string16* shortcut); | 241 string16* shortcut); |
| 209 | 242 |
| 210 // Gets the desktop path for the current user or all users (if system_level | |
| 211 // is true) and returns it in 'path' argument. Return true if successful, | |
| 212 // otherwise returns false. | |
| 213 static bool GetDesktopPath(bool system_level, FilePath* path); | |
| 214 | |
| 215 // Gets the Quick Launch shortcuts path for the current user and | |
| 216 // returns it in 'path' argument. Return true if successful, otherwise | |
| 217 // returns false. If system_level is true this function returns the path | |
| 218 // to Default Users Quick Launch shortcuts path. Adding a shortcut to Default | |
| 219 // User's profile only affects any new user profiles (not existing ones). | |
| 220 static bool GetQuickLaunchPath(bool system_level, FilePath* path); | |
| 221 | |
| 222 // Gets a mapping of all registered browser names (excluding browsers in the | 243 // Gets a mapping of all registered browser names (excluding browsers in the |
| 223 // |dist| distribution) and their reinstall command (which usually sets | 244 // |dist| distribution) and their reinstall command (which usually sets |
| 224 // browser as default). | 245 // browser as default). |
| 225 // Given browsers can be registered in HKCU (as of Win7) and/or in HKLM, this | 246 // Given browsers can be registered in HKCU (as of Win7) and/or in HKLM, this |
| 226 // method looks in both and gives precedence to values in HKCU as per the msdn | 247 // method looks in both and gives precedence to values in HKCU as per the msdn |
| 227 // standard: http://goo.gl/xjczJ. | 248 // standard: http://goo.gl/xjczJ. |
| 228 static void GetRegisteredBrowsers(BrowserDistribution* dist, | 249 static void GetRegisteredBrowsers(BrowserDistribution* dist, |
| 229 std::map<string16, string16>* browsers); | 250 std::map<string16, string16>* browsers); |
| 230 | 251 |
| 231 // Returns the suffix this user's Chrome install is registered with. | 252 // Returns the suffix this user's Chrome install is registered with. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 // to default browser entries names that it creates in the registry. | 380 // to default browser entries names that it creates in the registry. |
| 360 // |protocol| The protocol to register as being capable of handling.s | 381 // |protocol| The protocol to register as being capable of handling.s |
| 361 // |elevate_if_not_admin| if true will make this method try alternate methods | 382 // |elevate_if_not_admin| if true will make this method try alternate methods |
| 362 // as described above. | 383 // as described above. |
| 363 static bool RegisterChromeForProtocol(BrowserDistribution* dist, | 384 static bool RegisterChromeForProtocol(BrowserDistribution* dist, |
| 364 const string16& chrome_exe, | 385 const string16& chrome_exe, |
| 365 const string16& unique_suffix, | 386 const string16& unique_suffix, |
| 366 const string16& protocol, | 387 const string16& protocol, |
| 367 bool elevate_if_not_admin); | 388 bool elevate_if_not_admin); |
| 368 | 389 |
| 369 // Remove Chrome shortcut from Desktop. | 390 // Remove Chrome user-level shortcut from |location|. If SHORTCUT_SYSTEM_LEVEL |
| 370 // If |shell_change| is CURRENT_USER, the shortcut is removed from the | 391 // is specified in |options|, also remove the system-level shortcut for |
| 371 // Desktop folder of current user's profile. | 392 // |location|. |
| 372 // If |shell_change| is SYSTEM_LEVEL, the shortcut is removed from the | |
| 373 // Desktop folder of "All Users" profile. | |
| 374 // |options|: bitfield for which the options come from ChromeShortcutOptions. | 393 // |options|: bitfield for which the options come from ChromeShortcutOptions. |
| 375 // Only SHORTCUT_ALTERNATE is a valid option for this function. | 394 // Returns true if the specified shortcut is successfully deleted. |
| 376 static bool RemoveChromeDesktopShortcut(BrowserDistribution* dist, | 395 static bool RemoveChromeShortcut(ShortcutLocation location, |
| 377 int shell_change, | 396 BrowserDistribution* dist, |
| 378 uint32 options); | 397 uint32 options); |
| 379 | 398 |
| 380 // Removes a set of existing Chrome desktop shortcuts. |appended_names| is a | 399 // Removes a set of existing Chrome desktop shortcuts. |appended_names| is a |
| 381 // list of shortcut file names as obtained from | 400 // list of shortcut file names as obtained from |
| 382 // ShellUtil::GetChromeShortcutName. | 401 // ShellUtil::GetChromeShortcutName. |
| 383 static bool RemoveChromeDesktopShortcutsWithAppendedNames( | 402 static bool RemoveChromeDesktopShortcutsWithAppendedNames( |
| 384 const std::vector<string16>& appended_names); | 403 const std::vector<string16>& appended_names); |
| 385 | 404 |
| 386 // Remove Chrome shortcut from Quick Launch Bar. | |
| 387 // If shell_change is CURRENT_USER, the shortcut is removed from | |
| 388 // the Quick Launch folder of current user's profile. | |
| 389 // If shell_change is SYSTEM_LEVEL, the shortcut is removed from | |
| 390 // the Quick Launch folder of "Default User" profile. | |
| 391 static bool RemoveChromeQuickLaunchShortcut(BrowserDistribution* dist, | |
| 392 int shell_change); | |
| 393 | |
| 394 enum ChromeShortcutOptions { | |
| 395 SHORTCUT_NO_OPTIONS = 0, | |
| 396 // Set DualMode property for Windows 8 Metro-enabled shortcuts. | |
| 397 SHORTCUT_DUAL_MODE = 1 << 0, | |
| 398 // Create a new shortcut (overwriting if necessary). | |
| 399 SHORTCUT_CREATE_ALWAYS = 1 << 1, | |
| 400 // Use an alternate application name for the shortcut (e.g. "The Internet"). | |
| 401 // This option is only applied to the Desktop shortcut. | |
| 402 SHORTCUT_ALTERNATE = 1 << 2, | |
| 403 }; | |
| 404 | |
| 405 // Updates shortcut (or creates a new shortcut) at destination given by | |
| 406 // shortcut to a target given by chrome_exe. The arguments are given by | |
| 407 // |arguments| for the target and icon is set based on |icon_path| and | |
| 408 // |icon_index|. If create_new is set to true, the function will create a new | |
| 409 // shortcut if it doesn't exist. | |
| 410 // |options|: bitfield for which the options come from ChromeShortcutOptions. | |
| 411 // If SHORTCUT_CREATE_ALWAYS is not set in |options|, only specified (non- | |
| 412 // null) properties on an existing shortcut will be modified. If the shortcut | |
| 413 // does not exist, this method is a no-op and returns false. | |
| 414 static bool UpdateChromeShortcut(BrowserDistribution* dist, | |
| 415 const string16& chrome_exe, | |
| 416 const string16& shortcut, | |
| 417 const string16& arguments, | |
| 418 const string16& description, | |
| 419 const string16& icon_path, | |
| 420 int icon_index, | |
| 421 uint32 options); | |
| 422 | |
| 423 // Verify that a shortcut exists with the expected information. | 405 // Verify that a shortcut exists with the expected information. |
| 424 // |exe_path| The shortcut's exe. | 406 // |exe_path| The shortcut's exe. |
| 425 // |shortcut| The path to the shortcut. | 407 // |shortcut| The path to the shortcut. |
| 426 // |description| The shortcut's description. | 408 // |description| The shortcut's description. |
| 427 // |icon_index| The icon's index in the exe. | 409 // |icon_index| The icon's index in the exe. |
| 428 static VerifyShortcutStatus VerifyChromeShortcut(const string16& exe_path, | 410 static VerifyShortcutStatus VerifyChromeShortcut(const string16& exe_path, |
| 429 const string16& shortcut, | 411 const string16& shortcut, |
| 430 const string16& description, | 412 const string16& description, |
| 431 int icon_index); | 413 int icon_index); |
| 432 | 414 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 459 // required by the base32 standard for inputs that aren't a multiple of 5 | 441 // required by the base32 standard for inputs that aren't a multiple of 5 |
| 460 // bytes. | 442 // bytes. |
| 461 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); | 443 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); |
| 462 | 444 |
| 463 private: | 445 private: |
| 464 DISALLOW_COPY_AND_ASSIGN(ShellUtil); | 446 DISALLOW_COPY_AND_ASSIGN(ShellUtil); |
| 465 }; | 447 }; |
| 466 | 448 |
| 467 | 449 |
| 468 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 450 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
| OLD | NEW |