Index: Source/modules/mediasession/MediaSession.cpp |
diff --git a/Source/modules/mediasession/MediaSession.cpp b/Source/modules/mediasession/MediaSession.cpp |
index 937bf7f19d23f26aadf5c3f1ae0393ae0050d093..8b0445854697798e023501c6027dc34b990109f1 100644 |
--- a/Source/modules/mediasession/MediaSession.cpp |
+++ b/Source/modules/mediasession/MediaSession.cpp |
@@ -5,19 +5,52 @@ |
#include "config.h" |
#include "modules/mediasession/MediaSession.h" |
+#include "Source/bindings/core/v8/CallbackPromiseAdapter.h" |
+#include "bindings/core/v8/ScriptState.h" |
+#include "core/frame/LocalDOMWindow.h" |
+#include "core/frame/LocalFrame.h" |
+#include "core/loader/FrameLoaderClient.h" |
+#include "modules/mediasession/MediaSessionError.h" |
+ |
namespace blink { |
-MediaSession* MediaSession::create() |
+MediaSession::MediaSession(PassOwnPtr<WebMediaSession> webMediaSession) |
+ : m_webMediaSession(webMediaSession) |
+{ |
+ ASSERT(m_webMediaSession); |
+} |
+ |
+MediaSession* MediaSession::create(ScriptState* scriptState) |
{ |
- return new MediaSession; |
+ LocalDOMWindow* domWindow = scriptState->domWindow(); |
+ LocalFrame* frame = domWindow->frame(); |
+ FrameLoaderClient* client = frame->loader().client(); |
+ return new MediaSession(client->createWebMediaSession()); |
} |
-void MediaSession::activate() |
+MediaSession* MediaSession::createForTesting(PassOwnPtr<WebMediaSession> webMediaSession) |
{ |
+ return new MediaSession(webMediaSession); |
} |
-void MediaSession::deactivate() |
+ScriptPromise MediaSession::activate(ScriptState* scriptState) |
{ |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ |
+ m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessionError>(resolver)); |
+ |
+ return promise; |
+} |
+ |
+ScriptPromise MediaSession::deactivate(ScriptState* scriptState) |
+{ |
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
+ ScriptPromise promise = resolver->promise(); |
+ |
+ m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, MediaSessionError>(resolver)); |
+ |
+ return promise; |
} |
} // namespace blink |