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; |
grt (UTC plus 2)
2011/01/16 04:19:48
Add braces around this line since the if spans mul
amit
2011/01/16 07:54:28
Done.
| |
116 } | 112 } |
117 | 113 |
118 if (crx_path.size() == 0u) { | 114 if (crx_path.size() == 0u) { |
119 FilePath file_path; | 115 FilePath file_path; |
120 PathService::Get(base::DIR_PROGRAM_FILES, &file_path); | 116 PathService::Get(base::DIR_PROGRAM_FILES, &file_path); |
121 | 117 |
122 file_path = file_path.Append(L"Google").Append(L"CEEE"). | 118 file_path = file_path.Append(L"Google").Append(L"CEEE"). |
123 Append(L"Extensions"); | 119 Append(L"Extensions"); |
124 if (!file_path.empty()) { | 120 if (!file_path.empty()) { |
125 // First check for a .crx file (we prefer the .crx) | 121 // 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 || | 185 if (!success || |
190 extension_info.last_modified > GetInstalledExtensionTime()) { | 186 extension_info.last_modified > GetInstalledExtensionTime()) { |
191 return true; | 187 return true; |
192 } else { | 188 } else { |
193 // We also check that the current version of Chrome was the one | 189 // We also check that the current version of Chrome was the one |
194 // that attempted installation; if not, changes such as a change | 190 // that attempted installation; if not, changes such as a change |
195 // in the location of a profile directory might have occurred, and | 191 // in the location of a profile directory might have occurred, and |
196 // we might need to retry installation. | 192 // we might need to retry installation. |
197 std::wstring version_string; | 193 std::wstring version_string; |
198 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); | 194 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, KEY_READ); |
199 success = hkcu.ReadValue( | 195 success = hkcu.ReadValue(kRegistryValueCrxInstalledByVersion, |
200 kRegistryValueCrxInstalledByVersion, &version_string); | 196 &version_string) == ERROR_SUCCESS; |
201 return !success || version_string != TO_L_STRING(CHROME_VERSION_STRING); | 197 return !success || version_string != TO_L_STRING(CHROME_VERSION_STRING); |
202 } | 198 } |
203 } | 199 } |
204 | 200 |
205 return true; | 201 return true; |
206 } | 202 } |
207 | 203 |
208 return false; | 204 return false; |
209 } | 205 } |
210 | 206 |
211 void SetInstalledExtensionPath(const FilePath& path) { | 207 void SetInstalledExtensionPath(const FilePath& path) { |
212 base::PlatformFileInfo extension_info; | 208 base::PlatformFileInfo extension_info; |
213 const bool success = file_util::GetFileInfo(path, &extension_info); | 209 const bool success = file_util::GetFileInfo(path, &extension_info); |
214 const int64 crx_time = success ? | 210 const int64 crx_time = success ? |
215 extension_info.last_modified.ToInternalValue() : | 211 extension_info.last_modified.ToInternalValue() : |
216 base::Time::Now().ToInternalValue(); | 212 base::Time::Now().ToInternalValue(); |
217 | 213 |
218 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); | 214 base::win::RegKey key(HKEY_CURRENT_USER, kRegistryPath, KEY_WRITE); |
219 bool write_result = key.WriteValue(kRegistryValueCrxInstalledTime, | 215 LONG write_result = key.WriteValue(kRegistryValueCrxInstalledTime, |
220 &crx_time, | 216 &crx_time, |
221 sizeof(crx_time), | 217 sizeof(crx_time), |
222 REG_QWORD); | 218 REG_QWORD); |
223 DCHECK(write_result); | 219 DCHECK_EQ(ERROR_SUCCESS, write_result); |
224 write_result = key.WriteValue(kRegistryValueCrxInstalledPath, | 220 write_result = key.WriteValue(kRegistryValueCrxInstalledPath, |
225 path.value().c_str()); | 221 path.value().c_str()); |
226 DCHECK(write_result); | 222 DCHECK_EQ(ERROR_SUCCESS, write_result); |
227 | 223 |
228 write_result = key.WriteValue(kRegistryValueCrxInstalledByVersion, | 224 write_result = key.WriteValue(kRegistryValueCrxInstalledByVersion, |
229 TO_L_STRING(CHROME_VERSION_STRING)); | 225 TO_L_STRING(CHROME_VERSION_STRING)); |
226 DCHECK_EQ(ERROR_SUCCESS, write_result); | |
230 } | 227 } |
231 | 228 |
232 bool IsCrxOrEmpty(const std::wstring& path) { | 229 bool IsCrxOrEmpty(const std::wstring& path) { |
233 return (path.empty() || | 230 return (path.empty() || |
234 (path.substr(std::max(path.size() - 4, 0u)) == L".crx")); | 231 (path.substr(std::max(path.size() - 4, 0u)) == L".crx")); |
235 } | 232 } |
236 | 233 |
237 void SetOptionToolbandIsHidden(bool is_hidden) { | 234 void SetOptionToolbandIsHidden(bool is_hidden) { |
238 SetCeeeRegistryBoolean(kRegistryValueToolbandIsHidden, is_hidden); | 235 SetCeeeRegistryBoolean(kRegistryValueToolbandIsHidden, is_hidden); |
239 } | 236 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 key.append(kChromeFrameGuid); | 291 key.append(kChromeFrameGuid); |
295 return key; | 292 return key; |
296 } | 293 } |
297 | 294 |
298 // TODO(vitalybuka@google.com) : remove this code and use | 295 // TODO(vitalybuka@google.com) : remove this code and use |
299 // GoogleUpdateSettings::GetCollectStatsConsent() code. | 296 // GoogleUpdateSettings::GetCollectStatsConsent() code. |
300 // BrowserDistribution requires modification to know about CEEE (bb3136374). | 297 // BrowserDistribution requires modification to know about CEEE (bb3136374). |
301 bool GetCollectStatsConsent() { | 298 bool GetCollectStatsConsent() { |
302 std::wstring reg_path = GetCromeFrameClientStateKey(); | 299 std::wstring reg_path = GetCromeFrameClientStateKey(); |
303 base::win::RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); | 300 base::win::RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_READ); |
304 DWORD value; | 301 DWORD value = 0; |
305 if (!key.ReadValueDW(google_update::kRegUsageStatsField, &value)) { | 302 if (key.ReadValueDW(google_update::kRegUsageStatsField, &value) |
303 != ERROR_SUCCESS) { | |
306 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); | 304 base::win::RegKey hklm_key(HKEY_LOCAL_MACHINE, reg_path.c_str(), KEY_READ); |
307 if (!hklm_key.ReadValueDW(google_update::kRegUsageStatsField, &value)) | 305 key.ReadValueDW(google_update::kRegUsageStatsField, &value); |
308 return false; | |
309 } | 306 } |
307 | |
310 return (1 == value); | 308 return (1 == value); |
311 } | 309 } |
312 | 310 |
313 bool RefreshElevationPolicyIfNeeded() { | 311 bool RefreshElevationPolicyIfNeeded() { |
314 if (ie_util::GetIeVersion() < ie_util::IEVERSION_IE7) | 312 if (ie_util::GetIeVersion() < ie_util::IEVERSION_IE7) |
315 return false; | 313 return false; |
316 | 314 |
317 // This may access InternetRegistry instead of real one. However this is | 315 // This may access InternetRegistry instead of real one. However this is |
318 // acceptable, we just refresh policy twice. | 316 // acceptable, we just refresh policy twice. |
319 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, | 317 base::win::RegKey hkcu(HKEY_CURRENT_USER, kRegistryPath, |
320 KEY_WRITE | KEY_QUERY_VALUE); | 318 KEY_WRITE | KEY_QUERY_VALUE); |
321 LOG_IF(ERROR, !hkcu.Valid()) << "Failed to open reg key: " << kRegistryPath; | 319 LOG_IF(ERROR, !hkcu.Valid()) << "Failed to open reg key: " << kRegistryPath; |
322 if (!hkcu.Valid()) | 320 if (!hkcu.Valid()) |
323 return false; | 321 return false; |
324 | 322 |
325 std::wstring expected_version = TO_L_STRING(CHROME_VERSION_STRING); | 323 std::wstring expected_version = TO_L_STRING(CHROME_VERSION_STRING); |
326 | 324 |
327 static const wchar_t kValueName[] = L"last_elevation_refresh"; | 325 static const wchar_t kValueName[] = L"last_elevation_refresh"; |
328 std::wstring last_elevation_refresh_version; | 326 std::wstring last_elevation_refresh_version; |
329 bool result = hkcu.ReadValue(kValueName, &last_elevation_refresh_version); | 327 LONG result = hkcu.ReadValue(kValueName, &last_elevation_refresh_version); |
330 if (last_elevation_refresh_version == expected_version) | 328 if (last_elevation_refresh_version == expected_version) |
331 return false; | 329 return false; |
332 | 330 |
333 HRESULT hr = ::IERefreshElevationPolicy(); | 331 HRESULT hr = ::IERefreshElevationPolicy(); |
334 VLOG(1) << "Elevation policy refresh result: " << com::LogHr(hr); | 332 VLOG(1) << "Elevation policy refresh result: " << com::LogHr(hr); |
335 | 333 |
336 // Write after refreshing because it's better to refresh twice, than to miss | 334 // Write after refreshing because it's better to refresh twice, than to miss |
337 // once. | 335 // once. |
338 result = hkcu.WriteValue(kValueName, expected_version.c_str()); | 336 result = hkcu.WriteValue(kValueName, expected_version.c_str()); |
339 LOG_IF(ERROR, !result) << "Failed to write a registry value: " << kValueName; | 337 LOG_IF(ERROR, result != ERROR_SUCCESS) << "Failed to write a registry value: " |
338 << kValueName << " error: " << com::LogWe(result); | |
340 | 339 |
341 return true; | 340 return true; |
342 } | 341 } |
343 | 342 |
344 } // namespace ceee_module_util | 343 } // namespace ceee_module_util |
OLD | NEW |