mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
Bug 1258299 - Move RTCIdentityProvider to a dictionary, r=jib,khuey
MozReview-Commit-ID: K97lKyhlsW8
This commit is contained in:
parent
ccef41ec11
commit
2238c2d4d1
@ -231,7 +231,7 @@ IdpSandbox.prototype = {
|
||||
throw new Error('Error in IdP, check console for details');
|
||||
}
|
||||
|
||||
if (!registrar.idp) {
|
||||
if (!registrar.hasIdp) {
|
||||
throw new Error('IdP failed to call rtcIdentityProvider.register()');
|
||||
}
|
||||
return registrar;
|
||||
|
@ -101,6 +101,10 @@
|
||||
|
||||
if (!instructions.some(is('not_ready'))) {
|
||||
dump('registering idp.js' + global.location.hash + '\n');
|
||||
global.rtcIdentityProvider.register(new IDPJS());
|
||||
var idp = new IDPJS();
|
||||
global.rtcIdentityProvider.register({
|
||||
generateAssertion: idp.generateAssertion.bind(idp),
|
||||
validateAssertion: idp.validateAssertion.bind(idp)
|
||||
});
|
||||
}
|
||||
}(this));
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
#include "RTCIdentityProviderRegistrar.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/RTCIdentityProviderBinding.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
namespace mozilla {
|
||||
@ -20,12 +19,15 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(RTCIdentityProviderRegistrar)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(RTCIdentityProviderRegistrar)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(RTCIdentityProviderRegistrar,
|
||||
mGlobal, mIdp)
|
||||
mGlobal,
|
||||
mGenerateAssertionCallback,
|
||||
mValidateAssertionCallback)
|
||||
|
||||
RTCIdentityProviderRegistrar::RTCIdentityProviderRegistrar(
|
||||
nsIGlobalObject* aGlobal)
|
||||
: mGlobal(aGlobal)
|
||||
, mIdp(nullptr)
|
||||
, mGenerateAssertionCallback(nullptr)
|
||||
, mValidateAssertionCallback(nullptr)
|
||||
{
|
||||
MOZ_COUNT_CTOR(RTCIdentityProviderRegistrar);
|
||||
}
|
||||
@ -48,16 +50,16 @@ RTCIdentityProviderRegistrar::WrapObject(JSContext* aCx, JS::Handle<JSObject*> a
|
||||
}
|
||||
|
||||
void
|
||||
RTCIdentityProviderRegistrar::Register(RTCIdentityProvider& aIdp)
|
||||
RTCIdentityProviderRegistrar::Register(const RTCIdentityProvider& aIdp)
|
||||
{
|
||||
mIdp = &aIdp;
|
||||
mGenerateAssertionCallback = aIdp.mGenerateAssertion;
|
||||
mValidateAssertionCallback = aIdp.mValidateAssertion;
|
||||
}
|
||||
|
||||
already_AddRefed<RTCIdentityProvider>
|
||||
RTCIdentityProviderRegistrar::GetIdp()
|
||||
bool
|
||||
RTCIdentityProviderRegistrar::HasIdp() const
|
||||
{
|
||||
RefPtr<RTCIdentityProvider> idp = mIdp;
|
||||
return idp.forget();
|
||||
return mGenerateAssertionCallback && mValidateAssertionCallback;
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
@ -65,21 +67,21 @@ RTCIdentityProviderRegistrar::GenerateAssertion(
|
||||
const nsAString& aContents, const nsAString& aOrigin,
|
||||
const Optional<nsAString>& aUsernameHint, ErrorResult& aRv)
|
||||
{
|
||||
if (!mIdp) {
|
||||
if (!mGenerateAssertionCallback) {
|
||||
aRv.Throw(NS_ERROR_NOT_INITIALIZED);
|
||||
return nullptr;
|
||||
}
|
||||
return mIdp->GenerateAssertion(aContents, aOrigin, aUsernameHint, aRv);
|
||||
return mGenerateAssertionCallback->Call(aContents, aOrigin, aUsernameHint, aRv);
|
||||
}
|
||||
already_AddRefed<Promise>
|
||||
RTCIdentityProviderRegistrar::ValidateAssertion(
|
||||
const nsAString& aAssertion, const nsAString& aOrigin, ErrorResult& aRv)
|
||||
{
|
||||
if (!mIdp) {
|
||||
if (!mValidateAssertionCallback) {
|
||||
aRv.Throw(NS_ERROR_NOT_INITIALIZED);
|
||||
return nullptr;
|
||||
}
|
||||
return mIdp->ValidateAssertion(aAssertion, aOrigin, aRv);
|
||||
return mValidateAssertionCallback->Call(aAssertion, aOrigin, aRv);
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,11 +14,12 @@
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
#include "mozilla/dom/RTCIdentityProviderBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class RTCIdentityProvider;
|
||||
struct RTCIdentityProvider;
|
||||
|
||||
class RTCIdentityProviderRegistrar final : public nsISupports,
|
||||
public nsWrapperCache
|
||||
@ -33,9 +34,9 @@ public:
|
||||
nsIGlobalObject* GetParentObject() const;
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
// setter and getter
|
||||
void Register(RTCIdentityProvider& aIdp);
|
||||
already_AddRefed<RTCIdentityProvider> GetIdp();
|
||||
// setter and checker
|
||||
void Register(const RTCIdentityProvider& aIdp);
|
||||
bool HasIdp() const;
|
||||
|
||||
already_AddRefed<Promise>
|
||||
GenerateAssertion(const nsAString& aContents, const nsAString& aOrigin,
|
||||
@ -48,7 +49,8 @@ private:
|
||||
~RTCIdentityProviderRegistrar();
|
||||
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
RefPtr<RTCIdentityProvider> mIdp;
|
||||
RefPtr<GenerateAssertionCallback> mGenerateAssertionCallback;
|
||||
RefPtr<ValidateAssertionCallback> mValidateAssertionCallback;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -10,9 +10,9 @@
|
||||
interface RTCIdentityProviderRegistrar {
|
||||
void register(RTCIdentityProvider idp);
|
||||
|
||||
/* The IdP that was passed to register() to chrome code, if any. */
|
||||
/* Whether an IdP was passed to register() to chrome code. */
|
||||
[ChromeOnly]
|
||||
readonly attribute RTCIdentityProvider? idp;
|
||||
readonly attribute boolean hasIdp;
|
||||
/* The following two chrome-only functions forward to the corresponding
|
||||
* function on the registered IdP. This is necessary because the
|
||||
* JS-implemented WebIDL can't see these functions on `idp` above, chrome JS
|
||||
@ -30,14 +30,17 @@ interface RTCIdentityProviderRegistrar {
|
||||
validateAssertion(DOMString assertion, DOMString origin);
|
||||
};
|
||||
|
||||
callback interface RTCIdentityProvider {
|
||||
Promise<RTCIdentityAssertionResult>
|
||||
generateAssertion(DOMString contents, DOMString origin,
|
||||
optional DOMString usernameHint);
|
||||
Promise<RTCIdentityValidationResult>
|
||||
validateAssertion(DOMString assertion, DOMString origin);
|
||||
dictionary RTCIdentityProvider {
|
||||
required GenerateAssertionCallback generateAssertion;
|
||||
required ValidateAssertionCallback validateAssertion;
|
||||
};
|
||||
|
||||
callback GenerateAssertionCallback =
|
||||
Promise<RTCIdentityAssertionResult>
|
||||
(DOMString contents, DOMString origin, optional DOMString usernameHint);
|
||||
callback ValidateAssertionCallback =
|
||||
Promise<RTCIdentityValidationResult> (DOMString assertion, DOMString origin);
|
||||
|
||||
dictionary RTCIdentityAssertionResult {
|
||||
required RTCIdentityProviderDetails idp;
|
||||
required DOMString assertion;
|
||||
|
@ -27,9 +27,9 @@ function run_test() {
|
||||
|
||||
sb.equal = equal;
|
||||
Cu.evalInSandbox('(' + exerciseInterface.toSource() + ')();', sb);
|
||||
ok(sb.rtcIdentityProvider.idp);
|
||||
ok(sb.rtcIdentityProvider.hasIdp);
|
||||
|
||||
Cu.importGlobalProperties(['rtcIdentityProvider']);
|
||||
exerciseInterface();
|
||||
ok(rtcIdentityProvider.idp);
|
||||
ok(rtcIdentityProvider.hasIdp);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user