Commit d16ec600 authored by asanka@chromium.org's avatar asanka@chromium.org

Allow filename suggestions via a[download] for data URIs

Currently filename suggestions specified via a[download] are only honored if
the interface origin is allowed to read content retrieved from the target
resource origin. An embedder may enforce additional restrictions such as only
honoring the suggested name if there are no cross-origin redirects encountered
while fetching the resource.

The suggested filename determination algorithm at
http://www.w3.org/TR/html5/links.html#downloading-resources allows an exception
for data URIs. They should be considered same-origin as the interface. This
isn't currently the case since the origin of a data URI is considerd to be
unique and is not same-origin with anything since they lack a server-based
naming authority.

This CL implements the exception for data URIs so that they are considered
same-origin as their containing document for the purpose of handling the
suggested filename for a[download].

BUG=373182

Review URL: https://codereview.chromium.org/300543002

git-svn-id: svn://svn.chromium.org/blink/trunk@176085 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ee281f7c
Downloading URL with suggested filename "foo.pdf"
Tests that a suggested filename on a download attribute is allowed if the link is a data URL.
The suggested filename at the top should be foo.pdf.
<!DOCTYPE html>
<html>
<head>
<script src="/js-test-resources/js-test.js"></script>
<script type='text/javascript'>
if (window.testRunner) {
// The test will end when loadURLExternally() is invoked.
testRunner.waitUntilExternalURLLoad();
}
</script>
</head>
<body>
<p>
Tests that a suggested filename on a download attribute is allowed if
<a id="dl" href="data:application/octet-stream,Hello" download="foo.pdf">the link</a> is a data URL.
<p>
The suggested filename at the top should be foo.pdf.
<script>
function click(elmt)
{
if (!window.eventSender) {
return;
}
eventSender.mouseMoveTo(elmt.offsetLeft + 5, elmt.offsetTop + 5);
eventSender.mouseDown();
eventSender.mouseUp();
}
function runTest()
{
var link = document.getElementById("dl");
click(link);
}
runTest();
</script>
</body>
</html>
......@@ -384,7 +384,7 @@ void HTMLAnchorElement::handleClick(Event* event)
request.setHTTPReferrer(Referrer(referrer, document().referrerPolicy()));
}
bool isSameOrigin = document().securityOrigin()->canRequest(completedURL);
bool isSameOrigin = completedURL.protocolIsData() || document().securityOrigin()->canRequest(completedURL);
const AtomicString& suggestedName = (isSameOrigin ? fastGetAttribute(downloadAttr) : nullAtom);
frame->loader().client()->loadURLExternally(request, NavigationPolicyDownload, suggestedName);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment