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 1558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 | 1571 |
| 1572 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. | 1572 // If the folder specified by {|location|, |dist|, |level|} is empty, remove it. |
| 1573 // Otherwise do nothing. Returns true on success, including the vacuous case | 1573 // Otherwise do nothing. Returns true on success, including the vacuous case |
| 1574 // where no deletion occurred because directory is non-empty. | 1574 // where no deletion occurred because directory is non-empty. |
| 1575 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, | 1575 bool RemoveShortcutFolderIfEmpty(ShellUtil::ShortcutLocation location, |
| 1576 BrowserDistribution* dist, | 1576 BrowserDistribution* dist, |
| 1577 ShellUtil::ShellChange level) { | 1577 ShellUtil::ShellChange level) { |
| 1578 // Explicitly whitelist locations, since accidental calls can be very harmful. | 1578 // Explicitly whitelist locations, since accidental calls can be very harmful. |
| 1579 if (location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR && | 1579 if (location != |
| 1580 ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED && | |
| 1580 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && | 1581 location != ShellUtil::SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR && |
| 1581 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { | 1582 location != ShellUtil::SHORTCUT_LOCATION_APP_SHORTCUTS) { |
| 1582 NOTREACHED(); | 1583 NOTREACHED(); |
| 1583 return false; | 1584 return false; |
| 1584 } | 1585 } |
| 1585 | 1586 |
| 1586 base::FilePath shortcut_folder; | 1587 base::FilePath shortcut_folder; |
| 1587 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { | 1588 if (!ShellUtil::GetShortcutPath(location, dist, level, &shortcut_folder)) { |
| 1588 LOG(WARNING) << "Cannot find path at location " << location; | 1589 LOG(WARNING) << "Cannot find path at location " << location; |
| 1589 return false; | 1590 return false; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1654 return QuickIsChromeRegistered(dist, chrome_exe, suffix, | 1655 return QuickIsChromeRegistered(dist, chrome_exe, suffix, |
| 1655 CONFIRM_SHELL_REGISTRATION_IN_HKLM); | 1656 CONFIRM_SHELL_REGISTRATION_IN_HKLM); |
| 1656 } | 1657 } |
| 1657 | 1658 |
| 1658 bool ShellUtil::ShortcutLocationIsSupported( | 1659 bool ShellUtil::ShortcutLocationIsSupported( |
| 1659 ShellUtil::ShortcutLocation location) { | 1660 ShellUtil::ShortcutLocation location) { |
| 1660 switch (location) { | 1661 switch (location) { |
| 1661 case SHORTCUT_LOCATION_DESKTOP: // Falls through. | 1662 case SHORTCUT_LOCATION_DESKTOP: // Falls through. |
| 1662 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. | 1663 case SHORTCUT_LOCATION_QUICK_LAUNCH: // Falls through. |
| 1663 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. | 1664 case SHORTCUT_LOCATION_START_MENU_ROOT: // Falls through. |
| 1664 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: // Falls through. | 1665 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: // Falls through. |
| 1665 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | 1666 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
| 1666 return true; | 1667 return true; |
| 1667 case SHORTCUT_LOCATION_TASKBAR_PINS: | 1668 case SHORTCUT_LOCATION_TASKBAR_PINS: |
| 1668 return base::win::GetVersion() >= base::win::VERSION_WIN7; | 1669 return base::win::GetVersion() >= base::win::VERSION_WIN7; |
| 1669 case SHORTCUT_LOCATION_APP_SHORTCUTS: | 1670 case SHORTCUT_LOCATION_APP_SHORTCUTS: |
| 1670 return base::win::GetVersion() >= base::win::VERSION_WIN8; | 1671 return base::win::GetVersion() >= base::win::VERSION_WIN8; |
| 1671 default: | 1672 default: |
| 1672 NOTREACHED(); | 1673 NOTREACHED(); |
| 1673 return false; | 1674 return false; |
| 1674 } | 1675 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1688 break; | 1689 break; |
| 1689 case SHORTCUT_LOCATION_QUICK_LAUNCH: | 1690 case SHORTCUT_LOCATION_QUICK_LAUNCH: |
| 1690 // There is no support for a system-level Quick Launch shortcut. | 1691 // There is no support for a system-level Quick Launch shortcut. |
| 1691 DCHECK_EQ(level, CURRENT_USER); | 1692 DCHECK_EQ(level, CURRENT_USER); |
| 1692 dir_key = base::DIR_USER_QUICK_LAUNCH; | 1693 dir_key = base::DIR_USER_QUICK_LAUNCH; |
| 1693 break; | 1694 break; |
| 1694 case SHORTCUT_LOCATION_START_MENU_ROOT: | 1695 case SHORTCUT_LOCATION_START_MENU_ROOT: |
| 1695 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1696 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1696 base::DIR_COMMON_START_MENU; | 1697 base::DIR_COMMON_START_MENU; |
| 1697 break; | 1698 break; |
| 1698 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR: | 1699 case SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED: |
| 1699 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1700 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1700 base::DIR_COMMON_START_MENU; | 1701 base::DIR_COMMON_START_MENU; |
| 1701 folder_to_append = dist->GetStartMenuShortcutSubfolder( | 1702 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1702 BrowserDistribution::SUBFOLDER_CHROME); | 1703 BrowserDistribution::SUBFOLDER_CHROME); |
| 1703 break; | 1704 break; |
| 1704 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: | 1705 case SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR: |
| 1705 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : | 1706 dir_key = (level == CURRENT_USER) ? base::DIR_START_MENU : |
| 1706 base::DIR_COMMON_START_MENU; | 1707 base::DIR_COMMON_START_MENU; |
| 1707 folder_to_append = dist->GetStartMenuShortcutSubfolder( | 1708 folder_to_append = dist->GetStartMenuShortcutSubfolder( |
| 1708 BrowserDistribution::SUBFOLDER_APPS); | 1709 BrowserDistribution::SUBFOLDER_APPS); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1723 NOTREACHED() << dir_key; | 1724 NOTREACHED() << dir_key; |
| 1724 return false; | 1725 return false; |
| 1725 } | 1726 } |
| 1726 | 1727 |
| 1727 if (!folder_to_append.empty()) | 1728 if (!folder_to_append.empty()) |
| 1728 *path = path->Append(folder_to_append); | 1729 *path = path->Append(folder_to_append); |
| 1729 | 1730 |
| 1730 return true; | 1731 return true; |
| 1731 } | 1732 } |
| 1732 | 1733 |
| 1734 bool ShellUtil::MoveExistingShortcut( | |
|
grt (UTC plus 2)
2015/10/20 18:10:30
formatting nit:
bool ShellUtil::MoveExistingShortc
bcwhite
2015/10/20 18:25:43
Done.
| |
| 1735 ShortcutLocation old_location, | |
| 1736 ShortcutLocation new_location, | |
| 1737 BrowserDistribution* dist, | |
| 1738 const ShortcutProperties& properties) { | |
| 1739 // Explicitly whitelist locations to which this is applicable. | |
| 1740 if (old_location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED || | |
| 1741 new_location != SHORTCUT_LOCATION_START_MENU_ROOT) { | |
| 1742 NOTREACHED(); | |
| 1743 return false; | |
| 1744 } | |
| 1745 | |
| 1746 base::string16 shortcut_name( | |
|
gab
2015/10/20 18:25:59
const
| |
| 1747 ExtractShortcutNameFromProperties(dist, properties)); | |
| 1748 | |
| 1749 base::FilePath old_shortcut_path; | |
| 1750 base::FilePath new_shortcut_path; | |
| 1751 GetShortcutPath( | |
|
grt (UTC plus 2)
2015/10/20 18:10:30
nit:
GetShortcutPath(old_location, dist, propert
bcwhite
2015/10/20 18:25:43
Done.
| |
| 1752 old_location, dist, properties.level, &old_shortcut_path); | |
| 1753 GetShortcutPath( | |
| 1754 new_location, dist, properties.level, &new_shortcut_path); | |
| 1755 old_shortcut_path = old_shortcut_path.Append(shortcut_name); | |
| 1756 new_shortcut_path = new_shortcut_path.Append(shortcut_name); | |
| 1757 | |
| 1758 bool result = base::Move(old_shortcut_path, new_shortcut_path); | |
| 1759 | |
|
gab
2015/10/20 18:25:59
I'd say rm this empty line.
(or otherwise add an
bcwhite
2015/10/20 19:03:12
Done.
| |
| 1760 RemoveShortcutFolderIfEmpty(old_location, dist, properties.level); | |
| 1761 return result; | |
| 1762 } | |
| 1763 | |
| 1733 bool ShellUtil::CreateOrUpdateShortcut( | 1764 bool ShellUtil::CreateOrUpdateShortcut( |
| 1734 ShellUtil::ShortcutLocation location, | 1765 ShellUtil::ShortcutLocation location, |
|
gab
2015/10/20 18:25:59
Seems like you're cleaning up those extra namespac
bcwhite
2015/10/20 19:03:12
I was a little hesitant about that. Done.
| |
| 1735 BrowserDistribution* dist, | 1766 BrowserDistribution* dist, |
| 1736 const ShellUtil::ShortcutProperties& properties, | 1767 const ShellUtil::ShortcutProperties& properties, |
| 1737 ShellUtil::ShortcutOperation operation) { | 1768 ShellUtil::ShortcutOperation operation) { |
| 1738 // Explicitly whitelist locations to which this is applicable. | 1769 // Explicitly whitelist locations to which this is applicable. |
| 1739 if (location != SHORTCUT_LOCATION_DESKTOP && | 1770 if (location != SHORTCUT_LOCATION_DESKTOP && |
| 1740 location != SHORTCUT_LOCATION_QUICK_LAUNCH && | 1771 location != SHORTCUT_LOCATION_QUICK_LAUNCH && |
| 1741 location != SHORTCUT_LOCATION_START_MENU_ROOT && | 1772 location != SHORTCUT_LOCATION_START_MENU_ROOT && |
| 1742 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR && | 1773 location != SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED && |
| 1743 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { | 1774 location != SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR) { |
| 1744 NOTREACHED(); | 1775 NOTREACHED(); |
| 1745 return false; | 1776 return false; |
| 1746 } | 1777 } |
| 1747 | 1778 |
| 1748 DCHECK(dist); | 1779 DCHECK(dist); |
| 1749 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. | 1780 // |pin_to_taskbar| is only acknowledged when first creating the shortcut. |
| 1750 DCHECK(!properties.pin_to_taskbar || | 1781 DCHECK(!properties.pin_to_taskbar || |
| 1751 operation == SHELL_SHORTCUT_CREATE_ALWAYS || | 1782 operation == SHELL_SHORTCUT_CREATE_ALWAYS || |
| 1752 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); | 1783 operation == SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL); |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2393 // Main operation to apply to each shortcut in the directory specified. | 2424 // Main operation to apply to each shortcut in the directory specified. |
| 2394 ShortcutOperationCallback shortcut_operation( | 2425 ShortcutOperationCallback shortcut_operation( |
| 2395 location == SHORTCUT_LOCATION_TASKBAR_PINS | 2426 location == SHORTCUT_LOCATION_TASKBAR_PINS |
| 2396 ? base::Bind(&ShortcutOpUnpinFromTaskbar) | 2427 ? base::Bind(&ShortcutOpUnpinFromTaskbar) |
| 2397 : base::Bind(&ShortcutOpDelete)); | 2428 : base::Bind(&ShortcutOpDelete)); |
| 2398 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), | 2429 bool success = BatchShortcutAction(shortcut_filter.AsShortcutFilterCallback(), |
| 2399 shortcut_operation, location, dist, level, | 2430 shortcut_operation, location, dist, level, |
| 2400 NULL); | 2431 NULL); |
| 2401 // Remove chrome-specific shortcut folders if they are now empty. | 2432 // Remove chrome-specific shortcut folders if they are now empty. |
| 2402 if (success && | 2433 if (success && |
| 2403 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR || | 2434 (location == SHORTCUT_LOCATION_START_MENU_CHROME_DIR_DEPRECATED || |
| 2404 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || | 2435 location == SHORTCUT_LOCATION_START_MENU_CHROME_APPS_DIR || |
| 2405 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { | 2436 location == SHORTCUT_LOCATION_APP_SHORTCUTS)) { |
| 2406 success = RemoveShortcutFolderIfEmpty(location, dist, level); | 2437 success = RemoveShortcutFolderIfEmpty(location, dist, level); |
| 2407 } | 2438 } |
| 2408 return success; | 2439 return success; |
| 2409 } | 2440 } |
| 2410 | 2441 |
| 2411 // static | 2442 // static |
| 2412 bool ShellUtil::RetargetShortcutsWithArgs( | 2443 bool ShellUtil::RetargetShortcutsWithArgs( |
| 2413 ShellUtil::ShortcutLocation location, | 2444 ShellUtil::ShortcutLocation location, |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2559 base::string16 key_path(ShellUtil::kRegClasses); | 2590 base::string16 key_path(ShellUtil::kRegClasses); |
| 2560 key_path.push_back(base::FilePath::kSeparators[0]); | 2591 key_path.push_back(base::FilePath::kSeparators[0]); |
| 2561 key_path.append(prog_id); | 2592 key_path.append(prog_id); |
| 2562 return InstallUtil::DeleteRegistryKey( | 2593 return InstallUtil::DeleteRegistryKey( |
| 2563 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); | 2594 HKEY_CURRENT_USER, key_path, WorkItem::kWow64Default); |
| 2564 | 2595 |
| 2565 // TODO(mgiuca): Remove the extension association entries. This requires that | 2596 // TODO(mgiuca): Remove the extension association entries. This requires that |
| 2566 // the extensions associated with a particular prog_id are stored in that | 2597 // the extensions associated with a particular prog_id are stored in that |
| 2567 // prog_id's key. | 2598 // prog_id's key. |
| 2568 } | 2599 } |
| OLD | NEW |