Bug 975144 - Implementation of RTC identity DOM component, r=jib
authorMartin Thomson <martin.thomson@gmail.com>
Sun, 22 Feb 2015 10:57:20 +1300
changeset 257306 8859d04f962ac6e0581fb5523c778e0e94a05827
parent 257305 d3bb6e25fd0464349bb37a59bfaa4c4436fad937
child 257307 7cf45873e3682883bae83fa90c55e963fe40c402
push id4610
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:32:55 +0000
treeherdermozilla-beta@4df54044d9ef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjib
bugs975144
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 975144 - Implementation of RTC identity DOM component, r=jib
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',