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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 // Windows 8. | 723 // Windows 8. |
724 bool LaunchApplicationAssociationDialog(const string16& app_id) { | 724 bool LaunchApplicationAssociationDialog(const string16& app_id) { |
725 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; | 725 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; |
726 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); | 726 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); |
727 if (FAILED(hr)) | 727 if (FAILED(hr)) |
728 return false; | 728 return false; |
729 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); | 729 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); |
730 return SUCCEEDED(hr); | 730 return SUCCEEDED(hr); |
731 } | 731 } |
732 | 732 |
733 uint32 ConvertShellUtilShortcutOptionsToFileUtil(uint32 options) { | |
734 uint32 converted_options = 0; | |
735 if (options & ShellUtil::SHORTCUT_DUAL_MODE) | |
736 converted_options |= file_util::SHORTCUT_DUAL_MODE; | |
737 if (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) | |
738 converted_options |= file_util::SHORTCUT_CREATE_ALWAYS; | |
739 return converted_options; | |
740 } | |
741 | |
742 // As of r133333, the DelegateExecute verb handler was being registered for | 733 // As of r133333, the DelegateExecute verb handler was being registered for |
743 // Google Chrome installs on Windows 8 even though the binary itself wasn't | 734 // Google Chrome installs on Windows 8 even though the binary itself wasn't |
744 // present. This affected Chrome 20.0.1115.1 on the dev channel (and anyone who | 735 // present. This affected Chrome 20.0.1115.1 on the dev channel (and anyone who |
745 // pulled a Canary >= 20.0.1112.0 and installed it manually as Google Chrome). | 736 // pulled a Canary >= 20.0.1112.0 and installed it manually as Google Chrome). |
746 // This egregious hack is here to remove the bad values for those installs, and | 737 // This egregious hack is here to remove the bad values for those installs, and |
747 // should be removed after a reasonable time, say 2012-08-01. Anyone on Win8 | 738 // should be removed after a reasonable time, say 2012-08-01. Anyone on Win8 |
748 // dev channel who hasn't been autoupdated or manually updated by then will have | 739 // dev channel who hasn't been autoupdated or manually updated by then will have |
749 // to uninstall and reinstall Chrome to repair. See http://crbug.com/124666 and | 740 // to uninstall and reinstall Chrome to repair. See http://crbug.com/124666 and |
750 // http://crbug.com/123994 for gory details. | 741 // http://crbug.com/123994 for gory details. |
751 // This function is also used to remove DelegateExecute verb handler | 742 // This function is also used to remove DelegateExecute verb handler |
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1665 const FilePath chrome_path(FilePath(chrome_exe).DirName()); | 1656 const FilePath chrome_path(FilePath(chrome_exe).DirName()); |
1666 | 1657 |
1667 installer::MasterPreferences prefs( | 1658 installer::MasterPreferences prefs( |
1668 chrome_path.AppendASCII(installer::kDefaultMasterPrefs)); | 1659 chrome_path.AppendASCII(installer::kDefaultMasterPrefs)); |
1669 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { | 1660 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { |
1670 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, | 1661 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, |
1671 &icon_index); | 1662 &icon_index); |
1672 } | 1663 } |
1673 | 1664 |
1674 const string16 app_id(GetBrowserModelId(dist, chrome_exe)); | 1665 const string16 app_id(GetBrowserModelId(dist, chrome_exe)); |
| 1666 const bool is_dual_mode = ((options & ShellUtil::SHORTCUT_DUAL_MODE) != 0); |
| 1667 const file_util::ShortcutOperation operation = |
| 1668 (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0 ? |
| 1669 file_util::SHORTCUT_CREATE_ALWAYS : |
| 1670 file_util::SHORTCUT_UPDATE_EXISTING; |
1675 | 1671 |
| 1672 // TODO(gab): The shell_util interface will also be refactored in an upcoming |
| 1673 // CL to use a ShortcutProperties like interface for its shortcut methods. |
| 1674 file_util::ShortcutProperties shortcut_properties; |
| 1675 shortcut_properties.set_target(chrome_exe); |
| 1676 shortcut_properties.set_working_dir(chrome_path.value()); |
| 1677 shortcut_properties.set_arguments(arguments); |
| 1678 shortcut_properties.set_description(description); |
| 1679 shortcut_properties.set_icon(icon_path, icon_index); |
| 1680 shortcut_properties.set_app_id(app_id); |
| 1681 shortcut_properties.set_dual_mode(is_dual_mode); |
1676 return file_util::CreateOrUpdateShortcutLink( | 1682 return file_util::CreateOrUpdateShortcutLink( |
1677 chrome_exe.c_str(), | 1683 shortcut, shortcut_properties, operation); |
1678 shortcut.c_str(), | |
1679 chrome_path.value().c_str(), | |
1680 arguments.c_str(), | |
1681 description.c_str(), | |
1682 icon_path.c_str(), | |
1683 icon_index, | |
1684 app_id.c_str(), | |
1685 ConvertShellUtilShortcutOptionsToFileUtil(options)); | |
1686 } | |
1687 | |
1688 ShellUtil::VerifyShortcutStatus ShellUtil::VerifyChromeShortcut( | |
1689 const string16& exe_path, const string16& shortcut, | |
1690 const string16& description, int icon_index) { | |
1691 base::win::ScopedComPtr<IShellLink> i_shell_link; | |
1692 base::win::ScopedComPtr<IPersistFile> i_persist_file; | |
1693 wchar_t long_path[MAX_PATH] = {0}; | |
1694 wchar_t short_path[MAX_PATH] = {0}; | |
1695 wchar_t file_path[MAX_PATH] = {0}; | |
1696 wchar_t icon_path[MAX_PATH] = {0}; | |
1697 wchar_t desc[MAX_PATH] = {0}; | |
1698 int index = 0; | |
1699 | |
1700 // Get the shortcut's properties. | |
1701 if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL, | |
1702 CLSCTX_INPROC_SERVER)) || | |
1703 FAILED(i_persist_file.QueryFrom(i_shell_link)) || | |
1704 FAILED(i_persist_file->Load(shortcut.c_str(), 0)) || | |
1705 ::GetLongPathName(exe_path.c_str(), long_path, MAX_PATH) == 0 || | |
1706 ::GetShortPathName(exe_path.c_str(), short_path, MAX_PATH) == 0 || | |
1707 FAILED(i_shell_link->GetPath(file_path, MAX_PATH, NULL, | |
1708 SLGP_UNCPRIORITY)) || | |
1709 FAILED(i_shell_link->GetIconLocation(icon_path, MAX_PATH, &index)) || | |
1710 FAILED(i_shell_link->GetDescription(desc, MAX_PATH)) || | |
1711 FAILED(i_shell_link->GetDescription(desc, MAX_PATH))) | |
1712 return VERIFY_SHORTCUT_FAILURE_UNEXPECTED; | |
1713 | |
1714 FilePath path(file_path); | |
1715 if (path != FilePath(long_path) && path != FilePath(short_path)) | |
1716 return VERIFY_SHORTCUT_FAILURE_PATH; | |
1717 | |
1718 if (string16(desc) != string16(description)) | |
1719 return VERIFY_SHORTCUT_FAILURE_DESCRIPTION; | |
1720 | |
1721 if (index != icon_index) | |
1722 return VERIFY_SHORTCUT_FAILURE_ICON_INDEX; | |
1723 | |
1724 return VERIFY_SHORTCUT_SUCCESS; | |
1725 } | 1684 } |
1726 | 1685 |
1727 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { | 1686 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { |
1728 // Use a thread-safe cache for the user's suffix. | 1687 // Use a thread-safe cache for the user's suffix. |
1729 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 1688 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
1730 LAZY_INSTANCE_INITIALIZER; | 1689 LAZY_INSTANCE_INITIALIZER; |
1731 return suffix_instance.Get().GetSuffix(suffix); | 1690 return suffix_instance.Get().GetSuffix(suffix); |
1732 } | 1691 } |
1733 | 1692 |
1734 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { | 1693 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 // are any left...). | 1743 // are any left...). |
1785 if (free_bits >= 8 && next_byte_index < size) { | 1744 if (free_bits >= 8 && next_byte_index < size) { |
1786 free_bits -= 8; | 1745 free_bits -= 8; |
1787 bit_stream += bytes[next_byte_index++] << free_bits; | 1746 bit_stream += bytes[next_byte_index++] << free_bits; |
1788 } | 1747 } |
1789 } | 1748 } |
1790 | 1749 |
1791 DCHECK_EQ(ret.length(), encoded_length); | 1750 DCHECK_EQ(ret.length(), encoded_length); |
1792 return ret; | 1751 return ret; |
1793 } | 1752 } |
OLD | NEW |