Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/mediasession/MediaSession.h" | 6 #include "modules/mediasession/MediaSession.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | |
| 10 #include "bindings/core/v8/ScriptState.h" | |
| 11 #include "core/dom/DOMException.h" | |
| 12 #include "core/dom/ExceptionCode.h" | |
| 13 #include "core/frame/LocalDOMWindow.h" | |
| 14 #include "core/frame/LocalFrame.h" | |
| 15 #include "core/loader/FrameLoaderClient.h" | |
| 16 #include "modules/mediasession/MediaSessionError.h" | |
| 17 | |
| 8 namespace blink { | 18 namespace blink { |
| 9 | 19 |
| 10 MediaSession* MediaSession::create() | 20 MediaSession::MediaSession(PassOwnPtr<WebMediaSession> webMediaSession) |
| 21 : m_webMediaSession(webMediaSession) | |
| 11 { | 22 { |
| 12 return new MediaSession; | 23 ASSERT(m_webMediaSession); |
| 13 } | 24 } |
| 14 | 25 |
| 15 void MediaSession::activate() | 26 MediaSession* MediaSession::create(ExecutionContext* context, ExceptionState& ex ceptionState) |
| 16 { | 27 { |
| 28 Document* document = toDocument(context); | |
| 29 LocalFrame* frame = document->frame(); | |
| 30 FrameLoaderClient* client = frame->loader().client(); | |
| 31 OwnPtr<WebMediaSession> webMediaSession = client->createWebMediaSession(); | |
| 32 if (!webMediaSession) { | |
| 33 exceptionState.throwDOMException(NotSupportedError, "Missing platform im plementation."); | |
| 34 return nullptr; | |
|
mlamouri (slow - plz ping)
2015/10/09 13:01:28
I'm sceptical of that change. It means that if we
philipj_slow
2015/10/09 15:05:39
Neither this nor rejecting in activate() and deact
| |
| 35 } | |
| 36 return new MediaSession(webMediaSession.release()); | |
| 17 } | 37 } |
| 18 | 38 |
| 19 void MediaSession::deactivate() | 39 MediaSession* MediaSession::createForTesting(PassOwnPtr<WebMediaSession> webMedi aSession) |
| 20 { | 40 { |
| 41 return new MediaSession(webMediaSession); | |
| 42 } | |
| 43 | |
| 44 ScriptPromise MediaSession::activate(ScriptState* scriptState) | |
| 45 { | |
| 46 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 47 ScriptPromise promise = resolver->promise(); | |
| 48 | |
| 49 m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessionErr or>(resolver)); | |
| 50 return promise; | |
| 51 } | |
| 52 | |
| 53 ScriptPromise MediaSession::deactivate(ScriptState* scriptState) | |
| 54 { | |
| 55 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 56 ScriptPromise promise = resolver->promise(); | |
| 57 | |
| 58 m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, MediaSessionE rror>(resolver)); | |
| 59 return promise; | |
| 21 } | 60 } |
| 22 | 61 |
| 23 } // namespace blink | 62 } // namespace blink |
| OLD | NEW |