OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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_ |
11 | 11 |
12 #include <windows.h> | 12 #include <windows.h> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "chrome/installer/util/work_item_list.h" | 16 #include "chrome/installer/util/work_item_list.h" |
17 | 17 |
18 // This is a utility class that provides common shell integration methods | 18 // This is a utility class that provides common shell integration methods |
19 // that can be used by installer as well as Chrome. | 19 // that can be used by installer as well as Chrome. |
20 class ShellUtil { | 20 class ShellUtil { |
21 public: | 21 public: |
22 // Input to any methods that make changes to OS shell. | 22 // Input to any methods that make changes to OS shell. |
23 enum ShellChange { | 23 enum ShellChange { |
24 CURRENT_USER = 0x1, // Make any shell changes only at the user level | 24 CURRENT_USER = 0x1, // Make any shell changes only at the user level |
25 SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level | 25 SYSTEM_LEVEL = 0x2 // Make any shell changes only at the system level |
26 }; | 26 }; |
27 | 27 |
28 // Return value of AddChromeToSetAccessDefaults. | |
29 enum RegisterStatus { | |
30 SUCCESS, // Registration of Chrome successful (in HKLM) | |
31 FAILURE, // Registration failed (no changes made) | |
32 REGISTERED_PER_USER // Registered Chrome as per user (in HKCU) | |
33 }; | |
34 | |
35 // Relative path of DefaultIcon registry entry (prefixed with '\'). | 28 // Relative path of DefaultIcon registry entry (prefixed with '\'). |
36 static const wchar_t* kRegDefaultIcon; | 29 static const wchar_t* kRegDefaultIcon; |
37 | 30 |
38 // Relative path of "shell" registry key. | 31 // Relative path of "shell" registry key. |
39 static const wchar_t* kRegShellPath; | 32 static const wchar_t* kRegShellPath; |
40 | 33 |
41 // Relative path of shell open command in Windows registry | 34 // Relative path of shell open command in Windows registry |
42 // (i.e. \\shell\\open\\command). | 35 // (i.e. \\shell\\open\\command). |
43 static const wchar_t* kRegShellOpen; | 36 static const wchar_t* kRegShellOpen; |
44 | 37 |
(...skipping 10 matching lines...) Expand all Loading... |
55 static const wchar_t* kRegRegisteredApplications; | 48 static const wchar_t* kRegRegisteredApplications; |
56 | 49 |
57 // The key path and key name required to register Chrome on Windows such | 50 // The key path and key name required to register Chrome on Windows such |
58 // that it can be launched from Start->Run just by name (chrome.exe). | 51 // that it can be launched from Start->Run just by name (chrome.exe). |
59 static const wchar_t* kAppPathsRegistryKey; | 52 static const wchar_t* kAppPathsRegistryKey; |
60 static const wchar_t* kAppPathsRegistryPathName; | 53 static const wchar_t* kAppPathsRegistryPathName; |
61 | 54 |
62 // Name that we give to Chrome file association handler ProgId. | 55 // Name that we give to Chrome file association handler ProgId. |
63 static const wchar_t* kChromeHTMLProgId; | 56 static const wchar_t* kChromeHTMLProgId; |
64 | 57 |
65 // Description of Chrome file/URL association handler ProgId. | 58 // Description of Chrome file association handler ProgId. |
66 static const wchar_t* kChromeHTMLProgIdDesc; | 59 static const wchar_t* kChromeHTMLProgIdDesc; |
67 | 60 |
68 // Registry path that stores url associations on Vista. | 61 // Registry path that stores url associations on Vista. |
69 static const wchar_t* kRegVistaUrlPrefs; | 62 static const wchar_t* kRegVistaUrlPrefs; |
70 | 63 |
71 // File extensions that Chrome registers itself for. | 64 // File extensions that Chrome registers itself for. |
72 static const wchar_t* kFileAssociations[]; | 65 static const wchar_t* kFileAssociations[]; |
73 | 66 |
74 // Protocols that Chrome registers itself for. | 67 // Protocols that Chrome registers itself for. |
75 static const wchar_t* kProtocolAssociations[]; | 68 static const wchar_t* kProtocolAssociations[]; |
76 | 69 |
77 // Registry value name that is needed for ChromeHTML ProgId | 70 // Registry value name that is needed for ChromeHTML ProgId |
78 static const wchar_t* kRegUrlProtocol; | 71 static const wchar_t* kRegUrlProtocol; |
79 | 72 |
80 // Name that we give to Chrome extension file association handler ProgId. | 73 // Name that we give to Chrome extension file association handler ProgId. |
81 static const wchar_t* kChromeExtProgId; | 74 static const wchar_t* kChromeExtProgId; |
82 | 75 |
83 // Description of Chrome file/URL association handler ProgId. | 76 // Description of Chrome file/URL association handler ProgId. |
84 static const wchar_t* kChromeExtProgIdDesc; | 77 static const wchar_t* kChromeExtProgIdDesc; |
85 | 78 |
86 // This method adds Chrome to the list that shows up in Add/Remove Programs-> | |
87 // Set Program Access and Defaults and also creates Chrome ProgIds under | |
88 // Software\Classes. This method requires write access to HKLM so is just | |
89 // best effort deal. If write to HKLM fails and skip_if_not_admin is false, | |
90 // this method will: | |
91 // - add the ProgId entries to HKCU on XP. HKCU entries will not make | |
92 // Chrome show in Set Program Access and Defaults but they are still useful | |
93 // because we can make Chrome run when user clicks on http link or html | |
94 // file. | |
95 // - will try to launch setup.exe with admin priviledges on Vista to do | |
96 // these tasks. Users will see standard Vista elevation prompt and if they | |
97 // enter the right credentials, the write operation will work. | |
98 // Currently skip_if_not_admin is false only when user tries to make Chrome | |
99 // default browser and Chrome is not registered on the machine. | |
100 // | |
101 // chrome_exe: full path to chrome.exe. | |
102 // skip_if_not_admin: if false will make this method try alternate methods | |
103 // as described above. | |
104 static RegisterStatus AddChromeToSetAccessDefaults( | |
105 const std::wstring& chrome_exe, bool skip_if_not_admin); | |
106 | |
107 // Checks if we need Admin rights for registry cleanup by checking if any | 79 // Checks if we need Admin rights for registry cleanup by checking if any |
108 // entry exists in HKLM. | 80 // entry exists in HKLM. |
109 static bool AdminNeededForRegistryCleanup(); | 81 static bool AdminNeededForRegistryCleanup(); |
110 | 82 |
111 // Create Chrome shortcut on Desktop | 83 // Create Chrome shortcut on Desktop |
112 // If shell_change is CURRENT_USER, the shortcut is created in the | 84 // If shell_change is CURRENT_USER, the shortcut is created in the |
113 // Desktop folder of current user's profile. | 85 // Desktop folder of current user's profile. |
114 // If shell_change is SYSTEM_LEVEL, the shortcut is created in the | 86 // If shell_change is SYSTEM_LEVEL, the shortcut is created in the |
115 // Desktop folder of "All Users" profile. | 87 // Desktop folder of "All Users" profile. |
116 // If alternate is true, an alternate text for the shortcut is used. | 88 // If alternate is true, an alternate text for the shortcut is used. |
(...skipping 13 matching lines...) Expand all Loading... |
130 // system. | 102 // system. |
131 // create_new: If false, will only update the shortcut. If true, the function | 103 // create_new: If false, will only update the shortcut. If true, the function |
132 // will create a new shortcut if it doesn't exist already. | 104 // will create a new shortcut if it doesn't exist already. |
133 static bool CreateChromeQuickLaunchShortcut(const std::wstring& chrome_exe, | 105 static bool CreateChromeQuickLaunchShortcut(const std::wstring& chrome_exe, |
134 int shell_change, | 106 int shell_change, |
135 bool create_new); | 107 bool create_new); |
136 | 108 |
137 // This method appends the Chrome icon index inside chrome.exe to the | 109 // This method appends the Chrome icon index inside chrome.exe to the |
138 // chrome.exe path passed in as input, to generate the full path for | 110 // chrome.exe path passed in as input, to generate the full path for |
139 // Chrome icon that can be used as value for Windows registry keys. | 111 // Chrome icon that can be used as value for Windows registry keys. |
140 // chrome_icon: full path to chrome.exe. | 112 // |chrome_exe| full path to chrome.exe. |
141 static bool GetChromeIcon(std::wstring& chrome_icon); | 113 static std::wstring GetChromeIcon(const std::wstring& chrome_exe); |
142 | 114 |
143 // This method returns the command to open URLs/files using chrome. Typically | 115 // This method returns the command to open URLs/files using chrome. Typically |
144 // this command is written to the registry under shell\open\command key. | 116 // this command is written to the registry under shell\open\command key. |
145 // chrome_exe: the full path to chrome.exe | 117 // chrome_exe: the full path to chrome.exe |
146 static std::wstring GetChromeShellOpenCmd(const std::wstring& chrome_exe); | 118 static std::wstring GetChromeShellOpenCmd(const std::wstring& chrome_exe); |
147 | 119 |
148 // This method returns the command to open .crx files using chrome in order | 120 // This method returns the command to open .crx files using chrome in order |
149 // to install them as extensions. Similar to above method. | 121 // to install them as extensions. Similar to above method. |
150 static std::wstring GetChromeInstallExtensionCmd( | 122 static std::wstring GetChromeInstallExtensionCmd( |
151 const std::wstring& chrome_exe); | 123 const std::wstring& chrome_exe); |
152 | 124 |
153 // Returns the localized name of Chrome shortcut. If |alternate| is true | 125 // Returns the localized name of Chrome shortcut. If |alternate| is true |
154 // it returns a second localized text that is better suited for certain | 126 // it returns a second localized text that is better suited for certain |
155 // scenarios. | 127 // scenarios. |
156 static bool GetChromeShortcutName(std::wstring* shortcut, bool alternate); | 128 static bool GetChromeShortcutName(std::wstring* shortcut, bool alternate); |
157 | 129 |
158 // Gets the desktop path for the current user or all users (if system_level | 130 // Gets the desktop path for the current user or all users (if system_level |
159 // is true) and returns it in 'path' argument. Return true if successful, | 131 // is true) and returns it in 'path' argument. Return true if successful, |
160 // otherwise returns false. | 132 // otherwise returns false. |
161 static bool GetDesktopPath(bool system_level, std::wstring* path); | 133 static bool GetDesktopPath(bool system_level, std::wstring* path); |
162 | 134 |
163 // Gets the Quick Launch shortcuts path for the current user and | 135 // Gets the Quick Launch shortcuts path for the current user and |
164 // returns it in 'path' argument. Return true if successful, otherwise | 136 // returns it in 'path' argument. Return true if successful, otherwise |
165 // returns false. If system_level is true this function returns the path | 137 // returns false. If system_level is true this function returns the path |
166 // to Default Users Quick Launch shortcuts path. Adding a shortcut to Default | 138 // to Default Users Quick Launch shortcuts path. Adding a shortcut to Default |
167 // User's profile only affects any new user profiles (not existing ones). | 139 // User's profile only affects any new user profiles (not existing ones). |
168 static bool GetQuickLaunchPath(bool system_level, std::wstring* path); | 140 static bool GetQuickLaunchPath(bool system_level, std::wstring* path); |
169 | 141 |
170 // Make Chrome default browser. Before calling this function Chrome should | 142 // This function gets a suffix (user's login name) that can be added |
171 // already have been registered by calling AddChromeToSetAccessDefaults() | 143 // to Chromium default browser entry in the registry to create a unique name |
172 // method, otherwise this function will fail. | 144 // if there are multiple users on the machine, each with their own copy of |
| 145 // Chromium that they want to set as default browser. |
| 146 // This suffix value is assigned to |entry|. |
| 147 static bool GetUserSpecificDefaultBrowserSuffix(std::wstring* entry); |
| 148 |
| 149 // Make Chrome default browser. |
173 // shell_change: Defined whether to register as default browser at system | 150 // shell_change: Defined whether to register as default browser at system |
174 // level or user level. If value has ShellChange::SYSTEM_LEVEL | 151 // level or user level. If value has ShellChange::SYSTEM_LEVEL |
175 // we should be running as admin user. Currently this setting | 152 // we should be running as admin user. |
176 // does not have any effect on Vista where we always set | |
177 // as default only for the current user. | |
178 // chrome_exe: The chrome.exe path to register as default browser. | 153 // chrome_exe: The chrome.exe path to register as default browser. |
| 154 // elevate_if_not_admin: On Vista if user is not admin, try to elevate for |
| 155 // Chrome registration. |
179 static bool MakeChromeDefault(int shell_change, | 156 static bool MakeChromeDefault(int shell_change, |
180 const std::wstring& chrome_exe); | 157 const std::wstring& chrome_exe, |
| 158 bool elevate_if_not_admin); |
| 159 |
| 160 // This method adds Chrome to the list that shows up in Add/Remove Programs-> |
| 161 // Set Program Access and Defaults and also creates Chrome ProgIds under |
| 162 // Software\Classes. This method requires write access to HKLM so is just |
| 163 // best effort deal. If write to HKLM fails and elevate_if_not_admin is true, |
| 164 // this method will: |
| 165 // - add the ProgId entries to HKCU on XP. HKCU entries will not make |
| 166 // Chrome show in Set Program Access and Defaults but they are still useful |
| 167 // because we can make Chrome run when user clicks on http link or html |
| 168 // file. |
| 169 // - will try to launch setup.exe with admin priviledges on Vista to do |
| 170 // these tasks. Users will see standard Vista elevation prompt and if they |
| 171 // enter the right credentials, the write operation will work. |
| 172 // Currently elevate_if_not_admin is true only when user tries to make Chrome |
| 173 // default browser (through the UI or through installer options) and Chrome |
| 174 // is not registered on the machine. |
| 175 // |
| 176 // |chrome_exe| full path to chrome.exe. |
| 177 // |unique_suffix| Optional input. If given, this function appends the value |
| 178 // to default browser entries names that it creates in the registry. |
| 179 // |elevate_if_not_admin| if true will make this method try alternate methods |
| 180 // as described above. |
| 181 static bool RegisterChromeBrowser(const std::wstring& chrome_exe, |
| 182 const std::wstring& unique_suffix, |
| 183 bool elevate_if_not_admin); |
181 | 184 |
182 // Remove Chrome shortcut from Desktop. | 185 // Remove Chrome shortcut from Desktop. |
183 // If shell_change is CURRENT_USER, the shortcut is removed from the | 186 // If shell_change is CURRENT_USER, the shortcut is removed from the |
184 // Desktop folder of current user's profile. | 187 // Desktop folder of current user's profile. |
185 // If shell_change is SYSTEM_LEVEL, the shortcut is removed from the | 188 // If shell_change is SYSTEM_LEVEL, the shortcut is removed from the |
186 // Desktop folder of "All Users" profile. | 189 // Desktop folder of "All Users" profile. |
187 // If alternate is true, the shortcut with the alternate name is removed. See | 190 // If alternate is true, the shortcut with the alternate name is removed. See |
188 // CreateChromeDesktopShortcut() for more information. | 191 // CreateChromeDesktopShortcut() for more information. |
189 static bool RemoveChromeDesktopShortcut(int shell_change, bool alternate); | 192 static bool RemoveChromeDesktopShortcut(int shell_change, bool alternate); |
190 | 193 |
191 // Remove Chrome shortcut from Quick Launch Bar. | 194 // Remove Chrome shortcut from Quick Launch Bar. |
192 // If shell_change is CURRENT_USER, the shortcut is removed from | 195 // If shell_change is CURRENT_USER, the shortcut is removed from |
193 // the Quick Launch folder of current user's profile. | 196 // the Quick Launch folder of current user's profile. |
194 // If shell_change is SYSTEM_LEVEL, the shortcut is removed from | 197 // If shell_change is SYSTEM_LEVEL, the shortcut is removed from |
195 // the Quick Launch folder of "Default User" profile. | 198 // the Quick Launch folder of "Default User" profile. |
196 static bool RemoveChromeQuickLaunchShortcut(int shell_change); | 199 static bool RemoveChromeQuickLaunchShortcut(int shell_change); |
197 | 200 |
198 // Updates shortcut (or creates a new shortcut) at destination given by | 201 // Updates shortcut (or creates a new shortcut) at destination given by |
199 // shortcut to a target given by chrome_exe. The arguments is left NULL | 202 // shortcut to a target given by chrome_exe. The arguments is left NULL |
200 // for the target and icon is set as icon at index 0 from exe. | 203 // for the target and icon is set as icon at index 0 from exe. |
201 // If create_new is set to true, the function will create a new shortcut if | 204 // If create_new is set to true, the function will create a new shortcut if |
202 // if doesn't exist. | 205 // if doesn't exist. |
203 static bool UpdateChromeShortcut(const std::wstring& chrome_exe, | 206 static bool UpdateChromeShortcut(const std::wstring& chrome_exe, |
204 const std::wstring& shortcut, | 207 const std::wstring& shortcut, |
205 const std::wstring& description, | 208 const std::wstring& description, |
206 bool create_new); | 209 bool create_new); |
207 | 210 |
208 private: | 211 private: |
209 DISALLOW_EVIL_CONSTRUCTORS(ShellUtil); | 212 DISALLOW_COPY_AND_ASSIGN(ShellUtil); |
210 }; | 213 }; |
211 | 214 |
212 | 215 |
213 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H__ | 216 #endif // CHROME_INSTALLER_UTIL_SHELL_UTIL_H_ |
OLD | NEW |