Commit a397826c authored by yhirano's avatar yhirano Committed by Commit bot

Use net::HttpContentTypeDisposition in blink

This CL replaces blink::GetContentDispositionType implementation by
net::HttpContentTypeDisposition. There are some behavior differences between
these two implementations, but because the former is used only to see if
the disposition type is attachement, there is only one difference that matters.
The former returns kAttachement for empty content disposition type (e.g.,
";foo"), but the latter returns kInline. It looks the former is intended to
return kNone, but it returns kAttachment due to misuse of confusing
WTFString::Split interface.

Hence this CL adds IsContentDispositionAttachment and makes it return false
when a value with an empty content disposition type is given.

BUG=696967

Review-Url: https://codereview.chromium.org/2844353003
Cr-Commit-Position: refs/heads/master@{#467977}
parent 93f4a877
<!doctype html>
<html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
async_test(t => {
const url = 'resources/empty-content-disposition-type.php';
const iframe = document.createElement('iframe');
iframe.addEventListener('load', t.step_func(() => {
assert_equals(iframe.contentDocument.body.textContent, 'hello, world\n');
t.done();
}));
iframe.src = url;
document.body.appendChild(iframe);
}, 'load a page with an invalid content-disposition-type');
</script>
</body>
<?php
header('Content-Type: text/plain');
header('Content-Disposition: ;foo');
echo "hello, world";
?>
......@@ -507,8 +507,8 @@ bool DocumentLoader::ShouldContinueForResponse() const {
return false;
}
if (GetContentDispositionType(response_.HttpHeaderField(
HTTPNames::Content_Disposition)) == kContentDispositionAttachment) {
if (IsContentDispositionAttachment(
response_.HttpHeaderField(HTTPNames::Content_Disposition))) {
// The server wants us to download instead of replacing the page contents.
// Downloading is handled by the embedder, but we still get the initial
// response so that we can ignore it and clean up properly.
......
......@@ -32,6 +32,7 @@
#include "platform/network/HTTPParsers.h"
#include "net/http/http_content_disposition.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_util.h"
#include "platform/json/JSONParser.h"
......@@ -267,37 +268,10 @@ bool IsValidHTTPToken(const String& characters) {
return true;
}
ContentDispositionType GetContentDispositionType(
const String& content_disposition) {
if (content_disposition.IsEmpty())
return kContentDispositionNone;
Vector<String> parameters;
content_disposition.Split(';', parameters);
if (parameters.IsEmpty())
return kContentDispositionNone;
String disposition_type = parameters[0];
disposition_type.StripWhiteSpace();
if (DeprecatedEqualIgnoringCase(disposition_type, "inline"))
return kContentDispositionInline;
// Some broken sites just send bogus headers like
//
// Content-Disposition: ; filename="file"
// Content-Disposition: filename="file"
// Content-Disposition: name="file"
//
// without a disposition token... screen those out.
if (!IsValidHTTPToken(disposition_type))
return kContentDispositionNone;
// We have a content-disposition of "attachment" or unknown.
// RFC 2183, section 2.8 says that an unknown disposition
// value should be treated as "attachment"
return kContentDispositionAttachment;
bool IsContentDispositionAttachment(const String& content_disposition) {
CString cstring(content_disposition.Utf8());
std::string string(cstring.data(), cstring.length());
return net::HttpContentDisposition(string, std::string()).is_attachment();
}
bool ParseHTTPRefresh(const String& refresh,
......
......@@ -47,13 +47,6 @@ namespace blink {
class Suborigin;
class ResourceResponse;
typedef enum {
kContentDispositionNone,
kContentDispositionInline,
kContentDispositionAttachment,
kContentDispositionOther
} ContentDispositionType;
enum ContentTypeOptionsDisposition {
kContentTypeOptionsNone,
kContentTypeOptionsNosniff
......@@ -88,7 +81,7 @@ struct CacheControlHeader {
max_age(0.0) {}
};
PLATFORM_EXPORT ContentDispositionType GetContentDispositionType(const String&);
PLATFORM_EXPORT bool IsContentDispositionAttachment(const String&);
PLATFORM_EXPORT bool IsValidHTTPHeaderValue(const String&);
PLATFORM_EXPORT bool IsValidHTTPFieldContentRFC7230(const String&);
// Checks whether the given string conforms to the |token| ABNF production
......
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