Chromium Code Reviews| Index: third_party/WebKit/Source/modules/mediasession/MediaMetadataSanitizer.cpp |
| diff --git a/third_party/WebKit/Source/modules/mediasession/MediaMetadataSanitizer.cpp b/third_party/WebKit/Source/modules/mediasession/MediaMetadataSanitizer.cpp |
| index b3ab3d58566e010251a7c793c9f4cb68729a14c9..b2fc7480364797f2cbe1b6146015d07e79b742bd 100644 |
| --- a/third_party/WebKit/Source/modules/mediasession/MediaMetadataSanitizer.cpp |
| +++ b/third_party/WebKit/Source/modules/mediasession/MediaMetadataSanitizer.cpp |
| @@ -4,11 +4,14 @@ |
| #include "modules/mediasession/MediaMetadataSanitizer.h" |
| +#include "core/dom/ExecutionContext.h" |
| +#include "core/inspector/ConsoleMessage.h" |
| #include "modules/mediasession/MediaImage.h" |
| #include "modules/mediasession/MediaMetadata.h" |
| #include "public/platform/WebIconSizesParser.h" |
| #include "public/platform/WebSize.h" |
| #include "url/url_constants.h" |
| +#include "wtf/text/StringOperators.h" |
| namespace blink { |
| @@ -30,29 +33,40 @@ const size_t kMaxNumberOfMediaImages = 10; |
| // Maximum of sizes in a MediaImage. |
| const size_t kMaxNumberOfImageSizes = 10; |
| -bool checkMediaImageSrcSanity(const KURL& src) { |
| +bool checkMediaImageSrcSanity(const KURL& src, ExecutionContext* context) { |
| + // Console warning for invalid src is printed upon MediaImage creation. |
|
whywhat
2016/11/11 20:09:02
Do we want to do that? Maybe it's better to show t
Zhiqiang Zhang (Slow)
2016/11/11 20:56:44
Invalid src is dropped when passing metadata throu
|
| if (!src.isValid()) |
| return false; |
| + |
| if (!src.protocolIs(url::kHttpScheme) && !src.protocolIs(url::kHttpsScheme) && |
| !src.protocolIs(url::kDataScheme)) { |
| + context->addConsoleMessage(ConsoleMessage::create( |
| + JSMessageSource, WarningMessageLevel, |
| + "MediaImage src can only be of http/https/data scheme: " + |
| + src.getString())); |
| return false; |
| } |
| DCHECK(src.getString().is8Bit()); |
| - if (src.getString().length() > url::kMaxURLChars) |
| + if (src.getString().length() > url::kMaxURLChars) { |
| + context->addConsoleMessage(ConsoleMessage::create( |
| + JSMessageSource, WarningMessageLevel, |
| + "MediaImage src exceeds maximum URL length: " + src.getString())); |
| return false; |
| + } |
| return true; |
| } |
| // Sanitize MediaImage and do mojo serialization. Returns null when |
| // |image.src()| is bad. |
| blink::mojom::blink::MediaImagePtr sanitizeMediaImageAndConvertToMojo( |
| - const MediaImage* image) { |
| + const MediaImage* image, |
| + ExecutionContext* context) { |
| DCHECK(image); |
| blink::mojom::blink::MediaImagePtr mojoImage; |
| KURL url = KURL(ParsedURLString, image->src()); |
| - if (!checkMediaImageSrcSanity(url)) |
| + if (!checkMediaImageSrcSanity(url, context)) |
| return mojoImage; |
| mojoImage = blink::mojom::blink::MediaImage::New(); |
| @@ -61,8 +75,13 @@ blink::mojom::blink::MediaImagePtr sanitizeMediaImageAndConvertToMojo( |
| for (const auto& webSize : |
| WebIconSizesParser::parseIconSizes(image->sizes())) { |
| mojoImage->sizes.append(webSize); |
| - if (mojoImage->sizes.size() == kMaxNumberOfImageSizes) |
| + if (mojoImage->sizes.size() == kMaxNumberOfImageSizes) { |
| + context->addConsoleMessage(ConsoleMessage::create( |
| + JSMessageSource, WarningMessageLevel, |
| + "The number of MediaImage sizes exceeds the upper limit. " |
| + "All remaining MediaImage will be ignored")); |
| break; |
| + } |
| } |
| return mojoImage; |
| } |
| @@ -70,8 +89,8 @@ blink::mojom::blink::MediaImagePtr sanitizeMediaImageAndConvertToMojo( |
| } // anonymous namespace |
| blink::mojom::blink::MediaMetadataPtr |
| -MediaMetadataSanitizer::sanitizeAndConvertToMojo( |
| - const MediaMetadata* metadata) { |
| +MediaMetadataSanitizer::sanitizeAndConvertToMojo(const MediaMetadata* metadata, |
| + ExecutionContext* context) { |
| blink::mojom::blink::MediaMetadataPtr mojoMetadata; |
| if (!metadata) |
| return mojoMetadata; |
| @@ -84,11 +103,16 @@ MediaMetadataSanitizer::sanitizeAndConvertToMojo( |
| for (const auto image : metadata->artwork()) { |
| blink::mojom::blink::MediaImagePtr mojoImage = |
| - sanitizeMediaImageAndConvertToMojo(image.get()); |
| + sanitizeMediaImageAndConvertToMojo(image.get(), context); |
| if (!mojoImage.is_null()) |
| mojoMetadata->artwork.append(std::move(mojoImage)); |
| - if (mojoMetadata->artwork.size() == kMaxNumberOfMediaImages) |
| + if (mojoMetadata->artwork.size() == kMaxNumberOfMediaImages) { |
| + context->addConsoleMessage(ConsoleMessage::create( |
| + JSMessageSource, WarningMessageLevel, |
| + "The number of MediaImage sizes exceeds the upper limit. " |
| + "All remaining MediaImage will be ignored")); |
| break; |
| + } |
| } |
| return mojoMetadata; |
| } |