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

Side by Side 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: Revert throwing in the constructor; would needlessly complicate existing tests 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 unified diff | Download patch
OLDNEW
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 #if OS(ANDROID)
24 ASSERT(m_webMediaSession);
25 #else
26 ASSERT(!m_webMediaSession);
27 #endif // ANDROID
13 } 28 }
14 29
15 void MediaSession::activate() 30 MediaSession* MediaSession::create(ExecutionContext* context)
16 { 31 {
32 Document* document = toDocument(context);
33 LocalFrame* frame = document->frame();
34 FrameLoaderClient* client = frame->loader().client();
35 return new MediaSession(client->createWebMediaSession());
philipj_slow 2015/10/07 14:37:12 If we throw an exception when client->createWebMed
davve 2015/10/08 09:17:35 Done.
17 } 36 }
18 37
19 void MediaSession::deactivate() 38 MediaSession* MediaSession::createForTesting(PassOwnPtr<WebMediaSession> webMedi aSession)
20 { 39 {
40 return new MediaSession(webMediaSession);
41 }
42
43 ScriptPromise MediaSession::activate(ScriptState* scriptState)
44 {
45 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
46 ScriptPromise promise = resolver->promise();
47 if (m_webMediaSession)
48 m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessio nError>(resolver));
49 else
50 resolver->reject(DOMException::create(NotSupportedError, "Missing platfo rm implementation."));
mlamouri (slow - plz ping) 2015/10/07 14:19:30 I would argue that rejecting with DOMException and
davve 2015/10/08 09:17:35 By moving the exception throwing to the constructo
51 return promise;
52 }
53
54 ScriptPromise MediaSession::deactivate(ScriptState* scriptState)
55 {
56 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
57 ScriptPromise promise = resolver->promise();
58 if (m_webMediaSession)
59 m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, MediaSess ionError>(resolver));
60 else
61 resolver->reject(DOMException::create(NotSupportedError, "Missing platfo rm implementation."));
62 return promise;
21 } 63 }
22 64
23 } // namespace blink 65 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698