Chromium Code Reviews| 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 a3b93e1c3c2ce2c85782cb27ec1e0b50e8c7d27a..0284b83afedd51fc8c51a15d062de0abe9db0c73 100644 |
| --- a/third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp |
| +++ b/third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp |
| @@ -4,7 +4,6 @@ |
| #include "modules/mediasession/MediaMetadata.h" |
| -#include "core/dom/ExecutionContext.h" |
| #include "modules/mediasession/MediaImage.h" |
| #include "modules/mediasession/MediaMetadataInit.h" |
| #include "modules/mediasession/MediaSession.h" |
| @@ -12,19 +11,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.append(MediaImage::create(context, image)); |
| + setArtworkInternal(scriptState, metadata.artwork(), exceptionState); |
| } |
| String MediaMetadata::title() const { |
| @@ -39,10 +39,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()); |
|
Zhiqiang Zhang (Slow)
2017/01/05 16:03:08
Why not freeze them in the ctor?
Zhiqiang Zhang (Slow)
2017/01/05 16:06:40
I see it's following the pattern of Notification.c
mlamouri (slow - plz ping)
2017/01/05 19:28:22
Ack :)
|
| + |
| + 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 +70,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 +93,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() + |
|
Zhiqiang Zhang (Slow)
2017/01/05 16:03:08
Should this be URIError? I currently use it in the
mlamouri (slow - plz ping)
2017/01/05 19:28:22
TypeError is the one we use when something doesn't
|
| + "' 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); |