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

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

Issue 2612003002: Media Session: use dictionary instead of an interface for MediaImage. (Closed)
Patch Set: rebase and remove one more file Created 3 years, 11 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/MediaMetadataSanitizer.h" 5 #include "modules/mediasession/MediaMetadataSanitizer.h"
6 6
7 #include "core/dom/ExecutionContext.h" 7 #include "core/dom/ExecutionContext.h"
8 #include "core/inspector/ConsoleMessage.h" 8 #include "core/inspector/ConsoleMessage.h"
9 #include "modules/mediasession/MediaImage.h" 9 #include "modules/mediasession/MediaImage.h"
10 #include "modules/mediasession/MediaMetadata.h" 10 #include "modules/mediasession/MediaMetadata.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 JSMessageSource, WarningMessageLevel, 52 JSMessageSource, WarningMessageLevel,
53 "MediaImage src exceeds maximum URL length: " + src.getString())); 53 "MediaImage src exceeds maximum URL length: " + src.getString()));
54 return false; 54 return false;
55 } 55 }
56 return true; 56 return true;
57 } 57 }
58 58
59 // Sanitize MediaImage and do mojo serialization. Returns null when 59 // Sanitize MediaImage and do mojo serialization. Returns null when
60 // |image.src()| is bad. 60 // |image.src()| is bad.
61 blink::mojom::blink::MediaImagePtr sanitizeMediaImageAndConvertToMojo( 61 blink::mojom::blink::MediaImagePtr sanitizeMediaImageAndConvertToMojo(
62 const MediaImage* image, 62 const MediaImage& image,
63 ExecutionContext* context) { 63 ExecutionContext* context) {
64 DCHECK(image);
65
66 blink::mojom::blink::MediaImagePtr mojoImage; 64 blink::mojom::blink::MediaImagePtr mojoImage;
67 65
68 KURL url = KURL(ParsedURLString, image->src()); 66 KURL url = KURL(ParsedURLString, image.src());
Zhiqiang Zhang (Slow) 2017/01/04 16:05:24 Resolve to absolute URL if we decide to do it here
mlamouri (slow - plz ping) 2017/01/05 15:40:20 I did it when we set. Though, this code assumes it
69 if (!checkMediaImageSrcSanity(url, context)) 67 if (!checkMediaImageSrcSanity(url, context))
70 return mojoImage; 68 return mojoImage;
71 69
72 mojoImage = blink::mojom::blink::MediaImage::New(); 70 mojoImage = blink::mojom::blink::MediaImage::New();
73 mojoImage->src = url; 71 mojoImage->src = url;
74 mojoImage->type = image->type().left(kMaxImageTypeLength); 72 mojoImage->type = image.type().left(kMaxImageTypeLength);
75 for (const auto& webSize : 73 for (const auto& webSize :
76 WebIconSizesParser::parseIconSizes(image->sizes())) { 74 WebIconSizesParser::parseIconSizes(image.sizes())) {
77 mojoImage->sizes.append(webSize); 75 mojoImage->sizes.append(webSize);
78 if (mojoImage->sizes.size() == kMaxNumberOfImageSizes) { 76 if (mojoImage->sizes.size() == kMaxNumberOfImageSizes) {
79 context->addConsoleMessage(ConsoleMessage::create( 77 context->addConsoleMessage(ConsoleMessage::create(
80 JSMessageSource, WarningMessageLevel, 78 JSMessageSource, WarningMessageLevel,
81 "The number of MediaImage sizes exceeds the upper limit. " 79 "The number of MediaImage sizes exceeds the upper limit. "
82 "All remaining MediaImage will be ignored")); 80 "All remaining MediaImage will be ignored"));
83 break; 81 break;
84 } 82 }
85 } 83 }
86 return mojoImage; 84 return mojoImage;
87 } 85 }
88 86
89 } // anonymous namespace 87 } // anonymous namespace
90 88
91 blink::mojom::blink::MediaMetadataPtr 89 blink::mojom::blink::MediaMetadataPtr
92 MediaMetadataSanitizer::sanitizeAndConvertToMojo(const MediaMetadata* metadata, 90 MediaMetadataSanitizer::sanitizeAndConvertToMojo(const MediaMetadata* metadata,
93 ExecutionContext* context) { 91 ExecutionContext* context) {
94 blink::mojom::blink::MediaMetadataPtr mojoMetadata; 92 blink::mojom::blink::MediaMetadataPtr mojoMetadata;
95 if (!metadata) 93 if (!metadata)
96 return mojoMetadata; 94 return mojoMetadata;
97 95
98 mojoMetadata = blink::mojom::blink::MediaMetadata::New(); 96 mojoMetadata = blink::mojom::blink::MediaMetadata::New();
99 97
100 mojoMetadata->title = metadata->title().left(kMaxStringLength); 98 mojoMetadata->title = metadata->title().left(kMaxStringLength);
101 mojoMetadata->artist = metadata->artist().left(kMaxStringLength); 99 mojoMetadata->artist = metadata->artist().left(kMaxStringLength);
102 mojoMetadata->album = metadata->album().left(kMaxStringLength); 100 mojoMetadata->album = metadata->album().left(kMaxStringLength);
103 101
104 for (const auto image : metadata->artwork()) { 102 for (const MediaImage& image : metadata->artwork()) {
105 blink::mojom::blink::MediaImagePtr mojoImage = 103 blink::mojom::blink::MediaImagePtr mojoImage =
106 sanitizeMediaImageAndConvertToMojo(image.get(), context); 104 sanitizeMediaImageAndConvertToMojo(image, context);
107 if (!mojoImage.is_null()) 105 if (!mojoImage.is_null())
108 mojoMetadata->artwork.append(std::move(mojoImage)); 106 mojoMetadata->artwork.append(std::move(mojoImage));
109 if (mojoMetadata->artwork.size() == kMaxNumberOfMediaImages) { 107 if (mojoMetadata->artwork.size() == kMaxNumberOfMediaImages) {
110 context->addConsoleMessage(ConsoleMessage::create( 108 context->addConsoleMessage(ConsoleMessage::create(
111 JSMessageSource, WarningMessageLevel, 109 JSMessageSource, WarningMessageLevel,
112 "The number of MediaImage sizes exceeds the upper limit. " 110 "The number of MediaImage sizes exceeds the upper limit. "
113 "All remaining MediaImage will be ignored")); 111 "All remaining MediaImage will be ignored"));
114 break; 112 break;
115 } 113 }
116 } 114 }
117 return mojoMetadata; 115 return mojoMetadata;
118 } 116 }
119 117
120 } // namespace blink 118 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698