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 enum ChromeShortcutOptions { | |
39 SHORTCUT_NO_OPTIONS = 0, | |
40 // Set DualMode property for Windows 8 Metro-enabled shortcuts. | |
41 SHORTCUT_DUAL_MODE = 1 << 0, | |
42 // Create a new shortcut (overwriting if necessary). | |
43 SHORTCUT_CREATE_ALWAYS = 1 << 1, | |
44 // Use an alternate application name for the shortcut (e.g. "The Internet"). | |
45 // This option is only applied to the Desktop shortcut. | |
46 SHORTCUT_ALTERNATE = 1 << 2, | |
47 // Operate on the system-level variant of this shortcut (e.g. for Desktop | |
48 // shortcut C:\Users\Public\Desktop). | |
49 SHORTCUT_SYSTEM_LEVEL = 1 << 3, | |
50 // Pin this shortcut to the Win7+ taskbar. This option is only applied if | |
51 // SHORTCUT_CREATE_ALWAYS is also set and the shortcut is successfully | |
52 // created. | |
53 SHORTCUT_PIN_TO_TASKBAR = 1 << 4, | |
54 }; | |
55 | |
56 enum ShortcutLocation { | |
57 SHORTCUT_DESKTOP = 0, | |
58 SHORTCUT_QUICK_LAUNCH, | |
59 SHORTCUT_START_MENU, | |
60 SHORTCUT_START_MENU_UNINSTALL, | |
61 }; | |
62 | |
38 enum VerifyShortcutStatus { | 63 enum VerifyShortcutStatus { |
39 VERIFY_SHORTCUT_SUCCESS = 0, | 64 VERIFY_SHORTCUT_SUCCESS = 0, |
40 VERIFY_SHORTCUT_FAILURE_UNEXPECTED, | 65 VERIFY_SHORTCUT_FAILURE_UNEXPECTED, |
41 VERIFY_SHORTCUT_FAILURE_PATH, | 66 VERIFY_SHORTCUT_FAILURE_PATH, |
42 VERIFY_SHORTCUT_FAILURE_DESCRIPTION, | 67 VERIFY_SHORTCUT_FAILURE_DESCRIPTION, |
43 VERIFY_SHORTCUT_FAILURE_ICON_INDEX, | 68 VERIFY_SHORTCUT_FAILURE_ICON_INDEX, |
44 }; | 69 }; |
45 | 70 |
46 // Relative path of the URL Protocol registry entry (prefixed with '\'). | 71 // Relative path of the URL Protocol registry entry (prefixed with '\'). |
47 static const wchar_t* kRegURLProtocol; | 72 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. | 160 // Registry value name for the OpenWithProgids entry for file associations. |
136 static const wchar_t* kRegOpenWithProgids; | 161 static const wchar_t* kRegOpenWithProgids; |
137 | 162 |
138 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. | 163 // 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 | 164 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and |
140 // doesn't otherwise validate a full Chrome install in HKLM. | 165 // doesn't otherwise validate a full Chrome install in HKLM. |
141 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 166 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
142 const string16& chrome_exe, | 167 const string16& chrome_exe, |
143 const string16& suffix); | 168 const string16& suffix); |
144 | 169 |
145 // Creates Chrome shortcut on the Desktop. | 170 // Sets |path| to the path for a shortcut at the |location| desired at |
171 // |system_level| or not. | |
172 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, | |
173 bool system_level, | |
174 FilePath* path); | |
175 | |
176 // Updates Chrome shortcut in |location| (or creates it if |options| specify | |
177 // SHORTCUT_CREATE_ALWAYS). | |
146 // |dist| gives the type of browser distribution currently in use. | 178 // |dist| gives the type of browser distribution currently in use. |
147 // |chrome_exe| provides the target path information. | 179 // |exe_path| provides the target path information. |
148 // |description| provides the shortcut's "comment" property. | 180 // |description| provides the shortcut's "comment" property. |
149 // |appended_name| provides a string to be appended to the distribution name, | 181 // |appended_name| provides a string to be appended to the distribution name |
150 // and can be the empty string. | 182 // and can be the empty string. |
151 // |arguments| gives a set of arguments to be passed to the executable. | 183 // |arguments| gives a set of arguments to be passed to the executable. |
152 // |icon_path| provides the path to the icon file to use. | 184 // |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. | 185 // |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 | 186 // If |icon_path| is |exe_path| and |exe_path| points to chrome.exe: |
155 // Desktop folder of current user's profile. | 187 // |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. | 188 // |options|: bitfield for which the options come from ChromeShortcutOptions. |
189 // If SHORTCUT_CREATE_ALWAYS is not set in |options|, only specified (non- | |
190 // empty) properties on an existing shortcut will be modified. If the shortcut | |
191 // 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. | 192 // Returns true iff the method causes a shortcut to be created / updated. |
160 static bool CreateChromeDesktopShortcut(BrowserDistribution* dist, | 193 static bool CreateOrUpdateChromeShortcut(ShortcutLocation location, |
161 const string16& chrome_exe, | 194 BrowserDistribution* dist, |
162 const string16& description, | 195 const string16& chrome_exe, |
163 const string16& appended_name, | 196 const string16& description, |
164 const string16& arguments, | 197 const string16& appended_name, |
robertshield
2012/08/22 21:39:07
almost all callers of this pass string16() as the
| |
165 const string16& icon_path, | 198 const string16& arguments, |
166 int icon_index, | 199 const string16& icon_path, |
167 ShellChange shell_change, | 200 int icon_index, |
168 uint32 options); | 201 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 | 202 |
183 // This method appends the Chrome icon index inside chrome.exe to the | 203 // 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 | 204 // 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. | 205 // Chrome icon that can be used as value for Windows registry keys. |
186 // |chrome_exe| full path to chrome.exe. | 206 // |chrome_exe| full path to chrome.exe. |
187 static string16 GetChromeIcon(BrowserDistribution* dist, | 207 static string16 GetChromeIcon(BrowserDistribution* dist, |
188 const string16& chrome_exe); | 208 const string16& chrome_exe); |
189 | 209 |
190 // This method returns the command to open URLs/files using chrome. Typically | 210 // 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. | 211 // this command is written to the registry under shell\open\command key. |
192 // |chrome_exe|: the full path to chrome.exe | 212 // |chrome_exe|: the full path to chrome.exe |
193 static string16 GetChromeShellOpenCmd(const string16& chrome_exe); | 213 static string16 GetChromeShellOpenCmd(const string16& chrome_exe); |
194 | 214 |
195 // This method returns the command to be called by the DelegateExecute verb | 215 // 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 | 216 // 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. | 217 // the registry under the HKCR\Chrome\.exe\shell\(open|run)\command key. |
198 // |chrome_exe|: the full path to chrome.exe | 218 // |chrome_exe|: the full path to chrome.exe |
199 static string16 GetChromeDelegateCommand(const string16& chrome_exe); | 219 static string16 GetChromeDelegateCommand(const string16& chrome_exe); |
200 | 220 |
201 // Returns the localized name of Chrome shortcut in |shortcut|. If | 221 // 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 | 222 // 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 | 223 // |alternate| is true, a second localized text that is better suited for |
204 // certain scenarios is used. | 224 // certain scenarios is used (this only applies if |location| is |
205 static bool GetChromeShortcutName(BrowserDistribution* dist, | 225 // SHORTCUT_DESKTOP). |
226 static bool GetChromeShortcutName(ShellUtil::ShortcutLocation location, | |
227 BrowserDistribution* dist, | |
206 bool alternate, | 228 bool alternate, |
207 const string16& appended_name, | 229 const string16& appended_name, |
208 string16* shortcut); | 230 string16* shortcut); |
209 | 231 |
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 | 232 // Gets a mapping of all registered browser names (excluding browsers in the |
223 // |dist| distribution) and their reinstall command (which usually sets | 233 // |dist| distribution) and their reinstall command (which usually sets |
224 // browser as default). | 234 // browser as default). |
225 // Given browsers can be registered in HKCU (as of Win7) and/or in HKLM, this | 235 // 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 | 236 // method looks in both and gives precedence to values in HKCU as per the msdn |
227 // standard: http://goo.gl/xjczJ. | 237 // standard: http://goo.gl/xjczJ. |
228 static void GetRegisteredBrowsers(BrowserDistribution* dist, | 238 static void GetRegisteredBrowsers(BrowserDistribution* dist, |
229 std::map<string16, string16>* browsers); | 239 std::map<string16, string16>* browsers); |
230 | 240 |
231 // Returns the suffix this user's Chrome install is registered with. | 241 // 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. | 369 // to default browser entries names that it creates in the registry. |
360 // |protocol| The protocol to register as being capable of handling.s | 370 // |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 | 371 // |elevate_if_not_admin| if true will make this method try alternate methods |
362 // as described above. | 372 // as described above. |
363 static bool RegisterChromeForProtocol(BrowserDistribution* dist, | 373 static bool RegisterChromeForProtocol(BrowserDistribution* dist, |
364 const string16& chrome_exe, | 374 const string16& chrome_exe, |
365 const string16& unique_suffix, | 375 const string16& unique_suffix, |
366 const string16& protocol, | 376 const string16& protocol, |
367 bool elevate_if_not_admin); | 377 bool elevate_if_not_admin); |
368 | 378 |
369 // Remove Chrome shortcut from Desktop. | 379 // Remove Chrome user-level shortcut from |location|. If SHORTCUT_SYSTEM_LEVEL |
370 // If |shell_change| is CURRENT_USER, the shortcut is removed from the | 380 // is specified in |options|, also remove the system-level shortcut for |
371 // Desktop folder of current user's profile. | 381 // |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. | 382 // |options|: bitfield for which the options come from ChromeShortcutOptions. |
375 // Only SHORTCUT_ALTERNATE is a valid option for this function. | 383 // Returns true if the specified shortcut is successfully deleted. |
376 static bool RemoveChromeDesktopShortcut(BrowserDistribution* dist, | 384 static bool RemoveChromeShortcut(ShortcutLocation location, |
377 int shell_change, | 385 BrowserDistribution* dist, |
378 uint32 options); | 386 uint32 options); |
379 | 387 |
380 // Removes a set of existing Chrome desktop shortcuts. |appended_names| is a | 388 // Removes a set of existing Chrome desktop shortcuts. |appended_names| is a |
381 // list of shortcut file names as obtained from | 389 // list of shortcut file names as obtained from |
382 // ShellUtil::GetChromeShortcutName. | 390 // ShellUtil::GetChromeShortcutName. |
383 static bool RemoveChromeDesktopShortcutsWithAppendedNames( | 391 static bool RemoveChromeDesktopShortcutsWithAppendedNames( |
384 const std::vector<string16>& appended_names); | 392 const std::vector<string16>& appended_names); |
385 | 393 |
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. | 394 // Verify that a shortcut exists with the expected information. |
424 // |exe_path| The shortcut's exe. | 395 // |exe_path| The shortcut's exe. |
425 // |shortcut| The path to the shortcut. | 396 // |shortcut| The path to the shortcut. |
426 // |description| The shortcut's description. | 397 // |description| The shortcut's description. |
427 // |icon_index| The icon's index in the exe. | 398 // |icon_index| The icon's index in the exe. |
428 static VerifyShortcutStatus VerifyChromeShortcut(const string16& exe_path, | 399 static VerifyShortcutStatus VerifyChromeShortcut(const string16& exe_path, |
429 const string16& shortcut, | 400 const string16& shortcut, |
430 const string16& description, | 401 const string16& description, |
431 int icon_index); | 402 int icon_index); |
432 | 403 |
(...skipping 26 matching lines...) Expand all Loading... | |
459 // required by the base32 standard for inputs that aren't a multiple of 5 | 430 // required by the base32 standard for inputs that aren't a multiple of 5 |
460 // bytes. | 431 // bytes. |
461 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); | 432 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); |
462 | 433 |
463 private: | 434 private: |
464 DISALLOW_COPY_AND_ASSIGN(ShellUtil); | 435 DISALLOW_COPY_AND_ASSIGN(ShellUtil); |
465 }; | 436 }; |
466 | 437 |
467 | 438 |
468 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 439 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
OLD | NEW |