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 defines functions that integrate Chrome in Windows shell. These | 5 // This file defines functions that integrate Chrome in Windows shell. These |
| 6 // functions can be used by Chrome as well as Chrome installer. All of the | 6 // functions can be used by Chrome as well as Chrome installer. All of the |
| 7 // work is done by the local functions defined in anonymous namespace in | 7 // work is done by the local functions defined in anonymous namespace in |
| 8 // this class. | 8 // this class. |
| 9 | 9 |
| 10 #include "chrome/installer/util/shell_util.h" | 10 #include "chrome/installer/util/shell_util.h" |
| (...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 } | 1566 } |
| 1567 | 1567 |
| 1568 | 1568 |
| 1569 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. | 1569 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. |
| 1570 // Otherwise do nothing. Returns true on success, including the vacuous case | 1570 // Otherwise do nothing. Returns true on success, including the vacuous case |
| 1571 // where no deletion occurred because directory is non-empty. | 1571 // where no deletion occurred because directory is non-empty. |
| 1572 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, | 1572 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, |
| 1573 BrowserDistribution* dist, | 1573 BrowserDistribution* dist, |
| 1574 ShellUtil::ShellChange level) { | 1574 ShellUtil::ShellChange level) { |
| 1575 // Explicitly whitelist locations, since accidental calls can be very harmful. | 1575 // Explicitly whitelist locations, since accidental calls can be very harmful. |
| 1576 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR && | 1576 if (location != |
| 1577 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED && | |
| 1577 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && | 1578 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && |
| 1578 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { | 1579 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { |
| 1579 NOTREACHED(); | 1580 NOTREACHED(); |
| 1580 return false; | 1581 return false; |
| 1581 } | 1582 } |
| 1582 | 1583 |
| 1583 base::FilePath shortcut_folder; | 1584 base::FilePath shortcut_folder; |
| 1584 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | 1585 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
| 1585 LOG(WARNING) << "Cannot find path at location " << location; | 1586 LOG(WARNING) << "Cannot find path at location " << location; |
| 1586 return false; | 1587 return false; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1653 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
| 1653 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1654 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
| 1654 } | 1655 } |
| 1655 | 1656 |
| 1656 bool ShellUtil::ShortcutLocationIsSupported( | 1657 bool ShellUtil::ShortcutLocationIsSupported( |
| 1657 ShellUtil::ShortcutLocation location) { | 1658 ShellUtil::ShortcutLocation location) { |
| 1658 switch (location) { | 1659 switch (location) { |
| 1659 case SHORTCUT_LOCATION_DESKTOP: // Falls through. | 1660 case SHORTCUT_LOCATION_DESKTOP: // Falls through. |
| 1660 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. | 1661 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. |
| 1661 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. | 1662 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. |
| 1662 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through. | 1663 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: // Falls through. |
| 1663 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | 1664 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
| 1664 return true; | 1665 return true; |
| 1665 case SHORTCUT_LOCATION_TASKBAR_PINS: | 1666 case SHORTCUT_LOCATION_TASKBAR_PINS: |
| 1666 return base::win::GetVersion() >= base::win::VERSION_WIN7; | 1667 return base::win::GetVersion() >= base::win::VERSION_WIN7; |
| 1667 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1668 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
| 1668 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 1669 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
| 1669 default: | 1670 default: |
| 1670 NOTREACHED(); | 1671 NOTREACHED(); |
| 1671 return false; | 1672 return false; |
| 1672 } | 1673 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1686 break; | 1687 break; |
| 1687 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1688 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
| 1688 // There is no support for a system-level Quick Launch shortcut. | 1689 // There is no support for a system-level Quick Launch shortcut. |
| 1689 DCHECK_EQ(level, CURRENT_USER); | 1690 DCHECK_EQ(level, CURRENT_USER); |
| 1690 dir_key = base::DIR_USER_QUICK_LAUNCH; | 1691 dir_key = base::DIR_USER_QUICK_LAUNCH; |
| 1691 break; | 1692 break; |
| 1692 case SHORTCUT_LOCATION_START_MENU_ROOT: | 1693 case SHORTCUT_LOCATION_START_MENU_ROOT: |
| 1693 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1694 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1694 base::DIR_COMMON_START_MENU; | 1695 base::DIR_COMMON_START_MENU; |
| 1695 break; | 1696 break; |
| 1696 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: | 1697 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: |
| 1697 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1698 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1698 base::DIR_COMMON_START_MENU; | 1699 base::DIR_COMMON_START_MENU; |
| 1699 folder_to_append = dist->GetStartMenuShortcutSubfolder( | 1700 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1700 BrowserDistribution::SUBFOLDER_CHROME); | 1701 BrowserDistribution::SUBFOLDER_CHROME); |
| 1701 break; | 1702 break; |
| 1702 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | 1703 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
| 1703 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1704 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1704 base::DIR_COMMON_START_MENU; | 1705 base::DIR_COMMON_START_MENU; |
| 1705 folder_to_append = dist->GetStartMenuShortcutSubfolder( | 1706 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1706 BrowserDistribution::SUBFOLDER_APPS); | 1707 BrowserDistribution::SUBFOLDER_APPS); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1721 NOTREACHED() << dir_key; | 1722 NOTREACHED() << dir_key; |
| 1722 return false; | 1723 return false; |
| 1723 } | 1724 } |
| 1724 | 1725 |
| 1725 if (!folder_to_append.empty()) | 1726 if (!folder_to_append.empty()) |
| 1726 *path = path->Append(folder_to_append); | 1727 *path = path->Append(folder_to_append); |
| 1727 | 1728 |
| 1728 return true; | 1729 return true; |
| 1729 } | 1730 } |
| 1730 | 1731 |
| 1732 bool ShellUtil::MoveExistingShortcut( | |
| 1733 ShellUtil::ShortcutLocation old_location, | |
|
grt (UTC plus 2)
2015/10/19 17:28:45
omit ShellUtil::
bcwhite
2015/10/20 16:02:13
Done.
| |
| 1734 ShellUtil::ShortcutLocation new_location, | |
| 1735 BrowserDistribution* dist, | |
| 1736 ShellUtil::ShellChange shortcut_level, | |
| 1737 const ShellUtil::ShortcutProperties& properties) { | |
| 1738 // Explicitly whitelist locations to which this is applicable. | |
| 1739 if (old_location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED || | |
| 1740 new_location != SHORTCUT_LOCATION_START_MENU_ROOT) { | |
| 1741 NOTREACHED(); | |
| 1742 return false; | |
| 1743 } | |
| 1744 | |
| 1745 base::string16 shortcut_name( | |
| 1746 ExtractShortcutNameFromProperties(dist, properties)); | |
| 1747 | |
| 1748 base::FilePath old_shortcut_path; | |
| 1749 base::FilePath new_shortcut_path; | |
| 1750 ShellUtil::GetShortcutPath( | |
| 1751 old_location, dist, shortcut_level, &old_shortcut_path); | |
| 1752 ShellUtil::GetShortcutPath( | |
| 1753 new_location, dist, shortcut_level, &new_shortcut_path); | |
| 1754 old_shortcut_path = old_shortcut_path.Append(shortcut_name); | |
| 1755 new_shortcut_path = new_shortcut_path.Append(shortcut_name); | |
| 1756 | |
| 1757 bool result = !!::MoveFile(old_shortcut_path.value().c_str(), | |
|
grt (UTC plus 2)
2015/10/19 17:28:45
does base::Move (from base/files/file_util.h) work
bcwhite
2015/10/20 16:02:13
Done.
| |
| 1758 new_shortcut_path.value().c_str()); | |
| 1759 | |
| 1760 RemoveShortcutFolderIfEmpty(old_location, dist, shortcut_level); | |
| 1761 return result; | |
| 1762 } | |
| 1763 | |
| 1731 bool ShellUtil::CreateOrUpdateShortcut( | 1764 bool ShellUtil::CreateOrUpdateShortcut( |
| 1732 ShellUtil::ShortcutLocation location, | 1765 ShellUtil::ShortcutLocation location, |
| 1733 BrowserDistribution* dist, | 1766 BrowserDistribution* dist, |
| 1734 const ShellUtil::ShortcutProperties& properties, | 1767 const ShellUtil::ShortcutProperties& properties, |
| 1735 ShellUtil::ShortcutOperation operation) { | 1768 ShellUtil::ShortcutOperation operation) { |
| 1736 // Explicitly whitelist locations to which this is applicable. | 1769 // Explicitly whitelist locations to which this is applicable. |
| 1737 if (location != SHORTCUT_LOCATION_DESKTOP && | 1770 if (location != SHORTCUT_LOCATION_DESKTOP && |
| 1738 location != SHORTCUT_LOCATION_QUICK_LAUNCH && | 1771 location != SHORTCUT_LOCATION_QUICK_LAUNCH && |
| 1739 location != SHORTCUT_LOCATION_START_MENU_ROOT && | 1772 location != SHORTCUT_LOCATION_START_MENU_ROOT && |
| 1740 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR && | 1773 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED && |
| 1741 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { | 1774 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { |
| 1742 NOTREACHED(); | 1775 NOTREACHED(); |
| 1743 return false; | 1776 return false; |
| 1744 } | 1777 } |
| 1745 | 1778 |
| 1746 DCHECK(dist); | 1779 DCHECK(dist); |
| 1747 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. | 1780 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
| 1748 DCHECK(!properties.pin_to_taskbar || | 1781 DCHECK(!properties.pin_to_taskbar || |
| 1749 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1782 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
| 1750 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1783 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2399 // Main operation to apply to each shortcut in the directory specified. | 2432 // Main operation to apply to each shortcut in the directory specified. |
| 2400 ShortcutOperationCallback shortcut_operation( | 2433 ShortcutOperationCallback shortcut_operation( |
| 2401 location == SHORTCUT_LOCATION_TASKBAR_PINS | 2434 location == SHORTCUT_LOCATION_TASKBAR_PINS |
| 2402 ? base::Bind(&ShortcutOpUnpinFromTaskbar) | 2435 ? base::Bind(&ShortcutOpUnpinFromTaskbar) |
| 2403 : base::Bind(&ShortcutOpDelete)); | 2436 : base::Bind(&ShortcutOpDelete)); |
| 2404 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2437 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| 2405 shortcut_operation, location, dist, level, | 2438 shortcut_operation, location, dist, level, |
| 2406 NULL); | 2439 NULL); |
| 2407 // Remove chrome-specific shortcut folders if they are now empty. | 2440 // Remove chrome-specific shortcut folders if they are now empty. |
| 2408 if (success && | 2441 if (success && |
| 2409 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || | 2442 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED || |
| 2410 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || | 2443 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || |
| 2411 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { | 2444 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { |
| 2412 success = RemoveShortcutFolderIfEmpty(location, dist, level); | 2445 success = RemoveShortcutFolderIfEmpty(location, dist, level); |
| 2413 } | 2446 } |
| 2414 return success; | 2447 return success; |
| 2415 } | 2448 } |
| 2416 | 2449 |
| 2417 // static | 2450 // static |
| 2418 bool ShellUtil::RetargetShortcutsWithArgs( | 2451 bool ShellUtil::RetargetShortcutsWithArgs( |
| 2419 ShellUtil::ShortcutLocation location, | 2452 ShellUtil::ShortcutLocation location, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2565 base::string16 key_path(ShellUtil::kRegClasses); | 2598 base::string16 key_path(ShellUtil::kRegClasses); |
| 2566 key_path.push_back(base::FilePath::kSeparators[0]); | 2599 key_path.push_back(base::FilePath::kSeparators[0]); |
| 2567 key_path.append(prog_id); | 2600 key_path.append(prog_id); |
| 2568 return InstallUtil::DeleteRegistryKey( | 2601 return InstallUtil::DeleteRegistryKey( |
| 2569 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); | 2602 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); |
| 2570 | 2603 |
| 2571 // TODO(mgiuca): Remove the extension association entries. This requires that | 2604 // TODO(mgiuca): Remove the extension association entries. This requires that |
| 2572 // the extensions associated with a particular prog_id are stored in that | 2605 // the extensions associated with a particular prog_id are stored in that |
| 2573 // prog_id's key. | 2606 // prog_id's key. |
| 2574 } | 2607 } |
| OLD | NEW |