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

Side by Side Diff: third_party/WebKit/Source/modules/mediasession/MediaSession.cpp

Issue 2426653002: Adding mojo MediaSessionClient to support media controls (Closed)
Patch Set: Still rough, depends on "blink media controls" CL Created 4 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 "modules/mediasession/MediaSession.h" 5 #include "modules/mediasession/MediaSession.h"
6 6
7 #include "bindings/core/v8/ScriptState.h" 7 #include "bindings/core/v8/ScriptState.h"
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/ExecutionContext.h" 9 #include "core/dom/ExecutionContext.h"
10 #include "core/events/Event.h"
10 #include "core/frame/LocalFrame.h" 11 #include "core/frame/LocalFrame.h"
11 #include "modules/EventTargetModules.h" 12 #include "modules/EventTargetModules.h"
12 #include "modules/mediasession/MediaMetadata.h" 13 #include "modules/mediasession/MediaMetadata.h"
13 #include "modules/mediasession/MediaMetadataSanitizer.h" 14 #include "modules/mediasession/MediaMetadataSanitizer.h"
14 #include "public/platform/InterfaceProvider.h" 15 #include "public/platform/InterfaceProvider.h"
15 #include <memory> 16 #include <memory>
16 17
17 namespace blink { 18 namespace blink {
18 19
19 MediaSession::MediaSession(ScriptState* scriptState) 20 MediaSession::MediaSession(ScriptState* scriptState)
20 : m_scriptState(scriptState) {} 21 : m_scriptState(scriptState), m_clientBinding(this) {}
21 22
22 MediaSession* MediaSession::create(ScriptState* scriptState) { 23 MediaSession* MediaSession::create(ScriptState* scriptState) {
23 return new MediaSession(scriptState); 24 return new MediaSession(scriptState);
24 } 25 }
25 26
26 void MediaSession::setMetadata(MediaMetadata* metadata) { 27 void MediaSession::setMetadata(MediaMetadata* metadata) {
27 if (mojom::blink::MediaSessionService* service = 28 if (mojom::blink::MediaSessionService* service =
28 getService(m_scriptState.get())) { 29 getService(m_scriptState.get())) {
29 service->SetMetadata( 30 service->SetMetadata(
30 MediaMetadataSanitizer::sanitizeAndConvertToMojo(metadata)); 31 MediaMetadataSanitizer::sanitizeAndConvertToMojo(metadata));
(...skipping 17 matching lines...) Expand all
48 if (!m_service) { 49 if (!m_service) {
49 InterfaceProvider* interfaceProvider = nullptr; 50 InterfaceProvider* interfaceProvider = nullptr;
50 DCHECK(scriptState->getExecutionContext()->isDocument()) 51 DCHECK(scriptState->getExecutionContext()->isDocument())
51 << "MediaSession::getService() is only available from a frame"; 52 << "MediaSession::getService() is only available from a frame";
52 Document* document = toDocument(scriptState->getExecutionContext()); 53 Document* document = toDocument(scriptState->getExecutionContext());
53 if (document->frame()) 54 if (document->frame())
54 interfaceProvider = document->frame()->interfaceProvider(); 55 interfaceProvider = document->frame()->interfaceProvider();
55 56
56 if (interfaceProvider) 57 if (interfaceProvider)
57 interfaceProvider->getInterface(mojo::GetProxy(&m_service)); 58 interfaceProvider->getInterface(mojo::GetProxy(&m_service));
59
60 m_service->SetClient(m_clientBinding.CreateInterfacePtrAndBind());
58 } 61 }
59 return m_service.get(); 62 return m_service.get();
60 } 63 }
61 64
62 // TODO(zqzhang): register listener to MediaSessionService. See 65 #define DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(attribute) \
63 // https://crbug.com/xxxxxx 66 EventListener* MediaSession::on##attribute() { \
64 #define DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(attribute) \ 67 return getAttributeEventListener(EventTypeNames::attribute); \
65 EventListener* MediaSession::on##attribute() { \ 68 } \
66 return getAttributeEventListener(EventTypeNames::attribute); \ 69 void MediaSession::setOn##attribute(EventListener* listener) { \
67 } \ 70 setAttributeEventListener(EventTypeNames::attribute, listener); \
68 void MediaSession::setOn##attribute(EventListener* listener) { \ 71 if (mojom::blink::MediaSessionService* service = \
69 setAttributeEventListener(EventTypeNames::attribute, listener); \ 72 getService(m_scriptState.get())) { \
73 service->DidSetEventHandlerForAction(EventTypeNames::attribute, \
74 static_cast<bool>(listener)); \
75 } \
70 } 76 }
71 77
72 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(play); 78 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(play);
73 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(pause); 79 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(pause);
74 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(playpause); 80 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(playpause);
75 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(previoustrack); 81 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(previoustrack);
76 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(nexttrack); 82 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(nexttrack);
77 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekforward); 83 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekforward);
78 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekbackward); 84 DEFINE_MEDIA_SESSION_ATTRIBUTE_EVENT_LISTENER(seekbackward);
79 85
86 void MediaSession::DidReceivedAction(const WTF::String& action) {
87 StringView view(action);
88 dispatchEvent(Event::create(view.toAtomicString()));
89 }
90
80 DEFINE_TRACE(MediaSession) { 91 DEFINE_TRACE(MediaSession) {
81 visitor->trace(m_metadata); 92 visitor->trace(m_metadata);
82 EventTargetWithInlineData::trace(visitor); 93 EventTargetWithInlineData::trace(visitor);
83 } 94 }
84 95
85 } // namespace blink 96 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698