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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 if (_is_string) { | 184 if (_is_string) { |
185 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); | 185 items->AddSetRegValueWorkItem(root, _key_path, _name, _value, true); |
186 } else { | 186 } else { |
187 items->AddSetRegValueWorkItem(root, _key_path, _name, _int_value, true); | 187 items->AddSetRegValueWorkItem(root, _key_path, _name, _int_value, true); |
188 } | 188 } |
189 } | 189 } |
190 | 190 |
191 // Checks if the current registry entry exists in HKLM registry and the value | 191 // Checks if the current registry entry exists in HKLM registry and the value |
192 // is same. | 192 // is same. |
193 bool ExistsInHKLM() const { | 193 bool ExistsInHKLM() const { |
194 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str()); | 194 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str(), KEY_READ); |
195 bool found = false; | 195 bool found = false; |
196 if (_is_string) { | 196 if (_is_string) { |
197 std::wstring read_value; | 197 std::wstring read_value; |
198 found = (key.ReadValue(_name.c_str(), &read_value)) && | 198 found = (key.ReadValue(_name.c_str(), &read_value)) && |
199 (read_value.size() == _value.size()) && | 199 (read_value.size() == _value.size()) && |
200 (std::equal(_value.begin(), _value.end(), read_value.begin(), | 200 (std::equal(_value.begin(), _value.end(), read_value.begin(), |
201 CaseInsensitiveCompare<wchar_t>())); | 201 CaseInsensitiveCompare<wchar_t>())); |
202 } else { | 202 } else { |
203 DWORD read_value; | 203 DWORD read_value; |
204 found = key.ReadValueDW(_name.c_str(), &read_value) && | 204 found = key.ReadValueDW(_name.c_str(), &read_value) && |
205 read_value == _int_value; | 205 read_value == _int_value; |
206 } | 206 } |
207 key.Close(); | 207 key.Close(); |
208 return found; | 208 return found; |
209 } | 209 } |
210 | 210 |
211 // Checks if the current registry entry exists in HKLM registry | 211 // Checks if the current registry entry exists in HKLM registry |
212 // (only the name). | 212 // (only the name). |
213 bool NameExistsInHKLM() const { | 213 bool NameExistsInHKLM() const { |
214 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str()); | 214 RegKey key(HKEY_LOCAL_MACHINE, _key_path.c_str(), KEY_READ); |
215 bool found = false; | 215 bool found = false; |
216 if (_is_string) { | 216 if (_is_string) { |
217 std::wstring read_value; | 217 std::wstring read_value; |
218 found = key.ReadValue(_name.c_str(), &read_value); | 218 found = key.ReadValue(_name.c_str(), &read_value); |
219 } else { | 219 } else { |
220 DWORD read_value; | 220 DWORD read_value; |
221 found = key.ReadValueDW(_name.c_str(), &read_value); | 221 found = key.ReadValueDW(_name.c_str(), &read_value); |
222 } | 222 } |
223 key.Close(); | 223 key.Close(); |
224 return found; | 224 return found; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 // the new process will make the necessary changes and return SUCCESS that | 296 // the new process will make the necessary changes and return SUCCESS that |
297 // we capture and return. | 297 // we capture and return. |
298 bool ElevateAndRegisterChrome(const std::wstring& chrome_exe, | 298 bool ElevateAndRegisterChrome(const std::wstring& chrome_exe, |
299 const std::wstring& suffix) { | 299 const std::wstring& suffix) { |
300 std::wstring exe_path(file_util::GetDirectoryFromPath(chrome_exe)); | 300 std::wstring exe_path(file_util::GetDirectoryFromPath(chrome_exe)); |
301 file_util::AppendToPath(&exe_path, installer_util::kSetupExe); | 301 file_util::AppendToPath(&exe_path, installer_util::kSetupExe); |
302 if (!file_util::PathExists(FilePath::FromWStringHack(exe_path))) { | 302 if (!file_util::PathExists(FilePath::FromWStringHack(exe_path))) { |
303 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 303 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
304 HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? | 304 HKEY reg_root = InstallUtil::IsPerUserInstall(chrome_exe.c_str()) ? |
305 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; | 305 HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE; |
306 RegKey key(reg_root, dist->GetUninstallRegPath().c_str()); | 306 RegKey key(reg_root, dist->GetUninstallRegPath().c_str(), KEY_READ); |
307 key.ReadValue(installer_util::kUninstallStringField, &exe_path); | 307 key.ReadValue(installer_util::kUninstallStringField, &exe_path); |
308 CommandLine command_line = CommandLine::FromString(exe_path); | 308 CommandLine command_line = CommandLine::FromString(exe_path); |
309 exe_path = command_line.program(); | 309 exe_path = command_line.program(); |
310 } | 310 } |
311 if (file_util::PathExists(FilePath::FromWStringHack(exe_path))) { | 311 if (file_util::PathExists(FilePath::FromWStringHack(exe_path))) { |
312 std::wstring params(L"--"); | 312 std::wstring params(L"--"); |
313 params.append( | 313 params.append( |
314 ASCIIToWide(installer_util::switches::kRegisterChromeBrowser)); | 314 ASCIIToWide(installer_util::switches::kRegisterChromeBrowser)); |
315 params.append(L"=\"" + chrome_exe + L"\""); | 315 params.append(L"=\"" + chrome_exe + L"\""); |
316 if (!suffix.empty()) { | 316 if (!suffix.empty()) { |
(...skipping 25 matching lines...) Expand all Loading... |
342 // - Software\Clients\StartMenuInternet\Chromium\"" key should have a valid | 342 // - Software\Clients\StartMenuInternet\Chromium\"" key should have a valid |
343 // value. | 343 // value. |
344 // - The value should not be same as given value in |chrome_exe| | 344 // - The value should not be same as given value in |chrome_exe| |
345 // - Finally to handle the default install path (C:\Document and Settings\ | 345 // - Finally to handle the default install path (C:\Document and Settings\ |
346 // <user>\Local Settings\Application Data\Chromium\Application) the value | 346 // <user>\Local Settings\Application Data\Chromium\Application) the value |
347 // of the above key should differ from |chrome_exe| only in user name. | 347 // of the above key should differ from |chrome_exe| only in user name. |
348 bool AnotherUserHasDefaultBrowser(const std::wstring& chrome_exe) { | 348 bool AnotherUserHasDefaultBrowser(const std::wstring& chrome_exe) { |
349 std::wstring reg_key(ShellUtil::kRegStartMenuInternet); | 349 std::wstring reg_key(ShellUtil::kRegStartMenuInternet); |
350 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 350 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
351 reg_key.append(L"\\" + dist->GetApplicationName() + ShellUtil::kRegShellOpen); | 351 reg_key.append(L"\\" + dist->GetApplicationName() + ShellUtil::kRegShellOpen); |
352 RegKey key(HKEY_LOCAL_MACHINE, reg_key.c_str()); | 352 RegKey key(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_READ); |
353 std::wstring registry_chrome_exe; | 353 std::wstring registry_chrome_exe; |
354 if (!key.ReadValue(L"", ®istry_chrome_exe) || | 354 if (!key.ReadValue(L"", ®istry_chrome_exe) || |
355 registry_chrome_exe.length() < 2) | 355 registry_chrome_exe.length() < 2) |
356 return false; | 356 return false; |
357 | 357 |
358 registry_chrome_exe = registry_chrome_exe.substr(1, | 358 registry_chrome_exe = registry_chrome_exe.substr(1, |
359 registry_chrome_exe.length() - 2); | 359 registry_chrome_exe.length() - 2); |
360 if ((registry_chrome_exe.size() == chrome_exe.size()) && | 360 if ((registry_chrome_exe.size() == chrome_exe.size()) && |
361 (std::equal(chrome_exe.begin(), chrome_exe.end(), | 361 (std::equal(chrome_exe.begin(), chrome_exe.end(), |
362 registry_chrome_exe.begin(), | 362 registry_chrome_exe.begin(), |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 file_util::AppendToPath(path, kQuickLaunchPath); | 562 file_util::AppendToPath(path, kQuickLaunchPath); |
563 return true; | 563 return true; |
564 } | 564 } |
565 | 565 |
566 void ShellUtil::GetRegisteredBrowsers(std::map<std::wstring, | 566 void ShellUtil::GetRegisteredBrowsers(std::map<std::wstring, |
567 std::wstring>* browsers) { | 567 std::wstring>* browsers) { |
568 std::wstring base_key(ShellUtil::kRegStartMenuInternet); | 568 std::wstring base_key(ShellUtil::kRegStartMenuInternet); |
569 HKEY root = HKEY_LOCAL_MACHINE; | 569 HKEY root = HKEY_LOCAL_MACHINE; |
570 for (RegistryKeyIterator iter(root, base_key.c_str()); iter.Valid(); ++iter) { | 570 for (RegistryKeyIterator iter(root, base_key.c_str()); iter.Valid(); ++iter) { |
571 std::wstring key = base_key + L"\\" + iter.Name(); | 571 std::wstring key = base_key + L"\\" + iter.Name(); |
572 RegKey capabilities(root, (key + L"\\Capabilities").c_str()); | 572 RegKey capabilities(root, (key + L"\\Capabilities").c_str(), KEY_READ); |
573 std::wstring name; | 573 std::wstring name; |
574 if (!capabilities.Valid() || | 574 if (!capabilities.Valid() || |
575 !capabilities.ReadValue(L"ApplicationName", &name)) { | 575 !capabilities.ReadValue(L"ApplicationName", &name)) { |
576 RegKey base_key(root, key.c_str()); | 576 RegKey base_key(root, key.c_str(), KEY_READ); |
577 if (!base_key.ReadValue(L"", &name)) | 577 if (!base_key.ReadValue(L"", &name)) |
578 continue; | 578 continue; |
579 } | 579 } |
580 RegKey install_info(root, (key + L"\\InstallInfo").c_str()); | 580 RegKey install_info(root, (key + L"\\InstallInfo").c_str(), KEY_READ); |
581 std::wstring command; | 581 std::wstring command; |
582 if (!install_info.Valid() || | 582 if (!install_info.Valid() || |
583 !install_info.ReadValue(L"ReinstallCommand", &command)) | 583 !install_info.ReadValue(L"ReinstallCommand", &command)) |
584 continue; | 584 continue; |
585 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 585 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
586 if (!name.empty() && !command.empty() && | 586 if (!name.empty() && !command.empty() && |
587 name.find(dist->GetApplicationName()) == std::wstring::npos) | 587 name.find(dist->GetApplicationName()) == std::wstring::npos) |
588 (*browsers)[name] = command; | 588 (*browsers)[name] = command; |
589 } | 589 } |
590 } | 590 } |
591 | 591 |
592 bool ShellUtil::GetUserSpecificDefaultBrowserSuffix(std::wstring* entry) { | 592 bool ShellUtil::GetUserSpecificDefaultBrowserSuffix(std::wstring* entry) { |
593 wchar_t user_name[256]; | 593 wchar_t user_name[256]; |
594 DWORD size = _countof(user_name); | 594 DWORD size = _countof(user_name); |
595 if (::GetUserName(user_name, &size) == 0) | 595 if (::GetUserName(user_name, &size) == 0) |
596 return false; | 596 return false; |
597 entry->assign(L"."); | 597 entry->assign(L"."); |
598 entry->append(user_name); | 598 entry->append(user_name); |
599 | 599 |
600 std::wstring start_menu_entry(ShellUtil::kRegStartMenuInternet); | 600 std::wstring start_menu_entry(ShellUtil::kRegStartMenuInternet); |
601 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 601 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
602 start_menu_entry.append(L"\\" + dist->GetApplicationName() + *entry); | 602 start_menu_entry.append(L"\\" + dist->GetApplicationName() + *entry); |
603 RegKey key(HKEY_LOCAL_MACHINE, start_menu_entry.c_str()); | 603 RegKey key(HKEY_LOCAL_MACHINE, start_menu_entry.c_str(), KEY_READ); |
604 return key.Valid(); | 604 return key.Valid(); |
605 } | 605 } |
606 | 606 |
607 bool ShellUtil::MakeChromeDefault(int shell_change, | 607 bool ShellUtil::MakeChromeDefault(int shell_change, |
608 const std::wstring& chrome_exe, | 608 const std::wstring& chrome_exe, |
609 bool elevate_if_not_admin) { | 609 bool elevate_if_not_admin) { |
610 if (!BrowserDistribution::GetDistribution()->CanSetAsDefault()) | 610 if (!BrowserDistribution::GetDistribution()->CanSetAsDefault()) |
611 return false; | 611 return false; |
612 | 612 |
613 ShellUtil::RegisterChromeBrowser(chrome_exe, L"", elevate_if_not_admin); | 613 ShellUtil::RegisterChromeBrowser(chrome_exe, L"", elevate_if_not_admin); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
797 chrome_exe.c_str(), // target | 797 chrome_exe.c_str(), // target |
798 shortcut.c_str(), // shortcut | 798 shortcut.c_str(), // shortcut |
799 chrome_path.c_str(), // working dir | 799 chrome_path.c_str(), // working dir |
800 NULL, // arguments | 800 NULL, // arguments |
801 description.c_str(), // description | 801 description.c_str(), // description |
802 chrome_exe.c_str(), // icon file | 802 chrome_exe.c_str(), // icon file |
803 icon_index, // icon index | 803 icon_index, // icon index |
804 dist->GetBrowserAppId().c_str()); // app id | 804 dist->GetBrowserAppId().c_str()); // app id |
805 } | 805 } |
806 } | 806 } |
OLD | NEW |