gecko/dom/media/MediaDevices.cpp
Ehsan Akhgari 33bb32f549 Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj
This patch was automatically generated using the following script:

function convert() {
echo "Converting $1 to $2..."
find . \
       ! -wholename "*/.git*" \
       ! -wholename "obj-ff-dbg*" \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert MOZ_OVERRIDE override
convert MOZ_FINAL final
2015-03-21 12:28:04 -04:00

98 lines
2.6 KiB
C++

/* 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/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 "nsPIDOMWindow.h"
namespace mozilla {
namespace dom {
class MediaDevices::GumResolver : public nsIDOMGetUserMediaSuccessCallback
{
public:
NS_DECL_ISUPPORTS
explicit GumResolver(Promise* aPromise) : mPromise(aPromise) {}
NS_IMETHOD
OnSuccess(nsISupports* aStream) override
{
nsRefPtr<DOMLocalMediaStream> stream = do_QueryObject(aStream);
if (!stream) {
return NS_ERROR_FAILURE;
}
mPromise->MaybeResolve(stream);
return NS_OK;
}
private:
virtual ~GumResolver() {}
nsRefPtr<Promise> mPromise;
};
class MediaDevices::GumRejecter : public nsIDOMGetUserMediaErrorCallback
{
public:
NS_DECL_ISUPPORTS
explicit GumRejecter(Promise* aPromise) : mPromise(aPromise) {}
NS_IMETHOD
OnError(nsISupports* aError) override
{
nsRefPtr<MediaStreamError> error = do_QueryObject(aError);
if (!error) {
return NS_ERROR_FAILURE;
}
mPromise->MaybeReject(error);
return NS_OK;
}
private:
virtual ~GumRejecter() {}
nsRefPtr<Promise> mPromise;
};
NS_IMPL_ISUPPORTS(MediaDevices::GumResolver, nsIDOMGetUserMediaSuccessCallback)
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(!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();
}
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)
{
return MediaDevicesBinding::Wrap(aCx, this, aGivenProto);
}
} // namespace dom
} // namespace mozilla