Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: chrome_frame/chrome_tab.cc

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/plugin/plugin_test.cpp ('k') | chrome_frame/crash_reporting/crash_metrics.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
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
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_READ | KEY_WRITE)) { 437 if (ua_key.Create(parent_hive, kPostPlatformUAKey,
438 KEY_READ | KEY_WRITE) == ERROR_SUCCESS) {
438 // Make sure that we unregister ChromeFrame UA strings registered previously 439 // Make sure that we unregister ChromeFrame UA strings registered previously
439 wchar_t value_name[MAX_PATH + 1] = {}; 440 wchar_t value_name[MAX_PATH + 1] = {};
440 wchar_t value_data[MAX_PATH + 1] = {}; 441 wchar_t value_data[MAX_PATH + 1] = {};
441 442
442 DWORD value_index = 0; 443 DWORD value_index = 0;
443 while (value_index < ua_key.ValueCount()) { 444 while (value_index < ua_key.ValueCount()) {
444 DWORD name_size = arraysize(value_name); 445 DWORD name_size = arraysize(value_name);
445 DWORD value_size = arraysize(value_data); 446 DWORD value_size = arraysize(value_data);
446 DWORD type = 0; 447 DWORD type = 0;
447 LRESULT ret = ::RegEnumValue(ua_key.Handle(), value_index, value_name, 448 LRESULT ret = ::RegEnumValue(ua_key.Handle(), value_index, value_name,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 648
648 // Save given security descriptor to the backup key. 649 // Save given security descriptor to the backup key.
649 bool SaveSecurity(const CSecurityDesc& sd) { 650 bool SaveSecurity(const CSecurityDesc& sd) {
650 CString str; 651 CString str;
651 if (!sd.ToString(&str)) 652 if (!sd.ToString(&str))
652 return false; 653 return false;
653 654
654 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), 655 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(),
655 KEY_READ | KEY_WRITE); 656 KEY_READ | KEY_WRITE);
656 if (backup_key.Valid()) { 657 if (backup_key.Valid()) {
657 return backup_key.WriteValue(NULL, str.GetString()); 658 return backup_key.WriteValue(NULL, str.GetString()) == ERROR_SUCCESS;
658 } 659 }
659 660
660 return false; 661 return false;
661 } 662 }
662 663
663 // Restore security descriptor from backup key to given key name. 664 // Restore security descriptor from backup key to given key name.
664 bool RestoreSecurity(const wchar_t* key_name) { 665 bool RestoreSecurity(const wchar_t* key_name) {
665 std::wstring sddl; 666 std::wstring sddl;
666 if (!ReadBackupKey(&sddl)) 667 if (!ReadBackupKey(&sddl))
667 return false; 668 return false;
(...skipping 21 matching lines...) Expand all
689 690
690 private: 691 private:
691 // Read SDDL string from backup key 692 // Read SDDL string from backup key
692 bool ReadBackupKey(std::wstring* sddl) { 693 bool ReadBackupKey(std::wstring* sddl) {
693 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), KEY_READ); 694 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), KEY_READ);
694 if (!backup_key.Valid()) 695 if (!backup_key.Valid())
695 return false; 696 return false;
696 697
697 DWORD len = 0; 698 DWORD len = 0;
698 DWORD reg_type = REG_NONE; 699 DWORD reg_type = REG_NONE;
699 if (!backup_key.ReadValue(NULL, NULL, &len, &reg_type)) 700 if (backup_key.ReadValue(NULL, NULL, &len, &reg_type) != ERROR_SUCCESS)
700 return false; 701 return false;
701 702
702 if (reg_type != REG_SZ) 703 if (reg_type != REG_SZ)
703 return false; 704 return false;
704 705
705 size_t wchar_count = 1 + len / sizeof(wchar_t); 706 size_t wchar_count = 1 + len / sizeof(wchar_t);
706 if (!backup_key.ReadValue(NULL, WriteInto(sddl, wchar_count), &len, 707 if (backup_key.ReadValue(NULL, WriteInto(sddl, wchar_count), &len,
707 &reg_type)) { 708 &reg_type) != ERROR_SUCCESS) {
708 return false; 709 return false;
709 } 710 }
710 711
711 return true; 712 return true;
712 } 713 }
713 714
714 void DeleteBackupKey() { 715 void DeleteBackupKey() {
715 ::RegDeleteKey(HKEY_LOCAL_MACHINE, backup_key_name_.c_str()); 716 ::RegDeleteKey(HKEY_LOCAL_MACHINE, backup_key_name_.c_str());
716 } 717 }
717 718
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 CSid user_; 754 CSid user_;
754 }; 755 };
755 756
756 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) { 757 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) {
757 std::wstring key_name = kInternetSettings; 758 std::wstring key_name = kInternetSettings;
758 key_name.append(L"\\Secure Mime Handlers"); 759 key_name.append(L"\\Secure Mime Handlers");
759 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE); 760 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE);
760 if (!key.Valid()) 761 if (!key.Valid())
761 return false; 762 return false;
762 763
763 bool result; 764 LONG result1 = ERROR_SUCCESS;
765 LONG result2 = ERROR_SUCCESS;
764 if (set) { 766 if (set) {
765 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1); 767 result1 = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1);
766 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1) && result; 768 result2 = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1);
767 } else { 769 } else {
768 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument"); 770 result1 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument");
769 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1") && result; 771 result2 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1");
770 } 772 }
771 773
772 return result; 774 return (result2 == ERROR_SUCCESS) && (result2 == ERROR_SUCCESS);
773 } 775 }
774 776
775 bool RegisterSecuredMimeHandler(bool enable, bool is_system) { 777 bool RegisterSecuredMimeHandler(bool enable, bool is_system) {
776 if (!is_system) { 778 if (!is_system) {
777 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER); 779 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER);
778 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { 780 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) {
779 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); 781 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
780 } 782 }
781 783
782 std::wstring mime_key = kInternetSettings; 784 std::wstring mime_key = kInternetSettings;
(...skipping 27 matching lines...) Expand all
810 sd.GetDacl(&new_dacl); 812 sd.GetDacl(&new_dacl);
811 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); 813 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ);
812 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { 814 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) {
813 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); 815 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
814 } 816 }
815 } 817 }
816 818
817 backup.RestoreSecurity(object_name.c_str()); 819 backup.RestoreSecurity(object_name.c_str());
818 return result; 820 return result;
819 } 821 }
OLDNEW
« no previous file with comments | « chrome/test/plugin/plugin_test.cpp ('k') | chrome_frame/crash_reporting/crash_metrics.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698