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

Unified Diff: third_party/WebKit/Source/modules/mediasession/MediaSession.cpp

Issue 1370453002: Introduce WebMediaSession (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add virtual default destructor Created 5 years, 2 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: third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
diff --git a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
index 937bf7f19d23f26aadf5c3f1ae0393ae0050d093..316a3ed7423067215a4257bbaf01394aaba2c0eb 100644
--- a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
+++ b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
@@ -5,19 +5,53 @@
#include "config.h"
#include "modules/mediasession/MediaSession.h"
+#include "bindings/core/v8/CallbackPromiseAdapter.h"
+#include "bindings/core/v8/ScriptPromiseResolver.h"
+#include "bindings/core/v8/ScriptState.h"
+#include "core/dom/DOMException.h"
+#include "core/dom/ExceptionCode.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(ExecutionContext* context, ExceptionState& exceptionState)
{
- return new MediaSession;
+ Document* document = toDocument(context);
+ LocalFrame* frame = document->frame();
+ FrameLoaderClient* client = frame->loader().client();
+ OwnPtr<WebMediaSession> webMediaSession = client->createWebMediaSession();
+ if (!webMediaSession) {
+ exceptionState.throwDOMException(NotSupportedError, "Missing platform implementation.");
+ return nullptr;
+ }
+ return new MediaSession(webMediaSession.release());
}
-void MediaSession::activate()
+ScriptPromise MediaSession::activate(ScriptState* scriptState)
{
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessionError>(resolver));
+ return promise;
}
-void MediaSession::deactivate()
+ScriptPromise MediaSession::deactivate(ScriptState* scriptState)
{
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+
+ m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, void>(resolver));
+ return promise;
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698