| 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 5f47c82ef3f575561dc51bb84d86787eb00be185..38927ca83cd854244627d0fa8351a82519706ef0 100644
|
| --- a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
|
| +++ b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp
|
| @@ -12,65 +12,79 @@
|
| #include "core/frame/LocalDOMWindow.h"
|
| #include "core/frame/LocalFrame.h"
|
| #include "core/loader/FrameLoaderClient.h"
|
| +#include "modules/mediasession/MediaArtwork.h"
|
| #include "modules/mediasession/MediaMetadata.h"
|
| -#include "modules/mediasession/MediaSessionError.h"
|
| +#include "public/platform/InterfaceProvider.h"
|
| +#include "public/platform/WebIconSizesParser.h"
|
| #include <memory>
|
|
|
| namespace blink {
|
|
|
| -MediaSession::MediaSession(std::unique_ptr<WebMediaSession> webMediaSession)
|
| - : m_webMediaSession(std::move(webMediaSession))
|
| -{
|
| - DCHECK(m_webMediaSession);
|
| +namespace {
|
| +
|
| +mojom::blink::MediaMetadataIconPtr ToMojoMediaMetadataIcon(
|
| + const MediaArtwork* icon) {
|
| + DCHECK(icon);
|
| + mojom::blink::MediaMetadataIconPtr mojoIcon = mojom::blink::MediaMetadataIcon::New();
|
| + mojoIcon->src = KURL(ParsedURLString, icon->src());
|
| + mojoIcon->type = icon->type();
|
| + WebVector<WebSize> webSizes = WebIconSizesParser::parseIconSizes(icon->sizes());
|
| + mojoIcon->sizes.resize(webSizes.size());
|
| + memcpy(mojoIcon->sizes.data(), webSizes.data(), webSizes.size() * sizeof(WebSize));
|
| + return mojoIcon;
|
| }
|
|
|
| -MediaSession* MediaSession::create(ExecutionContext* context, ExceptionState& exceptionState)
|
| -{
|
| - Document* document = toDocument(context);
|
| - LocalFrame* frame = document->frame();
|
| - FrameLoaderClient* client = frame->loader().client();
|
| - std::unique_ptr<WebMediaSession> webMediaSession = client->createWebMediaSession();
|
| - if (!webMediaSession) {
|
| - exceptionState.throwDOMException(NotSupportedError, "Missing platform implementation.");
|
| - return nullptr;
|
| +mojom::blink::MediaMetadataPtr ToMojoMediaMetadata(
|
| + const MediaMetadata* metadata) {
|
| + mojom::blink::MediaMetadataPtr mojoMetadata;
|
| + if (!metadata)
|
| + return mojoMetadata;
|
| + mojoMetadata = mojom::blink::MediaMetadata::New();
|
| + mojoMetadata->title = metadata->title();
|
| + mojoMetadata->artist = metadata->artist();
|
| + mojoMetadata->album = metadata->album();
|
| + for (const auto& icon : metadata->artwork()) {
|
| + // TODO(zqzhang): do sanitization
|
| + mojoMetadata->artwork.append(ToMojoMediaMetadataIcon(icon.get()));
|
| }
|
| - return new MediaSession(std::move(webMediaSession));
|
| + return mojoMetadata;
|
| }
|
|
|
| -ScriptPromise MediaSession::activate(ScriptState* scriptState)
|
| -{
|
| - ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| - ScriptPromise promise = resolver->promise();
|
| +} // anonymous namespace
|
|
|
| - m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessionError>(resolver));
|
| - return promise;
|
| -}
|
| +MediaSession::MediaSession() = default;
|
|
|
| -ScriptPromise MediaSession::deactivate(ScriptState* scriptState)
|
| +MediaSession* MediaSession::create()
|
| {
|
| - ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| - ScriptPromise promise = resolver->promise();
|
| -
|
| - m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, void>(resolver));
|
| - return promise;
|
| + return new MediaSession();
|
| }
|
|
|
| -void MediaSession::setMetadata(MediaMetadata* metadata)
|
| +void MediaSession::setMetadata(ScriptState* scriptState, MediaMetadata* metadata)
|
| {
|
| - m_metadata = metadata;
|
| - if (metadata) {
|
| - WebMediaMetadata webMetadata = (WebMediaMetadata) *metadata;
|
| - m_webMediaSession->setMetadata(&webMetadata);
|
| - } else {
|
| - m_webMediaSession->setMetadata(nullptr);
|
| - }
|
| + if (getService(scriptState))
|
| + getService(scriptState)->SetMetadata(ToMojoMediaMetadata(metadata));
|
| }
|
|
|
| -MediaMetadata* MediaSession::metadata() const
|
| +MediaMetadata* MediaSession::metadata(ScriptState*) const
|
| {
|
| return m_metadata;
|
| }
|
|
|
| +mojom::blink::MediaSessionService* MediaSession::getService(ScriptState* scriptState)
|
| +{
|
| + if (!m_service) {
|
| + InterfaceProvider* interfaceProvider = nullptr;
|
| + DCHECK(scriptState->getExecutionContext()->isDocument()) << "MediaSession::getService() is only available from a frame";
|
| + Document* document = toDocument(scriptState->getExecutionContext());
|
| + if (document->frame())
|
| + interfaceProvider = document->frame()->interfaceProvider();
|
| +
|
| + if (interfaceProvider)
|
| + interfaceProvider->getInterface(mojo::GetProxy(&m_service));
|
| + }
|
| + return m_service.get();
|
| +}
|
| +
|
| DEFINE_TRACE(MediaSession)
|
| {
|
| visitor->trace(m_metadata);
|
|
|