URLs in srcset attributes are not made absolute upon copy and paste
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Aug 2014 19:08:59 +0000 (19:08 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 1 Aug 2014 19:08:59 +0000 (19:08 +0000)
commitbc7140b42f63e84610b7ff82a3a48a9a338766c3
treead84ffc381d45224bae7053c1569412b1ac07195
parent3efbd7eac8f9995f8fa8dbb8b13c6753644e1003
URLs in srcset attributes are not made absolute upon copy and paste
https://bugs.webkit.org/show_bug.cgi?id=135448

Reviewed by Ryosuke Niwa.

Source/WebCore:
When pasting, canonicalize URLs in srcset the same way we do with src.

Test: editing/pasteboard/img-srcset-copy-paste-canonicalization.html

* dom/Element.cpp:
(WebCore::Element::completeURLsInAttributeValue): Initial implemention, moved from markup.cpp.
* dom/Element.h:
(WebCore::Element::attributeContainsURL): New function for completeURLs to call.
(WebCore::Element::completeURLsInAttributeValue): Only called if attributeContainsURL returns
true. Default implementation simply calls isURLAttribute().
* editing/markup.cpp:
(WebCore::completeURLs): Call attributeContainsURL() and completeURLsInAttributeValue() to
complete the URL, so nodes can perform their own behavior.
* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::attributeContainsURL): Return true for srcset.
(WebCore::HTMLImageElement::completeUrlAttributeValue): Use our existing srcset parser to
parse the srcset attribute, then use its output to canonicalize URLs, and build it back up
into a string.
* html/HTMLImageElement.h:
(WebCore::HTMLImageElement::attributeContainsURL):
(WebCore::HTMLImageElement::completeUrlAttributeValue):
* html/parser/HTMLSrcsetParser.cpp: Make parseImageCandidatesFromSrcsetAttribute() public
and change its signature to return its result.
(WebCore::parseImageCandidatesFromSrcsetAttribute):
* html/parser/HTMLSrcsetParser.h: Ditto.

LayoutTests:
Copy and paste a srcset image with relative URLs, and make sure that the
pasted srcset attribute doesn't match what it was before. I can't actually
dump the new srcset because it will include a full path of the file on the
user's system, and would therefore be machine-specific.

* editing/pasteboard/img-srcset-copy-paste-canonicalization-expected.txt:
* editing/pasteboard/img-srcset-copy-paste-canonicalization.html: Paste and check.
* editing/pasteboard/resources/img-srcset-copy-paste-canonicalization-iframe.html:
This has to be an iframe because we don't perform any url canonicalization if we
are copying and pasting from a document into itself.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@171941 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/editing/pasteboard/img-srcset-copy-paste-canonicalization-expected.txt [new file with mode: 0644]
LayoutTests/editing/pasteboard/img-srcset-copy-paste-canonicalization.html [new file with mode: 0644]
LayoutTests/editing/pasteboard/resources/img-srcset-copy-paste-canonicalization-iframe.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp
Source/WebCore/dom/Element.h
Source/WebCore/editing/markup.cpp
Source/WebCore/html/HTMLImageElement.cpp
Source/WebCore/html/HTMLImageElement.h
Source/WebCore/html/parser/HTMLSrcsetParser.cpp
Source/WebCore/html/parser/HTMLSrcsetParser.h