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 // chrome_tab.cc : Implementation of DLL Exports. | 5 // chrome_tab.cc : Implementation of DLL Exports. |
6 | 6 |
7 // Include without path to make GYP build see it. | 7 // Include without path to make GYP build see it. |
8 #include "chrome_tab.h" // NOLINT | 8 #include "chrome_tab.h" // NOLINT |
9 | 9 |
10 #include <atlsecurity.h> | 10 #include <atlsecurity.h> |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 channel_name.find(L"ceee") != std::wstring::npos) { | 317 channel_name.find(L"ceee") != std::wstring::npos) { |
318 | 318 |
319 HKEY hive = HKEY_CURRENT_USER; | 319 HKEY hive = HKEY_CURRENT_USER; |
320 if (IsSystemProcess()) { | 320 if (IsSystemProcess()) { |
321 // For system installs, our updates will be running as SYSTEM which | 321 // For system installs, our updates will be running as SYSTEM which |
322 // makes writing to a RunOnce key under HKCU not so terribly useful. | 322 // makes writing to a RunOnce key under HKCU not so terribly useful. |
323 hive = HKEY_LOCAL_MACHINE; | 323 hive = HKEY_LOCAL_MACHINE; |
324 } | 324 } |
325 | 325 |
326 RegKey run_once; | 326 RegKey run_once; |
327 if (run_once.Create(hive, kRunOnce, KEY_READ | KEY_WRITE)) { | 327 LONG ret = run_once.Create(hive, kRunOnce, KEY_READ | KEY_WRITE); |
328 if (ret == ERROR_SUCCESS) { | |
328 CommandLine run_once_cmd(chrome_launcher::GetChromeExecutablePath()); | 329 CommandLine run_once_cmd(chrome_launcher::GetChromeExecutablePath()); |
329 run_once_cmd.AppendSwitchASCII(switches::kAutomationClientChannelID, | 330 run_once_cmd.AppendSwitchASCII(switches::kAutomationClientChannelID, |
330 "0"); | 331 "0"); |
331 run_once_cmd.AppendSwitch(switches::kChromeFrame); | 332 run_once_cmd.AppendSwitch(switches::kChromeFrame); |
332 if (run_once.WriteValue(L"A", | 333 ret = run_once.WriteValue(L"A", |
333 run_once_cmd.command_line_string().c_str())) { | 334 run_once_cmd.command_line_string().c_str()); |
334 result = S_OK; | |
335 } | |
336 } | 335 } |
grt (UTC plus 2)
2011/01/14 15:53:43
Looks like you're missing "if (ret == ERROR_SUCCES
amit
2011/01/15 01:28:11
Next HRESULT_FROM_WIN32 should translate ERROR_SUC
grt (UTC plus 2)
2011/01/16 04:19:48
Oh yeah. Sweet.
| |
336 result = HRESULT_FROM_WIN32(ret); | |
337 } else { | 337 } else { |
338 result = S_FALSE; | 338 result = S_FALSE; |
339 } | 339 } |
340 } else { | 340 } else { |
341 // We're on a non-XP version of Windows or on a stable channel. Nothing | 341 // We're on a non-XP version of Windows or on a stable channel. Nothing |
342 // needs doing. | 342 // needs doing. |
343 result = S_FALSE; | 343 result = S_FALSE; |
344 } | 344 } |
345 | 345 |
346 return result; | 346 return result; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; | 427 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; |
428 | 428 |
429 // To delete the user agent, set value to NULL. | 429 // To delete the user agent, set value to NULL. |
430 // The is_system parameter indicates whether this is a per machine or a per | 430 // The is_system parameter indicates whether this is a per machine or a per |
431 // user installation. | 431 // user installation. |
432 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) { | 432 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) { |
433 HRESULT hr = E_FAIL; | 433 HRESULT hr = E_FAIL; |
434 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 434 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
435 | 435 |
436 RegKey ua_key; | 436 RegKey ua_key; |
437 if (ua_key.Create(parent_hive, kPostPlatformUAKey, KEY_WRITE)) { | 437 if (ua_key.Create(parent_hive, kPostPlatformUAKey, |
438 KEY_WRITE) == ERROR_SUCCESS) { | |
438 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix; | 439 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix; |
439 chrome_frame_ua_value_name += GetCurrentModuleVersion(); | 440 chrome_frame_ua_value_name += GetCurrentModuleVersion(); |
440 if (value) { | 441 if (value) { |
441 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value); | 442 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value); |
442 } else { | 443 } else { |
443 ua_key.DeleteValue(chrome_frame_ua_value_name.c_str()); | 444 ua_key.DeleteValue(chrome_frame_ua_value_name.c_str()); |
444 } | 445 } |
445 hr = S_OK; | 446 hr = S_OK; |
446 } else { | 447 } else { |
447 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey; | 448 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 | 626 |
626 // Save given security descriptor to the backup key. | 627 // Save given security descriptor to the backup key. |
627 bool SaveSecurity(const CSecurityDesc& sd) { | 628 bool SaveSecurity(const CSecurityDesc& sd) { |
628 CString str; | 629 CString str; |
629 if (!sd.ToString(&str)) | 630 if (!sd.ToString(&str)) |
630 return false; | 631 return false; |
631 | 632 |
632 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), | 633 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), |
633 KEY_READ | KEY_WRITE); | 634 KEY_READ | KEY_WRITE); |
634 if (backup_key.Valid()) { | 635 if (backup_key.Valid()) { |
635 return backup_key.WriteValue(NULL, str.GetString()); | 636 return backup_key.WriteValue(NULL, str.GetString()) == ERROR_SUCCESS; |
636 } | 637 } |
637 | 638 |
638 return false; | 639 return false; |
639 } | 640 } |
640 | 641 |
641 // Restore security descriptor from backup key to given key name. | 642 // Restore security descriptor from backup key to given key name. |
642 bool RestoreSecurity(const wchar_t* key_name) { | 643 bool RestoreSecurity(const wchar_t* key_name) { |
643 std::wstring sddl; | 644 std::wstring sddl; |
644 if (!ReadBackupKey(&sddl)) | 645 if (!ReadBackupKey(&sddl)) |
645 return false; | 646 return false; |
(...skipping 21 matching lines...) Expand all Loading... | |
667 | 668 |
668 private: | 669 private: |
669 // Read SDDL string from backup key | 670 // Read SDDL string from backup key |
670 bool ReadBackupKey(std::wstring* sddl) { | 671 bool ReadBackupKey(std::wstring* sddl) { |
671 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), KEY_READ); | 672 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), KEY_READ); |
672 if (!backup_key.Valid()) | 673 if (!backup_key.Valid()) |
673 return false; | 674 return false; |
674 | 675 |
675 DWORD len = 0; | 676 DWORD len = 0; |
676 DWORD reg_type = REG_NONE; | 677 DWORD reg_type = REG_NONE; |
677 if (!backup_key.ReadValue(NULL, NULL, &len, ®_type)) | 678 if (backup_key.ReadValue(NULL, NULL, &len, ®_type) != ERROR_SUCCESS) |
678 return false; | 679 return false; |
679 | 680 |
680 if (reg_type != REG_SZ) | 681 if (reg_type != REG_SZ) |
681 return false; | 682 return false; |
682 | 683 |
683 size_t wchar_count = 1 + len / sizeof(wchar_t); | 684 size_t wchar_count = 1 + len / sizeof(wchar_t); |
684 if (!backup_key.ReadValue(NULL, WriteInto(sddl, wchar_count), &len, | 685 if (backup_key.ReadValue(NULL, WriteInto(sddl, wchar_count), &len, |
685 ®_type)) { | 686 ®_type) != ERROR_SUCCESS) { |
686 return false; | 687 return false; |
687 } | 688 } |
688 | 689 |
689 return true; | 690 return true; |
690 } | 691 } |
691 | 692 |
692 void DeleteBackupKey() { | 693 void DeleteBackupKey() { |
693 ::RegDeleteKey(HKEY_LOCAL_MACHINE, backup_key_name_.c_str()); | 694 ::RegDeleteKey(HKEY_LOCAL_MACHINE, backup_key_name_.c_str()); |
694 } | 695 } |
695 | 696 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
731 CSid user_; | 732 CSid user_; |
732 }; | 733 }; |
733 | 734 |
734 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) { | 735 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) { |
735 std::wstring key_name = kInternetSettings; | 736 std::wstring key_name = kInternetSettings; |
736 key_name.append(L"\\Secure Mime Handlers"); | 737 key_name.append(L"\\Secure Mime Handlers"); |
737 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE); | 738 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE); |
738 if (!key.Valid()) | 739 if (!key.Valid()) |
739 return false; | 740 return false; |
740 | 741 |
741 bool result; | 742 LONG result1 = ERROR_SUCCESS; |
743 LONG result2 = ERROR_SUCCESS; | |
742 if (set) { | 744 if (set) { |
743 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1); | 745 result1 = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1); |
744 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1) && result; | 746 result2 = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1); |
745 } else { | 747 } else { |
746 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument"); | 748 result1 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument"); |
747 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1") && result; | 749 result2 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1"); |
748 } | 750 } |
749 | 751 |
750 return result; | 752 return (result2 == ERROR_SUCCESS) && (result2 == ERROR_SUCCESS); |
751 } | 753 } |
752 | 754 |
753 bool RegisterSecuredMimeHandler(bool enable, bool is_system) { | 755 bool RegisterSecuredMimeHandler(bool enable, bool is_system) { |
754 if (!is_system) { | 756 if (!is_system) { |
755 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER); | 757 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER); |
756 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 758 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
757 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); | 759 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); |
758 } | 760 } |
759 | 761 |
760 std::wstring mime_key = kInternetSettings; | 762 std::wstring mime_key = kInternetSettings; |
(...skipping 27 matching lines...) Expand all Loading... | |
788 sd.GetDacl(&new_dacl); | 790 sd.GetDacl(&new_dacl); |
789 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); | 791 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); |
790 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { | 792 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { |
791 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); | 793 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); |
792 } | 794 } |
793 } | 795 } |
794 | 796 |
795 backup.RestoreSecurity(object_name.c_str()); | 797 backup.RestoreSecurity(object_name.c_str()); |
796 return result; | 798 return result; |
797 } | 799 } |
OLD | NEW |