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

Side by Side Diff: third_party/WebKit/Source/platform/network/NetworkUtils.cpp

Issue 2766583002: Set the same headers for data URLs in WebURLLoaderImpl and ResourceFetcher (Closed)
Patch Set: Rebase Created 3 years, 9 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 "platform/network/NetworkUtils.h" 5 #include "platform/network/NetworkUtils.h"
6 6
7 #include "components/mime_util/mime_util.h" 7 #include "components/mime_util/mime_util.h"
8 #include "net/base/data_url.h" 8 #include "net/base/data_url.h"
9 #include "net/base/ip_address.h" 9 #include "net/base/ip_address.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 11 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
12 #include "net/base/url_util.h" 12 #include "net/base/url_util.h"
13 #include "net/http/http_response_headers.h" 13 #include "net/http/http_response_headers.h"
14 #include "net/url_request/url_request_data_job.h"
14 #include "platform/SharedBuffer.h" 15 #include "platform/SharedBuffer.h"
16 #include "platform/loader/fetch/ResourceResponse.h"
15 #include "platform/weborigin/KURL.h" 17 #include "platform/weborigin/KURL.h"
16 #include "public/platform/URLConversion.h" 18 #include "public/platform/URLConversion.h"
17 #include "public/platform/WebString.h" 19 #include "public/platform/WebString.h"
18 #include "url/gurl.h" 20 #include "url/gurl.h"
19 #include "wtf/text/StringUTF8Adaptor.h" 21 #include "wtf/text/StringUTF8Adaptor.h"
20 #include "wtf/text/WTFString.h" 22 #include "wtf/text/WTFString.h"
21 23
22 namespace { 24 namespace {
23 25
24 net::registry_controlled_domains::PrivateRegistryFilter 26 net::registry_controlled_domains::PrivateRegistryFilter
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 58 }
57 59
58 String getDomainAndRegistry(const String& host, PrivateRegistryFilter filter) { 60 String getDomainAndRegistry(const String& host, PrivateRegistryFilter filter) {
59 StringUTF8Adaptor hostUtf8(host); 61 StringUTF8Adaptor hostUtf8(host);
60 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry( 62 std::string domain = net::registry_controlled_domains::GetDomainAndRegistry(
61 hostUtf8.asStringPiece(), getNetPrivateRegistryFilter(filter)); 63 hostUtf8.asStringPiece(), getNetPrivateRegistryFilter(filter));
62 return String(domain.data(), domain.length()); 64 return String(domain.data(), domain.length());
63 } 65 }
64 66
65 PassRefPtr<SharedBuffer> parseDataURL(const KURL& url, 67 PassRefPtr<SharedBuffer> parseDataURL(const KURL& url,
66 AtomicString& mimetype, 68 ResourceResponse& response) {
67 AtomicString& charset) { 69 // The following code contains duplication of GetInfoFromDataURL() and
70 // WebURLLoaderImpl::PopulateURLResponse() in
71 // content/child/web_url_loader_impl.cc. Merge them once content/child is
72 // moved to platform/.
68 std::string utf8MimeType; 73 std::string utf8MimeType;
69 std::string utf8Charset; 74 std::string utf8Charset;
70 std::string data; 75 std::string dataString;
71 if (net::DataURL::Parse(WebStringToGURL(url.getString()), &utf8MimeType, 76 scoped_refptr<net::HttpResponseHeaders> headers(
72 &utf8Charset, &data) && 77 new net::HttpResponseHeaders(std::string()));
73 mime_util::IsSupportedMimeType(utf8MimeType)) { 78
74 mimetype = WebString::fromUTF8(utf8MimeType); 79 int result = net::URLRequestDataJob::BuildResponse(
75 charset = WebString::fromUTF8(utf8Charset); 80 WebStringToGURL(url.getString()), &utf8MimeType, &utf8Charset,
76 return SharedBuffer::create(data.data(), data.size()); 81 &dataString, headers.get());
82 if (result != net::OK)
83 return nullptr;
84
85 if (!mime_util::IsSupportedMimeType(utf8MimeType))
86 return nullptr;
87
88 RefPtr<SharedBuffer> data =
89 SharedBuffer::create(dataString.data(), dataString.size());
90 response.setHTTPStatusCode(200);
91 response.setHTTPStatusText("OK");
92 response.setURL(url);
93 response.setMimeType(WebString::fromUTF8(utf8MimeType));
94 response.setExpectedContentLength(data->size());
95 response.setTextEncodingName(WebString::fromUTF8(utf8Charset));
96
97 size_t iter = 0;
98 std::string name;
99 std::string value;
100 while (headers->EnumerateHeaderLines(&iter, &name, &value)) {
101 response.addHTTPHeaderField(WebString::fromLatin1(name),
102 WebString::fromLatin1(value));
77 } 103 }
78 return nullptr; 104 return std::move(data);
kouhei (in TOK) 2017/03/23 00:37:15 I don't think std::move is needed here, as we can
hiroshige 2017/03/23 03:22:23 Done.
79 } 105 }
80 106
81 bool isRedirectResponseCode(int responseCode) { 107 bool isRedirectResponseCode(int responseCode) {
82 return net::HttpResponseHeaders::IsRedirectResponseCode(responseCode); 108 return net::HttpResponseHeaders::IsRedirectResponseCode(responseCode);
83 } 109 }
84 110
85 } // NetworkUtils 111 } // NetworkUtils
86 112
87 } // namespace blink 113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698