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 14 matching lines...) Expand all Loading... |
25 #include "base/memory/scoped_vector.h" | 25 #include "base/memory/scoped_vector.h" |
26 #include "base/path_service.h" | 26 #include "base/path_service.h" |
27 #include "base/string16.h" | 27 #include "base/string16.h" |
28 #include "base/string_number_conversions.h" | 28 #include "base/string_number_conversions.h" |
29 #include "base/string_split.h" | 29 #include "base/string_split.h" |
30 #include "base/string_util.h" | 30 #include "base/string_util.h" |
31 #include "base/utf_string_conversions.h" | 31 #include "base/utf_string_conversions.h" |
32 #include "base/values.h" | 32 #include "base/values.h" |
33 #include "base/win/registry.h" | 33 #include "base/win/registry.h" |
34 #include "base/win/scoped_comptr.h" | 34 #include "base/win/scoped_comptr.h" |
| 35 #include "base/win/shortcut.h" |
35 #include "base/win/win_util.h" | 36 #include "base/win/win_util.h" |
36 #include "base/win/windows_version.h" | 37 #include "base/win/windows_version.h" |
37 #include "chrome/common/chrome_constants.h" | 38 #include "chrome/common/chrome_constants.h" |
38 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/installer/util/browser_distribution.h" | 40 #include "chrome/installer/util/browser_distribution.h" |
40 #include "chrome/installer/util/install_util.h" | 41 #include "chrome/installer/util/install_util.h" |
41 #include "chrome/installer/util/master_preferences.h" | 42 #include "chrome/installer/util/master_preferences.h" |
42 #include "chrome/installer/util/master_preferences_constants.h" | 43 #include "chrome/installer/util/master_preferences_constants.h" |
43 | 44 |
44 using base::win::RegKey; | 45 using base::win::RegKey; |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 // Windows 8. | 724 // Windows 8. |
724 bool LaunchApplicationAssociationDialog(const string16& app_id) { | 725 bool LaunchApplicationAssociationDialog(const string16& app_id) { |
725 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; | 726 base::win::ScopedComPtr<IApplicationAssociationRegistrationUI> aarui; |
726 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); | 727 HRESULT hr = aarui.CreateInstance(CLSID_ApplicationAssociationRegistrationUI); |
727 if (FAILED(hr)) | 728 if (FAILED(hr)) |
728 return false; | 729 return false; |
729 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); | 730 hr = aarui->LaunchAdvancedAssociationUI(app_id.c_str()); |
730 return SUCCEEDED(hr); | 731 return SUCCEEDED(hr); |
731 } | 732 } |
732 | 733 |
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 | 734 // 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 | 735 // 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 | 736 // 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). | 737 // 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 | 738 // 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 | 739 // 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 | 740 // 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 | 741 // to uninstall and reinstall Chrome to repair. See http://crbug.com/124666 and |
750 // http://crbug.com/123994 for gory details. | 742 // http://crbug.com/123994 for gory details. |
751 // This function is also used to remove DelegateExecute verb handler | 743 // 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()); | 1657 const FilePath chrome_path(FilePath(chrome_exe).DirName()); |
1666 | 1658 |
1667 installer::MasterPreferences prefs( | 1659 installer::MasterPreferences prefs( |
1668 chrome_path.AppendASCII(installer::kDefaultMasterPrefs)); | 1660 chrome_path.AppendASCII(installer::kDefaultMasterPrefs)); |
1669 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { | 1661 if (FilePath::CompareEqualIgnoreCase(icon_path, chrome_exe)) { |
1670 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, | 1662 prefs.GetInt(installer::master_preferences::kChromeShortcutIconIndex, |
1671 &icon_index); | 1663 &icon_index); |
1672 } | 1664 } |
1673 | 1665 |
1674 const string16 app_id(GetBrowserModelId(dist, chrome_exe)); | 1666 const string16 app_id(GetBrowserModelId(dist, chrome_exe)); |
| 1667 const bool is_dual_mode = ((options & ShellUtil::SHORTCUT_DUAL_MODE) != 0); |
| 1668 const base::win::ShortcutOperation operation = |
| 1669 (options & ShellUtil::SHORTCUT_CREATE_ALWAYS) != 0 ? |
| 1670 base::win::SHORTCUT_CREATE_ALWAYS : |
| 1671 base::win::SHORTCUT_UPDATE_EXISTING; |
1675 | 1672 |
1676 return file_util::CreateOrUpdateShortcutLink( | 1673 // TODO(gab): The shell_util interface will also be refactored in an upcoming |
1677 chrome_exe.c_str(), | 1674 // CL to use a ShortcutProperties like interface for its shortcut methods. |
1678 shortcut.c_str(), | 1675 base::win::ShortcutProperties shortcut_properties; |
1679 chrome_path.value().c_str(), | 1676 shortcut_properties.set_target(FilePath(chrome_exe)); |
1680 arguments.c_str(), | 1677 shortcut_properties.set_working_dir(chrome_path); |
1681 description.c_str(), | 1678 shortcut_properties.set_arguments(arguments); |
1682 icon_path.c_str(), | 1679 shortcut_properties.set_description(description); |
1683 icon_index, | 1680 shortcut_properties.set_icon(FilePath(icon_path), icon_index); |
1684 app_id.c_str(), | 1681 shortcut_properties.set_app_id(app_id); |
1685 ConvertShellUtilShortcutOptionsToFileUtil(options)); | 1682 shortcut_properties.set_dual_mode(is_dual_mode); |
1686 } | 1683 return base::win::CreateOrUpdateShortcutLink( |
1687 | 1684 FilePath(shortcut), shortcut_properties, operation); |
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 } | 1685 } |
1726 | 1686 |
1727 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { | 1687 bool ShellUtil::GetUserSpecificRegistrySuffix(string16* suffix) { |
1728 // Use a thread-safe cache for the user's suffix. | 1688 // Use a thread-safe cache for the user's suffix. |
1729 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = | 1689 static base::LazyInstance<UserSpecificRegistrySuffix>::Leaky suffix_instance = |
1730 LAZY_INSTANCE_INITIALIZER; | 1690 LAZY_INSTANCE_INITIALIZER; |
1731 return suffix_instance.Get().GetSuffix(suffix); | 1691 return suffix_instance.Get().GetSuffix(suffix); |
1732 } | 1692 } |
1733 | 1693 |
1734 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { | 1694 bool ShellUtil::GetOldUserSpecificRegistrySuffix(string16* suffix) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 // are any left...). | 1744 // are any left...). |
1785 if (free_bits >= 8 && next_byte_index < size) { | 1745 if (free_bits >= 8 && next_byte_index < size) { |
1786 free_bits -= 8; | 1746 free_bits -= 8; |
1787 bit_stream += bytes[next_byte_index++] << free_bits; | 1747 bit_stream += bytes[next_byte_index++] << free_bits; |
1788 } | 1748 } |
1789 } | 1749 } |
1790 | 1750 |
1791 DCHECK_EQ(ret.length(), encoded_length); | 1751 DCHECK_EQ(ret.length(), encoded_length); |
1792 return ret; | 1752 return ret; |
1793 } | 1753 } |
OLD | NEW |