Chromium Code Reviews| 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 |
| (...skipping 236 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( | |
|
grt (UTC plus 2)
2015/10/20 18:10:30
formatting nit:
static bool MoveExistingShortcut
bcwhite
2015/10/20 18:25:43
Done.
gab
2015/10/20 18:25:59
Sounds like running "git cl format" will fix a few
bcwhite
2015/10/20 19:03:12
Done.
| |
| 329 ShortcutLocation old_location, | |
| 330 ShortcutLocation new_location, | |
| 331 BrowserDistribution* dist, | |
| 332 const ShortcutProperties& properties); | |
| 333 | |
| 325 // Updates shortcut in |location| (or creates it if |options| specify | 334 // Updates shortcut in |location| (or creates it if |options| specify |
| 326 // SHELL_SHORTCUT_CREATE_ALWAYS). | 335 // SHELL_SHORTCUT_CREATE_ALWAYS). |
| 327 // |dist| gives the type of browser distribution currently in use. | 336 // |dist| gives the type of browser distribution currently in use. |
| 328 // |properties| and |operation| affect this method as described on their | 337 // |properties| and |operation| affect this method as described on their |
| 329 // invidividual definitions above. | 338 // invidividual definitions above. |
| 330 // |location| may be one of SHORTCUT_LOCATION_DESKTOP, | 339 // |location| may be one of SHORTCUT_LOCATION_DESKTOP, |
| 331 // SHORTCUT_LOCATION_QUICK_LAUNCH, SHORTCUT_LOCATION_START_MENU_ROOT, | 340 // SHORTCUT_LOCATION_QUICK_LAUNCH, SHORTCUT_LOCATION_START_MENU_ROOT, |
| 332 // SHORTCUT_LOCATION_START_MENU_CHROME_DIR, or | 341 // SHORTCUT_LOCATION_START_MENU_CHROME_DIR, or |
| 333 // SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR. | 342 // SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR. |
| 334 static bool CreateOrUpdateShortcut( | 343 static bool CreateOrUpdateShortcut( |
| 335 ShellUtil::ShortcutLocation location, | 344 ShortcutLocation location, |
| 336 BrowserDistribution* dist, | 345 BrowserDistribution* dist, |
| 337 const ShellUtil::ShortcutProperties& properties, | 346 const ShortcutProperties& properties, |
| 338 ShellUtil::ShortcutOperation operation); | 347 ShortcutOperation operation); |
| 339 | 348 |
| 340 // Returns the string "|icon_path|,|icon_index|" (see, for example, | 349 // Returns the string "|icon_path|,|icon_index|" (see, for example, |
| 341 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). | 350 // http://msdn.microsoft.com/library/windows/desktop/dd391573.aspx). |
| 342 static base::string16 FormatIconLocation(const base::FilePath& icon_path, | 351 static base::string16 FormatIconLocation(const base::FilePath& icon_path, |
| 343 int icon_index); | 352 int icon_index); |
| 344 | 353 |
| 345 // This method returns the command to open URLs/files using chrome. Typically | 354 // 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. | 355 // this command is written to the registry under shell\open\command key. |
| 347 // |chrome_exe|: the full path to chrome.exe | 356 // |chrome_exe|: the full path to chrome.exe |
| 348 static base::string16 GetChromeShellOpenCmd(const base::FilePath& chrome_exe); | 357 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); | 545 bool elevate_if_not_admin); |
| 537 | 546 |
| 538 // Removes installed shortcut(s) at |location|. | 547 // Removes installed shortcut(s) at |location|. |
| 539 // |level|: CURRENT_USER to remove per-user shortcuts, or SYSTEM_LEVEL to | 548 // |level|: CURRENT_USER to remove per-user shortcuts, or SYSTEM_LEVEL to |
| 540 // remove all-users shortcuts. | 549 // remove all-users shortcuts. |
| 541 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when | 550 // |target_exe|: Shortcut target exe; shortcuts will only be deleted when |
| 542 // their target is |target_exe|. | 551 // their target is |target_exe|. |
| 543 // If |location| is a Chrome-specific folder, it will be deleted as well. | 552 // 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 | 553 // Returns true if all shortcuts pointing to |target_exe| are successfully |
| 545 // deleted, including the case where no such shortcuts are found. | 554 // deleted, including the case where no such shortcuts are found. |
| 546 static bool RemoveShortcuts(ShellUtil::ShortcutLocation location, | 555 static bool RemoveShortcuts(ShortcutLocation location, |
| 547 BrowserDistribution* dist, | 556 BrowserDistribution* dist, |
| 548 ShellChange level, | 557 ShellChange level, |
| 549 const base::FilePath& target_exe); | 558 const base::FilePath& target_exe); |
| 550 | 559 |
| 551 // Updates the target of all shortcuts in |location| that satisfy the | 560 // Updates the target of all shortcuts in |location| that satisfy the |
| 552 // following: | 561 // following: |
| 553 // - the shortcut's original target is |old_target_exe|, | 562 // - the shortcut's original target is |old_target_exe|, |
| 554 // - the original arguments are non-empty. | 563 // - the original arguments are non-empty. |
| 555 // If the shortcut's icon points to |old_target_exe|, then it also gets | 564 // If the shortcut's icon points to |old_target_exe|, then it also gets |
| 556 // redirected to |new_target_exe|. | 565 // redirected to |new_target_exe|. |
| 557 // Returns true if all updates to matching shortcuts are successful, including | 566 // Returns true if all updates to matching shortcuts are successful, including |
| 558 // the vacuous case where no matching shortcuts are found. | 567 // the vacuous case where no matching shortcuts are found. |
| 559 static bool RetargetShortcutsWithArgs( | 568 static bool RetargetShortcutsWithArgs( |
| 560 ShellUtil::ShortcutLocation location, | 569 ShortcutLocation location, |
| 561 BrowserDistribution* dist, | 570 BrowserDistribution* dist, |
| 562 ShellChange level, | 571 ShellChange level, |
| 563 const base::FilePath& old_target_exe, | 572 const base::FilePath& old_target_exe, |
| 564 const base::FilePath& new_target_exe); | 573 const base::FilePath& new_target_exe); |
| 565 | 574 |
| 566 typedef base::RefCountedData<base::CancellationFlag> SharedCancellationFlag; | 575 typedef base::RefCountedData<base::CancellationFlag> SharedCancellationFlag; |
| 567 | 576 |
| 568 // Appends Chrome shortcuts with non-whitelisted arguments to |shortcuts| if | 577 // Appends Chrome shortcuts with non-whitelisted arguments to |shortcuts| if |
| 569 // not NULL. If |do_removal|, also removes non-whitelisted arguments from | 578 // not NULL. If |do_removal|, also removes non-whitelisted arguments from |
| 570 // those shortcuts. This method will abort and return false if |cancel| is | 579 // those shortcuts. This method will abort and return false if |cancel| is |
| 571 // non-NULL and gets set at any point during this call. | 580 // non-NULL and gets set at any point during this call. |
| 572 static bool ShortcutListMaybeRemoveUnknownArgs( | 581 static bool ShortcutListMaybeRemoveUnknownArgs( |
| 573 ShellUtil::ShortcutLocation location, | 582 ShortcutLocation location, |
| 574 BrowserDistribution* dist, | 583 BrowserDistribution* dist, |
| 575 ShellChange level, | 584 ShellChange level, |
| 576 const base::FilePath& chrome_exe, | 585 const base::FilePath& chrome_exe, |
| 577 bool do_removal, | 586 bool do_removal, |
| 578 const scoped_refptr<SharedCancellationFlag>& cancel, | 587 const scoped_refptr<SharedCancellationFlag>& cancel, |
| 579 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts); | 588 std::vector<std::pair<base::FilePath, base::string16> >* shortcuts); |
| 580 | 589 |
| 581 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid | 590 // Sets |suffix| to the base 32 encoding of the md5 hash of this user's sid |
| 582 // preceded by a dot. | 591 // preceded by a dot. |
| 583 // This is guaranteed to be unique on the machine and 27 characters long | 592 // 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 | 648 // application, as given to AddFileAssociations. All information associated |
| 640 // with this name will be deleted. | 649 // with this name will be deleted. |
| 641 static bool DeleteFileAssociations(const base::string16& prog_id); | 650 static bool DeleteFileAssociations(const base::string16& prog_id); |
| 642 | 651 |
| 643 private: | 652 private: |
| 644 DISALLOW_COPY_AND_ASSIGN(ShellUtil); | 653 DISALLOW_COPY_AND_ASSIGN(ShellUtil); |
| 645 }; | 654 }; |
| 646 | 655 |
| 647 | 656 |
| 648 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ | 657 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
| OLD | NEW |