RTCIdentityProviderRegistrar.cpp (2629B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include "RTCIdentityProviderRegistrar.h" 7 8 #include "nsCycleCollectionParticipant.h" 9 10 namespace mozilla::dom { 11 12 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RTCIdentityProviderRegistrar) 13 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 14 NS_INTERFACE_MAP_ENTRY(nsISupports) 15 NS_INTERFACE_MAP_END 16 17 NS_IMPL_CYCLE_COLLECTING_ADDREF(RTCIdentityProviderRegistrar) 18 NS_IMPL_CYCLE_COLLECTING_RELEASE(RTCIdentityProviderRegistrar) 19 20 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(RTCIdentityProviderRegistrar, mGlobal, 21 mGenerateAssertionCallback, 22 mValidateAssertionCallback) 23 24 RTCIdentityProviderRegistrar::RTCIdentityProviderRegistrar( 25 nsIGlobalObject* aGlobal) 26 : mGlobal(aGlobal), 27 mGenerateAssertionCallback(nullptr), 28 mValidateAssertionCallback(nullptr) {} 29 30 RTCIdentityProviderRegistrar::~RTCIdentityProviderRegistrar() = default; 31 32 nsIGlobalObject* RTCIdentityProviderRegistrar::GetParentObject() const { 33 return mGlobal; 34 } 35 36 JSObject* RTCIdentityProviderRegistrar::WrapObject( 37 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 38 return RTCIdentityProviderRegistrar_Binding::Wrap(aCx, this, aGivenProto); 39 } 40 41 void RTCIdentityProviderRegistrar::Register(const RTCIdentityProvider& aIdp) { 42 mGenerateAssertionCallback = aIdp.mGenerateAssertion; 43 mValidateAssertionCallback = aIdp.mValidateAssertion; 44 } 45 46 bool RTCIdentityProviderRegistrar::HasIdp() const { 47 return mGenerateAssertionCallback && mValidateAssertionCallback; 48 } 49 50 already_AddRefed<Promise> RTCIdentityProviderRegistrar::GenerateAssertion( 51 const nsAString& aContents, const nsAString& aOrigin, 52 const RTCIdentityProviderOptions& aOptions, ErrorResult& aRv) { 53 if (!mGenerateAssertionCallback) { 54 aRv.Throw(NS_ERROR_NOT_INITIALIZED); 55 return nullptr; 56 } 57 RefPtr<GenerateAssertionCallback> callback(mGenerateAssertionCallback); 58 return callback->Call(aContents, aOrigin, aOptions, aRv); 59 } 60 already_AddRefed<Promise> RTCIdentityProviderRegistrar::ValidateAssertion( 61 const nsAString& aAssertion, const nsAString& aOrigin, ErrorResult& aRv) { 62 if (!mValidateAssertionCallback) { 63 aRv.Throw(NS_ERROR_NOT_INITIALIZED); 64 return nullptr; 65 } 66 RefPtr<ValidateAssertionCallback> callback(mValidateAssertionCallback); 67 return callback->Call(aAssertion, aOrigin, aRv); 68 } 69 70 } // namespace mozilla::dom