Bug 975144 - Implementation of RTC identity DOM component draft
authorMartin Thomson <martin.thomson@gmail.com>
Fri, 09 Jan 2015 15:42:01 -0800
changeset 236137 5b7a82623a9fe4815356ef5144a11fb40731eb95
parent 236136 704c1330fdf1b63579b404cb7499196fe52bb0aa
child 236138 f3c6cb74d6249540a61db7b682ad621f21a24652
push id389
push usermartin.thomson@gmail.com
push dateFri, 09 Jan 2015 23:59:51 +0000
bugs975144
milestone37.0a1
Bug 975144 - Implementation of RTC identity DOM component
dom/media/RTCIdentityProviderRegistrar.cpp
dom/media/RTCIdentityProviderRegistrar.h
dom/media/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/media/RTCIdentityProviderRegistrar.cpp
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "RTCIdentityProviderRegistrar.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/dom/RTCIdentityProviderBinding.h"
+#include "nsCycleCollectionParticipant.h"
+
+namespace mozilla {
+namespace dom {
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(RTCIdentityProviderRegistrar)
+  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(RTCIdentityProviderRegistrar)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(RTCIdentityProviderRegistrar)
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(RTCIdentityProviderRegistrar,
+                                      mGlobal, mIdp)
+
+RTCIdentityProviderRegistrar::RTCIdentityProviderRegistrar(
+    nsIGlobalObject* aGlobal)
+    : mGlobal(aGlobal)
+    , mIdp(nullptr)
+{
+  MOZ_COUNT_CTOR(RTCIdentityProviderRegistrar);
+}
+
+RTCIdentityProviderRegistrar::~RTCIdentityProviderRegistrar()
+{
+  MOZ_COUNT_DTOR(RTCIdentityProviderRegistrar);
+}
+
+nsIGlobalObject*
+RTCIdentityProviderRegistrar::GetParentObject() const
+{
+  return mGlobal;
+}
+
+JSObject*
+RTCIdentityProviderRegistrar::WrapObject(JSContext* aCx)
+{
+  return RTCIdentityProviderRegistrarBinding::Wrap(aCx, this);
+}
+
+void
+RTCIdentityProviderRegistrar::Register(RTCIdentityProvider& aIdp)
+{
+  mIdp = &aIdp;
+}
+
+already_AddRefed<RTCIdentityProvider>
+RTCIdentityProviderRegistrar::GetIdp()
+{
+  nsRefPtr<RTCIdentityProvider> idp = mIdp;
+  return idp.forget();
+}
+
+already_AddRefed<Promise>
+RTCIdentityProviderRegistrar::GenerateAssertion(
+  const nsAString& aContents, const nsAString& aOrigin,
+  const Optional<nsAString>& aUsernameHint, ErrorResult& aRv)
+{
+  if (!mIdp) {
+    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
+    return nullptr;
+  }
+  return mIdp->GenerateAssertion(aContents, aOrigin, aUsernameHint, aRv);
+}
+already_AddRefed<Promise>
+RTCIdentityProviderRegistrar::ValidateAssertion(
+  const nsAString& aAssertion, const nsAString& aOrigin, ErrorResult& aRv)
+{
+  if (!mIdp) {
+    aRv.Throw(NS_ERROR_NOT_INITIALIZED);
+    return nullptr;
+  }
+  return mIdp->ValidateAssertion(aAssertion, aOrigin, aRv);
+}
+
+
+
+} // namespace dom
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/media/RTCIdentityProviderRegistrar.h
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef RTCIDENTITYPROVIDER_H_
+#define RTCIDENTITYPROVIDER_H_
+
+#include "nsRefPtr.h"
+#include "nsCOMPtr.h"
+#include "nsISupportsImpl.h"
+#include "nsIGlobalObject.h"
+#include "nsWrapperCache.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/dom/Promise.h"
+#include "mozilla/dom/BindingDeclarations.h"
+
+namespace mozilla {
+namespace dom {
+
+class RTCIdentityProvider;
+
+class RTCIdentityProviderRegistrar MOZ_FINAL : public nsISupports,
+                                               public nsWrapperCache
+{
+public:
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(RTCIdentityProviderRegistrar)
+
+  explicit RTCIdentityProviderRegistrar(nsIGlobalObject* aGlobal);
+
+  // As required
+  nsIGlobalObject* GetParentObject() const;
+  virtual JSObject* WrapObject(JSContext* aCx);
+
+  // setter and getter
+  void Register(RTCIdentityProvider& aIdp);
+  already_AddRefed<RTCIdentityProvider> GetIdp();
+
+  already_AddRefed<Promise>
+  GenerateAssertion(const nsAString& aContents, const nsAString& aOrigin,
+                    const Optional<nsAString>& aUsernameHint, ErrorResult& aRv);
+  already_AddRefed<Promise>
+  ValidateAssertion(const nsAString& assertion, const nsAString& origin,
+                    ErrorResult& aRv);
+
+private:
+  ~RTCIdentityProviderRegistrar();
+
+  nsCOMPtr<nsIGlobalObject> mGlobal;
+  nsRefPtr<RTCIdentityProvider> mIdp;
+};
+
+} // namespace dom
+} // namespace mozilla
+
+#endif /* RTCIDENTITYPROVIDER_H_ */
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -142,16 +142,17 @@ if CONFIG['MOZ_B2G']:
 EXPORTS.mozilla.dom += [
     'AudioStreamTrack.h',
     'AudioTrack.h',
     'AudioTrackList.h',
     'GetUserMediaRequest.h',
     'MediaDevices.h',
     'MediaStreamError.h',
     'MediaStreamTrack.h',
+    'RTCIdentityProviderRegistrar.h',
     'TextTrack.h',
     'TextTrackCue.h',
     'TextTrackCueList.h',
     'TextTrackList.h',
     'TextTrackRegion.h',
     'VideoPlaybackQuality.h',
     'VideoStreamTrack.h',
     'VideoTrack.h',
@@ -188,16 +189,17 @@ UNIFIED_SOURCES += [
     'MediaShutdownManager.cpp',
     'MediaStreamError.cpp',
     'MediaStreamGraph.cpp',
     'MediaStreamTrack.cpp',
     'MediaTaskQueue.cpp',
     'MediaTrack.cpp',
     'MediaTrackList.cpp',
     'MP3FrameParser.cpp',
+    'RTCIdentityProviderRegistrar.cpp',
     'RtspMediaResource.cpp',
     'SharedThreadPool.cpp',
     'StreamBuffer.cpp',
     'TextTrack.cpp',
     'TextTrackCue.cpp',
     'TextTrackCueList.cpp',
     'TextTrackList.cpp',
     'TextTrackRegion.cpp',