| OLD | NEW |
| 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> |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 478 } |
| 479 | 479 |
| 480 enum RegistrationFlags { | 480 enum RegistrationFlags { |
| 481 ACTIVEX = 0x0001, | 481 ACTIVEX = 0x0001, |
| 482 ACTIVEDOC = 0x0002, | 482 ACTIVEDOC = 0x0002, |
| 483 GCF_PROTOCOL = 0x0004, | 483 GCF_PROTOCOL = 0x0004, |
| 484 BHO_CLSID = 0x0008, | 484 BHO_CLSID = 0x0008, |
| 485 BHO_REGISTRATION = 0x0010, | 485 BHO_REGISTRATION = 0x0010, |
| 486 TYPELIB = 0x0020, | 486 TYPELIB = 0x0020, |
| 487 | 487 |
| 488 NPAPI_PLUGIN = 0x1000, | |
| 489 | |
| 490 ALL = 0xFFFF | 488 ALL = 0xFFFF |
| 491 }; | 489 }; |
| 492 | 490 |
| 493 STDAPI CustomRegistration(UINT reg_flags, BOOL reg, bool is_system) { | 491 STDAPI CustomRegistration(UINT reg_flags, BOOL reg, bool is_system) { |
| 494 UINT flags = reg_flags; | 492 UINT flags = reg_flags; |
| 495 | 493 |
| 496 if (reg && (flags & (ACTIVEDOC | ACTIVEX))) | 494 if (reg && (flags & (ACTIVEDOC | ACTIVEX))) |
| 497 flags |= (TYPELIB | GCF_PROTOCOL); | 495 flags |= (TYPELIB | GCF_PROTOCOL); |
| 498 | 496 |
| 499 HRESULT hr = S_OK; | 497 HRESULT hr = S_OK; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 "OaEnablePerUserTLibRegistration")); | 562 "OaEnablePerUserTLibRegistration")); |
| 565 if (per_user_typelib_func) { | 563 if (per_user_typelib_func) { |
| 566 (*per_user_typelib_func)(); | 564 (*per_user_typelib_func)(); |
| 567 } | 565 } |
| 568 } | 566 } |
| 569 hr = (reg)? | 567 hr = (reg)? |
| 570 UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system) : | 568 UtilRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system) : |
| 571 UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system); | 569 UtilUnRegisterTypeLib(_AtlComModule.m_hInstTypeLib, NULL, !is_system); |
| 572 } | 570 } |
| 573 | 571 |
| 574 if ((hr == S_OK) && (flags & NPAPI_PLUGIN)) { | 572 // Unconditionally remove NPAPI registration when unregistering any component. |
| 575 hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, reg); | 573 if ((hr == S_OK) && !reg) { |
| 574 // Ignore failures. |
| 575 _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, reg); |
| 576 UtilRemovePersistentNPAPIMarker(); |
| 576 } | 577 } |
| 577 | 578 |
| 578 if (hr == S_OK) { | 579 if (hr == S_OK) { |
| 579 hr = _AtlModule.UpdateRegistryAppId(reg); | 580 hr = _AtlModule.UpdateRegistryAppId(reg); |
| 580 } | 581 } |
| 581 | 582 |
| 582 if (hr == S_OK) { | 583 if (hr == S_OK) { |
| 583 if (reg) { | 584 if (reg) { |
| 584 hr = SetChromeFrameUA(is_system, L"1"); | 585 hr = SetChromeFrameUA(is_system, L"1"); |
| 585 } else { | 586 } else { |
| 586 hr = SetChromeFrameUA(is_system, NULL); | 587 hr = SetChromeFrameUA(is_system, NULL); |
| 587 } | 588 } |
| 588 } | 589 } |
| 589 return hr; | 590 return hr; |
| 590 } | 591 } |
| 591 | 592 |
| 592 | 593 |
| 593 | 594 |
| 594 // DllRegisterServer - Adds entries to the system registry | 595 // DllRegisterServer - Adds entries to the system registry |
| 595 STDAPI DllRegisterServer() { | 596 STDAPI DllRegisterServer() { |
| 596 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | | 597 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | |
| 597 BHO_CLSID | BHO_REGISTRATION; | 598 BHO_CLSID | BHO_REGISTRATION; |
| 598 | 599 |
| 599 if (UtilIsPersistentNPAPIMarkerSet()) { | |
| 600 flags |= NPAPI_PLUGIN; | |
| 601 } | |
| 602 | |
| 603 HRESULT hr = CustomRegistration(flags, TRUE, true); | 600 HRESULT hr = CustomRegistration(flags, TRUE, true); |
| 604 if (SUCCEEDED(hr)) { | 601 if (SUCCEEDED(hr)) { |
| 605 SetupRunOnce(); | 602 SetupRunOnce(); |
| 606 } | 603 } |
| 607 | 604 |
| 608 return hr; | 605 return hr; |
| 609 } | 606 } |
| 610 | 607 |
| 611 // DllUnregisterServer - Removes entries from the system registry | 608 // DllUnregisterServer - Removes entries from the system registry |
| 612 STDAPI DllUnregisterServer() { | 609 STDAPI DllUnregisterServer() { |
| 613 HRESULT hr = CustomRegistration(ALL, FALSE, true); | 610 HRESULT hr = CustomRegistration(ALL, FALSE, true); |
| 614 return hr; | 611 return hr; |
| 615 } | 612 } |
| 616 | 613 |
| 617 // DllRegisterServer - Adds entries to the HKCU hive in the registry | 614 // DllRegisterServer - Adds entries to the HKCU hive in the registry |
| 618 STDAPI DllRegisterUserServer() { | 615 STDAPI DllRegisterUserServer() { |
| 619 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | | 616 UINT flags = ACTIVEX | ACTIVEDOC | TYPELIB | GCF_PROTOCOL | |
| 620 BHO_CLSID | BHO_REGISTRATION; | 617 BHO_CLSID | BHO_REGISTRATION; |
| 621 | 618 |
| 622 if (UtilIsPersistentNPAPIMarkerSet()) { | |
| 623 flags |= NPAPI_PLUGIN; | |
| 624 } | |
| 625 | |
| 626 HRESULT hr = CustomRegistration(flags, TRUE, false); | 619 HRESULT hr = CustomRegistration(flags, TRUE, false); |
| 627 if (SUCCEEDED(hr)) { | 620 if (SUCCEEDED(hr)) { |
| 628 SetupRunOnce(); | 621 SetupRunOnce(); |
| 629 } | 622 } |
| 630 | 623 |
| 631 return hr; | 624 return hr; |
| 632 } | 625 } |
| 633 | 626 |
| 634 // DllRegisterServer - Removes entries from the HKCU hive in the registry. | 627 // DllRegisterServer - Removes entries from the HKCU hive in the registry. |
| 635 STDAPI DllUnregisterUserServer() { | 628 STDAPI DllUnregisterUserServer() { |
| 636 HRESULT hr = CustomRegistration(ALL, FALSE, false); | 629 HRESULT hr = CustomRegistration(ALL, FALSE, false); |
| 637 return hr; | 630 return hr; |
| 638 } | 631 } |
| 639 | 632 |
| 640 // Registers the NPAPI plugin and sets the persistent marker that tells us | |
| 641 // to re-register it through updates. | |
| 642 STDAPI RegisterNPAPIPlugin() { | |
| 643 HRESULT hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, | |
| 644 TRUE); | |
| 645 if (SUCCEEDED(hr) && _AtlModule.do_system_registration_) { | |
| 646 if (!UtilChangePersistentNPAPIMarker(true)) { | |
| 647 hr = E_FAIL; | |
| 648 } | |
| 649 } | |
| 650 return hr; | |
| 651 } | |
| 652 | |
| 653 // Unregisters the NPAPI plugin and clears the persistent marker that tells us | |
| 654 // to re-register it through updates. | |
| 655 STDAPI UnregisterNPAPIPlugin() { | |
| 656 HRESULT hr = _AtlModule.UpdateRegistryFromResourceS(IDR_CHROMEFRAME_NPAPI, | |
| 657 FALSE); | |
| 658 if (SUCCEEDED(hr) && _AtlModule.do_system_registration_) { | |
| 659 if (!UtilChangePersistentNPAPIMarker(false)) { | |
| 660 hr = E_FAIL; | |
| 661 } | |
| 662 } | |
| 663 return hr; | |
| 664 } | |
| 665 | |
| 666 STDAPI RegisterNPAPIUserPlugin() { | |
| 667 _AtlModule.do_system_registration_ = false; | |
| 668 return RegisterNPAPIPlugin(); | |
| 669 } | |
| 670 | |
| 671 STDAPI UnregisterNPAPIUserPlugin() { | |
| 672 _AtlModule.do_system_registration_ = false; | |
| 673 return UnregisterNPAPIPlugin(); | |
| 674 } | |
| 675 | |
| 676 class SecurityDescBackup { | 633 class SecurityDescBackup { |
| 677 public: | 634 public: |
| 678 explicit SecurityDescBackup(const std::wstring& backup_key) | 635 explicit SecurityDescBackup(const std::wstring& backup_key) |
| 679 : backup_key_name_(backup_key) {} | 636 : backup_key_name_(backup_key) {} |
| 680 ~SecurityDescBackup() {} | 637 ~SecurityDescBackup() {} |
| 681 | 638 |
| 682 // Save given security descriptor to the backup key. | 639 // Save given security descriptor to the backup key. |
| 683 bool SaveSecurity(const CSecurityDesc& sd) { | 640 bool SaveSecurity(const CSecurityDesc& sd) { |
| 684 CString str; | 641 CString str; |
| 685 if (!sd.ToString(&str)) | 642 if (!sd.ToString(&str)) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 sd.GetDacl(&new_dacl); | 802 sd.GetDacl(&new_dacl); |
| 846 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); | 803 new_dacl.AddAllowedAce(token_.GetUser(), GENERIC_WRITE | GENERIC_READ); |
| 847 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { | 804 if (AtlSetDacl(object_name.c_str(), SE_REGISTRY_KEY, new_dacl)) { |
| 848 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); | 805 result = SetOrDeleteMimeHandlerKey(enable, HKEY_LOCAL_MACHINE); |
| 849 } | 806 } |
| 850 } | 807 } |
| 851 | 808 |
| 852 backup.RestoreSecurity(object_name.c_str()); | 809 backup.RestoreSecurity(object_name.c_str()); |
| 853 return result; | 810 return result; |
| 854 } | 811 } |
| OLD | NEW |