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

Side by Side Diff: chrome_frame/chrome_tab.cc

Issue 7824010: Make Chrome Frame registration and unregistration more robust. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 3 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 | « no previous file | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
11 11
12 #include "base/at_exit.h" 12 #include "base/at_exit.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/file_version_info.h" 15 #include "base/file_version_info.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/logging_win.h" 17 #include "base/logging_win.h"
18 #include "base/memory/scoped_vector.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/string_number_conversions.h" 20 #include "base/string_number_conversions.h"
20 #include "base/string_piece.h" 21 #include "base/string_piece.h"
21 #include "base/string_util.h" 22 #include "base/string_util.h"
22 #include "base/sys_string_conversions.h" 23 #include "base/sys_string_conversions.h"
23 #include "base/win/registry.h" 24 #include "base/win/registry.h"
24 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
25 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/installer/util/google_update_settings.h" 28 #include "chrome/installer/util/google_update_settings.h"
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 ACTIVEX = 0x0001, 484 ACTIVEX = 0x0001,
484 ACTIVEDOC = 0x0002, 485 ACTIVEDOC = 0x0002,
485 GCF_PROTOCOL = 0x0004, 486 GCF_PROTOCOL = 0x0004,
486 BHO_CLSID = 0x0008, 487 BHO_CLSID = 0x0008,
487 BHO_REGISTRATION = 0x0010, 488 BHO_REGISTRATION = 0x0010,
488 TYPELIB = 0x0020, 489 TYPELIB = 0x0020,
489 490
490 ALL = 0xFFFF 491 ALL = 0xFFFF
491 }; 492 };
492 493
494 class CustomRegistrationHelper {
grt (UTC plus 2) 2011/09/02 19:01:35 Looks like it wouldn't be hard to make this a pure
grt (UTC plus 2) 2011/09/02 19:01:35 On second thought, I'd be sorely tempted to simpli
robertshield 2011/09/03 05:36:21 Done.
robertshield 2011/09/03 05:36:21 This is a much nicer approach, changed as you sugg
495 public:
496 CustomRegistrationHelper(UINT reg_flags, bool is_system)
grt (UTC plus 2) 2011/09/02 19:01:35 i think uint32 is more stylistically appropriate.
robertshield 2011/09/03 05:36:21 Done.
497 : reg_flags_(reg_flags), is_system_(is_system) {
498 }
499
500 HRESULT Run(bool reg) {
501 return Do(reg);
502 }
503
504 HRESULT Rollback(bool reg) {
505 return Do(!reg);
506 }
507
508 protected:
509 virtual HRESULT Do(bool reg) = 0;
510
511 UINT reg_flags_;
512 bool is_system_;
513 };
514
515 class CRHSecuredMimeHandler : public CustomRegistrationHelper {
516 public:
517 CRHSecuredMimeHandler(UINT reg_flags, bool is_system)
518 : CustomRegistrationHelper(reg_flags, is_system) {}
519
520 private:
521 HRESULT Do(bool reg) {
grt (UTC plus 2) 2011/09/02 19:01:35 ) OVERRIDE { here and in all other classes.
robertshield 2011/09/03 05:36:21 No longer needed.
522 if (reg_flags_ & ACTIVEDOC) {
523 // Don't fail to unregister if we can't undo the secure mime
grt (UTC plus 2) 2011/09/02 19:01:35 This comment and code are stale; the decision of w
robertshield 2011/09/03 05:36:21 Done.
524 // handler registration. This was observed getting hit during
525 // uninstallation.
526 if (!RegisterSecuredMimeHandler(reg ? true : false, is_system_) && reg)
grt (UTC plus 2) 2011/09/02 19:01:35 "reg ? true : false" -> "reg"
robertshield 2011/09/03 05:36:21 Done.
527 return E_FAIL;
528 }
529 return S_OK;
530 }
531 };
532
grt (UTC plus 2) 2011/09/02 19:01:35 This seems to have been lost: class CRHActiveDoc :
robertshield 2011/09/03 05:36:21 good catch
533 class CRHActiveX : public CustomRegistrationHelper {
534 public:
535 CRHActiveX(UINT reg_flags, bool is_system)
536 : CustomRegistrationHelper(reg_flags, is_system) {}
537
538 private:
539 HRESULT Do(bool reg) {
540 if (reg_flags_ & ACTIVEX) {
541 // We have to call the static T::UpdateRegistry function instead of
542 // _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_ACTIVEX, reg)
543 // because there is specific OLEMISC replacement.
544 return ChromeFrameActivex::UpdateRegistry(reg);
545 }
546 return S_OK;
547 }
548 };
549
550 class CRHElevationPolicy : public CustomRegistrationHelper {
551 public:
552 CRHElevationPolicy(UINT reg_flags, bool is_system)
553 : CustomRegistrationHelper(reg_flags, is_system) {}
554
555 private:
556 HRESULT Do(bool reg) {
557 if ((reg_flags_ & (ACTIVEDOC | ACTIVEX)) && reg) {
558 // Register the elevation policy. We do this only for developer
559 // convenience as the installer is really responsible for doing this.
560 // Because of that, we do not unregister this policy and just leave that
561 // up to the installer.
562 _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_ELEVATION, reg);
grt (UTC plus 2) 2011/09/02 19:01:35 why no return this HRESULT?
robertshield 2011/09/03 05:36:21 This is strictly a developer convenience thing. We
563 RefreshElevationPolicy();
grt (UTC plus 2) 2011/09/02 19:01:35 why this not its own step with its own return HRES
robertshield 2011/09/03 05:36:21 Done.
564 }
565 return S_OK;
566 }
567 };
568
569 class CRHProtocol : public CustomRegistrationHelper {
570 public:
571 CRHProtocol(UINT reg_flags, bool is_system)
572 : CustomRegistrationHelper(reg_flags, is_system) {}
573
574 private:
575 HRESULT Do(bool reg) {
576 if (reg_flags_ & GCF_PROTOCOL) {
577 return _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEPROTOCOL, reg);
578 }
579 return S_OK;
580 }
581 };
582
583 class CRHBhoClsid : public CustomRegistrationHelper {
584 public:
585 CRHBhoClsid(UINT reg_flags, bool is_system)
586 : CustomRegistrationHelper(reg_flags, is_system) {}
587
588 private:
589 HRESULT Do(bool reg) {
590 if (reg_flags_ & BHO_CLSID) {
591 return Bho::UpdateRegistry(reg);
592 }
593 return S_OK;
594 }
595 };
596
597 class CRHBhoIERegistration : public CustomRegistrationHelper {
598 public:
599 CRHBhoIERegistration(UINT reg_flags, bool is_system)
600 : CustomRegistrationHelper(reg_flags, is_system) {}
601
602 private:
603 HRESULT Do(bool reg) {
604 if (reg_flags_ & BHO_REGISTRATION) {
605 if (is_system_) {
606 _AtlModule.UpdateRegistryFromResourceS(IDR_REGISTER_BHO, reg);
grt (UTC plus 2) 2011/09/02 19:01:35 why u no propagate error code?!?!!?
robertshield 2011/09/03 05:36:21 Fixed up the bho registration to proagate error co
607 } else {
608 if (reg) {
609 // Setup the long running process:
610 SetupUserLevelHelper();
grt (UTC plus 2) 2011/09/02 19:01:35 or here
robertshield 2011/09/03 05:36:21 Done.
611 } else {
612 // Unschedule the user-level helper. Note that we don't kill it here
613 // so that during updates we don't have a time window with no running
614 // helper. Uninstalls and updates will explicitly kill the helper from
615 // within the installer. Unregister existing run-at-startup entry.
616 base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, kRunKeyName);
grt (UTC plus 2) 2011/09/02 19:01:35 eh?
robertshield 2011/09/03 05:36:21 Done.
617 }
618 }
619 }
620 return S_OK;
621 }
622 };
623
624 class CRHTypeLib : public CustomRegistrationHelper {
625 public:
626 CRHTypeLib(UINT reg_flags, bool is_system)
627 : CustomRegistrationHelper(reg_flags, is_system) {}
628
629 private:
630 HRESULT Do(bool reg) {
631 if (reg_flags_ & TYPELIB) {
632 if (reg && !is_system_) {
633 // Enables the RegisterTypeLib Function function to override default
634 // registry mappings under Windows Vista Service Pack 1 (SP1),
635 // Windows Server 2008, and later operating system versions
636 typedef void (WINAPI* OaEnablePerUserTypeLibReg)(void);
637 OaEnablePerUserTypeLibReg per_user_typelib_func =
638 reinterpret_cast<OaEnablePerUserTypeLibReg>(
639 GetProcAddress(GetModuleHandle(L"oleaut32.dll"),
640 "OaEnablePerUserTLibRegistration"));
641 if (per_user_typelib_func) {
642 (*per_user_typelib_func)();
643 }
644 }
645 return reg ?
646 UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib,
647 NULL, !is_system_) :
648 UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib,
649 NULL, !is_system_);
650 }
651 return S_OK;
652 }
653 };
654
655 class CRHLegacyNPAPICleanup : public CustomRegistrationHelper {
656 public:
657 CRHLegacyNPAPICleanup(UINT reg_flags, bool is_system)
658 : CustomRegistrationHelper(reg_flags, is_system) {}
659
660 private:
661 HRESULT Do(bool reg) {
662 if (!reg) {
663 _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, reg);
grt (UTC plus 2) 2011/09/02 19:01:35 stylistically, i think this should return the erro
robertshield 2011/09/03 05:36:21 I tend to agree, but that means that I would need
grt (UTC plus 2) 2011/09/06 14:56:55 What makes this unregistration code special in tha
664 UtilRemovePersistentNPAPIMarker();
665 }
666 // Ignore failures.
grt (UTC plus 2) 2011/09/02 19:01:35 bad comment
robertshield 2011/09/03 05:36:21 the comment was correct, just unwanted ;)
grt (UTC plus 2) 2011/09/06 14:56:55 "Bad" in that it is in the wrong location. Methin
667 return S_OK;
668 }
669 };
670
671 class CRHAppId : public CustomRegistrationHelper {
672 public:
673 CRHAppId(UINT reg_flags, bool is_system)
674 : CustomRegistrationHelper(reg_flags, is_system) {}
675
676 private:
677 HRESULT Do(bool reg) {
678 return _AtlModule.UpdateRegistryAppId(reg);
679 }
680 };
681
682 class CRHUserAgent : public CustomRegistrationHelper {
683 public:
684 CRHUserAgent(UINT reg_flags, bool is_system)
685 : CustomRegistrationHelper(reg_flags, is_system) {}
686
687 private:
688 HRESULT Do(bool reg) {
689 if (reg) {
690 return SetChromeFrameUA(is_system_, L"1");
691 } else {
692 return SetChromeFrameUA(is_system_, NULL);
693 }
694 }
695 };
696
697 // Mux the failure step into the hresult. We take only the first four bits
698 // and stick those into the top four bits of the facility code. We also set the
699 // Customer bit to be polite. Graphically, we write our error code to the
700 // bits marked with ^:
701 // | 1 2 3 |
702 // |0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1|
grt (UTC plus 2) 2011/09/02 19:01:35 Interesting bit number choice. I think it'd be mo
robertshield 2011/09/03 05:36:21 I had copied this from the msdn link below, but su
grt (UTC plus 2) 2011/09/06 14:56:55 Funny: winerror.h has it the other way. :-)
703 // |S|R|C|N|X|Facility |Code |
704 // ^ ^ ^ ^ ^
705 // See http://msdn.microsoft.com/en-us/library/cc231198(PROT.10).aspx for
706 // more details on HRESULTS.
707 //
708 // The resulting error can be extracted by:
709 // error_code = (fiddled_hr & 0x07800000) >> 23
710 HRESULT MuxErrorIntoHRESULT(HRESULT hr, uint16 error_code) {
711 DCHECK((error_code & 15) == error_code);
grt (UTC plus 2) 2011/09/02 19:01:35 nit: i find 0x0F more obvious than 15. I think er
robertshield 2011/09/03 05:36:21 Done.
712
713 // Check that our four desired bits are clear.
714 // 0xF87FFFFF == 11111000011111111111111111111111
715 DCHECK(static_cast<HRESULT>(hr & 0xF87FFFFF) == hr) << hr;
grt (UTC plus 2) 2011/09/02 19:01:35 DCHECK_EQ(static_cast<HRESULT>(hr & 0xF87FFFFF), h
robertshield 2011/09/03 05:36:21 Done.
716
717 HRESULT fiddled_hr = ((error_code & 15) << 23) | hr;
grt (UTC plus 2) 2011/09/02 19:01:35 15 -> 0x0F and you may need to stick a cast in the
robertshield 2011/09/03 05:36:21 Done.
718 fiddled_hr |= 1 << 29; // Set the customer bit.
719
720 return fiddled_hr;
721 }
722
493 STDAPI CustomRegistration(UINT reg_flags, BOOL reg, bool is_system) { 723 STDAPI CustomRegistration(UINT reg_flags, BOOL reg, bool is_system) {
grt (UTC plus 2) 2011/09/02 19:01:35 Why is this STDAPI? Change to just returning an H
robertshield 2011/09/03 05:36:21 I think once upon a time this was intended to be a
494 UINT flags = reg_flags; 724 UINT flags = reg_flags;
495 725
496 if (reg && (flags & (ACTIVEDOC | ACTIVEX))) 726 if (reg && (flags & (ACTIVEDOC | ACTIVEX)))
497 flags |= (TYPELIB | GCF_PROTOCOL); 727 flags |= (TYPELIB | GCF_PROTOCOL);
498 728
499 HRESULT hr = S_OK; 729 HRESULT hr = S_OK;
500 730
501 // Set the flag that gets checked in AddCommonRGSReplacements before doing 731 // Set the flag that gets checked in AddCommonRGSReplacements before doing
502 // registration work. 732 // registration work.
503 _AtlModule.do_system_registration_ = is_system; 733 _AtlModule.do_system_registration_ = is_system;
504 734
505 if ((hr == S_OK) && (flags & ACTIVEDOC)) { 735 ScopedVector<CustomRegistrationHelper> registration_helpers;
grt (UTC plus 2) 2011/09/02 19:01:35 If you stick with the classes and vector approach,
robertshield 2011/09/03 05:36:21 Approach changed.
506 // Don't fail to unregister if we can't undo the secure mime 736 registration_helpers.push_back(
507 // handler registration. This was observed getting hit during 737 new CRHSecuredMimeHandler(reg_flags, is_system)); // 0
grt (UTC plus 2) 2011/09/02 19:01:35 |flags| rather than |reg_flags| should be used her
robertshield 2011/09/03 05:36:21 Done.
508 // uninstallation. 738 registration_helpers.push_back(
509 if (!RegisterSecuredMimeHandler(reg ? true : false, is_system) && reg) 739 new CRHActiveX(reg_flags, is_system)); // 1
510 return E_FAIL; 740 registration_helpers.push_back(
511 hr = ChromeActiveDocument::UpdateRegistry(reg); 741 new CRHElevationPolicy(reg_flags, is_system)); // 2
512 } 742 registration_helpers.push_back(
513 743 new CRHProtocol(reg_flags, is_system)); // 3
514 if ((hr == S_OK) && (flags & ACTIVEX)) { 744 registration_helpers.push_back(
515 // We have to call the static T::UpdateRegistry function instead of 745 new CRHBhoClsid(reg_flags, is_system)); // 4
516 // _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_ACTIVEX, reg) 746 registration_helpers.push_back(
517 // because there is specific OLEMISC replacement. 747 new CRHBhoIERegistration(reg_flags, is_system)); // 5
518 hr = ChromeFrameActivex::UpdateRegistry(reg); 748 registration_helpers.push_back(
519 } 749 new CRHTypeLib(reg_flags, is_system)); // 6
520 750 registration_helpers.push_back(
521 // Register the elevation policy. We do this only for developer convenience 751 new CRHLegacyNPAPICleanup(reg_flags, is_system)); // 7
522 // as the installer is really responsible for doing this. 752 registration_helpers.push_back(
523 // Because of that, we do not unregister this policy and just leave that up 753 new CRHAppId(reg_flags, is_system)); // 8
524 // to the installer. 754 registration_helpers.push_back(
525 if (hr == S_OK && (flags & (ACTIVEDOC | ACTIVEX)) && reg) { 755 new CRHUserAgent(reg_flags, is_system)); // 9
526 _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_ELEVATION, reg); 756
527 RefreshElevationPolicy(); 757 ScopedVector<CustomRegistrationHelper>::iterator reg_iter(
528 } 758 registration_helpers->begin());
529 759
530 if ((hr == S_OK) && (flags & GCF_PROTOCOL)) { 760 bool do_register = (reg == TRUE);
grt (UTC plus 2) 2011/09/02 19:01:35 reg != FALSE, unless you take my request to change
robertshield 2011/09/03 05:36:21 Done.
531 hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEPROTOCOL, reg); 761 bool rollback = false;
532 } 762
533 763 // This value will be muxed into the hresult in case of failure. It will
534 if ((hr == S_OK) && (flags & BHO_CLSID)) { 764 // correspond to the index of the failing step.
grt (UTC plus 2) 2011/09/02 19:01:35 Using the index of the step introduces a requireme
robertshield 2011/09/03 05:36:21 Thought about that but figured it would add even m
grt (UTC plus 2) 2011/09/06 14:56:55 It just means that you have to refer to the exact
535 hr = Bho::UpdateRegistry(reg); 765 uint16 registration_failure_step = 0;
grt (UTC plus 2) 2011/09/02 19:01:35 The arbiters of style say to use "int" for this.
robertshield 2011/09/03 05:36:21 Done.
536 } 766
537 767 for (; reg_iter != registration_helpers->end(); ++reg_iter) {
538 if ((hr == S_OK) && (flags & BHO_REGISTRATION)) { 768 if (!SUCCEEDED(hr = (*reg_iter)->Run(do_register))) {
grt (UTC plus 2) 2011/09/02 19:01:35 I don't know that this is banned by the style guid
robertshield 2011/09/03 05:36:21 Done.
539 if (is_system) { 769 if (do_register) {
540 _AtlModule.UpdateRegistryFromResourceS(IDR_REGISTER_BHO, reg); 770 // Only rollback during registration. During unregistration keep going.
541 } else { 771 rollback = true;
542 if (reg) { 772 break;
543 // Setup the long running process:
544 SetupUserLevelHelper();
545 } else {
546 // Unschedule the user-level helper. Note that we don't kill it here so
547 // that during updates we don't have a time window with no running
548 // helper. Uninstalls and updates will explicitly kill the helper from
549 // within the installer. Unregister existing run-at-startup entry.
550 base::win::RemoveCommandFromAutoRun(HKEY_CURRENT_USER, kRunKeyName);
551 } 773 }
552 } 774 }
553 } 775 registration_failure_step++;
554 776 }
555 if ((hr == S_OK) && (flags & TYPELIB)) { 777
556 if (reg && !is_system) { 778 if (rollback) {
557 // Enables the RegisterTypeLib Function function to override default 779 // Rollback all actions that preceded reg_iter's current position. Note that
558 // registry mappings under Windows Vista Service Pack 1 (SP1), 780 // this does not rollback the failing action.
grt (UTC plus 2) 2011/09/02 19:01:35 Consider rolling back the failing action. Otherwi
robertshield 2011/09/03 05:36:21 Done.
559 // Windows Server 2008, and later operating system versions 781 ScopedVector<CustomRegistrationHelper>::reverse_iterator rollback_iter(
grt (UTC plus 2) 2011/09/02 19:01:35 I don't see an advantage to making a new object fo
robertshield 2011/09/03 05:36:21 Changed to use an index.
560 typedef void (WINAPI* OaEnablePerUserTypeLibReg)(void); 782 reg_iter);
561 OaEnablePerUserTypeLibReg per_user_typelib_func = 783 for (; rollback_iter != registration_helpers->rend(); ++rollback_iter) {
562 reinterpret_cast<OaEnablePerUserTypeLibReg>( 784 (*rollback_iter)->Rollback(do_register);
563 GetProcAddress(GetModuleHandle(L"oleaut32.dll"), 785 }
564 "OaEnablePerUserTLibRegistration")); 786 }
565 if (per_user_typelib_func) { 787
566 (*per_user_typelib_func)(); 788 return MuxErrorIntoHRESULT(hr, registration_failure_step);
grt (UTC plus 2) 2011/09/02 19:01:35 Consider changing SelfRegWorkItem::RegisterDll as
robertshield 2011/09/03 05:36:21 Good idea, so changed.
567 }
568 }
569 hr = (reg)?
570 UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system) :
571 UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system);
572 }
573
574 // Unconditionally remove NPAPI registration when unregistering any component.
575 if ((hr == S_OK) && !reg) {
576 // Ignore failures.
577 _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, reg);
578 UtilRemovePersistentNPAPIMarker();
579 }
580
581 if (hr == S_OK) {
582 hr = _AtlModule.UpdateRegistryAppId(reg);
583 }
584
585 if (hr == S_OK) {
586 if (reg) {
587 hr = SetChromeFrameUA(is_system, L"1");
588 } else {
589 hr = SetChromeFrameUA(is_system, NULL);
590 }
591 }
592 return hr;
593 } 789 }
594 790
595
596
597 // DllRegisterServer - Adds entries to the system registry 791 // DllRegisterServer - Adds entries to the system registry
598 STDAPI DllRegisterServer() { 792 STDAPI DllRegisterServer() {
599 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | 793 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL |
600 BHO_CLSID | BHO_REGISTRATION; 794 BHO_CLSID | BHO_REGISTRATION;
601 795
602 HRESULT hr = CustomRegistration(flags, TRUE, true); 796 HRESULT hr = CustomRegistration(flags, TRUE, true);
grt (UTC plus 2) 2011/09/02 19:01:35 TRUE, true? Knowing that you didn't commit this s
robertshield 2011/09/03 05:36:21 Done.
603 if (SUCCEEDED(hr)) { 797 if (SUCCEEDED(hr)) {
604 SetupRunOnce(); 798 SetupRunOnce();
605 } 799 }
606 800
607 return hr; 801 return hr;
608 } 802 }
609 803
610 // DllUnregisterServer - Removes entries from the system registry 804 // DllUnregisterServer - Removes entries from the system registry
611 STDAPI DllUnregisterServer() { 805 STDAPI DllUnregisterServer() {
612 HRESULT hr = CustomRegistration(ALL, FALSE, true); 806 HRESULT hr = CustomRegistration(ALL, FALSE, true);
613 return hr; 807 return hr;
614 } 808 }
615 809
616 // DllRegisterServer - Adds entries to the HKCU hive in the registry 810 // DllRegisterServer - Adds entries to the HKCU hive in the registry
grt (UTC plus 2) 2011/09/02 19:01:35 Please fix comment while you're here.
robertshield 2011/09/03 05:36:21 Done.
617 STDAPI DllRegisterUserServer() { 811 STDAPI DllRegisterUserServer() {
618 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | 812 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL |
619 BHO_CLSID | BHO_REGISTRATION; 813 BHO_CLSID | BHO_REGISTRATION;
620 814
621 HRESULT hr = CustomRegistration(flags, TRUE, false); 815 HRESULT hr = CustomRegistration(flags, TRUE, false);
622 if (SUCCEEDED(hr)) { 816 if (SUCCEEDED(hr)) {
623 SetupRunOnce(); 817 SetupRunOnce();
624 } 818 }
625 819
626 return hr; 820 return hr;
627 } 821 }
628 822
629 // DllRegisterServer - Removes entries from the HKCU hive in the registry. 823 // DllRegisterServer - Removes entries from the HKCU hive in the registry.
grt (UTC plus 2) 2011/09/02 19:01:35 Please fix comment while you're here.
robertshield 2011/09/03 05:36:21 Done.
630 STDAPI DllUnregisterUserServer() { 824 STDAPI DllUnregisterUserServer() {
631 HRESULT hr = CustomRegistration(ALL, FALSE, false); 825 HRESULT hr = CustomRegistration(ALL, FALSE, false);
632 return hr; 826 return hr;
633 } 827 }
634 828
635 class SecurityDescBackup { 829 class SecurityDescBackup {
636 public: 830 public:
637 explicit SecurityDescBackup(const std::wstring& backup_key) 831 explicit SecurityDescBackup(const std::wstring& backup_key)
638 : backup_key_name_(backup_key) {} 832 : backup_key_name_(backup_key) {}
639 ~SecurityDescBackup() {} 833 ~SecurityDescBackup() {}
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 return user_; 933 return user_;
740 } 934 }
741 935
742 private: 936 private:
743 CAccessToken token_; 937 CAccessToken token_;
744 CTokenPrivileges take_ownership_; 938 CTokenPrivileges take_ownership_;
745 CTokenPrivileges restore_; 939 CTokenPrivileges restore_;
746 CSid user_; 940 CSid user_;
747 }; 941 };
748 942
749 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) { 943 static bool SetOrDeleteMimeHandlerKey(bool set, HKEY root_key) {
grt (UTC plus 2) 2011/09/02 19:01:35 change this to return an HRESULT.
robertshield 2011/09/03 05:36:21 Done.
750 std::wstring key_name = kInternetSettings; 944 std::wstring key_name = kInternetSettings;
751 key_name.append(L"\\Secure Mime Handlers"); 945 key_name.append(L"\\Secure Mime Handlers");
752 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE); 946 RegKey key(root_key, key_name.c_str(), KEY_READ | KEY_WRITE);
753 if (!key.Valid()) 947 if (!key.Valid())
754 return false; 948 return false;
755 949
756 LONG result1 = ERROR_SUCCESS; 950 LONG result1 = ERROR_SUCCESS;
757 LONG result2 = ERROR_SUCCESS; 951 LONG result2 = ERROR_SUCCESS;
758 if (set) { 952 if (set) {
759 result1 = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1); 953 result1 = key.WriteValue(L"ChromeTab.ChromeActiveDocument", 1);
760 result2 = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1); 954 result2 = key.WriteValue(L"ChromeTab.ChromeActiveDocument.1", 1);
761 } else { 955 } else {
762 result1 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument"); 956 result1 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument");
763 result2 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1"); 957 result2 = key.DeleteValue(L"ChromeTab.ChromeActiveDocument.1");
764 } 958 }
765 959
766 return (result2 == ERROR_SUCCESS) && (result2 == ERROR_SUCCESS); 960 return (result2 == ERROR_SUCCESS) && (result2 == ERROR_SUCCESS);
grt (UTC plus 2) 2011/09/02 19:01:35 Boy, this is funny. I'm sure I reviewed this and
robertshield 2011/09/03 05:36:21 Yes, this is awesome. Fixed.
767 } 961 }
768 962
769 bool RegisterSecuredMimeHandler(bool enable, bool is_system) { 963 bool RegisterSecuredMimeHandler(bool enable, bool is_system) {
grt (UTC plus 2) 2011/09/02 19:01:35 change this to return an HRESULT
robertshield 2011/09/03 05:36:21 Done.
770 if (!is_system) { 964 if (!is_system) {
771 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER); 965 return SetOrDeleteMimeHandlerKey(enable, HKEY_CURRENT_USER);
772 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) { 966 } else if (base::win::GetVersion() < base::win::VERSION_VISTA) {
773 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); 967 return SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
774 } 968 }
775 969
776 std::wstring mime_key = kInternetSettings; 970 std::wstring mime_key = kInternetSettings;
777 mime_key.append(L"\\Secure Mime Handlers"); 971 mime_key.append(L"\\Secure Mime Handlers");
778 std::wstring backup_key = kInternetSettings; 972 std::wstring backup_key = kInternetSettings;
779 backup_key.append(L"\\__backup_SMH__"); 973 backup_key.append(L"\\__backup_SMH__");
780 std::wstring object_name = L"MACHINE\\"; 974 std::wstring object_name = L"MACHINE\\";
781 object_name.append(mime_key); 975 object_name.append(mime_key);
782 976
783 TokenWithPrivileges token_; 977 TokenWithPrivileges token_;
784 if (!token_.EnablePrivileges()) 978 if (!token_.EnablePrivileges())
785 return false; 979 return false;
grt (UTC plus 2) 2011/09/02 19:01:35 return E_FAIL or HRESULT_FROM_WIN32(GetLastError()
robertshield 2011/09/03 05:36:21 Done.
786 980
787 // If there is a backup key - something bad happened; try to restore 981 // If there is a backup key - something bad happened; try to restore
788 // security on "Secure Mime Handlers" from the backup. 982 // security on "Secure Mime Handlers" from the backup.
789 SecurityDescBackup backup(backup_key); 983 SecurityDescBackup backup(backup_key);
790 backup.RestoreSecurity(object_name.c_str()); 984 backup.RestoreSecurity(object_name.c_str());
791 985
792 // Read old security descriptor of the Mime key first. 986 // Read old security descriptor of the Mime key first.
793 CSecurityDesc sd; 987 CSecurityDesc sd;
794 if (!AtlGetSecurityDescriptor(object_name.c_str(), SE_REGISTRY_KEY, &sd)) { 988 if (!AtlGetSecurityDescriptor(object_name.c_str(), SE_REGISTRY_KEY, &sd)) {
795 return false; 989 return false;
796 } 990 }
797 991
798 backup.SaveSecurity(sd); 992 backup.SaveSecurity(sd);
799 bool result = false; 993 bool result = false;
800 // set new owner 994 // set new owner
801 if (AtlSetOwnerSid(object_name.c_str(), SE_REGISTRY_KEY, token_.GetUser())) { 995 if (AtlSetOwnerSid(object_name.c_str(), SE_REGISTRY_KEY, token_.GetUser())) {
802 // set new dacl 996 // set new dacl
803 CDacl new_dacl; 997 CDacl new_dacl;
804 sd.GetDacl(&new_dacl); 998 sd.GetDacl(&new_dacl);
805 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); 999 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ);
806 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { 1000 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) {
807 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); 1001 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE);
808 } 1002 }
809 } 1003 }
810 1004
811 backup.RestoreSecurity(object_name.c_str()); 1005 backup.RestoreSecurity(object_name.c_str());
812 return result; 1006 return result;
813 } 1007 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698