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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 IS_DEFAULT, | 47 IS_DEFAULT, |
48 }; | 48 }; |
49 | 49 |
50 // Typical shortcut directories. Resolved in GetShortcutPath(). | 50 // Typical shortcut directories. Resolved in GetShortcutPath(). |
51 // Also used in ShortcutLocationIsSupported(). | 51 // Also used in ShortcutLocationIsSupported(). |
52 enum ShortcutLocation { | 52 enum ShortcutLocation { |
53 SHORTCUT_LOCATION_FIRST = 0, | 53 SHORTCUT_LOCATION_FIRST = 0, |
54 SHORTCUT_LOCATION_DESKTOP = SHORTCUT_LOCATION_FIRST, | 54 SHORTCUT_LOCATION_DESKTOP = SHORTCUT_LOCATION_FIRST, |
55 SHORTCUT_LOCATION_QUICK_LAUNCH, | 55 SHORTCUT_LOCATION_QUICK_LAUNCH, |
56 SHORTCUT_LOCATION_START_MENU_ROOT, | 56 SHORTCUT_LOCATION_START_MENU_ROOT, |
57 SHORTCUT_LOCATION_START_MENU_CHROME_DIR, | 57 SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED, // now placed in root |
58 SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, | 58 SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR, |
59 SHORTCUT_LOCATION_TASKBAR_PINS, // base::win::VERSION_WIN7 + | 59 SHORTCUT_LOCATION_TASKBAR_PINS, // base::win::VERSION_WIN7 + |
60 SHORTCUT_LOCATION_APP_SHORTCUTS, // base::win::VERSION_WIN8 + | 60 SHORTCUT_LOCATION_APP_SHORTCUTS, // base::win::VERSION_WIN8 + |
61 NUM_SHORTCUT_LOCATIONS | 61 NUM_SHORTCUT_LOCATIONS |
62 }; | 62 }; |
63 | 63 |
64 enum ShortcutOperation { | 64 enum ShortcutOperation { |
65 // Create a new shortcut (overwriting if necessary). | 65 // Create a new shortcut (overwriting if necessary). |
66 SHELL_SHORTCUT_CREATE_ALWAYS, | 66 SHELL_SHORTCUT_CREATE_ALWAYS, |
67 // Create the per-user shortcut only if its system-level equivalent (with | 67 // Create the per-user shortcut only if its system-level equivalent (with |
68 // the same name) is not present. | 68 // the same name) is not present. |
69 SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL, | 69 SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL, |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 304 |
305 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. | 305 // Returns true if |chrome_exe| is registered in HKLM with |suffix|. |
306 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and | 306 // Note: This only checks one deterministic key in HKLM for |chrome_exe| and |
307 // doesn't otherwise validate a full Chrome install in HKLM. | 307 // doesn't otherwise validate a full Chrome install in HKLM. |
308 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, | 308 static bool QuickIsChromeRegisteredInHKLM(BrowserDistribution* dist, |
309 const base::FilePath& chrome_exe, | 309 const base::FilePath& chrome_exe, |
310 const base::string16& suffix); | 310 const base::string16& suffix); |
311 | 311 |
312 // Returns true if the current Windows version supports the presence of | 312 // Returns true if the current Windows version supports the presence of |
313 // shortcuts at |location|. | 313 // shortcuts at |location|. |
314 static bool ShortcutLocationIsSupported(ShellUtil::ShortcutLocation location); | 314 static bool ShortcutLocationIsSupported(ShortcutLocation location); |
315 | 315 |
316 // Sets |path| to the path for a shortcut at the |location| desired for the | 316 // Sets |path| to the path for a shortcut at the |location| desired for the |
317 // given |level| (CURRENT_USER for per-user path and SYSTEM_LEVEL for | 317 // given |level| (CURRENT_USER for per-user path and SYSTEM_LEVEL for |
318 // all-users path). | 318 // all-users path). |
319 // Returns false on failure. | 319 // Returns false on failure. |
320 static bool GetShortcutPath(ShellUtil::ShortcutLocation location, | 320 static bool GetShortcutPath(ShortcutLocation location, |
321 BrowserDistribution* dist, | 321 BrowserDistribution* dist, |
322 ShellChange level, | 322 ShellChange level, |
323 base::FilePath* path); | 323 base::FilePath* path); |
324 | 324 |
| 325 // Move an existing shortcut from |old_location| to |new_location| for the |
| 326 // set |shortcut_level|. If the folder containing |old_location| is then |
| 327 // empty, it will be removed. |
| 328 static bool MoveExistingShortcut(ShortcutLocation old_location, |
| 329 ShortcutLocation new_location, |
| 330 BrowserDistribution* dist, |
| 331 const ShortcutProperties& properties); |
| 332 |
325 // Updates shortcut in |location| (or creates it if |options| specify | 333 // Updates shortcut in |location| (or creates it if |options| specify |
326 // SHELL_SHORTCUT_CREATE_ALWAYS). | 334 // SHELL_SHORTCUT_CREATE_ALWAYS). |
327 // |dist| gives the type of browser distribution currently in use. | 335 // |dist| gives the type of browser distribution currently in use. |
328 // |properties| and |operation| affect this method as described on their | 336 // |properties| and |operation| affect this method as described on their |
329 // invidividual definitions above. | 337 // invidividual definitions above. |
330 // |location| may be one of SHORTCUT_LOCATION_DESKTOP, | 338 // |location| may be one of SHORTCUT_LOCATION_DESKTOP, |
331 // SHORTCUT_LOCATION_QUICK_LAUNCH, SHORTCUT_LOCATION_START_MENU_ROOT, | 339 // SHORTCUT_LOCATION_QUICK_LAUNCH, SHORTCUT_LOCATION_START_MENU_ROOT, |
332 // SHORTCUT_LOCATION_START_MENU_CHROME_DIR, or | 340 // SHORTCUT_LOCATION_START_MENU_CHROME_DIR, or |
333 // SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR. | 341 // SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR. |
334 static bool CreateOrUpdateShortcut( | 342 static bool CreateOrUpdateShortcut( |
335 ShellUtil::ShortcutLocation location, | 343 ShortcutLocation location, |
336 BrowserDistribution* dist, | 344 BrowserDistribution* dist, |
337 const ShellUtil::ShortcutProperties& properties, | 345 const ShortcutProperties& properties, |
338 ShellUtil::ShortcutOperation operation); | 346 ShortcutOperation operation); |
339 | 347 |
340 // Returns the string "|icon_path|,|icon_index|" (see, for example, | 348 // Returns the string "|icon_path|,|icon_index|" (see, for example, |
341 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). | 349 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). |
342 static base::string16 FormatIconLocation(const base::FilePath& icon_path, | 350 static base::string16 FormatIconLocation(const base::FilePath& icon_path, |
343 int icon_index); | 351 int icon_index); |
344 | 352 |
345 // This method returns the command to open URLs/files using chrome. Typically | 353 // This method returns the command to open URLs/files using chrome. Typically |
346 // this command is written to the registry under shell\open\command key. | 354 // this command is written to the registry under shell\open\command key. |
347 // |chrome_exe|: the full path to chrome.exe | 355 // |chrome_exe|: the full path to chrome.exe |
348 static base::string16 GetChromeShellOpenCmd(const base::FilePath& chrome_exe); | 356 static base::string16 GetChromeShellOpenCmd(const base::FilePath& chrome_exe); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 bool elevate_if_not_admin); | 544 bool elevate_if_not_admin); |
537 | 545 |
538 // Removes installed shortcut(s) at |location|. | 546 // Removes installed shortcut(s) at |location|. |
539 // |level|: CURRENT_USER to remove per-user shortcuts, or SYSTEM_LEVEL to | 547 // |level|: CURRENT_USER to remove per-user shortcuts, or SYSTEM_LEVEL to |
540 // remove all-users shortcuts. | 548 // remove all-users shortcuts. |
541 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when | 549 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when |
542 // their target is |target_exe|. | 550 // their target is |target_exe|. |
543 // If |location| is a Chrome-specific folder, it will be deleted as well. | 551 // If |location| is a Chrome-specific folder, it will be deleted as well. |
544 // Returns true if all shortcuts pointing to |target_exe| are successfully | 552 // Returns true if all shortcuts pointing to |target_exe| are successfully |
545 // deleted, including the case where no such shortcuts are found. | 553 // deleted, including the case where no such shortcuts are found. |
546 static bool RemoveShortcuts(ShellUtil::ShortcutLocation location, | 554 static bool RemoveShortcuts(ShortcutLocation location, |
547 BrowserDistribution* dist, | 555 BrowserDistribution* dist, |
548 ShellChange level, | 556 ShellChange level, |
549 const base::FilePath& target_exe); | 557 const base::FilePath& target_exe); |
550 | 558 |
551 // Updates the target of all shortcuts in |location| that satisfy the | 559 // Updates the target of all shortcuts in |location| that satisfy the |
552 // following: | 560 // following: |
553 // - the shortcut's original target is |old_target_exe|, | 561 // - the shortcut's original target is |old_target_exe|, |
554 // - the original arguments are non-empty. | 562 // - the original arguments are non-empty. |
555 // If the shortcut's icon points to |old_target_exe|, then it also gets | 563 // If the shortcut's icon points to |old_target_exe|, then it also gets |
556 // redirected to |new_target_exe|. | 564 // redirected to |new_target_exe|. |
557 // Returns true if all updates to matching shortcuts are successful, including | 565 // Returns true if all updates to matching shortcuts are successful, including |
558 // the vacuous case where no matching shortcuts are found. | 566 // the vacuous case where no matching shortcuts are found. |
559 static bool RetargetShortcutsWithArgs( | 567 static bool RetargetShortcutsWithArgs( |
560 ShellUtil::ShortcutLocation location, | 568 ShortcutLocation location, |
561 BrowserDistribution* dist, | 569 BrowserDistribution* dist, |
562 ShellChange level, | 570 ShellChange level, |
563 const base::FilePath& old_target_exe, | 571 const base::FilePath& old_target_exe, |
564 const base::FilePath& new_target_exe); | 572 const base::FilePath& new_target_exe); |
565 | 573 |
566 typedef base::RefCountedData<base::CancellationFlag> SharedCancellationFlag; | 574 typedef base::RefCountedData<base::CancellationFlag> SharedCancellationFlag; |
567 | 575 |
568 // Appends Chrome shortcuts with non-whitelisted arguments to |shortcuts| if | 576 // Appends Chrome shortcuts with non-whitelisted arguments to |shortcuts| if |
569 // not NULL. If |do_removal|, also removes non-whitelisted arguments from | 577 // not NULL. If |do_removal|, also removes non-whitelisted arguments from |
570 // those shortcuts. This method will abort and return false if |cancel| is | 578 // those shortcuts. This method will abort and return false if |cancel| is |
571 // non-NULL and gets set at any point during this call. | 579 // non-NULL and gets set at any point during this call. |
572 static bool ShortcutListMaybeRemoveUnknownArgs( | 580 static bool ShortcutListMaybeRemoveUnknownArgs( |
573 ShellUtil::ShortcutLocation location, | 581 ShortcutLocation location, |
574 BrowserDistribution* dist, | 582 BrowserDistribution* dist, |
575 ShellChange level, | 583 ShellChange level, |
576 const base::FilePath& chrome_exe, | 584 const base::FilePath& chrome_exe, |
577 bool do_removal, | 585 bool do_removal, |
578 const scoped_refptr<SharedCancellationFlag>& cancel, | 586 const scoped_refptr<SharedCancellationFlag>& cancel, |
579 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts); | 587 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts); |
580 | 588 |
581 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid | 589 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid |
582 // preceded by a dot. | 590 // preceded by a dot. |
583 // This is guaranteed to be unique on the machine and 27 characters long | 591 // This is guaranteed to be unique on the machine and 27 characters long |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 // application, as given to AddFileAssociations. All information associated | 647 // application, as given to AddFileAssociations. All information associated |
640 // with this name will be deleted. | 648 // with this name will be deleted. |
641 static bool DeleteFileAssociations(const base::string16& prog_id); | 649 static bool DeleteFileAssociations(const base::string16& prog_id); |
642 | 650 |
643 private: | 651 private: |
644 DISALLOW_COPY_AND_ASSIGN(ShellUtil); | 652 DISALLOW_COPY_AND_ASSIGN(ShellUtil); |
645 }; | 653 }; |
646 | 654 |
647 | 655 |
648 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 656 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
OLD | NEW |