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

Unified Diff: third_party/WebKit/Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp

Issue 1416123005: Implement setSinkId() for media elements without src. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More jochen's comments Created 5 years, 1 month 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: third_party/WebKit/Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp
diff --git a/third_party/WebKit/Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp b/third_party/WebKit/Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp
index 930dc3c40b88e366c893b33e4f2691cb812f706b..e78421d2cda860562f68625bab49648e57a09deb 100644
--- a/third_party/WebKit/Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp
+++ b/third_party/WebKit/Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp
@@ -8,6 +8,7 @@
#include "bindings/core/v8/ScriptPromiseResolver.h"
#include "bindings/core/v8/ScriptState.h"
#include "core/dom/ExecutionContext.h"
+#include "modules/audio_output_devices/AudioOutputDeviceClient.h"
#include "modules/audio_output_devices/SetSinkIdCallbacks.h"
#include "public/platform/WebSecurityOrigin.h"
@@ -34,14 +35,25 @@ ScriptPromise HTMLMediaElementAudioOutputDevice::setSinkId(ScriptState* scriptSt
ASSERT(scriptState);
Peter Beverloo 2015/11/09 20:05:06 note: We seem to be missing step 1 of the algorith
Guido Urdaneta 2015/11/10 15:36:51 Done.
WebMediaPlayer* webMediaPlayer = element.webMediaPlayer();
- if (!webMediaPlayer)
- return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "No media player available"));
-
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ OwnPtr<SetSinkIdCallbacks> callbacks = adoptPtr(new SetSinkIdCallbacks(resolver, element, sinkId));
ExecutionContext* context = scriptState->executionContext();
ASSERT(context && context->isDocument());
- ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
- webMediaPlayer->setSinkId(sinkId, WebSecurityOrigin(context->securityOrigin()), new SetSinkIdCallbacks(resolver, element, sinkId));
+ if (webMediaPlayer) {
+ // Using leakPtr() to transfer ownership because |webMediaPlayer| is a platform object that takes raw pointers
+ webMediaPlayer->setSinkId(sinkId, WebSecurityOrigin(context->securityOrigin()), callbacks.leakPtr());
+ } else {
+ if (AudioOutputDeviceClient* client = AudioOutputDeviceClient::from(context)) {
+ client->checkIfAudioSinkExistsAndIsAuthorized(context, sinkId, callbacks.release());
+ } else {
+ // The context has been detached. Impossible to get a security origin to check.
+ ASSERT(context->activeDOMObjectsAreStopped());
+ resolver->reject();
Peter Beverloo 2015/11/09 20:05:06 nit: why not reject the resolver with the dom erro
Guido Urdaneta 2015/11/10 15:36:51 Done. Note that the implementation is slightly dif
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(SecurityError, "Impossible to authorize device for detached context"));
+ }
+ }
+
return resolver->promise();
}

Powered by Google App Engine
This is Rietveld 408576698