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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/network/NetworkUtils.cpp
diff --git a/third_party/WebKit/Source/platform/network/NetworkUtils.cpp b/third_party/WebKit/Source/platform/network/NetworkUtils.cpp
index ec49e5c3d93895bd2ef91c63c55c8e3093611b31..87c92412ed501aad1ef5f93a39d460f4128b3631 100644
--- a/third_party/WebKit/Source/platform/network/NetworkUtils.cpp
+++ b/third_party/WebKit/Source/platform/network/NetworkUtils.cpp
@@ -11,7 +11,9 @@
#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "net/base/url_util.h"
#include "net/http/http_response_headers.h"
+#include "net/url_request/url_request_data_job.h"
#include "platform/SharedBuffer.h"
+#include "platform/loader/fetch/ResourceResponse.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/URLConversion.h"
#include "public/platform/WebString.h"
@@ -63,19 +65,43 @@ String getDomainAndRegistry(const String& host, PrivateRegistryFilter filter) {
}
PassRefPtr<SharedBuffer> parseDataURL(const KURL& url,
- AtomicString& mimetype,
- AtomicString& charset) {
+ ResourceResponse& response) {
+ // The following code contains duplication of GetInfoFromDataURL() and
+ // WebURLLoaderImpl::PopulateURLResponse() in
+ // content/child/web_url_loader_impl.cc. Merge them once content/child is
+ // moved to platform/.
std::string utf8MimeType;
std::string utf8Charset;
- std::string data;
- if (net::DataURL::Parse(WebStringToGURL(url.getString()), &utf8MimeType,
- &utf8Charset, &data) &&
- mime_util::IsSupportedMimeType(utf8MimeType)) {
- mimetype = WebString::fromUTF8(utf8MimeType);
- charset = WebString::fromUTF8(utf8Charset);
- return SharedBuffer::create(data.data(), data.size());
+ std::string dataString;
+ scoped_refptr<net::HttpResponseHeaders> headers(
+ new net::HttpResponseHeaders(std::string()));
+
+ int result = net::URLRequestDataJob::BuildResponse(
+ WebStringToGURL(url.getString()), &utf8MimeType, &utf8Charset,
+ &dataString, headers.get());
+ if (result != net::OK)
+ return nullptr;
+
+ if (!mime_util::IsSupportedMimeType(utf8MimeType))
+ return nullptr;
+
+ RefPtr<SharedBuffer> data =
+ SharedBuffer::create(dataString.data(), dataString.size());
+ response.setHTTPStatusCode(200);
+ response.setHTTPStatusText("OK");
+ response.setURL(url);
+ response.setMimeType(WebString::fromUTF8(utf8MimeType));
+ response.setExpectedContentLength(data->size());
+ response.setTextEncodingName(WebString::fromUTF8(utf8Charset));
+
+ size_t iter = 0;
+ std::string name;
+ std::string value;
+ while (headers->EnumerateHeaderLines(&iter, &name, &value)) {
+ response.addHTTPHeaderField(WebString::fromLatin1(name),
+ WebString::fromLatin1(value));
}
- return nullptr;
+ 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.
}
bool isRedirectResponseCode(int responseCode) {

Powered by Google App Engine
This is Rietveld 408576698