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/ScriptState.h" | |
| 10 #include "core/frame/LocalDOMWindow.h" | |
| 11 #include "core/frame/LocalFrame.h" | |
| 12 #include "core/loader/FrameLoaderClient.h" | |
| 13 #include "modules/mediasession/MediaSessionError.h" | |
| 14 | |
| 8 namespace blink { | 15 namespace blink { |
| 9 | 16 |
| 10 MediaSession* MediaSession::create() | 17 MediaSession::MediaSession(PassOwnPtr<WebMediaSession> webMediaSession) |
| 18 : m_webMediaSession(webMediaSession) | |
| 11 { | 19 { |
| 12 return new MediaSession; | 20 #if OS(ANDROID) |
| 21 ASSERT(m_webMediaSession); | |
| 22 #else | |
| 23 ASSERT(!m_webMediaSession); | |
| 24 #endif // ANDROID | |
| 13 } | 25 } |
| 14 | 26 |
| 15 void MediaSession::activate() | 27 MediaSession* MediaSession::create(ScriptState* scriptState) |
|
mlamouri (slow - plz ping)
2015/09/28 15:16:03
The ExecutionContext should be enough. It will giv
davve
2015/10/06 12:05:13
Done.
| |
| 16 { | 28 { |
| 29 LocalDOMWindow* domWindow = scriptState->domWindow(); | |
| 30 LocalFrame* frame = domWindow->frame(); | |
| 31 FrameLoaderClient* client = frame->loader().client(); | |
| 32 return new MediaSession(client->createWebMediaSession()); | |
| 17 } | 33 } |
| 18 | 34 |
| 19 void MediaSession::deactivate() | 35 MediaSession* MediaSession::createForTesting(PassOwnPtr<WebMediaSession> webMedi aSession) |
| 20 { | 36 { |
| 37 return new MediaSession(webMediaSession); | |
| 38 } | |
| 39 | |
| 40 ScriptPromise MediaSession::activate(ScriptState* scriptState) | |
| 41 { | |
| 42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 43 ScriptPromise promise = resolver->promise(); | |
|
mlamouri (slow - plz ping)
2015/09/28 15:16:03
Do you need to create the |promise| here? You coul
davve
2015/10/06 12:05:13
Done.
| |
| 44 | |
| 45 #if OS(ANDROID) | |
|
mlamouri (slow - plz ping)
2015/09/28 15:16:03
Could we avoid the ifdef and let that happen at a
davve
2015/10/06 12:05:13
Using m_webMediaSession != NULL wfm.
| |
| 46 m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessionErr or>(resolver)); | |
| 47 #else | |
| 48 ScriptState::Scope scope(resolver->scriptState()); | |
| 49 v8::Isolate* isolate = resolver->scriptState()->isolate(); | |
| 50 resolver->reject(v8::Exception::Error(v8String(isolate, "Missing platform im plementation."))); | |
|
mlamouri (slow - plz ping)
2015/09/28 15:16:03
Could you fail with a NotSupportedError?
davve
2015/10/06 12:05:13
Done.
| |
| 51 #endif | |
| 52 | |
| 53 return promise; | |
| 54 } | |
| 55 | |
| 56 ScriptPromise MediaSession::deactivate(ScriptState* scriptState) | |
| 57 { | |
| 58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 59 ScriptPromise promise = resolver->promise(); | |
|
mlamouri (slow - plz ping)
2015/09/28 15:16:03
ditto
davve
2015/10/06 12:05:13
Done.
| |
| 60 | |
| 61 #if OS(ANDROID) | |
|
mlamouri (slow - plz ping)
2015/09/28 15:16:03
ditto
davve
2015/10/06 12:05:13
Done.
| |
| 62 m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, MediaSessionE rror>(resolver)); | |
| 63 #else | |
| 64 ScriptState::Scope scope(resolver->scriptState()); | |
| 65 v8::Isolate* isolate = resolver->scriptState()->isolate(); | |
| 66 resolver->reject(v8::Exception::Error(v8String(isolate, "Missing platform im plementation."))); | |
|
mlamouri (slow - plz ping)
2015/09/28 15:16:03
ditto
davve
2015/10/06 12:05:13
Done.
| |
| 67 #endif | |
| 68 | |
| 69 return promise; | |
| 21 } | 70 } |
| 22 | 71 |
| 23 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |