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 22 matching lines...) Expand all Loading... |
33 }; | 33 }; |
34 | 34 |
35 // Chrome's default handler state for a given protocol. | 35 // Chrome's default handler state for a given protocol. |
36 enum DefaultState { | 36 enum DefaultState { |
37 UNKNOWN_DEFAULT, | 37 UNKNOWN_DEFAULT, |
38 NOT_DEFAULT, | 38 NOT_DEFAULT, |
39 IS_DEFAULT, | 39 IS_DEFAULT, |
40 }; | 40 }; |
41 | 41 |
42 // Typical shortcut directories. Resolved in GetShortcutPath(). | 42 // Typical shortcut directories. Resolved in GetShortcutPath(). |
| 43 // Also used in ShortcutLocationIsSupported(). |
43 enum ShortcutLocation { | 44 enum ShortcutLocation { |
44 SHORTCUT_LOCATION_DESKTOP, | 45 SHORTCUT_LOCATION_DESKTOP, |
45 SHORTCUT_LOCATION_QUICK_LAUNCH, | 46 SHORTCUT_LOCATION_QUICK_LAUNCH, |
46 SHORTCUT_LOCATION_START_MENU, | 47 SHORTCUT_LOCATION_START_MENU, |
| 48 SHORTCUT_LOCATION_TASKBAR_PINS, // base::win::VERSION_WIN7 + |
| 49 SHORTCUT_LOCATION_APP_SHORTCUTS, // base::win::VERSION_WIN8 + |
47 }; | 50 }; |
48 | 51 |
49 enum ShortcutOperation { | 52 enum ShortcutOperation { |
50 // Create a new shortcut (overwriting if necessary). | 53 // Create a new shortcut (overwriting if necessary). |
51 SHELL_SHORTCUT_CREATE_ALWAYS, | 54 SHELL_SHORTCUT_CREATE_ALWAYS, |
52 // Create the per-user shortcut only if its system-level equivalent (with | 55 // Create the per-user shortcut only if its system-level equivalent (with |
53 // the same name) is not present. | 56 // the same name) is not present. |
54 SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL, | 57 SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL, |
55 // Overwrite an existing shortcut (fail if the shortcut doesn't exist). | 58 // Overwrite an existing shortcut (fail if the shortcut doesn't exist). |
56 // If the arguments are not specified on the new shortcut, keep the old | 59 // If the arguments are not specified on the new shortcut, keep the old |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // Registry value name for the OpenWithProgids entry for file associations. | 290 // Registry value name for the OpenWithProgids entry for file associations. |
288 static const wchar_t* kRegOpenWithProgids; | 291 static const wchar_t* kRegOpenWithProgids; |
289 | 292 |
290 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. | 293 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. |
291 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and | 294 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and |
292 // doesn't otherwise validate a full Chrome install in HKLM. | 295 // doesn't otherwise validate a full Chrome install in HKLM. |
293 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 296 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
294 const string16& chrome_exe, | 297 const string16& chrome_exe, |
295 const string16& suffix); | 298 const string16& suffix); |
296 | 299 |
| 300 // Returns true if the current Windows version supports the presence of |
| 301 // shortcuts at |location|. |
| 302 static bool ShortcutLocationIsSupported(ShellUtil::ShortcutLocation location); |
| 303 |
297 // Sets |path| to the path for a shortcut at the |location| desired for the | 304 // Sets |path| to the path for a shortcut at the |location| desired for the |
298 // given |level| (CURRENT_USER for per-user path and SYSTEM_LEVEL for | 305 // given |level| (CURRENT_USER for per-user path and SYSTEM_LEVEL for |
299 // all-users path). | 306 // all-users path). |
300 // Returns false on failure. | 307 // Returns false on failure. |
301 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, | 308 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, |
302 BrowserDistribution* dist, | 309 BrowserDistribution* dist, |
303 ShellChange level, | 310 ShellChange level, |
304 base::FilePath* path); | 311 base::FilePath* path); |
305 | 312 |
306 // Updates shortcut in |location| (or creates it if |options| specify | 313 // Updates shortcut in |location| (or creates it if |options| specify |
307 // SHELL_SHORTCUT_CREATE_ALWAYS). | 314 // SHELL_SHORTCUT_CREATE_ALWAYS). |
308 // |dist| gives the type of browser distribution currently in use. | 315 // |dist| gives the type of browser distribution currently in use. |
309 // |properties| and |operation| affect this method as described on their | 316 // |properties| and |operation| affect this method as described on their |
310 // invidividual definitions above. | 317 // invidividual definitions above. |
| 318 // |location| may be one of SHORTCUT_LOCATION_DESKTOP, |
| 319 // SHORTCUT_LOCATION_QUICK_LAUNCH, or SHORTCUT_LOCATION_START_MENU. |
311 static bool CreateOrUpdateShortcut( | 320 static bool CreateOrUpdateShortcut( |
312 ShellUtil::ShortcutLocation location, | 321 ShellUtil::ShortcutLocation location, |
313 BrowserDistribution* dist, | 322 BrowserDistribution* dist, |
314 const ShellUtil::ShortcutProperties& properties, | 323 const ShellUtil::ShortcutProperties& properties, |
315 ShellUtil::ShortcutOperation operation); | 324 ShellUtil::ShortcutOperation operation); |
316 | 325 |
317 // Returns the string "|icon_path|,|icon_index|" (see, for example, | 326 // Returns the string "|icon_path|,|icon_index|" (see, for example, |
318 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). | 327 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). |
319 static string16 FormatIconLocation(const string16& icon_path, int icon_index); | 328 static string16 FormatIconLocation(const string16& icon_path, int icon_index); |
320 | 329 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // |protocol| The protocol to register as being capable of handling.s | 500 // |protocol| The protocol to register as being capable of handling.s |
492 // |elevate_if_not_admin| if true will make this method try alternate methods | 501 // |elevate_if_not_admin| if true will make this method try alternate methods |
493 // as described above. | 502 // as described above. |
494 static bool RegisterChromeForProtocol(BrowserDistribution* dist, | 503 static bool RegisterChromeForProtocol(BrowserDistribution* dist, |
495 const string16& chrome_exe, | 504 const string16& chrome_exe, |
496 const string16& unique_suffix, | 505 const string16& unique_suffix, |
497 const string16& protocol, | 506 const string16& protocol, |
498 bool elevate_if_not_admin); | 507 bool elevate_if_not_admin); |
499 | 508 |
500 // Removes installed shortcut(s) at |location|. | 509 // Removes installed shortcut(s) at |location|. |
| 510 // |level|: CURRENT_USER to remove per-user shortcuts, or SYSTEM_LEVEL to |
| 511 // remove all-users shortcuts. |
501 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when | 512 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when |
502 // their target is |target_exe|. | 513 // their target is |target_exe|. |
503 // |level|: CURRENT_USER to remove the per-user shortcut and SYSTEM_LEVEL to | |
504 // remove the all-users shortcut. | |
505 // |shortcut_name|: If non-null, remove the shortcut named |shortcut_name| at | |
506 // location; otherwise remove all shortcuts to |target_exe| at |location|. | |
507 // If |location| is SHORTCUT_LOCATION_START_MENU, the shortcut folder specific | 514 // If |location| is SHORTCUT_LOCATION_START_MENU, the shortcut folder specific |
508 // to |dist| is deleted. | 515 // to |dist| is deleted. |
509 // Also attempts to unpin the removed shortcut(s) from the taskbar. | 516 // Returns true if all shortcuts pointing to |target_exe| are successfully |
510 // Returns true if the shortcut(s) were successfully deleted (or there were | 517 // deleted, including the case where no such shortcuts are found. |
511 // none at |location| pointing to |target_exe|). | 518 static bool RemoveShortcuts(ShellUtil::ShortcutLocation location, |
512 static bool RemoveShortcut(ShellUtil::ShortcutLocation location, | 519 BrowserDistribution* dist, |
513 BrowserDistribution* dist, | 520 ShellChange level, |
514 const base::FilePath& target_exe, | 521 const base::FilePath& target_exe); |
515 ShellChange level, | |
516 const string16* shortcut_name); | |
517 | 522 |
518 // Enumerates all shortcuts pinned to the taskbar and deletes those pointing | 523 // Iterates over all shortcuts at |location| that targets |target_exe|, |
519 // to |target_exe|. | 524 // and applies update via |shortcut_properties|. |
520 // base::win::TaskbarUnpinShortcutLink() should be prefered, but this is | 525 // Returns true if all shortcuts pointing to |target_exe| are successfully |
521 // useful on uninstall as the parent shortcut of a pin might no longer exist | 526 // updated, including the case where no such shortcuts are found. |
522 // (thus making it impossible to unpin it via that API). | 527 static bool UpdateShortcuts( |
523 static void RemoveTaskbarShortcuts(const string16& target_exe); | 528 ShellUtil::ShortcutLocation location, |
524 | 529 BrowserDistribution* dist, |
525 // This will remove all secondary tiles from the start screen for |dist|. | 530 ShellChange level, |
526 static void RemoveStartScreenShortcuts(BrowserDistribution* dist, | 531 const base::FilePath& target_exe, |
527 const string16& target_exe); | 532 const ShellUtil::ShortcutProperties& properties); |
528 | 533 |
529 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid | 534 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid |
530 // preceded by a dot. | 535 // preceded by a dot. |
531 // This is guaranteed to be unique on the machine and 27 characters long | 536 // This is guaranteed to be unique on the machine and 27 characters long |
532 // (including the '.'). | 537 // (including the '.'). |
533 // This suffix is then meant to be added to all registration that may conflict | 538 // This suffix is then meant to be added to all registration that may conflict |
534 // with another user-level Chrome install. | 539 // with another user-level Chrome install. |
535 // Note that prior to Chrome 21, the suffix registered used to be the user's | 540 // Note that prior to Chrome 21, the suffix registered used to be the user's |
536 // username (see GetOldUserSpecificRegistrySuffix() below). We still honor old | 541 // username (see GetOldUserSpecificRegistrySuffix() below). We still honor old |
537 // installs registered that way, but it was wrong because some of the | 542 // installs registered that way, but it was wrong because some of the |
(...skipping 17 matching lines...) Expand all Loading... |
555 // required by the base32 standard for inputs that aren't a multiple of 5 | 560 // required by the base32 standard for inputs that aren't a multiple of 5 |
556 // bytes. | 561 // bytes. |
557 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); | 562 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); |
558 | 563 |
559 private: | 564 private: |
560 DISALLOW_COPY_AND_ASSIGN(ShellUtil); | 565 DISALLOW_COPY_AND_ASSIGN(ShellUtil); |
561 }; | 566 }; |
562 | 567 |
563 | 568 |
564 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 569 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
OLD | NEW |