AuthenticatorResponse.cpp (1739B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "mozilla/dom/AuthenticatorResponse.h" 8 9 #include "mozilla/Base64.h" 10 #include "mozilla/dom/TypedArray.h" 11 #include "nsPIDOMWindow.h" 12 #include "nsWrapperCache.h" 13 14 namespace mozilla::dom { 15 16 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_WITH_JS_MEMBERS( 17 AuthenticatorResponse, (mParent), (mClientDataJSONCachedObj)) 18 19 NS_IMPL_CYCLE_COLLECTING_ADDREF(AuthenticatorResponse) 20 NS_IMPL_CYCLE_COLLECTING_RELEASE(AuthenticatorResponse) 21 22 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AuthenticatorResponse) 23 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 24 NS_INTERFACE_MAP_ENTRY(nsISupports) 25 NS_INTERFACE_MAP_END 26 27 AuthenticatorResponse::AuthenticatorResponse(nsPIDOMWindowInner* aParent) 28 : mParent(aParent), mClientDataJSONCachedObj(nullptr) { 29 // Call HoldJSObjects() in subclasses. 30 } 31 32 AuthenticatorResponse::~AuthenticatorResponse() { 33 // Call DropJSObjects() in subclasses. 34 } 35 36 nsISupports* AuthenticatorResponse::GetParentObject() const { return mParent; } 37 38 void AuthenticatorResponse::GetClientDataJSON( 39 JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) { 40 if (!mClientDataJSONCachedObj) { 41 mClientDataJSONCachedObj = ArrayBuffer::Create(aCx, mClientDataJSON, aRv); 42 if (aRv.Failed()) { 43 return; 44 } 45 } 46 aValue.set(mClientDataJSONCachedObj); 47 } 48 49 void AuthenticatorResponse::SetClientDataJSON(const nsCString& aBuffer) { 50 mClientDataJSON.Assign(aBuffer); 51 } 52 53 } // namespace mozilla::dom