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 // 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 // Checks if the current registry entry exists in HKLM registry and the value | 196 // Checks if the current registry entry exists in HKLM registry and the value |
197 // is same. | 197 // is same. |
198 bool ExistsInHKLM() const { | 198 bool ExistsInHKLM() const { |
199 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str(), KEY_READ); | 199 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str(), KEY_READ); |
200 bool found = false; | 200 bool found = false; |
201 if (_is_string) { | 201 if (_is_string) { |
202 std::wstring read_value; | 202 std::wstring read_value; |
203 found = (key.ReadValue(_name.c_str(), &read_value)) && | 203 found = (key.ReadValue(_name.c_str(), &read_value) == ERROR_SUCCESS) && |
204 (read_value.size() == _value.size()) && | 204 (read_value.size() == _value.size()) && |
205 (std::equal(_value.begin(), _value.end(), read_value.begin(), | 205 (std::equal(_value.begin(), _value.end(), read_value.begin(), |
206 base::CaseInsensitiveCompare<wchar_t>())); | 206 base::CaseInsensitiveCompare<wchar_t>())); |
207 } else { | 207 } else { |
208 DWORD read_value; | 208 DWORD read_value; |
209 found = key.ReadValueDW(_name.c_str(), &read_value) && | 209 found = (key.ReadValueDW(_name.c_str(), &read_value) == ERROR_SUCCESS) && |
210 read_value == _int_value; | 210 (read_value == _int_value); |
211 } | 211 } |
212 key.Close(); | 212 key.Close(); |
213 return found; | 213 return found; |
214 } | 214 } |
215 | 215 |
216 // Checks if the current registry entry exists in HKLM registry | 216 // Checks if the current registry entry exists in HKLM registry |
217 // (only the name). | 217 // (only the name). |
218 bool NameExistsInHKLM() const { | 218 bool NameExistsInHKLM() const { |
219 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str(), KEY_READ); | 219 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str(), KEY_READ); |
220 bool found = false; | 220 bool found = false; |
221 if (_is_string) { | 221 if (_is_string) { |
222 std::wstring read_value; | 222 std::wstring read_value; |
223 found = key.ReadValue(_name.c_str(), &read_value); | 223 found = key.ReadValue(_name.c_str(), &read_value) == ERROR_SUCCESS; |
224 } else { | 224 } else { |
225 DWORD read_value; | 225 DWORD read_value; |
226 found = key.ReadValueDW(_name.c_str(), &read_value); | 226 found = key.ReadValueDW(_name.c_str(), &read_value) == ERROR_SUCCESS; |
227 } | 227 } |
228 key.Close(); | 228 key.Close(); |
229 return found; | 229 return found; |
230 } | 230 } |
231 | 231 |
232 private: | 232 private: |
233 DISALLOW_COPY_AND_ASSIGN(RegistryEntry); | 233 DISALLOW_COPY_AND_ASSIGN(RegistryEntry); |
234 | 234 |
235 // Create a object that represent default value of a key | 235 // Create a object that represent default value of a key |
236 RegistryEntry(const std::wstring& key_path, const std::wstring& value) | 236 RegistryEntry(const std::wstring& key_path, const std::wstring& value) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 // - The value should not be same as given value in |chrome_exe| | 349 // - The value should not be same as given value in |chrome_exe| |
350 // - Finally to handle the default install path (C:\Document and Settings\ | 350 // - Finally to handle the default install path (C:\Document and Settings\ |
351 // <user>\Local Settings\Application Data\Chromium\Application) the value | 351 // <user>\Local Settings\Application Data\Chromium\Application) the value |
352 // of the above key should differ from |chrome_exe| only in user name. | 352 // of the above key should differ from |chrome_exe| only in user name. |
353 bool AnotherUserHasDefaultBrowser(BrowserDistribution* dist, | 353 bool AnotherUserHasDefaultBrowser(BrowserDistribution* dist, |
354 const std::wstring& chrome_exe) { | 354 const std::wstring& chrome_exe) { |
355 std::wstring reg_key(ShellUtil::kRegStartMenuInternet); | 355 std::wstring reg_key(ShellUtil::kRegStartMenuInternet); |
356 reg_key.append(L"\\" + dist->GetApplicationName() + ShellUtil::kRegShellOpen); | 356 reg_key.append(L"\\" + dist->GetApplicationName() + ShellUtil::kRegShellOpen); |
357 RegKey key(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_READ); | 357 RegKey key(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_READ); |
358 std::wstring registry_chrome_exe; | 358 std::wstring registry_chrome_exe; |
359 if (!key.ReadValue(L"", ®istry_chrome_exe) || | 359 if ((key.ReadValue(L"", ®istry_chrome_exe) != ERROR_SUCCESS) || |
360 registry_chrome_exe.length() < 2) | 360 registry_chrome_exe.length() < 2) |
361 return false; | 361 return false; |
362 | 362 |
363 registry_chrome_exe = registry_chrome_exe.substr(1, | 363 registry_chrome_exe = registry_chrome_exe.substr(1, |
364 registry_chrome_exe.length() - 2); | 364 registry_chrome_exe.length() - 2); |
365 if ((registry_chrome_exe.size() == chrome_exe.size()) && | 365 if ((registry_chrome_exe.size() == chrome_exe.size()) && |
366 (std::equal(chrome_exe.begin(), chrome_exe.end(), | 366 (std::equal(chrome_exe.begin(), chrome_exe.end(), |
367 registry_chrome_exe.begin(), | 367 registry_chrome_exe.begin(), |
368 base::CaseInsensitiveCompare<wchar_t>()))) { | 368 base::CaseInsensitiveCompare<wchar_t>()))) { |
369 return false; | 369 return false; |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 std::map<std::wstring, | 576 std::map<std::wstring, |
577 std::wstring>* browsers) { | 577 std::wstring>* browsers) { |
578 std::wstring base_key(ShellUtil::kRegStartMenuInternet); | 578 std::wstring base_key(ShellUtil::kRegStartMenuInternet); |
579 HKEY root = HKEY_LOCAL_MACHINE; | 579 HKEY root = HKEY_LOCAL_MACHINE; |
580 for (base::win::RegistryKeyIterator iter(root, base_key.c_str()); | 580 for (base::win::RegistryKeyIterator iter(root, base_key.c_str()); |
581 iter.Valid(); ++iter) { | 581 iter.Valid(); ++iter) { |
582 std::wstring key = base_key + L"\\" + iter.Name(); | 582 std::wstring key = base_key + L"\\" + iter.Name(); |
583 RegKey capabilities(root, (key + L"\\Capabilities").c_str(), KEY_READ); | 583 RegKey capabilities(root, (key + L"\\Capabilities").c_str(), KEY_READ); |
584 std::wstring name; | 584 std::wstring name; |
585 if (!capabilities.Valid() || | 585 if (!capabilities.Valid() || |
586 !capabilities.ReadValue(L"ApplicationName", &name)) { | 586 capabilities.ReadValue(L"ApplicationName", &name) != ERROR_SUCCESS) { |
587 RegKey base_key(root, key.c_str(), KEY_READ); | 587 RegKey base_key(root, key.c_str(), KEY_READ); |
588 if (!base_key.ReadValue(L"", &name)) | 588 if (base_key.ReadValue(L"", &name) != ERROR_SUCCESS) |
589 continue; | 589 continue; |
590 } | 590 } |
591 RegKey install_info(root, (key + L"\\InstallInfo").c_str(), KEY_READ); | 591 RegKey install_info(root, (key + L"\\InstallInfo").c_str(), KEY_READ); |
592 std::wstring command; | 592 std::wstring command; |
593 if (!install_info.Valid() || | 593 if (!install_info.Valid() || |
594 !install_info.ReadValue(L"ReinstallCommand", &command)) | 594 (install_info.ReadValue(L"ReinstallCommand", |
| 595 &command) != ERROR_SUCCESS)) |
595 continue; | 596 continue; |
596 if (!name.empty() && !command.empty() && | 597 if (!name.empty() && !command.empty() && |
597 name.find(dist->GetApplicationName()) == std::wstring::npos) | 598 name.find(dist->GetApplicationName()) == std::wstring::npos) |
598 (*browsers)[name] = command; | 599 (*browsers)[name] = command; |
599 } | 600 } |
600 } | 601 } |
601 | 602 |
602 bool ShellUtil::GetUserSpecificDefaultBrowserSuffix(BrowserDistribution* dist, | 603 bool ShellUtil::GetUserSpecificDefaultBrowserSuffix(BrowserDistribution* dist, |
603 std::wstring* entry) { | 604 std::wstring* entry) { |
604 wchar_t user_name[256]; | 605 wchar_t user_name[256]; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 chrome_exe.c_str(), // target | 809 chrome_exe.c_str(), // target |
809 shortcut.c_str(), // shortcut | 810 shortcut.c_str(), // shortcut |
810 chrome_path.c_str(), // working dir | 811 chrome_path.c_str(), // working dir |
811 NULL, // arguments | 812 NULL, // arguments |
812 description.c_str(), // description | 813 description.c_str(), // description |
813 chrome_exe.c_str(), // icon file | 814 chrome_exe.c_str(), // icon file |
814 icon_index, // icon index | 815 icon_index, // icon index |
815 dist->GetBrowserAppId().c_str()); // app id | 816 dist->GetBrowserAppId().c_str()); // app id |
816 } | 817 } |
817 } | 818 } |
OLD | NEW |