Changeset 171941 in webkit
- Timestamp:
- Aug 1, 2014, 12:08:59 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r171916 r171941 1 2014-07-30 Myles C. Maxfield <mmaxfield@apple.com> 2 3 URLs in srcset attributes are not made absolute upon copy and paste 4 https://bugs.webkit.org/show_bug.cgi?id=135448 5 6 Reviewed by Ryosuke Niwa. 7 8 Copy and paste a srcset image with relative URLs, and make sure that the 9 pasted srcset attribute doesn't match what it was before. I can't actually 10 dump the new srcset because it will include a full path of the file on the 11 user's system, and would therefore be machine-specific. 12 13 * editing/pasteboard/img-srcset-copy-paste-canonicalization-expected.txt: 14 * editing/pasteboard/img-srcset-copy-paste-canonicalization.html: Paste and check. 15 * editing/pasteboard/resources/img-srcset-copy-paste-canonicalization-iframe.html: 16 This has to be an iframe because we don't perform any url canonicalization if we 17 are copying and pasting from a document into itself. 18 1 19 2014-08-01 Michał Pakuła vel Rutka <m.pakula@samsung.com> 2 20 -
trunk/Source/WebCore/ChangeLog
r171939 r171941 1 2014-07-30 Myles C. Maxfield <mmaxfield@apple.com> 2 3 URLs in srcset attributes are not made absolute upon copy and paste 4 https://bugs.webkit.org/show_bug.cgi?id=135448 5 6 Reviewed by Ryosuke Niwa. 7 8 When pasting, canonicalize URLs in srcset the same way we do with src. 9 10 Test: editing/pasteboard/img-srcset-copy-paste-canonicalization.html 11 12 * dom/Element.cpp: 13 (WebCore::Element::completeURLsInAttributeValue): Initial implemention, moved from markup.cpp. 14 * dom/Element.h: 15 (WebCore::Element::attributeContainsURL): New function for completeURLs to call. 16 (WebCore::Element::completeURLsInAttributeValue): Only called if attributeContainsURL returns 17 true. Default implementation simply calls isURLAttribute(). 18 * editing/markup.cpp: 19 (WebCore::completeURLs): Call attributeContainsURL() and completeURLsInAttributeValue() to 20 complete the URL, so nodes can perform their own behavior. 21 * html/HTMLImageElement.cpp: 22 (WebCore::HTMLImageElement::attributeContainsURL): Return true for srcset. 23 (WebCore::HTMLImageElement::completeUrlAttributeValue): Use our existing srcset parser to 24 parse the srcset attribute, then use its output to canonicalize URLs, and build it back up 25 into a string. 26 * html/HTMLImageElement.h: 27 (WebCore::HTMLImageElement::attributeContainsURL): 28 (WebCore::HTMLImageElement::completeUrlAttributeValue): 29 * html/parser/HTMLSrcsetParser.cpp: Make parseImageCandidatesFromSrcsetAttribute() public 30 and change its signature to return its result. 31 (WebCore::parseImageCandidatesFromSrcsetAttribute): 32 * html/parser/HTMLSrcsetParser.h: Ditto. 33 1 34 2014-07-31 Andreas Kling <akling@apple.com> 2 35 -
trunk/Source/WebCore/dom/Element.cpp
r171014 r171941 3023 3023 } 3024 3024 3025 String Element::completeURLsInAttributeValue(const URL& base, const Attribute& attribute) const 3026 { 3027 return URL(base, attribute.value()).string(); 3028 } 3029 3025 3030 } // namespace WebCore -
trunk/Source/WebCore/dom/Element.h
r171014 r171941 394 394 395 395 virtual bool isURLAttribute(const Attribute&) const { return false; } 396 virtual bool attributeContainsURL(const Attribute& attribute) const { return isURLAttribute(attribute); } 397 virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const; 396 398 virtual bool isHTMLContentAttribute(const Attribute&) const { return false; } 397 399 -
trunk/Source/WebCore/editing/markup.cpp
r166150 r171941 105 105 continue; 106 106 for (const Attribute& attribute : element.attributesIterator()) { 107 if (element. isURLAttribute(attribute) && !attribute.value().isEmpty())108 changes.append(AttributeChange(&element, attribute.name(), URL(parsedBaseURL, attribute.value()).string()));107 if (element.attributeContainsURL(attribute) && !attribute.value().isEmpty()) 108 changes.append(AttributeChange(&element, attribute.name(), element.completeURLsInAttributeValue(parsedBaseURL, attribute))); 109 109 } 110 110 } -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r170774 r171941 40 40 #include "ShadowRoot.h" 41 41 #include "SourceSizeList.h" 42 #include <wtf/text/StringBuilder.h> 42 43 43 44 #if ENABLE(SERVICE_CONTROLS) … … 354 355 } 355 356 357 bool HTMLImageElement::attributeContainsURL(const Attribute& attribute) const 358 { 359 return attribute.name() == srcsetAttr 360 || HTMLElement::attributeContainsURL(attribute); 361 } 362 363 String HTMLImageElement::completeURLsInAttributeValue(const URL& base, const Attribute& attribute) const 364 { 365 if (attribute.name() == srcsetAttr) { 366 Vector<ImageCandidate> imageCandidates = parseImageCandidatesFromSrcsetAttribute(StringView(attribute.value())); 367 StringBuilder result; 368 for (const auto& candidate : imageCandidates) { 369 if (&candidate != &imageCandidates[0]) 370 result.appendLiteral(", "); 371 result.append(URL(base, candidate.string.toString()).string()); 372 if (candidate.density != UninitializedDescriptor) { 373 result.append(' '); 374 result.appendNumber(candidate.density); 375 result.append('x'); 376 } 377 if (candidate.resourceWidth != UninitializedDescriptor) { 378 result.append(' '); 379 result.appendNumber(candidate.resourceWidth); 380 result.append('x'); 381 } 382 } 383 return result.toString(); 384 } 385 return HTMLElement::completeURLsInAttributeValue(base, attribute); 386 } 387 356 388 bool HTMLImageElement::matchesLowercasedUsemap(const AtomicStringImpl& name) const 357 389 { -
trunk/Source/WebCore/html/HTMLImageElement.h
r170576 r171941 109 109 110 110 virtual bool isURLAttribute(const Attribute&) const override; 111 virtual bool attributeContainsURL(const Attribute&) const override; 112 virtual String completeURLsInAttributeValue(const URL& base, const Attribute&) const override; 111 113 112 114 virtual bool draggable() const override; -
trunk/Source/WebCore/html/parser/HTMLSrcsetParser.cpp
r170576 r171941 163 163 // http://picture.responsiveimages.org/#parse-srcset-attr 164 164 template<typename CharType> 165 static void parseImageCandidatesFromSrcsetAttribute(const CharType* attributeStart, unsigned length, Vector<ImageCandidate>& imageCandidates) 166 { 165 static Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(const CharType* attributeStart, unsigned length) 166 { 167 Vector<ImageCandidate> imageCandidates; 168 167 169 const CharType* attributeEnd = attributeStart + length; 168 170 … … 208 210 // 11. Return to the step labeled splitting loop. 209 211 } 210 } 211 212 static void parseImageCandidatesFromSrcsetAttribute(StringView attribute, Vector<ImageCandidate>& imageCandidates) 212 return imageCandidates; 213 } 214 215 Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(StringView attribute) 213 216 { 214 217 // FIXME: We should consider replacing the direct pointers in the parsing process with StringView and positions. 215 218 if (attribute.is8Bit()) 216 parseImageCandidatesFromSrcsetAttribute<LChar>(attribute.characters8(), attribute.length(), imageCandidates);219 return parseImageCandidatesFromSrcsetAttribute<LChar>(attribute.characters8(), attribute.length()); 217 220 else 218 parseImageCandidatesFromSrcsetAttribute<UChar>(attribute.characters16(), attribute.length(), imageCandidates);221 return parseImageCandidatesFromSrcsetAttribute<UChar>(attribute.characters16(), attribute.length()); 219 222 } 220 223 … … 276 279 } 277 280 278 Vector<ImageCandidate> imageCandidates; 279 280 parseImageCandidatesFromSrcsetAttribute(StringView(srcsetAttribute), imageCandidates); 281 Vector<ImageCandidate> imageCandidates = parseImageCandidatesFromSrcsetAttribute(StringView(srcsetAttribute)); 281 282 282 283 if (!srcAttribute.isEmpty()) -
trunk/Source/WebCore/html/parser/HTMLSrcsetParser.h
r170576 r171941 105 105 ); 106 106 107 Vector<ImageCandidate> parseImageCandidatesFromSrcsetAttribute(StringView attribute); 108 107 109 } 108 110
Note:
See TracChangeset
for help on using the changeset viewer.