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

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
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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 channel_name.find(L"ceee") != std::wstring::npos) { 313 channel_name.find(L"ceee") != std::wstring::npos) {
314 314
315 HKEY hive = HKEY_CURRENT_USER; 315 HKEY hive = HKEY_CURRENT_USER;
316 if (IsSystemProcess()) { 316 if (IsSystemProcess()) {
317 // For system installs, our updates will be running as SYSTEM which 317 // For system installs, our updates will be running as SYSTEM which
318 // makes writing to a RunOnce key under HKCU not so terribly useful. 318 // makes writing to a RunOnce key under HKCU not so terribly useful.
319 hive = HKEY_LOCAL_MACHINE; 319 hive = HKEY_LOCAL_MACHINE;
320 } 320 }
321 321
322 RegKey run_once; 322 RegKey run_once;
323 if (run_once.Create(hive, kRunOnce, KEY_READ | KEY_WRITE)) { 323 LONG ret = run_once.Create(hive, kRunOnce, KEY_READ | KEY_WRITE);
324 if (ret == ERROR_SUCCESS) {
324 CommandLine run_once_cmd(chrome_launcher::GetChromeExecutablePath()); 325 CommandLine run_once_cmd(chrome_launcher::GetChromeExecutablePath());
325 run_once_cmd.AppendSwitchASCII(switches::kAutomationClientChannelID, 326 run_once_cmd.AppendSwitchASCII(switches::kAutomationClientChannelID,
326 "0"); 327 "0");
327 run_once_cmd.AppendSwitch(switches::kChromeFrame); 328 run_once_cmd.AppendSwitch(switches::kChromeFrame);
328 if (run_once.WriteValue(L"A", 329 ret = run_once.WriteValue(L"A",
329 run_once_cmd.command_line_string().c_str())) { 330 run_once_cmd.command_line_string().c_str());
330 result = S_OK; 331 result = HRESULT_FROM_WIN32(ret);
331 }
332 } 332 }
333 } else { 333 } else {
334 result = S_FALSE; 334 result = S_FALSE;
335 } 335 }
336 } else { 336 } else {
337 // We're on a non-XP version of Windows or on a stable channel. Nothing 337 // We're on a non-XP version of Windows or on a stable channel. Nothing
338 // needs doing. 338 // needs doing.
339 result = S_FALSE; 339 result = S_FALSE;
340 } 340 }
341 341
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 const wchar_t kChromeFramePrefix[] = L"chromeframe/"; 423 const wchar_t kChromeFramePrefix[] = L"chromeframe/";
424 424
425 // To delete the user agent, set value to NULL. 425 // To delete the user agent, set value to NULL.
426 // The is_system parameter indicates whether this is a per machine or a per 426 // The is_system parameter indicates whether this is a per machine or a per
427 // user installation. 427 // user installation.
428 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) { 428 HRESULT SetChromeFrameUA(bool is_system, const wchar_t* value) {
429 HRESULT hr = E_FAIL; 429 HRESULT hr = E_FAIL;
430 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 430 HKEY parent_hive = is_system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
431 431
432 RegKey ua_key; 432 RegKey ua_key;
433 if (ua_key.Create(parent_hive, kPostPlatformUAKey, KEY_WRITE)) { 433 LONG result = ua_key.Create(parent_hive, kPostPlatformUAKey, KEY_WRITE);
434 if (result == ERROR_SUCCESS) {
434 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix; 435 std::wstring chrome_frame_ua_value_name = kChromeFramePrefix;
435 chrome_frame_ua_value_name += GetCurrentModuleVersion(); 436 chrome_frame_ua_value_name += GetCurrentModuleVersion();
436 if (value) { 437 if (value) {
437 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value); 438 ua_key.WriteValue(chrome_frame_ua_value_name.c_str(), value);
438 } else { 439 } else {
439 ua_key.DeleteValue(chrome_frame_ua_value_name.c_str()); 440 ua_key.DeleteValue(chrome_frame_ua_value_name.c_str());
440 } 441 }
441 hr = S_OK; 442 hr = S_OK;
442 } else { 443 } else {
443 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey; 444 DLOG(ERROR) << __FUNCTION__ << ": " << kPostPlatformUAKey;
grt (UTC plus 2) 2011/01/11 03:51:30 com::LogWe(result) also
444 hr = E_UNEXPECTED; 445 hr = E_UNEXPECTED;
445 } 446 }
446 return hr; 447 return hr;
447 } 448 }
448 449
449 enum RegistrationFlags { 450 enum RegistrationFlags {
450 ACTIVEX = 0x0001, 451 ACTIVEX = 0x0001,
451 ACTIVEDOC = 0x0002, 452 ACTIVEDOC = 0x0002,
452 GCF_PROTOCOL = 0x0004, 453 GCF_PROTOCOL = 0x0004,
453 BHO_CLSID = 0x0008, 454 BHO_CLSID = 0x0008,
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 622
622 // Save given security descriptor to the backup key. 623 // Save given security descriptor to the backup key.
623 bool SaveSecurity(const CSecurityDesc& sd) { 624 bool SaveSecurity(const CSecurityDesc& sd) {
624 CString str; 625 CString str;
625 if (!sd.ToString(&str)) 626 if (!sd.ToString(&str))
626 return false; 627 return false;
627 628
628 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), 629 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(),
629 KEY_READ | KEY_WRITE); 630 KEY_READ | KEY_WRITE);
630 if (backup_key.Valid()) { 631 if (backup_key.Valid()) {
631 return backup_key.WriteValue(NULL, str.GetString()); 632 return backup_key.WriteValue(NULL, str.GetString()) == ERROR_SUCCESS;
632 } 633 }
633 634
634 return false; 635 return false;
635 } 636 }
636 637
637 // Restore security descriptor from backup key to given key name. 638 // Restore security descriptor from backup key to given key name.
638 bool RestoreSecurity(const wchar_t* key_name) { 639 bool RestoreSecurity(const wchar_t* key_name) {
639 std::wstring sddl; 640 std::wstring sddl;
640 if (!ReadBackupKey(&sddl)) 641 if (!ReadBackupKey(&sddl))
641 return false; 642 return false;
(...skipping 21 matching lines...) Expand all
663 664
664 private: 665 private:
665 // Read SDDL string from backup key 666 // Read SDDL string from backup key
666 bool ReadBackupKey(std::wstring* sddl) { 667 bool ReadBackupKey(std::wstring* sddl) {
667 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), KEY_READ); 668 RegKey backup_key(HKEY_LOCAL_MACHINE, backup_key_name_.c_str(), KEY_READ);
668 if (!backup_key.Valid()) 669 if (!backup_key.Valid())
669 return false; 670 return false;
670 671
671 DWORD len = 0; 672 DWORD len = 0;
672 DWORD reg_type = REG_NONE; 673 DWORD reg_type = REG_NONE;
673 if (!backup_key.ReadValue(NULL, NULL, &len, &reg_type)) 674 if (backup_key.ReadValue(NULL, NULL, &len, &reg_type) != ERROR_SUCCESS)
674 return false; 675 return false;
675 676
676 if (reg_type != REG_SZ) 677 if (reg_type != REG_SZ)
677 return false; 678 return false;
678 679
679 size_t wchar_count = 1 + len / sizeof(wchar_t); 680 size_t wchar_count = 1 + len / sizeof(wchar_t);
680 if (!backup_key.ReadValue(NULL, WriteInto(sddl, wchar_count), &len, 681 if (backup_key.ReadValue(NULL, WriteInto(sddl, wchar_count), &len,
681 &reg_type)) { 682 &reg_type) != ERROR_SUCCESS) {
682 return false; 683 return false;
683 } 684 }
684 685
685 return true; 686 return true;
686 } 687 }
687 688
688 void DeleteBackupKey() { 689 void DeleteBackupKey() {
689 ::RegDeleteKey(HKEY_LOCAL_MACHINE, backup_key_name_.c_str()); 690 ::RegDeleteKey(HKEY_LOCAL_MACHINE, backup_key_name_.c_str());
690 } 691 }
691 692
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 CSid user_; 728 CSid user_;
728 }; 729 };
729 730
730 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) { 731 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) {
731 std::wstring key_name = kInternetSettings; 732 std::wstring key_name = kInternetSettings;
732 key_name.append(L"\\Secure Mime Handlers"); 733 key_name.append(L"\\Secure Mime Handlers");
733 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE); 734 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE);
734 if (!key.Valid()) 735 if (!key.Valid())
735 return false; 736 return false;
736 737
737 bool result; 738 LONG result = ERROR_SUCCESS;
738 if (set) { 739 if (set) {
739 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1); 740 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1);
740 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1) && result; 741 if (result == ERROR_SUCCESS)
grt (UTC plus 2) 2011/01/11 03:51:30 is this change in behavior intentional?
amit 2011/01/12 04:11:23 It's not. good catch!
742 result = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1);
741 } else { 743 } else {
742 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument"); 744 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument");
743 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1") && result; 745 if (result == ERROR_SUCCESS)
746 result = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1");
grt (UTC plus 2) 2011/01/11 03:51:30 Don't we want to do the second delete even if the
amit 2011/01/12 04:11:23 Done.
744 } 747 }
745 748
746 return result; 749 return result == ERROR_SUCCESS;
747 } 750 }
748 751
749 bool RegisterSecuredMimeHandler(bool enable, bool is_system) { 752 bool RegisterSecuredMimeHandler(bool enable, bool is_system) {
750 if (!is_system) { 753 if (!is_system) {
751 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER); 754 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER);
752 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { 755 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) {
753 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); 756 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
754 } 757 }
755 758
756 std::wstring mime_key = kInternetSettings; 759 std::wstring mime_key = kInternetSettings;
(...skipping 27 matching lines...) Expand all
784 sd.GetDacl(&new_dacl); 787 sd.GetDacl(&new_dacl);
785 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); 788 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ);
786 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { 789 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) {
787 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); 790 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
788 } 791 }
789 } 792 }
790 793
791 backup.RestoreSecurity(object_name.c_str()); 794 backup.RestoreSecurity(object_name.c_str());
792 return result; 795 return result;
793 } 796 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698