Back out 6 changesets (bug 1046245) for thinking that MSVC would have anything to do with a __PRETTY_FUNCTION__
authorPhil Ringnalda <philringnalda@gmail.com>
Sat, 28 Mar 2015 19:57:17 -0700
changeset 265266 99c3baae746dab74dee6bee92173621ce20b4dc1
parent 265265 015fa1d7c54805889f3cfe179f63b6c60ebd1fdc
child 265267 3de12fe1b92743951aeb66ab08a2b05f0b0a2487
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1046245
milestone39.0a1
backs out9e3ecca831d87c957a7ae8e7e5fe758d7385a785
87dc145f4da8b721dfcc04b4de8508d58e354e40
01606cf19a777a84436b5edea1232d0fef37b3f2
2ed2b15fe94055f08517d4c8fff63ce97fe30988
2b99b193828ac8f8f66adb2803bc1b3448ede6ce
d1ac67faccbbaa92c68f8d9f2a5b702f32fa4c23
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
Back out 6 changesets (bug 1046245) for thinking that MSVC would have anything to do with a __PRETTY_FUNCTION__ CLOSED TREE Backed out changeset 9e3ecca831d8 (bug 1046245) Backed out changeset 87dc145f4da8 (bug 1046245) Backed out changeset 01606cf19a77 (bug 1046245) Backed out changeset 2ed2b15fe940 (bug 1046245) Backed out changeset 2b99b193828a (bug 1046245) Backed out changeset d1ac67faccbb (bug 1046245)
browser/base/content/sanitize.js
dom/media/MediaDeviceInfo.cpp
dom/media/MediaDeviceInfo.h
dom/media/MediaDevices.cpp
dom/media/MediaDevices.h
dom/media/MediaManager.cpp
dom/media/MediaManager.h
dom/media/VideoUtils.cpp
dom/media/VideoUtils.h
dom/media/moz.build
dom/media/nsIMediaManager.idl
dom/media/systemservices/MediaChild.cpp
dom/media/systemservices/MediaChild.h
dom/media/systemservices/MediaParent.cpp
dom/media/systemservices/MediaParent.h
dom/media/systemservices/MediaUtils.cpp
dom/media/systemservices/MediaUtils.h
dom/media/systemservices/PMedia.ipdl
dom/media/systemservices/moz.build
dom/tests/mochitest/general/test_interfaces.html
dom/webidl/MediaDeviceInfo.webidl
dom/webidl/MediaDevices.webidl
dom/webidl/moz.build
ipc/glue/BackgroundChildImpl.cpp
ipc/glue/BackgroundChildImpl.h
ipc/glue/BackgroundParentImpl.cpp
ipc/glue/BackgroundParentImpl.h
ipc/glue/PBackground.ipdl
security/manager/ssl/src/nsNSSModule.cpp
--- a/browser/base/content/sanitize.js
+++ b/browser/base/content/sanitize.js
@@ -194,21 +194,16 @@ Sanitizer.prototype = {
               cookieMgr.remove(cookie.host, cookie.name, cookie.path, false);
           }
         }
         else {
           // Remove everything
           cookieMgr.removeAll();
         }
 
-        // Clear deviceIds. Done asynchronously (returns before complete).
-        let mediaMgr = Components.classes["@mozilla.org/mediaManagerService;1"]
-                                 .getService(Ci.nsIMediaManagerService);
-        mediaMgr.sanitizeDeviceIds(this.range && this.range[0]);
-
         // Clear plugin data.
         const phInterface = Ci.nsIPluginHost;
         const FLAG_CLEAR_ALL = phInterface.FLAG_CLEAR_ALL;
         let ph = Cc["@mozilla.org/plugin/host;1"].getService(phInterface);
 
         // Determine age range in seconds. (-1 means clear all.) We don't know
         // that this.range[1] is actually now, so we compute age range based
         // on the lower bound. If this.range results in a negative age, do
deleted file mode 100644
--- a/dom/media/MediaDeviceInfo.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/* 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 "mozilla/dom/MediaDeviceInfo.h"
-#include "mozilla/dom/MediaStreamBinding.h"
-#include "mozilla/MediaManager.h"
-#include "nsIScriptGlobalObject.h"
-
-namespace mozilla {
-namespace dom {
-
-MediaDeviceInfo::MediaDeviceInfo(const nsAString& aDeviceId,
-                                 MediaDeviceKind aKind,
-                                 const nsAString& aLabel,
-                                 const nsAString& aGroupId)
-  : mKind(aKind)
-  , mDeviceId(aDeviceId)
-  , mLabel(aLabel)
-  , mGroupId(aGroupId) {}
-
-NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(MediaDeviceInfo)
-NS_IMPL_CYCLE_COLLECTING_ADDREF(MediaDeviceInfo)
-NS_IMPL_CYCLE_COLLECTING_RELEASE(MediaDeviceInfo)
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(MediaDeviceInfo)
-  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
-  NS_INTERFACE_MAP_ENTRY(nsISupports)
-NS_INTERFACE_MAP_END
-
-JSObject*
-MediaDeviceInfo::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
-{
-  return MediaDeviceInfoBinding::Wrap(aCx, this, aGivenProto);
-}
-
-nsISupports* MediaDeviceInfo::GetParentObject()
-{
-  return nullptr;
-}
-
-void MediaDeviceInfo::GetDeviceId(nsString& retval)
-{
-  retval = mDeviceId;
-}
-
-MediaDeviceKind
-MediaDeviceInfo::Kind()
-{
-  return mKind;
-}
-
-void MediaDeviceInfo::GetGroupId(nsString& retval)
-{
-  retval = mGroupId;
-}
-
-void MediaDeviceInfo::GetLabel(nsString& retval)
-{
-  retval = mLabel;
-}
-
-MediaDeviceKind Kind();
-void GetLabel(nsString& retval);
-void GetGroupId(nsString& retval);
-
-} // namespace dom
-} // namespace mozilla
deleted file mode 100644
--- a/dom/media/MediaDeviceInfo.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/* 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 mozilla_dom_MediaDeviceInfo_h
-#define mozilla_dom_MediaDeviceInfo_h
-
-#include "mozilla/ErrorResult.h"
-#include "nsISupportsImpl.h"
-#include "mozilla/dom/BindingUtils.h"
-#include "MediaDeviceInfoBinding.h"
-#include "nsPIDOMWindow.h"
-
-namespace mozilla {
-namespace dom {
-
-class Promise;
-struct MediaStreamConstraints;
-
-#define MOZILLA_DOM_MEDIADEVICEINFO_IMPLEMENTATION_IID \
-{0x25091870, 0x84d6, 0x4acf, {0xaf, 0x97, 0x6e, 0xd5, 0x5b, 0xe0, 0x47, 0xb2}}
-
-class MediaDeviceInfo final : public nsISupports, public nsWrapperCache
-{
-public:
-  explicit MediaDeviceInfo(const nsAString& aDeviceId,
-                           MediaDeviceKind aKind,
-                           const nsAString& aLabel,
-                           const nsAString& aGroupId = nsString());
-
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaDeviceInfo)
-  NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIADEVICEINFO_IMPLEMENTATION_IID)
-
-  JSObject*
-  WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
-
-  nsISupports* GetParentObject();
-
-  void GetDeviceId(nsString& retval);
-  MediaDeviceKind Kind();
-  void GetLabel(nsString& retval);
-  void GetGroupId(nsString& retval);
-
-private:
-  MediaDeviceKind mKind;
-  nsString mDeviceId;
-  nsString mLabel;
-  nsString mGroupId;
-
-  virtual ~MediaDeviceInfo() {}
-};
-
-NS_DEFINE_STATIC_IID_ACCESSOR(MediaDeviceInfo,
-                              MOZILLA_DOM_MEDIADEVICEINFO_IMPLEMENTATION_IID)
-
-} // namespace dom
-} // namespace mozilla
-
-#endif // mozilla_dom_MediaDeviceInfo_h
--- a/dom/media/MediaDevices.cpp
+++ b/dom/media/MediaDevices.cpp
@@ -4,17 +4,16 @@
 
 #include "mozilla/dom/MediaDevices.h"
 #include "mozilla/dom/MediaStreamBinding.h"
 #include "mozilla/dom/MediaDevicesBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/MediaManager.h"
 #include "nsIEventTarget.h"
 #include "nsIScriptGlobalObject.h"
-#include "nsIPermissionManager.h"
 #include "nsPIDOMWindow.h"
 
 namespace mozilla {
 namespace dom {
 
 class MediaDevices::GumResolver : public nsIDOMGetUserMediaSuccessCallback
 {
 public:
@@ -33,119 +32,16 @@ public:
     return NS_OK;
   }
 
 private:
   virtual ~GumResolver() {}
   nsRefPtr<Promise> mPromise;
 };
 
-class MediaDevices::EnumDevResolver : public nsIGetUserMediaDevicesSuccessCallback
-{
-  static bool HasAPersistentPermission(uint64_t aWindowId)
-  {
-    nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
-        (nsGlobalWindow::GetInnerWindowWithId(aWindowId));
-    if (NS_WARN_IF(!window)) {
-      return false;
-    }
-    // Check if this site has persistent permissions.
-    nsresult rv;
-    nsCOMPtr<nsIPermissionManager> mgr =
-      do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return false; // no permission manager no permissions!
-    }
-
-    uint32_t audio = nsIPermissionManager::UNKNOWN_ACTION;
-    uint32_t video = nsIPermissionManager::UNKNOWN_ACTION;
-    {
-      auto* principal = window->GetExtantDoc()->NodePrincipal();
-      rv = mgr->TestExactPermissionFromPrincipal(principal, "microphone", &audio);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return false;
-      }
-      rv = mgr->TestExactPermissionFromPrincipal(principal, "camera", &video);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return false;
-      }
-    }
-    return audio == nsIPermissionManager::ALLOW_ACTION ||
-           video == nsIPermissionManager::ALLOW_ACTION;
-  }
-
-public:
-  NS_DECL_ISUPPORTS
-
-  EnumDevResolver(Promise* aPromise, uint64_t aWindowId)
-  : mPromise(aPromise), mWindowId(aWindowId) {}
-
-  NS_IMETHOD
-  OnSuccess(nsIVariant* aDevices) override
-  {
-    // Cribbed from MediaPermissionGonk.cpp
-    nsIID elementIID;
-    uint16_t elementType;
-
-    // Create array for nsIMediaDevice
-    nsTArray<nsCOMPtr<nsIMediaDevice>> devices;
-    // Contain the fumes
-    {
-      void* rawArray;
-      uint32_t arrayLen;
-      nsresult rv;
-      rv = aDevices->GetAsArray(&elementType, &elementIID, &arrayLen, &rawArray);
-      NS_ENSURE_SUCCESS(rv, rv);
-
-      if (elementType != nsIDataType::VTYPE_INTERFACE) {
-        NS_Free(rawArray);
-        return NS_ERROR_FAILURE;
-      }
-
-      nsISupports **supportsArray = reinterpret_cast<nsISupports **>(rawArray);
-      for (uint32_t i = 0; i < arrayLen; ++i) {
-        nsCOMPtr<nsIMediaDevice> device(do_QueryInterface(supportsArray[i]));
-        devices.AppendElement(device);
-        NS_IF_RELEASE(supportsArray[i]); // explicitly decrease refcount for rawptr
-      }
-      NS_Free(rawArray); // explicitly free memory from nsIVariant::GetAsArray
-    }
-    nsTArray<nsRefPtr<MediaDeviceInfo>> infos;
-    for (auto& device : devices) {
-      nsString type;
-      device->GetType(type);
-      bool isVideo = type.EqualsLiteral("video");
-      bool isAudio = type.EqualsLiteral("audio");
-      if (isVideo || isAudio) {
-        MediaDeviceKind kind = isVideo ?
-            MediaDeviceKind::Videoinput : MediaDeviceKind::Audioinput;
-        nsString id;
-        nsString name;
-        device->GetId(id);
-        // Include name only if page currently has a gUM stream active or
-        // persistent permissions (audio or video) have been granted
-        if (MediaManager::Get()->IsWindowActivelyCapturing(mWindowId) ||
-            HasAPersistentPermission(mWindowId) ||
-            Preferences::GetBool("media.navigator.permission.disabled", false)) {
-          device->GetName(name);
-        }
-        nsRefPtr<MediaDeviceInfo> info = new MediaDeviceInfo(id, kind, name);
-        infos.AppendElement(info);
-      }
-    }
-    mPromise->MaybeResolve(infos);
-    return NS_OK;
-  }
-
-private:
-  virtual ~EnumDevResolver() {}
-  nsRefPtr<Promise> mPromise;
-  uint64_t mWindowId;
-};
-
 class MediaDevices::GumRejecter : public nsIDOMGetUserMediaErrorCallback
 {
 public:
   NS_DECL_ISUPPORTS
 
   explicit GumRejecter(Promise* aPromise) : mPromise(aPromise) {}
 
   NS_IMETHOD
@@ -160,51 +56,36 @@ public:
   }
 
 private:
   virtual ~GumRejecter() {}
   nsRefPtr<Promise> mPromise;
 };
 
 NS_IMPL_ISUPPORTS(MediaDevices::GumResolver, nsIDOMGetUserMediaSuccessCallback)
-NS_IMPL_ISUPPORTS(MediaDevices::EnumDevResolver, nsIGetUserMediaDevicesSuccessCallback)
 NS_IMPL_ISUPPORTS(MediaDevices::GumRejecter, nsIDOMGetUserMediaErrorCallback)
 
 already_AddRefed<Promise>
 MediaDevices::GetUserMedia(const MediaStreamConstraints& aConstraints,
                            ErrorResult &aRv)
 {
+  ErrorResult rv;
   nsPIDOMWindow* window = GetOwner();
   nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(window);
   nsRefPtr<Promise> p = Promise::Create(go, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
+  NS_ENSURE_TRUE(!rv.Failed(), nullptr);
 
   nsRefPtr<GumResolver> resolver = new GumResolver(p);
   nsRefPtr<GumRejecter> rejecter = new GumRejecter(p);
 
   aRv = MediaManager::Get()->GetUserMedia(window, aConstraints,
                                           resolver, rejecter);
   return p.forget();
 }
 
-already_AddRefed<Promise>
-MediaDevices::EnumerateDevices(ErrorResult &aRv)
-{
-  nsPIDOMWindow* window = GetOwner();
-  nsCOMPtr<nsIGlobalObject> go = do_QueryInterface(window);
-  nsRefPtr<Promise> p = Promise::Create(go, aRv);
-  NS_ENSURE_TRUE(!aRv.Failed(), nullptr);
-
-  nsRefPtr<EnumDevResolver> resolver = new EnumDevResolver(p, window->WindowID());
-  nsRefPtr<GumRejecter> rejecter = new GumRejecter(p);
-
-  aRv = MediaManager::Get()->EnumerateDevices(window, resolver, rejecter);
-  return p.forget();
-}
-
 NS_IMPL_ADDREF_INHERITED(MediaDevices, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(MediaDevices, DOMEventTargetHelper)
 NS_INTERFACE_MAP_BEGIN(MediaDevices)
   NS_INTERFACE_MAP_ENTRY(MediaDevices)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
 
 JSObject*
 MediaDevices::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
--- a/dom/media/MediaDevices.h
+++ b/dom/media/MediaDevices.h
@@ -1,14 +1,14 @@
 /* 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 mozilla_dom_MediaDevices_h
-#define mozilla_dom_MediaDevices_h
+#ifndef MediaDevices_h__
+#define MediaDevices_h__
 
 #include "mozilla/ErrorResult.h"
 #include "nsISupportsImpl.h"
 #include "mozilla/DOMEventTargetHelper.h"
 #include "mozilla/dom/BindingUtils.h"
 #include "nsPIDOMWindow.h"
 
 namespace mozilla {
@@ -30,26 +30,22 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIADEVICES_IMPLEMENTATION_IID)
 
   JSObject* WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto) override;
 
   already_AddRefed<Promise>
   GetUserMedia(const MediaStreamConstraints& aConstraints, ErrorResult &aRv);
 
-  already_AddRefed<Promise>
-  EnumerateDevices(ErrorResult &aRv);
-
 private:
   class GumResolver;
-  class EnumDevResolver;
   class GumRejecter;
 
   virtual ~MediaDevices() {}
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(MediaDevices,
                               MOZILLA_DOM_MEDIADEVICES_IMPLEMENTATION_IID)
 
 } // namespace dom
 } // namespace mozilla
 
-#endif // mozilla_dom_MediaDevices_h
+#endif // MediaDevices_h__
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -20,47 +20,33 @@
 #include "nsIPopupWindowManager.h"
 #include "nsISupportsArray.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIIDNService.h"
 #include "nsNetUtil.h"
-#include "nsPrincipal.h"
-#include "nsICryptoHash.h"
-#include "nsICryptoHMAC.h"
-#include "nsIKeyModule.h"
-#include "nsAppDirectoryServiceDefs.h"
-#include "nsIInputStream.h"
-#include "nsILineInputStream.h"
 #include "mozilla/Types.h"
 #include "mozilla/PeerIdentity.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/File.h"
 #include "mozilla/dom/MediaStreamBinding.h"
 #include "mozilla/dom/MediaStreamTrackBinding.h"
 #include "mozilla/dom/GetUserMediaRequestBinding.h"
 #include "mozilla/Preferences.h"
-#include "mozilla/Base64.h"
-#include "mozilla/ipc/BackgroundChild.h"
-#include "mozilla/media/MediaChild.h"
 #include "MediaTrackConstraints.h"
-#include "VideoUtils.h"
+
 #include "Latency.h"
 
 // For PR_snprintf
 #include "prprf.h"
 
 #include "nsJSUtils.h"
 #include "nsGlobalWindow.h"
-#include "nsIUUIDGenerator.h"
-#include "nspr.h"
-#include "nss.h"
-#include "pk11pub.h"
 
 /* Using WebRTC backend on Desktops (Mac, Windows, Linux), otherwise default */
 #include "MediaEngineDefault.h"
 #if defined(MOZ_WEBRTC)
 #include "MediaEngineWebRTC.h"
 #include "browser_logging/WebRtcLog.h"
 #endif
 
@@ -203,71 +189,55 @@ HostHasPermission(nsIURI &docURI)
     }
 
     begin = end + 1;
   } while (end < domainWhiteList.Length());
 
   return false;
 }
 
-/**
- * Send an error back to content.
- * Do this only on the main thread. The onSuccess callback is also passed here
- * so it can be released correctly.
- */
-template<class SuccessCallbackType>
-class ErrorCallbackRunnable : public nsRunnable
+ErrorCallbackRunnable::ErrorCallbackRunnable(
+  nsCOMPtr<nsIDOMGetUserMediaSuccessCallback>& aOnSuccess,
+  nsCOMPtr<nsIDOMGetUserMediaErrorCallback>& aOnFailure,
+  MediaMgrError& aError,
+  uint64_t aWindowID)
+  : mError(&aError)
+  , mWindowID(aWindowID)
+  , mManager(MediaManager::GetInstance())
 {
-public:
-  ErrorCallbackRunnable(
-    nsCOMPtr<SuccessCallbackType>& aOnSuccess,
-    nsCOMPtr<nsIDOMGetUserMediaErrorCallback>& aOnFailure,
-    MediaMgrError& aError,
-    uint64_t aWindowID)
-    : mError(&aError)
-    , mWindowID(aWindowID)
-    , mManager(MediaManager::GetInstance())
-  {
-    mOnSuccess.swap(aOnSuccess);
-    mOnFailure.swap(aOnFailure);
-  }
+  mOnSuccess.swap(aOnSuccess);
+  mOnFailure.swap(aOnFailure);
+}
+
+ErrorCallbackRunnable::~ErrorCallbackRunnable()
+{
+  MOZ_ASSERT(!mOnSuccess && !mOnFailure);
+}
 
-  NS_IMETHODIMP
-  Run()
-  {
-    NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
-
-    nsCOMPtr<SuccessCallbackType> onSuccess = mOnSuccess.forget();
-    nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onFailure = mOnFailure.forget();
+NS_IMETHODIMP
+ErrorCallbackRunnable::Run()
+{
+  // Only run if the window is still active.
+  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
-    // Only run if the window is still active.
-    if (!(mManager->IsWindowStillActive(mWindowID))) {
-      return NS_OK;
-    }
-    // This is safe since we're on main-thread, and the windowlist can only
-    // be invalidated from the main-thread (see OnNavigation)
-    nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(mWindowID);
-    if (window) {
-      nsRefPtr<MediaStreamError> error = new MediaStreamError(window, *mError);
-      onFailure->OnError(error);
-    }
+  nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onSuccess = mOnSuccess.forget();
+  nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onFailure = mOnFailure.forget();
+
+  if (!(mManager->IsWindowStillActive(mWindowID))) {
     return NS_OK;
   }
-private:
-  ~ErrorCallbackRunnable()
-  {
-    MOZ_ASSERT(!mOnSuccess && !mOnFailure);
+  // This is safe since we're on main-thread, and the windowlist can only
+  // be invalidated from the main-thread (see OnNavigation)
+  nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(mWindowID);
+  if (window) {
+    nsRefPtr<MediaStreamError> error = new MediaStreamError(window, *mError);
+    onFailure->OnError(error);
   }
-
-  nsCOMPtr<SuccessCallbackType> mOnSuccess;
-  nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
-  nsRefPtr<MediaMgrError> mError;
-  uint64_t mWindowID;
-  nsRefPtr<MediaManager> mManager; // get ref to this when creating the runnable
-};
+  return NS_OK;
+}
 
 /**
  * Invoke the "onSuccess" callback in content. The callback will take a
  * DOMBlob in the case of {picture:true}, and a MediaStream in the case of
  * {audio:true} or {video:true}. There is a constructor available for each
  * form. Do this only on the main thread.
  */
 class SuccessCallbackRunnable : public nsRunnable
@@ -327,111 +297,60 @@ public:
     : mDevices(aDevices)
     , mWindowID(aWindowID)
     , mManager(MediaManager::GetInstance())
   {
     mOnSuccess.swap(aOnSuccess);
     mOnFailure.swap(aOnFailure);
   }
 
-  nsresult
-  AnonymizeId(nsAString& aId, const nsACString& aOriginKey)
-  {
-    nsresult rv;
-    nsCOMPtr<nsIKeyObjectFactory> factory =
-      do_GetService("@mozilla.org/security/keyobjectfactory;1", &rv);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    nsCString rawKey;
-    rv = Base64Decode(aOriginKey, rawKey);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    nsCOMPtr<nsIKeyObject> key;
-    rv = factory->KeyFromString(nsIKeyObject::HMAC, rawKey, getter_AddRefs(key));
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    nsCOMPtr<nsICryptoHMAC> hasher =
-      do_CreateInstance(NS_CRYPTO_HMAC_CONTRACTID, &rv);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    rv = hasher->Init(nsICryptoHMAC::SHA256, key);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    NS_ConvertUTF16toUTF8 id(aId);
-    rv = hasher->Update(reinterpret_cast<const uint8_t*> (id.get()), id.Length());
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-    nsCString mac;
-    rv = hasher->Finish(true, mac);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-
-    aId = NS_ConvertUTF8toUTF16(mac);
-    return NS_OK;
-  }
-
   NS_IMETHOD
   Run()
   {
     NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
     // Only run if window is still on our active list.
     if (!mManager->IsWindowStillActive(mWindowID)) {
       return NS_OK;
     }
 
     nsCOMPtr<nsIWritableVariant> devices =
       do_CreateInstance("@mozilla.org/variant;1");
 
-    size_t len = mDevices->Length();
+    int32_t len = mDevices->Length();
     if (len == 0) {
       // XXX
       // We should in the future return an empty array, and dynamically add
       // devices to the dropdowns if things are hotplugged while the
       // requester is up.
       nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(mWindowID);
       if (window) {
         nsRefPtr<MediaStreamError> error = new MediaStreamError(window,
             NS_LITERAL_STRING("NotFoundError"));
         mOnFailure->OnError(error);
       }
       return NS_OK;
     }
 
     nsTArray<nsIMediaDevice*> tmp(len);
-    for (auto& device : *mDevices) {
-      if (!mOriginKey.IsEmpty()) {
-        nsString id;
-        device->GetId(id);
-        AnonymizeId(id, mOriginKey);
-        device->SetId(id);
-      }
-      tmp.AppendElement(device);
+    for (int32_t i = 0; i < len; i++) {
+      tmp.AppendElement(mDevices->ElementAt(i));
     }
 
     devices->SetAsArray(nsIDataType::VTYPE_INTERFACE,
                         &NS_GET_IID(nsIMediaDevice),
                         mDevices->Length(),
                         const_cast<void*>(
                           static_cast<const void*>(tmp.Elements())
                         ));
 
     mOnSuccess->OnSuccess(devices);
     return NS_OK;
   }
 
-  nsCString mOriginKey;
 private:
   nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> mOnSuccess;
   nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
   nsAutoPtr<nsTArray<nsRefPtr<MediaDevice>>> mDevices;
   uint64_t mWindowID;
   nsRefPtr<MediaManager> mManager;
 };
 
@@ -592,22 +511,16 @@ AudioDevice::GetType(nsAString& aType)
 
 NS_IMETHODIMP
 MediaDevice::GetId(nsAString& aID)
 {
   aID.Assign(mID);
   return NS_OK;
 }
 
-void
-MediaDevice::SetId(const nsAString& aID)
-{
-  mID.Assign(aID);
-}
-
 NS_IMETHODIMP
 MediaDevice::GetFacingMode(nsAString& aFacingMode)
 {
   if (mHasFacingMode) {
     aFacingMode.Assign(NS_ConvertUTF8toUTF16(
         dom::VideoFacingModeEnumValues::strings[uint32_t(mFacingMode)].value));
   } else {
     aFacingMode.Truncate(0);
@@ -808,36 +721,16 @@ public:
   bool mAgcOn;
   bool mNoiseOn;
   uint32_t mEcho;
   uint32_t mAgc;
   uint32_t mNoise;
   uint32_t mPlayoutDelay;
 };
 
-
-void
-MediaOperationTask::ReturnCallbackError(nsresult rv, const char* errorLog)
-{
-  MM_LOG(("%s , rv=%d", errorLog, rv));
-  NS_DispatchToMainThread(new ReleaseMediaOperationResource(mStream.forget(),
-      mOnTracksAvailableCallback.forget()));
-  nsString log;
-
-  log.AssignASCII(errorLog);
-  nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onSuccess;
-  nsRefPtr<MediaMgrError> error = new MediaMgrError(
-    NS_LITERAL_STRING("InternalError"), log);
-  NS_DispatchToMainThread(
-    new ErrorCallbackRunnable<nsIDOMGetUserMediaSuccessCallback>(onSuccess,
-                                                                 mOnFailure,
-                                                                 *error,
-                                                                 mWindowID));
-}
-
 /**
  * Creates a MediaStream, attaches a listener and fires off a success callback
  * to the DOM with the stream. We also pass in the error callback so it can
  * be released correctly.
  *
  * All of this must be done on the main thread!
  *
  * Note that the various GetUserMedia Runnable classes currently allow for
@@ -1193,34 +1086,31 @@ public:
 
   ~GetUserMediaTask() {
   }
 
   void
   Fail(const nsAString& aName,
        const nsAString& aMessage = EmptyString()) {
     nsRefPtr<MediaMgrError> error = new MediaMgrError(aName, aMessage);
-    nsRefPtr<ErrorCallbackRunnable<nsIDOMGetUserMediaSuccessCallback>> runnable =
-      new ErrorCallbackRunnable<nsIDOMGetUserMediaSuccessCallback>(mOnSuccess,
-                                                                   mOnFailure,
-                                                                   *error,
-                                                                   mWindowID);
+    nsRefPtr<ErrorCallbackRunnable> runnable =
+      new ErrorCallbackRunnable(mOnSuccess, mOnFailure, *error, mWindowID);
     // These should be empty now
     MOZ_ASSERT(!mOnSuccess);
     MOZ_ASSERT(!mOnFailure);
 
     NS_DispatchToMainThread(runnable);
     // Do after ErrorCallbackRunnable Run()s, as it checks active window list
     NS_DispatchToMainThread(new GetUserMediaListenerRemove(mWindowID, mListener));
   }
 
   void
   Run()
   {
-    MOZ_ASSERT(!NS_IsMainThread());
+    NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
     MOZ_ASSERT(mOnSuccess);
     MOZ_ASSERT(mOnFailure);
 
     MediaEngine* backend = mBackend;
     // Was a backend provided?
     if (!backend) {
       backend = mManager->GetBackend(mWindowID);
     }
@@ -1414,133 +1304,90 @@ public:
     return NS_OK;
   }
 
 private:
   nsAutoPtr<GetUserMediaTask> mTask;
 };
 #endif
 
-class SanitizeDeviceIdsTask : public Task
-{
-public:
-  explicit SanitizeDeviceIdsTask(int64_t aSinceWhen)
-  : mSinceWhen(aSinceWhen) {}
-
-  void // NS_IMETHOD
-  Run()
-  {
-    MOZ_ASSERT(!NS_IsMainThread());
-    nsRefPtr<media::ChildPledge<bool>> p =
-        mozilla::media::SanitizeOriginKeys(mSinceWhen); // we fire and forget
-  }
-private:
-  int64_t mSinceWhen;
-};
-
 /**
  * Similar to GetUserMediaTask, but used for the chrome-only
  * GetUserMediaDevices function. Enumerates a list of audio & video devices,
  * wraps them up in nsIMediaDevice objects and returns it to the success
  * callback.
- *
- * All code in this class runs on the MediaManager thread.
  */
 class GetUserMediaDevicesTask : public Task
 {
 public:
   GetUserMediaDevicesTask(
     const MediaStreamConstraints& aConstraints,
     already_AddRefed<nsIGetUserMediaDevicesSuccessCallback> aOnSuccess,
     already_AddRefed<nsIDOMGetUserMediaErrorCallback> aOnFailure,
     uint64_t aWindowId, nsACString& aAudioLoopbackDev,
-    nsACString& aVideoLoopbackDev, bool aPrivileged, const nsACString& aOrigin,
-    bool aInPrivateBrowsing, bool aUseFakeDevices)
+    nsACString& aVideoLoopbackDev, bool aUseFakeDevices)
     : mConstraints(aConstraints)
     , mOnSuccess(aOnSuccess)
     , mOnFailure(aOnFailure)
     , mManager(MediaManager::GetInstance())
     , mWindowId(aWindowId)
     , mLoopbackAudioDevice(aAudioLoopbackDev)
     , mLoopbackVideoDevice(aVideoLoopbackDev)
-    , mPrivileged(aPrivileged)
-    , mOrigin(aOrigin)
-    , mInPrivateBrowsing(aInPrivateBrowsing)
     , mUseFakeDevices(aUseFakeDevices) {}
 
   void // NS_IMETHOD
   Run()
   {
-    MOZ_ASSERT(!NS_IsMainThread());
+    NS_ASSERTION(!NS_IsMainThread(), "Don't call on main thread");
 
     nsRefPtr<MediaEngine> backend;
     if (mConstraints.mFake || mUseFakeDevices)
       backend = new MediaEngineDefault(mConstraints.mFakeTracks);
     else
       backend = mManager->GetBackend(mWindowId);
 
     typedef nsTArray<nsRefPtr<MediaDevice>> SourceSet;
 
-    ScopedDeletePtr<SourceSet> result(new SourceSet);
+    ScopedDeletePtr<SourceSet> final(new SourceSet);
     if (IsOn(mConstraints.mVideo)) {
-      nsTArray<nsRefPtr<VideoDevice>> sources;
+      nsTArray<nsRefPtr<VideoDevice>> s;
       GetSources(backend, GetInvariant(mConstraints.mVideo),
-                 &MediaEngine::EnumerateVideoDevices, sources,
-                 mLoopbackVideoDevice.get());
-      for (auto& source : sources) {
-        result->AppendElement(source);
+                 &MediaEngine::EnumerateVideoDevices, s, mLoopbackVideoDevice.get());
+      for (uint32_t i = 0; i < s.Length(); i++) {
+        final->AppendElement(s[i]);
       }
     }
     if (IsOn(mConstraints.mAudio)) {
-      nsTArray<nsRefPtr<AudioDevice>> sources;
+      nsTArray<nsRefPtr<AudioDevice>> s;
       GetSources(backend, GetInvariant(mConstraints.mAudio),
-                 &MediaEngine::EnumerateAudioDevices, sources,
-                 mLoopbackAudioDevice.get());
-      for (auto& source : sources) {
-        result->AppendElement(source);
+                 &MediaEngine::EnumerateAudioDevices, s, mLoopbackAudioDevice.get());
+      for (uint32_t i = 0; i < s.Length(); i++) {
+        final->AppendElement(s[i]);
       }
     }
-    nsRefPtr<DeviceSuccessCallbackRunnable> runnable
-        (new DeviceSuccessCallbackRunnable(mWindowId, mOnSuccess, mOnFailure,
-                                           result.forget()));
-    if (mPrivileged) {
-      NS_DispatchToMainThread(runnable);
-    } else {
-      // Get persistent origin-unique uuid to anonymize deviceIds back on main.
-      //
-      // GetOriginKey is an async API that returns a pledge (as promise-like
-      // pattern). We use .Then() to pass in a lambda to run back on this
-      // thread once GetOriginKey resolves asynchronously . The "runnable"
-      // nsRefPtr is "captured" (passed by value) into the lambda.
-      nsRefPtr<media::ChildPledge<nsCString>> p =
-          media::GetOriginKey(mOrigin, mInPrivateBrowsing);
-      p->Then([runnable](nsCString result) mutable {
-        runnable->mOriginKey = result;
-        NS_DispatchToMainThread(runnable);
-      });
-    }
-    // One of the Runnables have taken these.
+
+    NS_DispatchToMainThread(new DeviceSuccessCallbackRunnable(mWindowId,
+                                                              mOnSuccess, mOnFailure,
+                                                              final.forget()));
+    // DeviceSuccessCallbackRunnable should have taken these.
     MOZ_ASSERT(!mOnSuccess && !mOnFailure);
   }
 
 private:
   MediaStreamConstraints mConstraints;
   nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> mOnSuccess;
   nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
   nsRefPtr<MediaManager> mManager;
   uint64_t mWindowId;
   const nsString mCallId;
   // Audio & Video loopback devices to be used based on
   // the preference settings. This is currently used for
   // automated media tests only.
   nsCString mLoopbackAudioDevice;
   nsCString mLoopbackVideoDevice;
-  bool mPrivileged;
-  nsCString mOrigin;
-  bool mInPrivateBrowsing;
   bool mUseFakeDevices;
 };
 
 MediaManager::MediaManager()
   : mMediaThread(nullptr)
   , mMutex("mozilla::MediaManager")
   , mBackend(nullptr) {
   mPrefs.mWidth  = 0; // adaptive default
@@ -1559,26 +1406,16 @@ MediaManager::MediaManager()
   LOG(("%s: default prefs: %dx%d @%dfps (min %d)", __FUNCTION__,
        mPrefs.mWidth, mPrefs.mHeight, mPrefs.mFPS, mPrefs.mMinFPS));
 }
 
 NS_IMPL_ISUPPORTS(MediaManager, nsIMediaManagerService, nsIObserver)
 
 /* static */ StaticRefPtr<MediaManager> MediaManager::sSingleton;
 
-#ifdef DEBUG
-/* static */ bool
-MediaManager::IsInMediaThread()
-{
-  return sSingleton?
-      (sSingleton->mMediaThread->thread_id() == PlatformThread::CurrentId()) :
-      false;
-}
-#endif
-
 // NOTE: never Dispatch(....,NS_DISPATCH_SYNC) to the MediaManager
 // thread from the MainThread, as we NS_DISPATCH_SYNC to MainThread
 // from MediaManager thread.
 /* static */  MediaManager*
 MediaManager::Get() {
   if (!sSingleton) {
     NS_ASSERTION(NS_IsMainThread(), "Only create MediaManager on main thread");
 #ifdef DEBUG
@@ -1735,18 +1572,26 @@ MediaManager::GetUserMedia(
     // Hack: should init singleton earlier unless it's expensive (mem or CPU)
     (void) MediaManager::Get();
 #ifdef MOZ_B2G
     // Initialize MediaPermissionManager before send out any permission request.
     (void) MediaPermissionManager::GetInstance();
 #endif //MOZ_B2G
   }
 
+  // Store the WindowID in a hash table and mark as active. The entry is removed
+  // when this window is closed or navigated away from.
   uint64_t windowID = aWindow->WindowID();
-  StreamListeners* listeners = AddWindowID(windowID);
+  // This is safe since we're on main-thread, and the windowlist can only
+  // be invalidated from the main-thread (see OnNavigation)
+  StreamListeners* listeners = GetActiveWindows()->Get(windowID);
+  if (!listeners) {
+    listeners = new StreamListeners;
+    GetActiveWindows()->Put(windowID, listeners);
+  }
 
   // Create a disabled listener to act as a placeholder
   GetUserMediaCallbackMediaStreamListener* listener =
     new GetUserMediaCallbackMediaStreamListener(mMediaThread, windowID);
 
   // No need for locking because we always do this in the main thread.
   listeners->AppendElement(listener);
 
@@ -1951,18 +1796,17 @@ MediaManager::GetUserMedia(
   return NS_OK;
 }
 
 nsresult
 MediaManager::GetUserMediaDevices(nsPIDOMWindow* aWindow,
   const MediaStreamConstraints& aConstraints,
   nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
   nsIDOMGetUserMediaErrorCallback* aOnFailure,
-  uint64_t aInnerWindowID,
-  bool aPrivileged)
+  uint64_t aInnerWindowID)
 {
   NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
 
   NS_ENSURE_TRUE(aOnFailure, NS_ERROR_NULL_POINTER);
   NS_ENSURE_TRUE(aOnSuccess, NS_ERROR_NULL_POINTER);
 
   nsCOMPtr<nsIGetUserMediaDevicesSuccessCallback> onSuccess(aOnSuccess);
   nsCOMPtr<nsIDOMGetUserMediaErrorCallback> onFailure(aOnFailure);
@@ -1970,50 +1814,25 @@ MediaManager::GetUserMediaDevices(nsPIDO
   // Check if the preference for using loopback devices is enabled.
   nsAdoptingCString loopbackAudioDevice =
     Preferences::GetCString("media.audio_loopback_dev");
   nsAdoptingCString loopbackVideoDevice =
     Preferences::GetCString("media.video_loopback_dev");
   bool useFakeStreams =
     Preferences::GetBool("media.navigator.streams.fake", false);
 
-  nsCString origin;
-  nsPrincipal::GetOriginForURI(aWindow->GetDocumentURI(),
-                               getter_Copies(origin));
-  bool inPrivateBrowsing;
-  {
-    nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
-    nsCOMPtr<nsILoadContext> loadContext = doc->GetLoadContext();
-    inPrivateBrowsing = loadContext && loadContext->UsePrivateBrowsing();
-  }
   MediaManager::GetMessageLoop()->PostTask(FROM_HERE,
     new GetUserMediaDevicesTask(
       aConstraints, onSuccess.forget(), onFailure.forget(),
       (aInnerWindowID ? aInnerWindowID : aWindow->WindowID()),
-      loopbackAudioDevice, loopbackVideoDevice, aPrivileged, origin,
-      inPrivateBrowsing, useFakeStreams));
+      loopbackAudioDevice, loopbackVideoDevice, useFakeStreams));
 
   return NS_OK;
 }
 
-nsresult
-MediaManager::EnumerateDevices(nsPIDOMWindow* aWindow,
-                               nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
-                               nsIDOMGetUserMediaErrorCallback* aOnFailure)
-{
-  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
-
-  MediaStreamConstraints c;
-  c.mVideo.SetAsBoolean() = true;
-  c.mAudio.SetAsBoolean() = true;
-
-  AddWindowID(aWindow->WindowID());
-  return GetUserMediaDevices(aWindow, c, aOnSuccess, aOnFailure, 0, false);
-}
-
 MediaEngine*
 MediaManager::GetBackend(uint64_t aWindowId)
 {
   // Plugin backends as appropriate. The default engine also currently
   // includes picture support for Android.
   // This IS called off main-thread.
   MutexAutoLock lock(mMutex);
   if (!mBackend) {
@@ -2072,32 +1891,16 @@ MediaManager::OnNavigation(uint64_t aWin
       (nsGlobalWindow::GetInnerWindowWithId(aWindowID));
   if (window) {
     IterateWindowListeners(window, StopSharingCallback, nullptr);
   } else {
     RemoveWindowID(aWindowID);
   }
 }
 
-StreamListeners*
-MediaManager::AddWindowID(uint64_t aWindowId)
-{
-  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
-  // Store the WindowID in a hash table and mark as active. The entry is removed
-  // when this window is closed or navigated away from.
-  // This is safe since we're on main-thread, and the windowlist can only
-  // be invalidated from the main-thread (see OnNavigation)
-  StreamListeners* listeners = GetActiveWindows()->Get(aWindowId);
-  if (!listeners) {
-    listeners = new StreamListeners;
-    GetActiveWindows()->Put(aWindowId, listeners);
-  }
-  return listeners;
-}
-
 void
 MediaManager::RemoveWindowID(uint64_t aWindowId)
 {
   mActiveWindows.Remove(aWindowId);
 
   // get outer windowID
   nsPIDOMWindow *window = static_cast<nsPIDOMWindow*>
     (nsGlobalWindow::GetInnerWindowWithId(aWindowId));
@@ -2201,57 +2004,31 @@ MediaManager::Observe(nsISupports* aSubj
     nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
     if (prefs) {
       prefs->RemoveObserver("media.navigator.video.default_width", this);
       prefs->RemoveObserver("media.navigator.video.default_height", this);
       prefs->RemoveObserver("media.navigator.video.default_fps", this);
       prefs->RemoveObserver("media.navigator.video.default_minfps", this);
     }
 
-    // Because mMediaThread is not an nsThread, we must dispatch to it so it can
-    // clean up BackgroundChild. Continue stopping thread once this is done.
-
-    class ShutdownTask : public Task
+    // Close off any remaining active windows.
     {
-    public:
-      explicit ShutdownTask(nsRunnable* aReply) : mReply(aReply) {}
-    private:
-      virtual void
-      Run()
-      {
-        MOZ_ASSERT(MediaManager::IsInMediaThread());
-        mozilla::ipc::BackgroundChild::CloseForCurrentThread();
-        NS_DispatchToMainThread(mReply);
-      }
-      nsRefPtr<nsRunnable> mReply;
-    };
-
-    // Post ShutdownTask to execute on mMediaThread and pass in a lambda
-    // callback to be executed back on this thread once it is done.
-    //
-    // The lambda callback "captures" the 'this' pointer for member access.
-    // This is safe since this is guaranteed to be here since sSingleton isn't
-    // cleared until the lambda function clears it.
-
-    MediaManager::GetMessageLoop()->PostTask(FROM_HERE, new ShutdownTask(
-        media::CallbackRunnable::New([this]() mutable {
-      // Close off any remaining active windows.
       MutexAutoLock lock(mMutex);
       GetActiveWindows()->Clear();
       mActiveCallbacks.Clear();
       mCallIds.Clear();
       LOG(("Releasing MediaManager singleton and thread"));
       // Note: won't be released immediately as the Observer has a ref to us
       sSingleton = nullptr;
       if (mMediaThread) {
         mMediaThread->Stop();
       }
       mBackend = nullptr;
-      return NS_OK;
-    })));
+    }
+
     return NS_OK;
 
   } else if (!strcmp(aTopic, "getUserMedia:response:allow")) {
     nsString key(aData);
     nsAutoPtr<GetUserMediaTask> task;
     mActiveCallbacks.RemoveAndForget(key, task);
     if (!task) {
       return NS_OK;
@@ -2477,27 +2254,16 @@ MediaManager::MediaCaptureWindowState(ns
   LOG(("%s: window %lld capturing %s %s %s %s %s %s", __FUNCTION__, piWin ? piWin->WindowID() : -1,
        *aVideo ? "video" : "", *aAudio ? "audio" : "",
        *aScreenShare ? "screenshare" : "",  *aWindowShare ? "windowshare" : "",
        *aAppShare ? "appshare" : "", *aBrowserShare ? "browsershare" : ""));
 #endif
   return NS_OK;
 }
 
-NS_IMETHODIMP
-MediaManager::SanitizeDeviceIds(int64_t aSinceWhen)
-{
-  NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
-  LOG(("%s: sinceWhen = %llu", __FUNCTION__, aSinceWhen));
-
-  MediaManager::GetMessageLoop()->PostTask(FROM_HERE,
-    new SanitizeDeviceIdsTask(aSinceWhen));
-  return NS_OK;
-}
-
 static void
 StopScreensharingCallback(MediaManager *aThis,
                           uint64_t aWindowID,
                           StreamListeners *aListeners,
                           void *aData)
 {
   if (aListeners) {
     auto length = aListeners->Length();
@@ -2574,34 +2340,16 @@ MediaManager::StopMediaStreams()
     array->GetElementAt(i, getter_AddRefs(window));
     nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(window));
     if (win) {
       OnNavigation(win->WindowID());
     }
   }
 }
 
-bool
-MediaManager::IsWindowActivelyCapturing(uint64_t aWindowId)
-{
-  nsCOMPtr<nsISupportsArray> array;
-  GetActiveMediaCaptureWindows(getter_AddRefs(array));
-  uint32_t len;
-  array->Count(&len);
-  for (uint32_t i = 0; i < len; i++) {
-    nsCOMPtr<nsISupports> window;
-    array->GetElementAt(i, getter_AddRefs(window));
-    nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(window));
-    if (win && win->WindowID() == aWindowId) {
-      return true;
-    }
-  }
-  return false;
-}
-
 void
 GetUserMediaCallbackMediaStreamListener::AudioConfig(bool aEchoOn,
               uint32_t aEcho,
               bool aAgcOn, uint32_t aAGC,
               bool aNoiseOn, uint32_t aNoise,
               int32_t aPlayoutDelay)
 {
   if (mAudioSource) {
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -295,16 +295,39 @@ typedef enum {
   MEDIA_STOP,
   MEDIA_STOP_TRACK,
   MEDIA_DIRECT_LISTENERS
 } MediaOperation;
 
 class MediaManager;
 class GetUserMediaTask;
 
+/**
+ * Send an error back to content.
+ * Do this only on the main thread. The onSuccess callback is also passed here
+ * so it can be released correctly.
+ */
+class ErrorCallbackRunnable : public nsRunnable
+{
+public:
+  ErrorCallbackRunnable(
+    nsCOMPtr<nsIDOMGetUserMediaSuccessCallback>& aOnSuccess,
+    nsCOMPtr<nsIDOMGetUserMediaErrorCallback>& aOnFailure,
+    MediaMgrError& aError, uint64_t aWindowID);
+  NS_IMETHOD Run();
+private:
+  ~ErrorCallbackRunnable();
+
+  nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> mOnSuccess;
+  nsCOMPtr<nsIDOMGetUserMediaErrorCallback> mOnFailure;
+  nsRefPtr<MediaMgrError> mError;
+  uint64_t mWindowID;
+  nsRefPtr<MediaManager> mManager; // get ref to this when creating the runnable
+};
+
 class ReleaseMediaOperationResource : public nsRunnable
 {
 public:
   ReleaseMediaOperationResource(already_AddRefed<DOMMediaStream> aStream,
     DOMMediaStream::OnTracksAvailableCallback* aOnTracksAvailableCallback):
     mStream(aStream),
     mOnTracksAvailableCallback(aOnTracksAvailableCallback) {}
   NS_IMETHOD Run() override {return NS_OK;}
@@ -341,17 +364,30 @@ public:
   {}
 
   ~MediaOperationTask()
   {
     // MediaStreams can be released on any thread.
   }
 
   void
-  ReturnCallbackError(nsresult rv, const char* errorLog);
+  ReturnCallbackError(nsresult rv, const char* errorLog)
+  {
+    MM_LOG(("%s , rv=%d", errorLog, rv));
+    NS_DispatchToMainThread(new ReleaseMediaOperationResource(mStream.forget(),
+          mOnTracksAvailableCallback.forget()));
+    nsString log;
+
+    log.AssignASCII(errorLog);
+    nsCOMPtr<nsIDOMGetUserMediaSuccessCallback> onSuccess;
+    nsRefPtr<MediaMgrError> error = new MediaMgrError(
+        NS_LITERAL_STRING("InternalError"), log);
+    NS_DispatchToMainThread(new ErrorCallbackRunnable(onSuccess, mOnFailure,
+        *error, mWindowID));
+  }
 
   void
   Run()
   {
     SourceMediaStream *source = mListener->GetSourceStream();
     // No locking between these is required as all the callbacks for the
     // same MediaStream will occur on the same thread.
     if (!source) // means the stream was never Activated()
@@ -462,17 +498,16 @@ typedef nsTArray<nsRefPtr<GetUserMediaCa
 typedef nsClassHashtable<nsUint64HashKey, StreamListeners> WindowTable;
 
 class MediaDevice : public nsIMediaDevice
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIMEDIADEVICE
 
-  void SetId(const nsAString& aID);
 protected:
   virtual ~MediaDevice() {}
   explicit MediaDevice(MediaEngineSource* aSource);
   nsString mName;
   nsString mID;
   bool mHasFacingMode;
   dom::VideoFacingModeEnum mFacingMode;
   dom::MediaSourceEnum mMediaSource;
@@ -516,19 +551,16 @@ public:
   static already_AddRefed<MediaManager> GetInstance();
 
   // NOTE: never Dispatch(....,NS_DISPATCH_SYNC) to the MediaManager
   // thread from the MainThread, as we NS_DISPATCH_SYNC to MainThread
   // from MediaManager thread.
   static MediaManager* Get();
   static MediaManager* GetIfExists();
   static MessageLoop* GetMessageLoop();
-#ifdef DEBUG
-  static bool IsInMediaThread();
-#endif
 
   static bool Exists()
   {
     return !!sSingleton;
   }
 
   static nsresult NotifyRecordingStatusChange(nsPIDOMWindow* aWindow,
                                               const nsString& aMsg,
@@ -558,31 +590,22 @@ public:
     const dom::MediaStreamConstraints& aConstraints,
     nsIDOMGetUserMediaSuccessCallback* onSuccess,
     nsIDOMGetUserMediaErrorCallback* onError);
 
   nsresult GetUserMediaDevices(nsPIDOMWindow* aWindow,
     const dom::MediaStreamConstraints& aConstraints,
     nsIGetUserMediaDevicesSuccessCallback* onSuccess,
     nsIDOMGetUserMediaErrorCallback* onError,
-    uint64_t aInnerWindowID = 0,
-    bool aPrivileged = true);
-
-  nsresult EnumerateDevices(nsPIDOMWindow* aWindow,
-                            nsIGetUserMediaDevicesSuccessCallback* aOnSuccess,
-                            nsIDOMGetUserMediaErrorCallback* aOnFailure);
-
-  nsresult EnumerateDevices(nsPIDOMWindow* aWindow, dom::Promise& aPromise);
+    uint64_t aInnerWindowID = 0);
   void OnNavigation(uint64_t aWindowID);
-  bool IsWindowActivelyCapturing(uint64_t aWindowId);
 
   MediaEnginePrefs mPrefs;
 
 private:
-  StreamListeners* AddWindowID(uint64_t aWindowId);
   WindowTable *GetActiveWindows() {
     NS_ASSERTION(NS_IsMainThread(), "Only access windowlist on main thread");
     return &mActiveWindows;
   }
 
   void GetPref(nsIPrefBranch *aBranch, const char *aPref,
                const char *aData, int32_t *aVal);
   void GetPrefBool(nsIPrefBranch *aBranch, const char *aPref,
@@ -600,17 +623,16 @@ private:
                               void *aData);
 
   void StopMediaStreams();
 
   // ONLY access from MainThread so we don't need to lock
   WindowTable mActiveWindows;
   nsClassHashtable<nsStringHashKey, GetUserMediaTask> mActiveCallbacks;
   nsClassHashtable<nsUint64HashKey, nsTArray<nsString>> mCallIds;
-
   // Always exists
   nsAutoPtr<base::Thread> mMediaThread;
 
   Mutex mMutex;
   // protected with mMutex:
   RefPtr<MediaEngine> mBackend;
 
   static StaticRefPtr<MediaManager> sSingleton;
--- a/dom/media/VideoUtils.cpp
+++ b/dom/media/VideoUtils.cpp
@@ -256,52 +256,49 @@ ExtractH264CodecDetails(const nsAString&
   // otherwise collect 0 for unknown.
   Telemetry::Accumulate(Telemetry::VIDEO_CANPLAYTYPE_H264_LEVEL,
                         (aLevel >= 10 && aLevel <= 52) ? aLevel : 0);
 
   return true;
 }
 
 nsresult
-GenerateRandomName(nsCString& aOutSalt, uint32_t aLength)
+GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength)
 {
   nsresult rv;
   nsCOMPtr<nsIRandomGenerator> rg =
     do_GetService("@mozilla.org/security/random-generator;1", &rv);
   if (NS_FAILED(rv)) return rv;
 
-  // For each three bytes of random data we will get four bytes of ASCII.
+  // For each three bytes of random data we will get four bytes of
+  // ASCII. Request a bit more to be safe and truncate to the length
+  // we want at the end.
   const uint32_t requiredBytesLength =
-    static_cast<uint32_t>((aLength + 3) / 4 * 3);
+    static_cast<uint32_t>((aLength + 1) / 4 * 3);
 
   uint8_t* buffer;
   rv = rg->GenerateRandomBytes(requiredBytesLength, &buffer);
   if (NS_FAILED(rv)) return rv;
 
   nsAutoCString temp;
   nsDependentCSubstring randomData(reinterpret_cast<const char*>(buffer),
                                    requiredBytesLength);
   rv = Base64Encode(randomData, temp);
   NS_Free(buffer);
   buffer = nullptr;
   if (NS_FAILED (rv)) return rv;
 
-  aOutSalt = temp;
-  return NS_OK;
-}
-
-nsresult
-GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength)
-{
-  nsresult rv = GenerateRandomName(aOutSalt, aLength);
-  if (NS_FAILED(rv)) return rv;
+  temp.Truncate(aLength);
 
   // Base64 characters are alphanumeric (a-zA-Z0-9) and '+' and '/', so we need
   // to replace illegal characters -- notably '/'
-  aOutSalt.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
+  temp.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS, '_');
+
+  aOutSalt = temp;
+
   return NS_OK;
 }
 
 class CreateTaskQueueTask : public nsRunnable {
 public:
   NS_IMETHOD Run() {
     MOZ_ASSERT(NS_IsMainThread());
     mTaskQueue = new MediaTaskQueue(GetMediaThreadPool());
--- a/dom/media/VideoUtils.h
+++ b/dom/media/VideoUtils.h
@@ -256,21 +256,17 @@ enum H264_LEVEL {
 // for more details.
 // Returns false on failure.
 bool
 ExtractH264CodecDetails(const nsAString& aCodecs,
                         int16_t& aProfile,
                         int16_t& aLevel);
 
 // Use a cryptographic quality PRNG to generate raw random bytes
-// and convert that to a base64 string.
-nsresult
-GenerateRandomName(nsCString& aOutSalt, uint32_t aLength);
-
-// This version returns a string suitable for use as a file or URL
+// and convert that to a base64 string suitable for use as a file or URL
 // path. This is based on code from nsExternalAppHandler::SetUpTempFile.
 nsresult
 GenerateRandomPathName(nsCString& aOutSalt, uint32_t aLength);
 
 class MediaTaskQueue;
 class FlushableMediaTaskQueue;
 
 already_AddRefed<MediaTaskQueue>
--- a/dom/media/moz.build
+++ b/dom/media/moz.build
@@ -141,17 +141,16 @@ if CONFIG['MOZ_B2G']:
         'MediaPermissionGonk.h',
     ]
 
 EXPORTS.mozilla.dom += [
     'AudioStreamTrack.h',
     'AudioTrack.h',
     'AudioTrackList.h',
     'GetUserMediaRequest.h',
-    'MediaDeviceInfo.h',
     'MediaDevices.h',
     'MediaStreamError.h',
     'MediaStreamTrack.h',
     'RTCIdentityProviderRegistrar.h',
     'TextTrack.h',
     'TextTrackCue.h',
     'TextTrackCueList.h',
     'TextTrackList.h',
@@ -179,17 +178,16 @@ UNIFIED_SOURCES += [
     'GetUserMediaRequest.cpp',
     'GraphDriver.cpp',
     'Latency.cpp',
     'MediaCache.cpp',
     'MediaData.cpp',
     'MediaDecoder.cpp',
     'MediaDecoderReader.cpp',
     'MediaDecoderStateMachine.cpp',
-    'MediaDeviceInfo.cpp',
     'MediaDevices.cpp',
     'MediaManager.cpp',
     'MediaRecorder.cpp',
     'MediaResource.cpp',
     'MediaShutdownManager.cpp',
     'MediaStreamError.cpp',
     'MediaStreamGraph.cpp',
     'MediaStreamTrack.cpp',
--- a/dom/media/nsIMediaManager.idl
+++ b/dom/media/nsIMediaManager.idl
@@ -7,23 +7,19 @@
 interface nsISupportsArray;
 interface nsIDOMWindow;
 
 %{C++
 #define NS_MEDIAMANAGERSERVICE_CID {0xabc622ea, 0x9655, 0x4123, {0x80, 0xd9, 0x22, 0x62, 0x1b, 0xdd, 0x54, 0x65}}
 #define MEDIAMANAGERSERVICE_CONTRACTID "@mozilla.org/mediaManagerService;1"
 %}
 
-[scriptable, builtinclass, uuid(24b23e01-33fd-401f-ba25-6e52658750b0)]
+[scriptable, builtinclass, uuid(9b10661f-77b3-47f7-a8de-ee58daaff5d2)]
 interface nsIMediaManagerService : nsISupports
 {
   /* return a array of inner windows that have active captures */
   readonly attribute nsISupportsArray activeMediaCaptureWindows;
 
   /* Get the capture state for the given window and all descendant windows (iframes, etc) */
   void mediaCaptureWindowState(in nsIDOMWindow aWindow, out boolean aVideo, out boolean aAudio,
                                [optional] out boolean aScreenShare, [optional] out boolean aWindowShare,
                                [optional] out boolean aAppShare, [optional] out boolean aBrowserShare);
-
-  /* Clear per-orgin list of persistent DeviceIds stored for enumerateDevices
-     sinceTime is milliseconds since 1 January 1970 00:00:00 UTC. 0 = clear all */
-  void sanitizeDeviceIds(in long long sinceWhen);
 };
deleted file mode 100644
--- a/dom/media/systemservices/MediaChild.cpp
+++ /dev/null
@@ -1,175 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp : */
-/* 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 "MediaChild.h"
-
-#include "mozilla/ipc/BackgroundChild.h"
-#include "mozilla/ipc/PBackgroundChild.h"
-#include "nsGlobalWindow.h"
-#include "mozilla/MediaManager.h"
-#include "prlog.h"
-
-#undef LOG
-#if defined(PR_LOGGING)
-extern PRLogModuleInfo *gMediaParentLog;
-#define LOG(args) PR_LOG(gMediaParentLog, PR_LOG_DEBUG, args)
-#else
-#define LOG(args)
-#endif
-
-PRLogModuleInfo *gMediaChildLog;
-
-namespace mozilla {
-namespace media {
-
-static Child* sChild;
-
-template<typename ValueType> void
-ChildPledge<ValueType>::ActorCreated(PBackgroundChild* aActor)
-{
-  if (!sChild) {
-    // Create PMedia by sending a message to the parent
-    sChild = static_cast<Child*>(aActor->SendPMediaConstructor());
-  }
-  Run(sChild);
-}
-
-template<typename ValueType> void
-ChildPledge<ValueType>::ActorFailed()
-{
-  Pledge<ValueType>::Reject(NS_ERROR_UNEXPECTED);
-}
-
-template<typename ValueType> NS_IMPL_ADDREF(ChildPledge<ValueType>)
-template<typename ValueType> NS_IMPL_RELEASE(ChildPledge<ValueType>)
-template<typename ValueType> NS_INTERFACE_MAP_BEGIN(ChildPledge<ValueType>)
-NS_INTERFACE_MAP_ENTRY(nsIIPCBackgroundChildCreateCallback)
-NS_INTERFACE_MAP_END
-
-already_AddRefed<ChildPledge<nsCString>>
-GetOriginKey(const nsCString& aOrigin, bool aPrivateBrowsing)
-{
-  class Pledge : public ChildPledge<nsCString>
-  {
-  public:
-    explicit Pledge(const nsCString& aOrigin, bool aPrivateBrowsing)
-    : mOrigin(aOrigin), mPrivateBrowsing(aPrivateBrowsing) {}
-  private:
-    ~Pledge() {}
-    void Run(PMediaChild* aChild)
-    {
-      Child* child = static_cast<Child*>(aChild);
-
-      uint32_t id = child->AddRequestPledge(*this);
-      child->SendGetOriginKey(id, mOrigin, mPrivateBrowsing);
-    }
-    const nsCString mOrigin;
-    const bool mPrivateBrowsing;
-  };
-
-  nsRefPtr<ChildPledge<nsCString>> p = new Pledge(aOrigin, aPrivateBrowsing);
-  nsCOMPtr<nsIIPCBackgroundChildCreateCallback> cb = do_QueryObject(p);
-  bool ok = ipc::BackgroundChild::GetOrCreateForCurrentThread(cb);
-  MOZ_RELEASE_ASSERT(ok);
-  return p.forget();
-}
-
-already_AddRefed<ChildPledge<bool>>
-SanitizeOriginKeys(const uint64_t& aSinceWhen)
-{
-  class Pledge : public ChildPledge<bool>
-  {
-  public:
-    explicit Pledge(const uint64_t& aSinceWhen) : mSinceWhen(aSinceWhen) {}
-  private:
-    void Run(PMediaChild* aMedia)
-    {
-      aMedia->SendSanitizeOriginKeys(mSinceWhen);
-      mValue = true;
-      LOG(("SanitizeOriginKeys since %llu", mSinceWhen));
-      Resolve();
-    }
-    const uint64_t mSinceWhen;
-  };
-
-  nsRefPtr<ChildPledge<bool>> p = new Pledge(aSinceWhen);
-  nsCOMPtr<nsIIPCBackgroundChildCreateCallback> cb = do_QueryObject(p);
-  bool ok = ipc::BackgroundChild::GetOrCreateForCurrentThread(cb);
-  MOZ_RELEASE_ASSERT(ok);
-  return p.forget();
-}
-
-Child::Child()
-{
-#if defined(PR_LOGGING)
-  if (!gMediaChildLog) {
-    gMediaChildLog = PR_NewLogModule("MediaChild");
-  }
-#endif
-  LOG(("media::Child: %p", this));
-  MOZ_COUNT_CTOR(Child);
-}
-
-Child::~Child()
-{
-  LOG(("~media::Child: %p", this));
-  sChild = nullptr;
-  MOZ_COUNT_DTOR(Child);
-}
-
-uint32_t Child::sRequestCounter = 0;
-
-uint32_t
-Child::AddRequestPledge(ChildPledge<nsCString>& aPledge)
-{
-  uint32_t id = ++sRequestCounter;
-  nsRefPtr<ChildPledge<nsCString>> ptr(&aPledge);
-  mRequestPledges.AppendElement(PledgeEntry(id, ptr));
-  return id;
-}
-
-already_AddRefed<ChildPledge<nsCString>>
-Child::RemoveRequestPledge(uint32_t aRequestId)
-{
-  for (PledgeEntry& entry : mRequestPledges) {
-    if (entry.first == aRequestId) {
-      nsRefPtr<ChildPledge<nsCString>> ref;
-      ref.swap(entry.second);
-      mRequestPledges.RemoveElement(entry);
-      return ref.forget();
-    }
-  }
-  MOZ_ASSERT_UNREACHABLE("Received response with no matching media::ChildPledge!");
-  return nullptr;
-}
-
-bool
-Child::RecvGetOriginKeyResponse(const uint32_t& aRequestId, const nsCString& aKey)
-{
-  nsRefPtr<ChildPledge<nsCString>> pledge = RemoveRequestPledge(aRequestId);
-  if (pledge) {
-    pledge->Resolve(aKey);
-  }
-  return true;
-}
-
-PMediaChild*
-AllocPMediaChild()
-{
-  Child* obj = new Child();
-  obj->AddRef();
-  return obj;
-}
-
-bool
-DeallocPMediaChild(media::PMediaChild *aActor)
-{
-  static_cast<Child*>(aActor)->Release();
-  return true;
-}
-
-}
-}
deleted file mode 100644
--- a/dom/media/systemservices/MediaChild.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp : */
-/* 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 mozilla_MediaChild_h
-#define mozilla_MediaChild_h
-
-#include "mozilla/dom/ContentChild.h"
-#include "mozilla/media/PMediaChild.h"
-#include "mozilla/media/PMediaParent.h"
-#include "nsIIPCBackgroundChildCreateCallback.h"
-#include "MediaUtils.h"
-
-namespace mozilla {
-namespace media {
-
-// media::Child implements proxying to the chrome process for some media-related
-// functions, for the moment just:
-//
-// GetOriginKey() - get a cookie-like persisted unique key for a given origin.
-// SanitizeOriginKeys() - reset persisted unique keys.
-
-// GetOriginKey and SanitizeOriginKeys are asynchronous APIs that return pledges
-// (promise-like objects) with the future value. Use pledge.Then(func) to access.
-
-class Child;
-
-template<typename ValueType>
-class ChildPledge : public Pledge<ValueType>,
-                    public nsIIPCBackgroundChildCreateCallback
-{
-  friend Child;
-  NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
-  NS_DECL_ISUPPORTS
-public:
-  explicit ChildPledge() {};
-protected:
-  virtual ~ChildPledge() {}
-  virtual void Run(PMediaChild* aMedia) = 0;
-};
-
-already_AddRefed<ChildPledge<nsCString>>
-GetOriginKey(const nsCString& aOrigin, bool aPrivateBrowsing);
-
-already_AddRefed<ChildPledge<bool>>
-SanitizeOriginKeys(const uint64_t& aSinceWhen);
-
-class Child : public PMediaChild
-{
-  NS_INLINE_DECL_REFCOUNTING(Child)
-public:
-  Child();
-
-  bool RecvGetOriginKeyResponse(const uint32_t& aRequestId, const nsCString& aKey);
-
-  uint32_t AddRequestPledge(ChildPledge<nsCString>& aPledge);
-  already_AddRefed<ChildPledge<nsCString>> RemoveRequestPledge(uint32_t aRequestId);
-private:
-  virtual ~Child();
-
-  typedef std::pair<uint32_t,nsRefPtr<ChildPledge<nsCString>>> PledgeEntry;
-  static uint32_t sRequestCounter;
-  nsTArray<PledgeEntry> mRequestPledges;
-};
-
-PMediaChild* AllocPMediaChild();
-bool DeallocPMediaChild(PMediaChild *aActor);
-
-} // namespace media
-} // namespace mozilla
-
-#endif  // mozilla_MediaChild_h
deleted file mode 100644
--- a/dom/media/systemservices/MediaParent.cpp
+++ /dev/null
@@ -1,456 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp : */
-/* 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 "MediaParent.h"
-
-#include "mozilla/Base64.h"
-#include <mozilla/StaticMutex.h>
-
-#include "MediaUtils.h"
-#include "MediaEngine.h"
-#include "VideoUtils.h"
-#include "nsThreadUtils.h"
-#include "nsNetUtil.h"
-#include "nsILineInputStream.h"
-#include "nsAppDirectoryServiceDefs.h"
-#include "nsISupportsImpl.h"
-#include "prlog.h"
-
-#undef LOG
-#if defined(PR_LOGGING)
-PRLogModuleInfo *gMediaParentLog;
-#define LOG(args) PR_LOG(gMediaParentLog, PR_LOG_DEBUG, args)
-#else
-#define LOG(args)
-#endif
-
-// A file in the profile dir is used to persist mOriginKeys used to anonymize
-// deviceIds to be unique per origin, to avoid them being supercookies.
-
-#define ORIGINKEYS_FILE "enumerate_devices.txt"
-#define ORIGINKEYS_VERSION "1"
-
-namespace mozilla {
-namespace media {
-
-static StaticMutex gMutex;
-static ParentSingleton* sParentSingleton = nullptr;
-
-class ParentSingleton : public nsISupports
-{
-  NS_DECL_ISUPPORTS
-
-  class OriginKey
-  {
-  public:
-    static const size_t DecodedLength = 18;
-
-    OriginKey(const nsACString& aKey, int64_t aSecondsStamp)
-    : mKey(aKey)
-    , mSecondsStamp(aSecondsStamp) {}
-
-    nsCString mKey; // Base64 encoded.
-    int64_t mSecondsStamp;
-  };
-
-  class OriginKeysTable
-  {
-  public:
-    OriginKeysTable() {}
-
-    nsresult
-    GetOriginKey(const nsACString& aOrigin, nsCString& result)
-    {
-      OriginKey* key;
-      if (!mKeys.Get(aOrigin, &key)) {
-        nsCString salt; // Make a new one
-        nsresult rv = GenerateRandomName(salt, key->DecodedLength * 4 / 3);
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          return rv;
-        }
-        key = new OriginKey(salt, PR_Now() / PR_USEC_PER_SEC);
-        mKeys.Put(aOrigin, key);
-      }
-      result = key->mKey;
-      return NS_OK;
-    }
-
-    static PLDHashOperator
-    HashCleaner(const nsACString& aOrigin, nsAutoPtr<OriginKey>& aOriginKey,
-                void *aUserArg)
-    {
-      OriginKey* since = static_cast<OriginKey*>(aUserArg);
-
-      LOG((((aOriginKey->mSecondsStamp >= since->mSecondsStamp)?
-            "%s: REMOVE %lld >= %lld" :
-            "%s: KEEP   %lld < %lld"),
-            __FUNCTION__, aOriginKey->mSecondsStamp, since->mSecondsStamp));
-
-      return (aOriginKey->mSecondsStamp >= since->mSecondsStamp)?
-          PL_DHASH_REMOVE : PL_DHASH_NEXT;
-    }
-
-    void Clear(int64_t aSinceWhen)
-    {
-      // Avoid int64_t* <-> void* casting offset
-      OriginKey since(nsCString(), aSinceWhen  / PR_USEC_PER_SEC);
-      mKeys.Enumerate(HashCleaner, &since);
-    }
-
-  protected:
-    nsClassHashtable<nsCStringHashKey, OriginKey> mKeys;
-  };
-
-  class OriginKeysLoader : public OriginKeysTable
-  {
-  public:
-    OriginKeysLoader()
-    {
-      Load();
-    }
-
-    nsresult
-    GetOriginKey(const nsACString& aOrigin, nsCString& result)
-    {
-      auto before = mKeys.Count();
-      OriginKeysTable::GetOriginKey(aOrigin, result);
-      if (mKeys.Count() != before) {
-        Save();
-      }
-      return NS_OK;
-    }
-
-    already_AddRefed<nsIFile>
-    GetFile()
-    {
-      if (!mProfileDir) {
-        nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
-                                             getter_AddRefs(mProfileDir));
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          return nullptr;
-        }
-      }
-      nsCOMPtr<nsIFile> file;
-      nsresult rv = mProfileDir->Clone(getter_AddRefs(file));
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return nullptr;
-      }
-      file->Append(NS_LITERAL_STRING(ORIGINKEYS_FILE));
-      return file.forget();
-    }
-
-    // Format of file is key secondsstamp origin (first line is version #):
-    //
-    // 1
-    // rOMAAbFujNwKyIpj4RJ3Wt5Q 1424733961 http://fiddle.jshell.net
-    // rOMAAbFujNwKyIpj4RJ3Wt5Q 1424734841 http://mozilla.github.io
-    // etc.
-
-    nsresult Read()
-    {
-      nsCOMPtr<nsIFile> file = GetFile();
-      if (NS_WARN_IF(!file)) {
-        return NS_ERROR_UNEXPECTED;
-      }
-      bool exists;
-      nsresult rv = file->Exists(&exists);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      if (!exists) {
-        return NS_OK;
-      }
-
-      nsCOMPtr<nsIInputStream> stream;
-      rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      nsCOMPtr<nsILineInputStream> i = do_QueryInterface(stream);
-      MOZ_ASSERT(i);
-
-      nsCString line;
-      bool hasMoreLines;
-      rv = i->ReadLine(line, &hasMoreLines);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      if (!line.EqualsLiteral(ORIGINKEYS_VERSION)) {
-        // If version on disk is newer than we can understand then ignore it.
-        return NS_OK;
-      }
-
-      while (hasMoreLines) {
-        rv = i->ReadLine(line, &hasMoreLines);
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          return rv;
-        }
-        // Read key secondsstamp origin.
-        // Ignore any lines that don't fit format in the comment above exactly.
-        int32_t f = line.FindChar(' ');
-        if (f < 0) {
-          continue;
-        }
-        const nsACString& key = Substring(line, 0, f);
-        const nsACString& s = Substring(line, f+1);
-        f = s.FindChar(' ');
-        if (f < 0) {
-          continue;
-        }
-        int64_t secondsstamp = nsCString(Substring(s, 0, f)).ToInteger64(&rv);
-        if (NS_FAILED(rv)) {
-          continue;
-        }
-        const nsACString& origin = Substring(s, f+1);
-
-        // Validate key
-        if (key.Length() != OriginKey::DecodedLength) {
-          continue;
-        }
-        nsCString dummy;
-        rv = Base64Decode(key, dummy);
-        if (NS_FAILED(rv)) {
-          continue;
-        }
-        mKeys.Put(origin, new OriginKey(key, secondsstamp));
-      }
-      return NS_OK;
-    }
-
-    static PLDHashOperator
-    HashWriter(const nsACString& aOrigin, OriginKey* aOriginKey, void *aUserArg)
-    {
-      auto* stream = static_cast<nsIOutputStream *>(aUserArg);
-
-      nsCString buffer;
-      buffer.Append(aOriginKey->mKey);
-      buffer.Append(' ');
-      buffer.AppendInt(aOriginKey->mSecondsStamp);
-      buffer.Append(' ');
-      buffer.Append(aOrigin);
-      buffer.Append('\n');
-
-      uint32_t count;
-      nsresult rv = stream->Write(buffer.Data(), buffer.Length(), &count);
-      if (NS_WARN_IF(NS_FAILED(rv)) || count != buffer.Length()) {
-        return PL_DHASH_STOP;
-      }
-      return PL_DHASH_NEXT;
-    }
-
-    nsresult
-    Write()
-    {
-      nsCOMPtr<nsIFile> file = GetFile();
-      if (NS_WARN_IF(!file)) {
-        return NS_ERROR_UNEXPECTED;
-      }
-
-      nsCOMPtr<nsIOutputStream> stream;
-      nsresult rv = NS_NewSafeLocalFileOutputStream(getter_AddRefs(stream), file);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      nsAutoCString buffer;
-      buffer.AppendLiteral(ORIGINKEYS_VERSION);
-      buffer.Append('\n');
-
-      uint32_t count;
-      rv = stream->Write(buffer.Data(), buffer.Length(), &count);
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      if (count != buffer.Length()) {
-        return NS_ERROR_UNEXPECTED;
-      }
-      mKeys.EnumerateRead(HashWriter, stream.get());
-
-      nsCOMPtr<nsISafeOutputStream> safeStream = do_QueryInterface(stream);
-      MOZ_ASSERT(safeStream);
-
-      rv = safeStream->Finish();
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      return NS_OK;
-    }
-
-    nsresult Load()
-    {
-      nsresult rv = Read();
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        Delete();
-      }
-      return rv;
-    }
-
-    nsresult Save()
-    {
-      nsresult rv = Write();
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        NS_WARNING("Failed to write data for EnumerateDevices id-persistence.");
-        Delete();
-      }
-      return rv;
-    }
-
-    void Clear(int64_t aSinceWhen)
-    {
-      OriginKeysTable::Clear(aSinceWhen);
-      Delete();
-      Save();
-    }
-
-    nsresult Delete()
-    {
-      nsCOMPtr<nsIFile> file = GetFile();
-      if (NS_WARN_IF(!file)) {
-        return NS_ERROR_UNEXPECTED;
-      }
-      nsresult rv = file->Remove(false);
-      if (rv == NS_ERROR_FILE_NOT_FOUND) {
-        return NS_OK;
-      }
-      if (NS_WARN_IF(NS_FAILED(rv))) {
-        return rv;
-      }
-      return NS_OK;
-    }
-
-  private:
-    nsCOMPtr<nsIFile> mProfileDir;
-  };
-
-private:
-  virtual ~ParentSingleton()
-  {
-    sParentSingleton = nullptr;
-    LOG((__PRETTY_FUNCTION__));
-  }
-
-public:
-  static ParentSingleton* Get()
-  {
-    // Protect creation of singleton and access from multiple Background threads.
-    //
-    // Multiple Background threads happen because sanitize.js calls us from the
-    // chrome process and gets a thread separate from the one servicing ipc from
-    // the content process.
-
-    StaticMutexAutoLock lock(gMutex);
-    if (!sParentSingleton) {
-      sParentSingleton = new ParentSingleton();
-    }
-    return sParentSingleton;
-  }
-
-  OriginKeysLoader mOriginKeys;
-  OriginKeysTable mPrivateBrowsingOriginKeys;
-};
-
-NS_IMPL_ISUPPORTS0(ParentSingleton)
-
-bool
-Parent::RecvGetOriginKey(const uint32_t& aRequestId,
-                         const nsCString& aOrigin,
-                         const bool& aPrivateBrowsing)
-{
-  // Hand over to stream-transport thread.
-
-  nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
-  MOZ_ASSERT(sts);
-  nsRefPtr<ParentSingleton> singleton(mSingleton);
-
-  nsRefPtr<PledgeRunnable<nsCString>> p = PledgeRunnable<nsCString>::New(
-      [singleton, aOrigin, aPrivateBrowsing](nsCString& aResult) {
-    if (aPrivateBrowsing) {
-      singleton->mPrivateBrowsingOriginKeys.GetOriginKey(aOrigin, aResult);
-    } else {
-      singleton->mOriginKeys.GetOriginKey(aOrigin, aResult);
-    }
-    return NS_OK;
-  });
-  nsresult rv = sts->Dispatch(p, NS_DISPATCH_NORMAL);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return false;
-  }
-  nsRefPtr<media::Parent> keepAlive(this);
-  p->Then([this, keepAlive, aRequestId](const nsCString& aKey) mutable {
-    if (!mDestroyed) {
-      unused << SendGetOriginKeyResponse(aRequestId, aKey);
-    }
-    return NS_OK;
-  });
-  return true;
-}
-
-bool
-Parent::RecvSanitizeOriginKeys(const uint64_t& aSinceWhen)
-{
-  // Hand over to stream-transport thread.
-
-  nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
-  MOZ_ASSERT(sts);
-  nsRefPtr<ParentSingleton> singleton(mSingleton);
-
-  nsRefPtr<PledgeRunnable<bool>> p = PledgeRunnable<bool>::New(
-      [singleton, aSinceWhen](bool) {
-    singleton->mPrivateBrowsingOriginKeys.Clear(aSinceWhen);
-    singleton->mOriginKeys.Clear(aSinceWhen);
-    return NS_OK;
-  });
-  nsresult rv = sts->Dispatch(p, NS_DISPATCH_NORMAL);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return false;
-  }
-  return true;
-}
-
-void
-Parent::ActorDestroy(ActorDestroyReason aWhy)
-{
-  // No more IPC from here
-  mDestroyed = true;
-  LOG((__PRETTY_FUNCTION__));
-}
-
-Parent::Parent()
-  : mSingleton(ParentSingleton::Get())
-  , mDestroyed(false)
-{
-#if defined(PR_LOGGING)
-  if (!gMediaParentLog)
-    gMediaParentLog = PR_NewLogModule("MediaParent");
-#endif
-  LOG(("media::Parent: %p", this));
-
-  MOZ_COUNT_CTOR(Parent);
-}
-
-Parent::~Parent()
-{
-  LOG(("~media::Parent: %p", this));
-
-  MOZ_COUNT_DTOR(Parent);
-}
-
-PMediaParent*
-AllocPMediaParent()
-{
-  Parent* obj = new Parent();
-  obj->AddRef();
-  return obj;
-}
-
-bool
-DeallocPMediaParent(media::PMediaParent *aActor)
-{
-  static_cast<Parent*>(aActor)->Release();
-  return true;
-}
-
-}
-}
deleted file mode 100644
--- a/dom/media/systemservices/MediaParent.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp : */
-/* 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 mozilla_MediaParent_h
-#define mozilla_MediaParent_h
-
-#include "MediaChild.h"
-
-#include "mozilla/dom/ContentParent.h"
-#include "mozilla/media/PMediaParent.h"
-
-namespace mozilla {
-namespace media {
-
-// media::Parent implements the chrome-process side of ipc for media::Child APIs
-
-class ParentSingleton;
-
-class Parent : public PMediaParent
-{
-  NS_INLINE_DECL_REFCOUNTING(Parent)
-public:
-  virtual bool RecvGetOriginKey(const uint32_t& aRequestId,
-                                const nsCString& aOrigin,
-                                const bool& aPrivateBrowsing) override;
-  virtual bool RecvSanitizeOriginKeys(const uint64_t& aSinceWhen) override;
-  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
-
-  Parent();
-private:
-  virtual ~Parent();
-
-  nsRefPtr<ParentSingleton> mSingleton;
-  bool mDestroyed;
-};
-
-PMediaParent* AllocPMediaParent();
-bool DeallocPMediaParent(PMediaParent *aActor);
-
-} // namespace media
-} // namespace mozilla
-
-#endif  // mozilla_MediaParent_h
deleted file mode 100644
--- a/dom/media/systemservices/MediaUtils.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp : */
-/* 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 "MediaUtils.h"
-
-namespace mozilla {
-namespace media {
-
-}
-}
deleted file mode 100644
--- a/dom/media/systemservices/MediaUtils.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set sw=2 ts=8 et ft=cpp : */
-/* 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 mozilla_MediaUtils_h
-#define mozilla_MediaUtils_h
-
-#include "nsAutoPtr.h"
-#include "nsThreadUtils.h"
-
-namespace mozilla {
-namespace media {
-
-// A media::Pledge is a promise-like pattern for c++ that takes lambda functions.
-//
-// Asynchronous APIs that proxy to the chrome process and back, may return a
-// pledge to allow callers to use pledge.Then() to specify a lambda function to
-// invoke with the result once the asynchronous API resolves later back on the
-// same thread.
-//
-// An advantage of this pattern is that lambdas allow "capturing" of local
-// variables, much like closures in JavaScript.
-
-template<typename ValueType>
-class Pledge
-{
-  // TODO: Remove workaround once mozilla allows std::function from <functional>
-  class FunctorsBase
-  {
-  public:
-    FunctorsBase() {}
-    virtual void Succeed(const ValueType& result) = 0;
-    virtual void Fail(nsresult rv) = 0;
-    virtual ~FunctorsBase() {};
-  };
-
-public:
-  explicit Pledge() : mDone(false), mResult(NS_OK) {}
-
-  template<typename OnSuccessType>
-  void Then(OnSuccessType aOnSuccess)
-  {
-    Then(aOnSuccess, [](nsresult){});
-  }
-
-  template<typename OnSuccessType, typename OnFailureType>
-  void Then(OnSuccessType aOnSuccess, OnFailureType aOnFailure)
-  {
-    class F : public FunctorsBase
-    {
-    public:
-      F(OnSuccessType& aOnSuccess, OnFailureType& aOnFailure)
-        : mOnSuccess(aOnSuccess), mOnFailure(aOnFailure) {}
-
-      void Succeed(const ValueType& result)
-      {
-        mOnSuccess(result);
-      }
-      void Fail(nsresult rv)
-      {
-        mOnFailure(rv);
-      };
-
-      OnSuccessType mOnSuccess;
-      OnFailureType mOnFailure;
-    };
-    mFunctors = new F(aOnSuccess, aOnFailure);
-
-    if (mDone) {
-      if (mResult == NS_OK) {
-        mFunctors->Succeed(mValue);
-      } else {
-        mFunctors->Fail(mResult);
-      }
-    }
-  }
-
-protected:
-  void Resolve(const ValueType& aValue)
-  {
-    mValue = aValue;
-    Resolve();
-  }
-
-  void Resolve()
-  {
-    if (!mDone) {
-      mDone = true;
-      MOZ_ASSERT(mResult == NS_OK);
-      if (mFunctors) {
-        mFunctors->Succeed(mValue);
-      }
-    }
-  }
-
-  void Reject(nsresult rv)
-  {
-    if (!mDone) {
-      mDone = true;
-      mResult = rv;
-      if (mFunctors) {
-        mFunctors->Fail(mResult);
-      }
-    }
-  }
-
-  ValueType mValue;
-protected:
-  bool mDone;
-  nsresult mResult;
-private:
-  nsAutoPtr<FunctorsBase> mFunctors;
-};
-
-// General purpose runnable that also acts as a Pledge for the resulting value.
-// Use PledgeRunnable<>::New() factory function to use with lambdas.
-
-template<typename ValueType>
-class PledgeRunnable : public Pledge<ValueType>, public nsRunnable
-{
-public:
-  template<typename OnRunType>
-  static PledgeRunnable<ValueType>*
-  New(OnRunType aOnRun)
-  {
-    class P : public PledgeRunnable<ValueType>
-    {
-    public:
-      explicit P(OnRunType& aOnRun)
-      : mOriginThread(NS_GetCurrentThread())
-      , mOnRun(aOnRun)
-      , mHasRun(false) {}
-    private:
-      virtual ~P() {}
-      NS_IMETHODIMP
-      Run()
-      {
-        if (!mHasRun) {
-          P::mResult = mOnRun(P::mValue);
-          mHasRun = true;
-          return mOriginThread->Dispatch(this, NS_DISPATCH_NORMAL);
-        }
-        bool on;
-        MOZ_RELEASE_ASSERT(NS_SUCCEEDED(mOriginThread->IsOnCurrentThread(&on)));
-        MOZ_RELEASE_ASSERT(on);
-
-        if (NS_SUCCEEDED(P::mResult)) {
-          P::Resolve();
-        } else {
-          P::Reject(P::mResult);
-        }
-        return NS_OK;
-      }
-      nsCOMPtr<nsIThread> mOriginThread;
-      OnRunType mOnRun;
-      bool mHasRun;
-    };
-
-    return new P(aOnRun);
-  }
-
-protected:
-  virtual ~PledgeRunnable() {}
-};
-
-// General purpose runnable with an eye toward lambdas
-
-namespace CallbackRunnable
-{
-template<typename OnRunType>
-class Impl : public nsRunnable
-{
-public:
-  explicit Impl(OnRunType& aOnRun) : mOnRun(aOnRun) {}
-private:
-  NS_IMETHODIMP
-  Run()
-  {
-    return mOnRun();
-  }
-  OnRunType mOnRun;
-};
-
-template<typename OnRunType>
-Impl<OnRunType>*
-New(OnRunType aOnRun)
-{
-  return new Impl<OnRunType>(aOnRun);
-}
-}
-
-}
-}
-
-#endif // mozilla_MediaUtils_h
deleted file mode 100644
--- a/dom/media/systemservices/PMedia.ipdl
+++ /dev/null
@@ -1,35 +0,0 @@
-/* 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 protocol PContent;
-include protocol PBackground;
-
-namespace mozilla {
-namespace media {
-
-protocol PMedia
-{
-  manager PBackground;
-
-parent:
-  /**
-   * Requests a persistent unique secret key for each origin.
-   * Has no expiry, but is cleared by age along with cookies.
-   * This is needed by mediaDevices.enumerateDevices() to produce persistent
-   * deviceIds that wont work cross-origin.
-   */
-  GetOriginKey(uint32_t aRequestId, nsCString aOrigin, bool aPrivateBrowsing);
-
-  /**
-   * On clear cookies. Fire and forget.
-   */
-  SanitizeOriginKeys(uint64_t aSinceWhen);
-
-child:
-  GetOriginKeyResponse(uint32_t aRequestId, nsCString key);
-  __delete__();
-};
-
-} // namespace media
-} // namespace mozilla
--- a/dom/media/systemservices/moz.build
+++ b/dom/media/systemservices/moz.build
@@ -32,29 +32,13 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'coco
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
     CXXFLAGS += [
         '-I%s/%s' % (CONFIG['ANDROID_SOURCE'], d) for d in [
             'frameworks/wilhelm/include',
             'system/media/wilhelm/include',
         ]
     ]
 
-EXPORTS.mozilla.media += ['MediaChild.h',
-            'MediaParent.h',
-            'MediaUtils.h'
-]
-UNIFIED_SOURCES += ['MediaChild.cpp',
-                    'MediaParent.cpp',
-                    'MediaUtils.cpp'
-]
-IPDL_SOURCES += [
-    'PMedia.ipdl',
-]
-# /dom/base needed for nsGlobalWindow.h in MediaChild.cpp
-LOCAL_INCLUDES += [
-    '/dom/base',
-]
-
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xul'
 
 FAIL_ON_WARNINGS = True
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -640,18 +640,16 @@ var interfaceNamesInGlobalScope =
     "KeyEvent",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "KeyboardEvent",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "LocalMediaStream",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "Location",
 // IMPORTANT: Do not change this list without review from a DOM peer!
-    "MediaDeviceInfo",
-// IMPORTANT: Do not change this list without review from a DOM peer!
     "MediaDevices",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "MediaElementAudioSourceNode",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "MediaError",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "MediaKeyError", pref: "media.eme.apiVisible"},
 // IMPORTANT: Do not change this list without review from a DOM peer!
deleted file mode 100644
--- a/dom/webidl/MediaDeviceInfo.webidl
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*- Mode: IDL; 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/.
- *
- * The origin of this IDL file is
- * http://dev.w3.org/2011/webrtc/editor/getusermedia.html
- */
-
-enum MediaDeviceKind {
-  "audioinput",
-  "audiooutput",
-  "videoinput"
-};
-
-[Func="Navigator::HasUserMediaSupport"]
-interface MediaDeviceInfo {
-  readonly attribute DOMString       deviceId;
-  readonly attribute MediaDeviceKind kind;
-  readonly attribute DOMString       label;
-  readonly attribute DOMString       groupId;
-};
--- a/dom/webidl/MediaDevices.webidl
+++ b/dom/webidl/MediaDevices.webidl
@@ -7,17 +7,17 @@
  * http://dev.w3.org/2011/webrtc/editor/getusermedia.html
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
 [Func="Navigator::HasUserMediaSupport"]
 interface MediaDevices : EventTarget {
-//  attribute EventHandler ondevicechange;
+//    attribute EventHandler ondevicechange;
+//
+//    void enumerateDevices (MediaDeviceInfoCallback resultCallback);
+//
 //  static Dictionary getSupportedConstraints (DOMString kind);
 
-  [Throws]
-  Promise<sequence<MediaDeviceInfo>> enumerateDevices();
-
-  [Throws]
+  [Throws, Func="Navigator::HasUserMediaSupport"]
   Promise<MediaStream> getUserMedia(optional MediaStreamConstraints constraints);
 };
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -257,17 +257,16 @@ WEBIDL_FILES = [
     'KeyAlgorithm.webidl',
     'KeyboardEvent.webidl',
     'KeyEvent.webidl',
     'LegacyQueryInterface.webidl',
     'LinkStyle.webidl',
     'ListBoxObject.webidl',
     'LocalMediaStream.webidl',
     'Location.webidl',
-    'MediaDeviceInfo.webidl',
     'MediaDevices.webidl',
     'MediaElementAudioSourceNode.webidl',
     'MediaError.webidl',
     'MediaList.webidl',
     'MediaQueryList.webidl',
     'MediaRecorder.webidl',
     'MediaSource.webidl',
     'MediaStream.webidl',
--- a/ipc/glue/BackgroundChildImpl.cpp
+++ b/ipc/glue/BackgroundChildImpl.cpp
@@ -2,17 +2,16 @@
  * 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 "BackgroundChildImpl.h"
 
 #include "ActorsChild.h" // IndexedDB
 #include "BroadcastChannelChild.h"
 #include "FileDescriptorSetChild.h"
-#include "mozilla/media/MediaChild.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/PBlobChild.h"
 #include "mozilla/dom/cache/ActorUtils.h"
 #include "mozilla/dom/indexedDB/PBackgroundIDBFactoryChild.h"
 #include "mozilla/dom/ipc/BlobChild.h"
 #include "mozilla/ipc/PBackgroundTestChild.h"
 #include "mozilla/layout/VsyncChild.h"
 #include "nsID.h"
@@ -277,28 +276,16 @@ BackgroundChildImpl::AllocPCacheStreamCo
 
 bool
 BackgroundChildImpl::DeallocPCacheStreamControlChild(PCacheStreamControlChild* aActor)
 {
   dom::cache::DeallocPCacheStreamControlChild(aActor);
   return true;
 }
 
-media::PMediaChild*
-BackgroundChildImpl::AllocPMediaChild()
-{
-  return media::AllocPMediaChild();
-}
-
-bool
-BackgroundChildImpl::DeallocPMediaChild(media::PMediaChild *aActor)
-{
-  return media::DeallocPMediaChild(aActor);
-}
-
 } // namespace ipc
 } // namespace mozilla
 
 bool
 TestChild::Recv__delete__(const nsCString& aTestArg)
 {
   MOZ_RELEASE_ASSERT(aTestArg == mTestArg,
                      "BackgroundTest message was corrupted!");
--- a/ipc/glue/BackgroundChildImpl.h
+++ b/ipc/glue/BackgroundChildImpl.h
@@ -66,22 +66,16 @@ protected:
 
   virtual PFileDescriptorSetChild*
   AllocPFileDescriptorSetChild(const FileDescriptor& aFileDescriptor)
                                override;
 
   virtual bool
   DeallocPFileDescriptorSetChild(PFileDescriptorSetChild* aActor) override;
 
-  virtual PMediaChild*
-  AllocPMediaChild() override;
-
-  virtual bool
-  DeallocPMediaChild(PMediaChild* aActor) override;
-
   virtual PVsyncChild*
   AllocPVsyncChild() override;
 
   virtual bool
   DeallocPVsyncChild(PVsyncChild* aActor) override;
 
   virtual PBroadcastChannelChild*
   AllocPBroadcastChannelChild(const PrincipalInfo& aPrincipalInfo,
--- a/ipc/glue/BackgroundParentImpl.cpp
+++ b/ipc/glue/BackgroundParentImpl.cpp
@@ -1,17 +1,16 @@
 /* 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 "BackgroundParentImpl.h"
 
 #include "BroadcastChannelParent.h"
 #include "FileDescriptorSetParent.h"
-#include "mozilla/media/MediaParent.h"
 #include "mozilla/AppProcessChecker.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/PBlobParent.h"
 #include "mozilla/dom/ServiceWorkerRegistrar.h"
 #include "mozilla/dom/cache/ActorUtils.h"
 #include "mozilla/dom/indexedDB/ActorsParent.h"
 #include "mozilla/dom/ipc/BlobParent.h"
@@ -356,28 +355,16 @@ BackgroundParentImpl::DeallocPBroadcastC
   AssertIsInMainProcess();
   AssertIsOnBackgroundThread();
   MOZ_ASSERT(aActor);
 
   delete static_cast<BroadcastChannelParent*>(aActor);
   return true;
 }
 
-media::PMediaParent*
-BackgroundParentImpl::AllocPMediaParent()
-{
-  return media::AllocPMediaParent();
-}
-
-bool
-BackgroundParentImpl::DeallocPMediaParent(media::PMediaParent *aActor)
-{
-  return media::DeallocPMediaParent(aActor);
-}
-
 namespace {
 
 class RegisterServiceWorkerCallback final : public nsRunnable
 {
 public:
   explicit RegisterServiceWorkerCallback(
                                      const ServiceWorkerRegistrationData& aData)
     : mData(aData)
--- a/ipc/glue/BackgroundParentImpl.h
+++ b/ipc/glue/BackgroundParentImpl.h
@@ -79,22 +79,16 @@ protected:
   RecvPBroadcastChannelConstructor(PBroadcastChannelParent* actor,
                                    const PrincipalInfo& aPrincipalInfo,
                                    const nsString& origin,
                                    const nsString& channel) override;
 
   virtual bool
   DeallocPBroadcastChannelParent(PBroadcastChannelParent* aActor) override;
 
-  virtual PMediaParent*
-  AllocPMediaParent() override;
-
-  virtual bool
-  DeallocPMediaParent(PMediaParent* aActor) override;
-
   virtual bool
   RecvRegisterServiceWorker(const ServiceWorkerRegistrationData& aData)
                             override;
 
   virtual bool
   RecvUnregisterServiceWorker(const PrincipalInfo& aPrincipalInfo,
                               const nsString& aScope) override;
 
--- a/ipc/glue/PBackground.ipdl
+++ b/ipc/glue/PBackground.ipdl
@@ -6,17 +6,16 @@ include protocol PBackgroundIDBFactory;
 include protocol PBackgroundTest;
 include protocol PBlob;
 include protocol PBroadcastChannel;
 include protocol PCache;
 include protocol PCacheStorage;
 include protocol PCacheStreamControl;
 include protocol PFileDescriptorSet;
 include protocol PVsync;
-include protocol PMedia;
 
 include DOMTypes;
 include PBackgroundSharedTypes;
 include PBackgroundIDBSharedTypes;
 include ServiceWorkerRegistrarTypes;
 
 using mozilla::dom::cache::Namespace from "mozilla/dom/cache/Types.h";
 include "mozilla/dom/cache/IPCUtils.h";
@@ -30,26 +29,24 @@ sync protocol PBackground
   manages PBackgroundTest;
   manages PBlob;
   manages PBroadcastChannel;
   manages PCache;
   manages PCacheStorage;
   manages PCacheStreamControl;
   manages PFileDescriptorSet;
   manages PVsync;
-  manages PMedia;
 
 parent:
   // Only called at startup during mochitests to check the basic infrastructure.
   PBackgroundTest(nsCString testArg);
 
   PBackgroundIDBFactory(LoggingInfo loggingInfo);
 
   PVsync();
-  PMedia();
 
   PBroadcastChannel(PrincipalInfo pInfo, nsString origin, nsString channel);
 
   RegisterServiceWorker(ServiceWorkerRegistrationData data);
   UnregisterServiceWorker(PrincipalInfo principalInfo,
                           nsString scope);
   ShutdownServiceWorkerRegistrar();
 
--- a/security/manager/ssl/src/nsNSSModule.cpp
+++ b/security/manager/ssl/src/nsNSSModule.cpp
@@ -164,17 +164,17 @@ static nsresult                         
                                                                               \
     return rv;                                                                \
 }
 
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nssLoadingComponent, nsNSSComponent,
                                         Init)
 
 using namespace mozilla::psm;
-
+  
 namespace {
 
 // Use the special factory constructor for everything this module implements,
 // because all code could potentially require the NSS library.
 // Our factory constructor takes an additional boolean parameter.
 // Only for the nsNSSComponent, set this to true.
 // All other classes must have this set to false.
 
@@ -194,19 +194,19 @@ NS_NSS_GENERIC_FACTORY_CONSTRUCTOR_BYPRO
                                              nsNSSCertListFakeTransport)
 #ifdef MOZ_XUL
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsCertTree)
 #endif
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsPkcs11)
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsCertPicker)
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nssEnsure, nsNTLMAuthModule, InitTest)
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsureChromeOrContent, nsCryptoHash)
-NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsureChromeOrContent, nsCryptoHMAC)
-NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsureChromeOrContent, nsKeyObject)
-NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsureChromeOrContent, nsKeyObjectFactory)
+NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsCryptoHMAC)
+NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsKeyObject)
+NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsKeyObjectFactory)
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsDataSignatureVerifier)
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsure, nsRandomGenerator)
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsureOnChromeOnly, nsSSLStatus)
 NS_NSS_GENERIC_FACTORY_CONSTRUCTOR(nssEnsureOnChromeOnly, TransportSecurityInfo)
 
 typedef mozilla::psm::NSSErrorsService NSSErrorsService;
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NSSErrorsService, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsNSSVersion)