Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Unified Diff: Source/modules/mediastream/MediaDevices.cpp

Issue 1202553002: Implement navigator.mediaDevices.getUserMedia() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review comments (cleanup) Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/modules/mediastream/MediaDevices.cpp
diff --git a/Source/modules/mediastream/MediaDevices.cpp b/Source/modules/mediastream/MediaDevices.cpp
index 24537ad028652b24b8f408fdaa2e7731527d617d..b8a4aa933599cde3f1f27e301ac4d94af0a03e9a 100644
--- a/Source/modules/mediastream/MediaDevices.cpp
+++ b/Source/modules/mediastream/MediaDevices.cpp
@@ -11,6 +11,10 @@
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "modules/mediastream/MediaStream.h"
+#include "modules/mediastream/NavigatorMediaStream.h"
+#include "modules/mediastream/NavigatorUserMediaErrorCallback.h"
+#include "modules/mediastream/NavigatorUserMediaSuccessCallback.h"
#include "modules/mediastream/UserMediaController.h"
namespace blink {
@@ -26,4 +30,58 @@ ScriptPromise MediaDevices::enumerateDevices(ScriptState* scriptState)
return request->start();
}
+namespace {
+
+class PromiseSuccessCallback: public NavigatorUserMediaSuccessCallback {
Peter Beverloo 2015/06/23 12:44:16 You should override the destructor here, to make s
Peter Beverloo 2015/06/23 12:44:16 micro nit: empty space before the colon. For Promi
hta - Chromium 2015/06/26 09:28:59 Just an empty destructor? https://www.chromium.or
Peter Beverloo 2015/06/26 12:36:55 Yeah, an empty one would work (the interesting bit
+public:
+ PromiseSuccessCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver)
+ : m_resolver(resolver)
+ {
+ }
+ void handleEvent(MediaStream* stream)
+ {
+ m_resolver->resolve(stream);
+ }
+private:
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> m_resolver;
+};
+
+class PromiseErrorCallback: public NavigatorUserMediaErrorCallback {
+public:
+ PromiseErrorCallback(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver)
+ : m_resolver(resolver)
+ {
+ }
+ void handleEvent(NavigatorUserMediaError* error)
+ {
+ m_resolver->reject(error);
+ }
+private:
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> m_resolver;
+};
+
+} // namespace
+
+ScriptPromise MediaDevices::getUserMedia(ScriptState* scriptState, const Dictionary& options, ExceptionState& exceptionState)
+{
+ RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
+
+ NavigatorUserMediaSuccessCallback* successCallback = new PromiseSuccessCallback(resolver);
+ NavigatorUserMediaErrorCallback* errorCallback = new PromiseErrorCallback(resolver);
Guido Urdaneta 2015/06/23 10:57:02 Are you deleting these pointers somewhere?
Peter Beverloo 2015/06/23 12:44:16 These will be stored as Member<>s in UserMediaRequ
hta - Chromium 2015/06/26 09:28:59 Just checking .. there's no problem with keeping t
Peter Beverloo 2015/06/26 12:36:55 Having the raw pointers here is fine. In the Oilpa
+
+ Document* document = toDocument(scriptState->executionContext());
+ UserMediaController* userMedia = UserMediaController::from(document->frame());
+ if (!userMedia)
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "No media device controller available; is this a detached window?"));
+
+ UserMediaRequest* request = UserMediaRequest::create(document, userMedia, options, successCallback, errorCallback, exceptionState);
+ if (!request) {
+ ASSERT(exceptionState.hadException());
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError, "Creating the request failed - internal error?"));
Peter Beverloo 2015/06/23 12:44:16 Why do you create a new exception here, rather tha
hta - Chromium 2015/06/26 09:28:59 Returning the passed-up exception works better, th
+ }
+
+ request->start();
+ return resolver->promise();
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698