| Index: third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp
|
| diff --git a/third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp b/third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp
|
| index 93c2aa86bcec8d8ee9a7a7a9c337f5043e8e9ecf..59ba3fce1f011c7121295a80879b4f691796b266 100644
|
| --- a/third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp
|
| +++ b/third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp
|
| @@ -4,7 +4,9 @@
|
|
|
| #include "modules/mediasession/MediaMetadata.h"
|
|
|
| -#include "core/dom/ExecutionContext.h"
|
| +#include "bindings/core/v8/ExceptionState.h"
|
| +#include "bindings/core/v8/ScriptState.h"
|
| +#include "bindings/core/v8/ToV8.h"
|
| #include "modules/mediasession/MediaImage.h"
|
| #include "modules/mediasession/MediaMetadataInit.h"
|
| #include "modules/mediasession/MediaSession.h"
|
| @@ -12,19 +14,20 @@
|
| namespace blink {
|
|
|
| // static
|
| -MediaMetadata* MediaMetadata::create(ExecutionContext* context,
|
| - const MediaMetadataInit& metadata) {
|
| - return new MediaMetadata(context, metadata);
|
| +MediaMetadata* MediaMetadata::create(ScriptState* scriptState,
|
| + const MediaMetadataInit& metadata,
|
| + ExceptionState& exceptionState) {
|
| + return new MediaMetadata(scriptState, metadata, exceptionState);
|
| }
|
|
|
| -MediaMetadata::MediaMetadata(ExecutionContext* context,
|
| - const MediaMetadataInit& metadata)
|
| +MediaMetadata::MediaMetadata(ScriptState* scriptState,
|
| + const MediaMetadataInit& metadata,
|
| + ExceptionState& exceptionState)
|
| : m_notifySessionTimer(this, &MediaMetadata::notifySessionTimerFired) {
|
| m_title = metadata.title();
|
| m_artist = metadata.artist();
|
| m_album = metadata.album();
|
| - for (const auto& image : metadata.artwork())
|
| - m_artwork.push_back(MediaImage::create(context, image));
|
| + setArtworkInternal(scriptState, metadata.artwork(), exceptionState);
|
| }
|
|
|
| String MediaMetadata::title() const {
|
| @@ -39,10 +42,22 @@ String MediaMetadata::album() const {
|
| return m_album;
|
| }
|
|
|
| -const HeapVector<Member<MediaImage>>& MediaMetadata::artwork() const {
|
| +const HeapVector<MediaImage>& MediaMetadata::artwork() const {
|
| return m_artwork;
|
| }
|
|
|
| +Vector<v8::Local<v8::Value>> MediaMetadata::artwork(
|
| + ScriptState* scriptState) const {
|
| + Vector<v8::Local<v8::Value>> result(m_artwork.size());
|
| +
|
| + for (size_t i = 0; i < m_artwork.size(); ++i) {
|
| + result[i] =
|
| + freezeV8Object(ToV8(m_artwork[i], scriptState), scriptState->isolate());
|
| + }
|
| +
|
| + return result;
|
| +}
|
| +
|
| void MediaMetadata::setTitle(const String& title) {
|
| m_title = title;
|
| notifySessionAsync();
|
| @@ -58,8 +73,10 @@ void MediaMetadata::setAlbum(const String& album) {
|
| notifySessionAsync();
|
| }
|
|
|
| -void MediaMetadata::setArtwork(const HeapVector<Member<MediaImage>>& artwork) {
|
| - m_artwork = artwork;
|
| +void MediaMetadata::setArtwork(ScriptState* scriptState,
|
| + const HeapVector<MediaImage>& artwork,
|
| + ExceptionState& exceptionState) {
|
| + setArtworkInternal(scriptState, artwork, exceptionState);
|
| notifySessionAsync();
|
| }
|
|
|
| @@ -79,6 +96,25 @@ void MediaMetadata::notifySessionTimerFired(TimerBase*) {
|
| m_session->onMetadataChanged();
|
| }
|
|
|
| +void MediaMetadata::setArtworkInternal(ScriptState* scriptState,
|
| + const HeapVector<MediaImage>& artwork,
|
| + ExceptionState& exceptionState) {
|
| + HeapVector<MediaImage> processedArtwork(artwork);
|
| +
|
| + for (MediaImage& image : processedArtwork) {
|
| + KURL url = scriptState->getExecutionContext()->completeURL(image.src());
|
| + if (!url.isValid()) {
|
| + exceptionState.throwTypeError("'" + image.src() +
|
| + "' can't be resolved to a valid URL.");
|
| + return;
|
| + }
|
| + image.setSrc(url);
|
| + }
|
| +
|
| + DCHECK(!exceptionState.hadException());
|
| + m_artwork.swap(processedArtwork);
|
| +}
|
| +
|
| DEFINE_TRACE(MediaMetadata) {
|
| visitor->trace(m_artwork);
|
| visitor->trace(m_session);
|
|
|