Commit 4c4627d5 authored by Makoto Shimazu's avatar Makoto Shimazu Committed by Commit Bot

Make FetchAPIRequest::headers use case insensitive Compare

This is a prerequisite step for using FetchAPIRequest instead of
ServiceWorkerFetchRequest. ServiceWorkerFetchRequest has a member |headers| with
CaseInsensitiveCompare, but FetchAPIRequest has a member |headers| with the
default Compare function, so that this will cause behavior changes. This CL is
to change FetchAPIRequest::headers to use CaseInsensitiveCompare.

Bug: 908344, 789854
Change-Id: I8e1736d5c5ab2d291ff7c126afa0f4025983b84d
Reviewed-on: https://chromium-review.googlesource.com/c/1356463
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613074}
parent 98e53045
......@@ -170,7 +170,7 @@ BackgroundFetchTestBase::CreateRequestWithProvidedResponse(
request->method = method;
request->is_reload = false;
request->referrer = blink::mojom::Referrer::New();
request->headers = base::flat_map<std::string, std::string>();
request->headers = {};
return request;
}
......
......@@ -285,11 +285,12 @@ ServiceWorkerUtils::DeserializeFetchRequestFromString(
}
// static
//
// TODO(https://crbug.com/789854): Remove this function and replace
// ServiceWorkerHeadersMap with FetchAPIRequestHeadersMap.
ServiceWorkerHeaderMap ServiceWorkerUtils::ToServiceWorkerHeaderMap(
const RequestHeaderMap& header_) {
content::ServiceWorkerHeaderMap header;
header.insert(header_.begin(), header_.end());
return header;
const blink::FetchAPIRequestHeadersMap& headers) {
return {headers.begin(), headers.end()};
}
bool LongestScopeMatcher::MatchLongest(const GURL& scope) {
......
......@@ -17,6 +17,7 @@
#include "content/public/common/content_switches.h"
#include "content/public/common/resource_type.h"
#include "net/http/http_request_headers.h"
#include "third_party/blink/public/common/fetch/fetch_api_request_headers_map.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
#include "url/gurl.h"
......@@ -24,7 +25,6 @@ namespace content {
class ServiceWorkerUtils {
public:
using RequestHeaderMap = base::flat_map<std::string, std::string>;
static bool IsMainResourceType(ResourceType type) {
return IsResourceTypeFrame(type) || type == RESOURCE_TYPE_SHARED_WORKER;
......@@ -88,10 +88,8 @@ class ServiceWorkerUtils {
CONTENT_EXPORT static blink::mojom::FetchAPIRequestPtr
DeserializeFetchRequestFromString(const std::string& serialized);
// TODO(https://crbug.com/789854) Remove this once ServiceWorkerHeaderMap is
// removed.
CONTENT_EXPORT static content::ServiceWorkerHeaderMap
ToServiceWorkerHeaderMap(const RequestHeaderMap& header_);
ToServiceWorkerHeaderMap(const blink::FetchAPIRequestHeadersMap& headers);
private:
static bool IsPathRestrictionSatisfiedInternal(
......
......@@ -130,7 +130,7 @@ blink::mojom::FetchAPIRequestPtr CreateFetchAPIRequest(
auto request = blink::mojom::FetchAPIRequest::New();
request->url = url;
request->method = method;
request->headers = headers;
request->headers = {headers.begin(), headers.end()};
request->referrer = std::move(referrer);
request->is_reload = is_reload;
return request;
......
......@@ -45,6 +45,8 @@ source_set("headers") {
"experiments/memory_ablation_experiment.h",
"feature_policy/feature_policy.h",
"features.h",
"fetch/fetch_api_request_headers_map.h",
"fetch/fetch_api_request_headers_mojom_traits.h",
"frame/frame_owner_element_type.h",
"frame/frame_policy.h",
"frame/from_ad_state.h",
......
file://third_party/blink/renderer/core/fetch/OWNERS
per-file *_mojom_traits*.*=set noparent
per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS
per-file *.typemap=set noparent
per-file *.typemap=file://ipc/SECURITY_OWNERS
# TEAM: blink-network-dev@chromium.org
# COMPONENT: Blink>Network>FetchAPI
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
mojom = "//third_party/blink/public/mojom/fetch/fetch_api_request.mojom"
public_headers = [
"//base/containers/flat_map.h",
"//base/strings/string_util.h",
"//third_party/blink/public/common/fetch/fetch_api_request_headers_map.h",
]
traits_headers = [ "//third_party/blink/public/common/fetch/fetch_api_request_headers_mojom_traits.h" ]
type_mappings = [ "blink.mojom.FetchAPIRequestHeaders=blink::FetchAPIRequestHeadersMap[move_only]" ]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FETCH_FETCH_API_REQUEST_HEADERS_MAP_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FETCH_FETCH_API_REQUEST_HEADERS_MAP_H_
#include <string>
#include "base/containers/flat_map.h"
#include "base/strings/string_util.h"
namespace blink {
struct FetchAPIRequestHeadersCompare {
bool operator()(const std::string& lhs, const std::string& rhs) const {
return base::CompareCaseInsensitiveASCII(lhs, rhs) < 0;
}
};
using FetchAPIRequestHeadersMap =
base::flat_map<std::string, std::string, FetchAPIRequestHeadersCompare>;
} // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_FETCH_FETCH_API_REQUEST_HEADERS_MAP_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FETCH_FETCH_API_REQUEST_HEADERS_MOJOM_TRAITS_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_FETCH_FETCH_API_REQUEST_HEADERS_MOJOM_TRAITS_H_
#include <string>
#include "base/containers/flat_map.h"
#include "base/strings/string_util.h"
#include "third_party/blink/public/common/fetch/fetch_api_request_headers_map.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
namespace mojo {
template <>
struct StructTraits<blink::mojom::FetchAPIRequestHeadersDataView,
blink::FetchAPIRequestHeadersMap> {
static base::flat_map<std::string, std::string> headers(
const blink::FetchAPIRequestHeadersMap& in_headers) {
return {in_headers.begin(), in_headers.end()};
}
static bool Read(blink::mojom::FetchAPIRequestHeadersDataView in,
blink::FetchAPIRequestHeadersMap* out) {
return in.ReadHeaders(out);
}
};
} // namespace mojo
#endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_FETCH_FETCH_API_REQUEST_HEADERS_MOJOM_TRAITS_H_
......@@ -100,6 +100,12 @@ enum FetchImportanceMode {
kImportanceHigh
};
// Request headers for FetchAPIRequest. This is typemapped to a container with a
// case insensitive compare or hash function.
struct FetchAPIRequestHeaders {
map<string, string> headers;
};
struct FetchAPIRequest {
network.mojom.FetchRequestMode mode = network.mojom.FetchRequestMode.kNoCors;
bool is_main_resource_load = false;
......@@ -108,7 +114,7 @@ struct FetchAPIRequest {
network.mojom.RequestContextFrameType.kNone;
url.mojom.Url url;
string method;
map<string, string> headers;
FetchAPIRequestHeaders headers;
SerializedBlob? blob;
Referrer? referrer;
network.mojom.FetchCredentialsMode credentials_mode =
......
......@@ -5,6 +5,7 @@
# These are typemaps which are exposed by Blink to its embedder.
typemaps = [
"//third_party/blink/public/platform/content_security_policy.typemap",
"//third_party/blink/public/common/fetch/fetch_api_request_headers.typemap",
"//third_party/blink/public/common/indexeddb/indexed_db_default.typemap",
"//third_party/blink/public/common/manifest/display_mode.typemap",
"//third_party/blink/public/common/manifest/manifest.typemap",
......
......@@ -75,8 +75,10 @@ TEST(ServiceWorkerRequestTest, FromAndToFetchAPIRequest) {
fetch_api_request->cache_mode = kCacheMode;
fetch_api_request->redirect_mode = kRedirectMode;
fetch_api_request->request_context_type = kContext;
for (int i = 0; headers[i].key; ++i)
fetch_api_request->headers.insert(headers[i].key, headers[i].value);
for (int i = 0; headers[i].key; ++i) {
fetch_api_request->headers.insert(String(headers[i].key),
String(headers[i].value));
}
fetch_api_request->referrer =
mojom::blink::Referrer::New(KURL(NullURL(), referrer), kReferrerPolicy);
......
......@@ -1210,6 +1210,7 @@ jumbo_component("platform") {
"mojo/bluetooth_struct_traits.h",
"mojo/canonical_cookie_mojom_traits.cc",
"mojo/canonical_cookie_mojom_traits.h",
"mojo/fetch_api_request_headers_mojom_traits.h",
"mojo/interface_invalidator.cc",
"mojo/interface_invalidator.h",
"mojo/mojo_helper.h",
......
......@@ -15,6 +15,7 @@ typemaps = [
"//third_party/blink/renderer/platform/mojo/big_buffer.typemap",
"//third_party/blink/renderer/platform/mojo/big_string.typemap",
"//third_party/blink/renderer/platform/mojo/canonical_cookie.typemap",
"//third_party/blink/renderer/platform/mojo/fetch_api_request_headers.typemap",
"//third_party/blink/renderer/platform/mojo/file.typemap",
"//third_party/blink/renderer/platform/mojo/geometry.typemap",
"//third_party/blink/renderer/platform/mojo/kurl.typemap",
......
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
mojom = "//third_party/blink/public/mojom/fetch/fetch_api_request.mojom"
public_headers = [
"//third_party/blink/renderer/platform/wtf/hash_map.h",
"//third_party/blink/renderer/platform/wtf/text/string_hash.h",
"//third_party/blink/renderer/platform/wtf/text/wtf_string.h",
]
traits_headers = [ "//third_party/blink/renderer/platform/mojo/fetch_api_request_headers_mojom_traits.h" ]
deps = [
"//third_party/blink/renderer/platform/wtf",
]
type_mappings = [ "blink.mojom.FetchAPIRequestHeaders=WTF::HashMap<WTF::String, WTF::String, WTF::CaseFoldingHash>[move_only]" ]
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_FETCH_API_REQUEST_HEADERS_MOJOM_TRAITS_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_FETCH_API_REQUEST_HEADERS_MOJOM_TRAITS_H_
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/renderer/platform/wtf/hash_map.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace mojo {
template <>
struct StructTraits<
blink::mojom::blink::FetchAPIRequestHeaders::DataView,
WTF::HashMap<WTF::String, WTF::String, WTF::CaseFoldingHash>> {
static WTF::HashMap<WTF::String, WTF::String> headers(
const WTF::HashMap<WTF::String, WTF::String, WTF::CaseFoldingHash>&
input) {
WTF::HashMap<WTF::String, WTF::String> map;
for (const auto& tuple : input)
map.insert(tuple.key, tuple.value);
return map;
}
static bool Read(
blink::mojom::blink::FetchAPIRequestHeaders::DataView in,
WTF::HashMap<WTF::String, WTF::String, WTF::CaseFoldingHash>* out) {
WTF::HashMap<WTF::String, WTF::String> in_headers;
if (!in.ReadHeaders(&in_headers))
return false;
for (const auto& tuple : in_headers)
out->insert(tuple.key, tuple.value);
return true;
}
};
} // namespace mojo
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_MOJO_FETCH_API_REQUEST_HEADERS_MOJOM_TRAITS_H_
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