OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // CEEE module-wide utilities. | 5 // CEEE module-wide utilities. |
6 | 6 |
7 #include "ceee/ie/common/ceee_module_util.h" | 7 #include "ceee/ie/common/ceee_module_util.h" |
8 | 8 |
9 #include <iepmapi.h> | 9 #include <iepmapi.h> |
10 | 10 |
(...skipping 25 matching lines...) Expand all Loading... |
36 // Global state needed by the BHO and the | 36 // Global state needed by the BHO and the |
37 // toolband, to indicate whether ShowDW calls should affect | 37 // toolband, to indicate whether ShowDW calls should affect |
38 // registry tracking of the user's visibility preference. A | 38 // registry tracking of the user's visibility preference. A |
39 // non-zero value indicates that the calls should be ignored. | 39 // non-zero value indicates that the calls should be ignored. |
40 LONG g_ignore_show_dw_changes = 0; | 40 LONG g_ignore_show_dw_changes = 0; |
41 | 41 |
42 bool GetCeeeRegistryBoolean(const wchar_t* key, bool default_value) { | 42 bool GetCeeeRegistryBoolean(const wchar_t* key, bool default_value) { |
43 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); | 43 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); |
44 LOG_IF(ERROR, !hkcu.Valid()) << "Could not open reg key: " << kRegistryPath; | 44 LOG_IF(ERROR, !hkcu.Valid()) << "Could not open reg key: " << kRegistryPath; |
45 | 45 |
46 DWORD dword_value_representation = 0; | 46 DWORD value = default_value ? 1 : 0; |
47 DWORD size = sizeof(dword_value_representation); | 47 hkcu.ReadValueDW(key, &value); |
48 DWORD type = REG_DWORD; | 48 return value != 0; |
49 | |
50 if (!hkcu.Valid() || | |
51 !hkcu.ReadValue(key, &dword_value_representation, &size, &type)) { | |
52 return default_value; | |
53 } | |
54 | |
55 return dword_value_representation != 0; | |
56 } | 49 } |
57 | 50 |
58 void SetCeeeRegistryBoolean(const wchar_t* key, bool assign_value) { | 51 void SetCeeeRegistryBoolean(const wchar_t* key, bool assign_value) { |
59 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); | 52 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); |
60 LOG_IF(ERROR, !hkcu.Valid()) << "Could not open reg key: " << kRegistryPath; | 53 LOG_IF(ERROR, !hkcu.Valid()) << "Could not open reg key: " << kRegistryPath; |
61 | 54 |
62 DWORD dword_value_representation = assign_value ? 1 : 0; | 55 DWORD dword_value_representation = assign_value ? 1 : 0; |
63 bool write_result = hkcu.WriteValue(key, &dword_value_representation, | 56 LONG write_result = hkcu.WriteValue(key, &dword_value_representation, |
64 sizeof(dword_value_representation), | 57 sizeof(dword_value_representation), |
65 REG_DWORD); | 58 REG_DWORD); |
66 | 59 |
67 LOG_IF(ERROR, !write_result) << "Failed to write a registry key: " << key; | 60 LOG_IF(ERROR, write_result != ERROR_SUCCESS) |
| 61 << "Failed to write a registry key: " << key |
| 62 << " error: " << com::LogWe(write_result); |
68 } | 63 } |
69 | 64 |
70 } // anonymous namespace | 65 } // anonymous namespace |
71 | 66 |
72 namespace ceee_module_util { | 67 namespace ceee_module_util { |
73 | 68 |
74 | 69 |
75 // The name of the profile we want ChromeFrame to use (for Internet Explorer). | 70 // The name of the profile we want ChromeFrame to use (for Internet Explorer). |
76 const wchar_t kChromeProfileName[] = L"iexplore"; | 71 const wchar_t kChromeProfileName[] = L"iexplore"; |
77 | 72 |
(...skipping 26 matching lines...) Expand all Loading... |
104 // "[32-bit program files]\Google\CEEE\Extensions", look for the | 99 // "[32-bit program files]\Google\CEEE\Extensions", look for the |
105 // first valid directory and use that. Eventually, when we support more | 100 // first valid directory and use that. Eventually, when we support more |
106 // than one extension, we can load/install all directories and/or crx files | 101 // than one extension, we can load/install all directories and/or crx files |
107 // found here. | 102 // found here. |
108 std::wstring crx_path; | 103 std::wstring crx_path; |
109 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); | 104 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); |
110 base::win::RegKey hklm(HKEY_LOCAL_MACHINE, kRegistryPath, KEY_READ); | 105 base::win::RegKey hklm(HKEY_LOCAL_MACHINE, kRegistryPath, KEY_READ); |
111 | 106 |
112 base::win::RegKey* keys[] = { &hkcu, &hklm }; | 107 base::win::RegKey* keys[] = { &hkcu, &hklm }; |
113 for (int i = 0; i < arraysize(keys); ++i) { | 108 for (int i = 0; i < arraysize(keys); ++i) { |
114 if (keys[i]->Valid() && keys[i]->ReadValue(kRegistryValue, &crx_path)) | 109 if (keys[i]->Valid() && |
| 110 (keys[i]->ReadValue(kRegistryValue, &crx_path) == ERROR_SUCCESS)) { |
115 break; | 111 break; |
| 112 } |
116 } | 113 } |
117 | 114 |
118 if (crx_path.size() == 0u) { | 115 if (crx_path.size() == 0u) { |
119 FilePath file_path; | 116 FilePath file_path; |
120 PathService::Get(base::DIR_PROGRAM_FILES, &file_path); | 117 PathService::Get(base::DIR_PROGRAM_FILES, &file_path); |
121 | 118 |
122 file_path = file_path.Append(L"Google").Append(L"CEEE"). | 119 file_path = file_path.Append(L"Google").Append(L"CEEE"). |
123 Append(L"Extensions"); | 120 Append(L"Extensions"); |
124 if (!file_path.empty()) { | 121 if (!file_path.empty()) { |
125 // First check for a .crx file (we prefer the .crx) | 122 // First check for a .crx file (we prefer the .crx) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 if (!success || | 186 if (!success || |
190 extension_info.last_modified > GetInstalledExtensionTime()) { | 187 extension_info.last_modified > GetInstalledExtensionTime()) { |
191 return true; | 188 return true; |
192 } else { | 189 } else { |
193 // We also check that the current version of Chrome was the one | 190 // We also check that the current version of Chrome was the one |
194 // that attempted installation; if not, changes such as a change | 191 // that attempted installation; if not, changes such as a change |
195 // in the location of a profile directory might have occurred, and | 192 // in the location of a profile directory might have occurred, and |
196 // we might need to retry installation. | 193 // we might need to retry installation. |
197 std::wstring version_string; | 194 std::wstring version_string; |
198 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); | 195 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); |
199 success = hkcu.ReadValue( | 196 success = hkcu.ReadValue(kRegistryValueCrxInstalledByVersion, |
200 kRegistryValueCrxInstalledByVersion, &version_string); | 197 &version_string) == ERROR_SUCCESS; |
201 return !success || version_string != TO_L_STRING(CHROME_VERSION_STRING); | 198 return !success || version_string != TO_L_STRING(CHROME_VERSION_STRING); |
202 } | 199 } |
203 } | 200 } |
204 | 201 |
205 return true; | 202 return true; |
206 } | 203 } |
207 | 204 |
208 return false; | 205 return false; |
209 } | 206 } |
210 | 207 |
211 void SetInstalledExtensionPath(const FilePath& path) { | 208 void SetInstalledExtensionPath(const FilePath& path) { |
212 base::PlatformFileInfo extension_info; | 209 base::PlatformFileInfo extension_info; |
213 const bool success = file_util::GetFileInfo(path, &extension_info); | 210 const bool success = file_util::GetFileInfo(path, &extension_info); |
214 const int64 crx_time = success ? | 211 const int64 crx_time = success ? |
215 extension_info.last_modified.ToInternalValue() : | 212 extension_info.last_modified.ToInternalValue() : |
216 base::Time::Now().ToInternalValue(); | 213 base::Time::Now().ToInternalValue(); |
217 | 214 |
218 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); | 215 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); |
219 bool write_result = key.WriteValue(kRegistryValueCrxInstalledTime, | 216 LONG write_result = key.WriteValue(kRegistryValueCrxInstalledTime, |
220 &crx_time, | 217 &crx_time, |
221 sizeof(crx_time), | 218 sizeof(crx_time), |
222 REG_QWORD); | 219 REG_QWORD); |
223 DCHECK(write_result); | 220 DCHECK_EQ(ERROR_SUCCESS, write_result); |
224 write_result = key.WriteValue(kRegistryValueCrxInstalledPath, | 221 write_result = key.WriteValue(kRegistryValueCrxInstalledPath, |
225 path.value().c_str()); | 222 path.value().c_str()); |
226 DCHECK(write_result); | 223 DCHECK_EQ(ERROR_SUCCESS, write_result); |
227 | 224 |
228 write_result = key.WriteValue(kRegistryValueCrxInstalledByVersion, | 225 write_result = key.WriteValue(kRegistryValueCrxInstalledByVersion, |
229 TO_L_STRING(CHROME_VERSION_STRING)); | 226 TO_L_STRING(CHROME_VERSION_STRING)); |
| 227 DCHECK_EQ(ERROR_SUCCESS, write_result); |
230 } | 228 } |
231 | 229 |
232 bool IsCrxOrEmpty(const std::wstring& path) { | 230 bool IsCrxOrEmpty(const std::wstring& path) { |
233 return (path.empty() || | 231 return (path.empty() || |
234 (path.substr(std::max(path.size() - 4, 0u)) == L".crx")); | 232 (path.substr(std::max(path.size() - 4, 0u)) == L".crx")); |
235 } | 233 } |
236 | 234 |
237 void SetOptionToolbandIsHidden(bool is_hidden) { | 235 void SetOptionToolbandIsHidden(bool is_hidden) { |
238 SetCeeeRegistryBoolean(kRegistryValueToolbandIsHidden, is_hidden); | 236 SetCeeeRegistryBoolean(kRegistryValueToolbandIsHidden, is_hidden); |
239 } | 237 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 key.append(kChromeFrameGuid); | 292 key.append(kChromeFrameGuid); |
295 return key; | 293 return key; |
296 } | 294 } |
297 | 295 |
298 // TODO(vitalybuka@google.com) : remove this code and use | 296 // TODO(vitalybuka@google.com) : remove this code and use |
299 // GoogleUpdateSettings::GetCollectStatsConsent() code. | 297 // GoogleUpdateSettings::GetCollectStatsConsent() code. |
300 // BrowserDistribution requires modification to know about CEEE (bb3136374). | 298 // BrowserDistribution requires modification to know about CEEE (bb3136374). |
301 bool GetCollectStatsConsent() { | 299 bool GetCollectStatsConsent() { |
302 std::wstring reg_path = GetCromeFrameClientStateKey(); | 300 std::wstring reg_path = GetCromeFrameClientStateKey(); |
303 base::win::RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); | 301 base::win::RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); |
304 DWORD value; | 302 DWORD value = 0; |
305 if (!key.ReadValueDW(google_update::kRegUsageStatsField, &value)) { | 303 if (key.ReadValueDW(google_update::kRegUsageStatsField, &value) != |
| 304 ERROR_SUCCESS) { |
306 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | 305 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); |
307 if (!hklm_key.ReadValueDW(google_update::kRegUsageStatsField, &value)) | 306 key.ReadValueDW(google_update::kRegUsageStatsField, &value); |
308 return false; | |
309 } | 307 } |
| 308 |
310 return (1 == value); | 309 return (1 == value); |
311 } | 310 } |
312 | 311 |
313 bool RefreshElevationPolicyIfNeeded() { | 312 bool RefreshElevationPolicyIfNeeded() { |
314 if (ie_util::GetIeVersion() < ie_util::IEVERSION_IE7) | 313 if (ie_util::GetIeVersion() < ie_util::IEVERSION_IE7) |
315 return false; | 314 return false; |
316 | 315 |
317 // This may access InternetRegistry instead of real one. However this is | 316 // This may access InternetRegistry instead of real one. However this is |
318 // acceptable, we just refresh policy twice. | 317 // acceptable, we just refresh policy twice. |
319 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, | 318 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, |
320 KEY_WRITE | KEY_QUERY_VALUE); | 319 KEY_WRITE | KEY_QUERY_VALUE); |
321 LOG_IF(ERROR, !hkcu.Valid()) << "Failed to open reg key: " << kRegistryPath; | 320 LOG_IF(ERROR, !hkcu.Valid()) << "Failed to open reg key: " << kRegistryPath; |
322 if (!hkcu.Valid()) | 321 if (!hkcu.Valid()) |
323 return false; | 322 return false; |
324 | 323 |
325 std::wstring expected_version = TO_L_STRING(CHROME_VERSION_STRING); | 324 std::wstring expected_version = TO_L_STRING(CHROME_VERSION_STRING); |
326 | 325 |
327 static const wchar_t kValueName[] = L"last_elevation_refresh"; | 326 static const wchar_t kValueName[] = L"last_elevation_refresh"; |
328 std::wstring last_elevation_refresh_version; | 327 std::wstring last_elevation_refresh_version; |
329 bool result = hkcu.ReadValue(kValueName, &last_elevation_refresh_version); | 328 LONG result = hkcu.ReadValue(kValueName, &last_elevation_refresh_version); |
330 if (last_elevation_refresh_version == expected_version) | 329 if (last_elevation_refresh_version == expected_version) |
331 return false; | 330 return false; |
332 | 331 |
333 HRESULT hr = ::IERefreshElevationPolicy(); | 332 HRESULT hr = ::IERefreshElevationPolicy(); |
334 VLOG(1) << "Elevation policy refresh result: " << com::LogHr(hr); | 333 VLOG(1) << "Elevation policy refresh result: " << com::LogHr(hr); |
335 | 334 |
336 // Write after refreshing because it's better to refresh twice, than to miss | 335 // Write after refreshing because it's better to refresh twice, than to miss |
337 // once. | 336 // once. |
338 result = hkcu.WriteValue(kValueName, expected_version.c_str()); | 337 result = hkcu.WriteValue(kValueName, expected_version.c_str()); |
339 LOG_IF(ERROR, !result) << "Failed to write a registry value: " << kValueName; | 338 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed to write a registry value: " |
| 339 << kValueName << " error: " << com::LogWe(result); |
340 | 340 |
341 return true; | 341 return true; |
342 } | 342 } |
343 | 343 |
344 } // namespace ceee_module_util | 344 } // namespace ceee_module_util |
OLD | NEW |