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_ |
11 | 11 |
12 #include <windows.h> | 12 #include <windows.h> |
13 | 13 |
14 #include <map> | 14 #include <map> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/string16.h" | 20 #include "base/string16.h" |
21 #include "chrome/installer/util/work_item_list.h" | 21 #include "chrome/installer/util/work_item_list.h" |
22 | 22 |
23 class BrowserDistribution; | 23 class BrowserDistribution; |
24 | 24 |
25 namespace base { | |
26 namespace win { | |
27 struct ShortcutProperties; | |
28 } // namespace win | |
29 } // namespace base | |
30 | |
25 // This is a utility class that provides common shell integration methods | 31 // This is a utility class that provides common shell integration methods |
26 // that can be used by installer as well as Chrome. | 32 // that can be used by installer as well as Chrome. |
27 class ShellUtil { | 33 class ShellUtil { |
28 public: | 34 public: |
29 // Input to any methods that make changes to OS shell. | 35 // Input to any methods that make changes to OS shell. |
30 enum ShellChange { | 36 enum ShellChange { |
31 CURRENT_USER = 0x1, // Make any shell changes only at the user level | 37 CURRENT_USER = 0x1, // Make any shell changes only at the user level |
32 SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level | 38 SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level |
33 }; | 39 }; |
34 | 40 |
35 // Chrome's default handler state for a given protocol. | 41 // Chrome's default handler state for a given protocol. |
36 enum DefaultState { | 42 enum DefaultState { |
37 UNKNOWN_DEFAULT, | 43 UNKNOWN_DEFAULT, |
38 NOT_DEFAULT, | 44 NOT_DEFAULT, |
39 IS_DEFAULT, | 45 IS_DEFAULT, |
40 }; | 46 }; |
41 | 47 |
42 // Typical shortcut directories. Resolved in GetShortcutPath(). | 48 // Typical shortcut directories. Resolved in GetShortcutPath(). |
49 // Also used in ShortcutLocationIsSupported(). | |
43 enum ShortcutLocation { | 50 enum ShortcutLocation { |
44 SHORTCUT_LOCATION_DESKTOP, | 51 SHORTCUT_LOCATION_DESKTOP, |
45 SHORTCUT_LOCATION_QUICK_LAUNCH, | 52 SHORTCUT_LOCATION_QUICK_LAUNCH, |
46 SHORTCUT_LOCATION_START_MENU, | 53 SHORTCUT_LOCATION_START_MENU, |
54 SHORTCUT_LOCATION_TASKBAR_PINS, // base::win::VERSION_WIN7 + | |
55 SHORTCUT_LOCATION_APP_SHORTCUTS, // base::win::VERSION_WIN8 + | |
47 }; | 56 }; |
48 | 57 |
49 enum ShortcutOperation { | 58 enum ShortcutOperation { |
50 // Create a new shortcut (overwriting if necessary). | 59 // Create a new shortcut (overwriting if necessary). |
51 SHELL_SHORTCUT_CREATE_ALWAYS, | 60 SHELL_SHORTCUT_CREATE_ALWAYS, |
52 // Create the per-user shortcut only if its system-level equivalent (with | 61 // Create the per-user shortcut only if its system-level equivalent (with |
53 // the same name) is not present. | 62 // the same name) is not present. |
54 SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL, | 63 SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL, |
55 // Overwrite an existing shortcut (fail if the shortcut doesn't exist). | 64 // 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 | 65 // 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. | 296 // Registry value name for the OpenWithProgids entry for file associations. |
288 static const wchar_t* kRegOpenWithProgids; | 297 static const wchar_t* kRegOpenWithProgids; |
289 | 298 |
290 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. | 299 // 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 | 300 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and |
292 // doesn't otherwise validate a full Chrome install in HKLM. | 301 // doesn't otherwise validate a full Chrome install in HKLM. |
293 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 302 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
294 const string16& chrome_exe, | 303 const string16& chrome_exe, |
295 const string16& suffix); | 304 const string16& suffix); |
296 | 305 |
306 // Returns true if the current Windows version supports the presence of | |
307 // shortcuts at |location|. | |
308 static bool ShortcutLocationIsSupported(ShellUtil::ShortcutLocation location); | |
309 | |
297 // Sets |path| to the path for a shortcut at the |location| desired for the | 310 // 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 | 311 // given |level| (CURRENT_USER for per-user path and SYSTEM_LEVEL for |
299 // all-users path). | 312 // all-users path). |
300 // Returns false on failure. | 313 // Returns false on failure. |
301 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, | 314 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, |
302 BrowserDistribution* dist, | 315 BrowserDistribution* dist, |
303 ShellChange level, | 316 ShellChange level, |
304 base::FilePath* path); | 317 base::FilePath* path); |
305 | 318 |
306 // Updates shortcut in |location| (or creates it if |options| specify | 319 // Updates shortcut in |location| (or creates it if |options| specify |
307 // SHELL_SHORTCUT_CREATE_ALWAYS). | 320 // SHELL_SHORTCUT_CREATE_ALWAYS). |
308 // |dist| gives the type of browser distribution currently in use. | 321 // |dist| gives the type of browser distribution currently in use. |
309 // |properties| and |operation| affect this method as described on their | 322 // |properties| and |operation| affect this method as described on their |
310 // invidividual definitions above. | 323 // invidividual definitions above. |
324 // |location| may be one of SHORTCUT_LOCATION_DESKTOP, | |
325 // SHORTCUT_LOCATION_QUICK_LAUNCH, or SHORTCUT_LOCATION_START_MENU. | |
311 static bool CreateOrUpdateShortcut( | 326 static bool CreateOrUpdateShortcut( |
312 ShellUtil::ShortcutLocation location, | 327 ShellUtil::ShortcutLocation location, |
313 BrowserDistribution* dist, | 328 BrowserDistribution* dist, |
314 const ShellUtil::ShortcutProperties& properties, | 329 const ShellUtil::ShortcutProperties& properties, |
315 ShellUtil::ShortcutOperation operation); | 330 ShellUtil::ShortcutOperation operation); |
316 | 331 |
317 // Returns the string "|icon_path|,|icon_index|" (see, for example, | 332 // Returns the string "|icon_path|,|icon_index|" (see, for example, |
318 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). | 333 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). |
319 static string16 FormatIconLocation(const string16& icon_path, int icon_index); | 334 static string16 FormatIconLocation(const string16& icon_path, int icon_index); |
320 | 335 |
(...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 | 506 // |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 | 507 // |elevate_if_not_admin| if true will make this method try alternate methods |
493 // as described above. | 508 // as described above. |
494 static bool RegisterChromeForProtocol(BrowserDistribution* dist, | 509 static bool RegisterChromeForProtocol(BrowserDistribution* dist, |
495 const string16& chrome_exe, | 510 const string16& chrome_exe, |
496 const string16& unique_suffix, | 511 const string16& unique_suffix, |
497 const string16& protocol, | 512 const string16& protocol, |
498 bool elevate_if_not_admin); | 513 bool elevate_if_not_admin); |
499 | 514 |
500 // Removes installed shortcut(s) at |location|. | 515 // Removes installed shortcut(s) at |location|. |
516 // |level|: CURRENT_USER to remove per-user shortcuts, or SYSTEM_LEVEL to | |
517 // remove all-users shortcuts. | |
501 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when | 518 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when |
502 // their target is |target_exe|. | 519 // 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 | 520 // If |location| is SHORTCUT_LOCATION_START_MENU, the shortcut folder specific |
508 // to |dist| is deleted. | 521 // to |dist| is deleted. |
509 // Also attempts to unpin the removed shortcut(s) from the taskbar. | 522 // Also attempts to unpin the removed shortcut(s) from the taskbar. |
gab
2013/05/02 19:20:50
This part is no longer true.
huangs
2013/05/02 20:48:02
Deleted.
| |
510 // Returns true if the shortcut(s) were successfully deleted (or there were | 523 // Returns true if all shortcuts are successfully deleted, including the |
511 // none at |location| pointing to |target_exe|). | 524 // vacuous case no shortcuts are found. |
gab
2013/05/02 19:20:50
// Returns true if all shortcuts pointing to |targ
huangs
2013/05/02 20:48:02
Done.
| |
512 static bool RemoveShortcut(ShellUtil::ShortcutLocation location, | 525 static bool RemoveShortcuts(ShellUtil::ShortcutLocation location, |
513 BrowserDistribution* dist, | 526 BrowserDistribution* dist, |
514 const base::FilePath& target_exe, | 527 ShellChange level, |
515 ShellChange level, | 528 const base::FilePath& target_exe); |
516 const string16* shortcut_name); | |
517 | 529 |
518 // Enumerates all shortcuts pinned to the taskbar and deletes those pointing | 530 // Iterates over all shortcuts at |location| that targets |target_exe|, |
519 // to |target_exe|. | 531 // and applies update via |shortcut_properties|. |
520 // base::win::TaskbarUnpinShortcutLink() should be prefered, but this is | 532 // Returns true if all shortcuts are successfully updated, including the |
521 // useful on uninstall as the parent shortcut of a pin might no longer exist | 533 // vacuous case no shortcuts are found. |
gab
2013/05/02 19:20:50
I'd suggest:
// Returns true if all shortcuts poin
huangs
2013/05/02 20:48:02
Done.
| |
522 // (thus making it impossible to unpin it via that API). | 534 static bool UpdateShortcuts( |
523 static void RemoveTaskbarShortcuts(const string16& target_exe); | 535 ShellUtil::ShortcutLocation location, |
524 | 536 BrowserDistribution* dist, |
525 // This will remove all secondary tiles from the start screen for |dist|. | 537 ShellChange level, |
526 static void RemoveStartScreenShortcuts(BrowserDistribution* dist, | 538 const base::FilePath& target_exe, |
527 const string16& target_exe); | 539 const base::win::ShortcutProperties& shortcut_properties); |
gab
2013/05/02 19:20:50
Use a ShellUtil::ShortcutProperties and use Transl
huangs
2013/05/02 20:48:02
Done. Doing translation only once in UpdateShortc
gab
2013/05/02 21:23:59
Indeed :)!
| |
528 | 540 |
529 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid | 541 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid |
530 // preceded by a dot. | 542 // preceded by a dot. |
531 // This is guaranteed to be unique on the machine and 27 characters long | 543 // This is guaranteed to be unique on the machine and 27 characters long |
532 // (including the '.'). | 544 // (including the '.'). |
533 // This suffix is then meant to be added to all registration that may conflict | 545 // This suffix is then meant to be added to all registration that may conflict |
534 // with another user-level Chrome install. | 546 // with another user-level Chrome install. |
535 // Note that prior to Chrome 21, the suffix registered used to be the user's | 547 // Note that prior to Chrome 21, the suffix registered used to be the user's |
536 // username (see GetOldUserSpecificRegistrySuffix() below). We still honor old | 548 // username (see GetOldUserSpecificRegistrySuffix() below). We still honor old |
537 // installs registered that way, but it was wrong because some of the | 549 // 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 | 567 // required by the base32 standard for inputs that aren't a multiple of 5 |
556 // bytes. | 568 // bytes. |
557 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); | 569 static string16 ByteArrayToBase32(const uint8* bytes, size_t size); |
558 | 570 |
559 private: | 571 private: |
560 DISALLOW_COPY_AND_ASSIGN(ShellUtil); | 572 DISALLOW_COPY_AND_ASSIGN(ShellUtil); |
561 }; | 573 }; |
562 | 574 |
563 | 575 |
564 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 576 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
OLD | NEW |