Skip to content

Commit

Permalink
Rename SignedExchangeHeader to SignedExchangeEnvelope.
Browse files Browse the repository at this point in the history
Previous name SignedExchangeHeader is confusing as it implies the reference
to the HTTP headers of the exchange, but it is not.
The "application/signed-exchange" format is commonly referred to envelope,
so this CL changes it to use the name instead.

Overview in the doc:
https://docs.google.com/document/d/1A458poqQsW8fD-Zur601-eokpxPA6zkUzTiquo2eI9E/edit

Bug: 847315
Change-Id: Ieb8e741af8f599456810910dece77c1e6531b568
Reviewed-on: https://chromium-review.googlesource.com/1075873
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562348}
  • Loading branch information
nyaxt authored and Commit Bot committed May 29, 2018
1 parent deb91bb commit f3419f0
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 115 deletions.
4 changes: 2 additions & 2 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1724,10 +1724,10 @@ jumbo_source_set("browser") {
"web_package/signed_exchange_consts.h",
"web_package/signed_exchange_devtools_proxy.cc",
"web_package/signed_exchange_devtools_proxy.h",
"web_package/signed_exchange_envelope.cc",
"web_package/signed_exchange_envelope.h",
"web_package/signed_exchange_handler.cc",
"web_package/signed_exchange_handler.h",
"web_package/signed_exchange_header.cc",
"web_package/signed_exchange_header.h",
"web_package/signed_exchange_signature_header_field.cc",
"web_package/signed_exchange_signature_header_field.h",
"web_package/signed_exchange_signature_verifier.cc",
Expand Down
4 changes: 2 additions & 2 deletions content/browser/devtools/protocol/network_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "content/browser/frame_host/navigation_request.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/storage_partition_impl.h"
#include "content/browser/web_package/signed_exchange_header.h"
#include "content/browser/web_package/signed_exchange_envelope.h"
#include "content/common/navigation_params.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -1651,7 +1651,7 @@ void NetworkHandler::OnSignedExchangeReceived(
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeHeader>& header,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<std::string>& error_messages) {
Expand Down
4 changes: 2 additions & 2 deletions content/browser/devtools/protocol/network_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InterceptionHandle;
class NavigationHandle;
class NavigationRequest;
class NavigationThrottle;
class SignedExchangeHeader;
class SignedExchangeEnvelope;
class StoragePartition;
struct GlobalRequestID;
struct InterceptedRequestInfo;
Expand Down Expand Up @@ -166,7 +166,7 @@ class NetworkHandler : public DevToolsDomainHandler,
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeHeader>& header,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<std::string>& error_messages);
Expand Down
4 changes: 2 additions & 2 deletions content/browser/devtools/render_frame_devtools_agent_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/site_instance_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/browser/web_package/signed_exchange_header.h"
#include "content/browser/web_package/signed_exchange_envelope.h"
#include "content/common/view_messages.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
Expand Down Expand Up @@ -230,7 +230,7 @@ void RenderFrameDevToolsAgentHost::OnSignedExchangeReceived(
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeHeader>& header,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<std::string>& error_messages) {
Expand Down
4 changes: 2 additions & 2 deletions content/browser/devtools/render_frame_devtools_agent_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class NavigationHandleImpl;
class NavigationRequest;
class NavigationThrottle;
class RenderFrameHostImpl;
class SignedExchangeHeader;
class SignedExchangeEnvelope;

class CONTENT_EXPORT RenderFrameDevToolsAgentHost
: public DevToolsAgentHostImpl,
Expand Down Expand Up @@ -102,7 +102,7 @@ class CONTENT_EXPORT RenderFrameDevToolsAgentHost
base::Optional<const base::UnguessableToken> devtools_navigation_token,
const GURL& outer_request_url,
const network::ResourceResponseHead& outer_response,
const base::Optional<SignedExchangeHeader>& header,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const base::Optional<net::SSLInfo>& ssl_info,
const std::vector<std::string>& error_messages);
Expand Down
6 changes: 3 additions & 3 deletions content/browser/web_package/signed_exchange_devtools_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "base/trace_event/trace_event.h"
#include "content/browser/devtools/render_frame_devtools_agent_host.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/web_package/signed_exchange_header.h"
#include "content/browser/web_package/signed_exchange_envelope.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
Expand Down Expand Up @@ -73,7 +73,7 @@ void OnSignedExchangeReceivedOnUI(
const GURL& outer_request_url,
scoped_refptr<network::ResourceResponse> outer_response,
base::Optional<const base::UnguessableToken> devtools_navigation_token,
base::Optional<SignedExchangeHeader> header,
base::Optional<SignedExchangeEnvelope> header,
scoped_refptr<net::X509Certificate> certificate,
base::Optional<net::SSLInfo> ssl_info,
std::vector<std::string> error_messages) {
Expand Down Expand Up @@ -162,7 +162,7 @@ void SignedExchangeDevToolsProxy::CertificateRequestCompleted(
}

void SignedExchangeDevToolsProxy::OnSignedExchangeReceived(
const base::Optional<SignedExchangeHeader>& header,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const net::SSLInfo* ssl_info) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
Expand Down
4 changes: 2 additions & 2 deletions content/browser/web_package/signed_exchange_devtools_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct URLLoaderCompletionStatus;
} // namespace network

namespace content {
class SignedExchangeHeader;
class SignedExchangeEnvelope;

// SignedExchangeDevToolsProxy lives on the IO thread and sends messages to
// DevTools via the UI thread to show signed exchange related information.
Expand Down Expand Up @@ -68,7 +68,7 @@ class CONTENT_EXPORT SignedExchangeDevToolsProxy {
const network::URLLoaderCompletionStatus& status);

void OnSignedExchangeReceived(
const base::Optional<SignedExchangeHeader>& header,
const base::Optional<SignedExchangeEnvelope>& header,
const scoped_refptr<net::X509Certificate>& certificate,
const net::SSLInfo* ssl_info);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/web_package/signed_exchange_header.h"
#include "content/browser/web_package/signed_exchange_envelope.h"

#include <utility>

Expand Down Expand Up @@ -68,7 +68,7 @@ bool IsMethodCacheable(base::StringPiece method) {
}

bool ParseRequestMap(const cbor::CBORValue& value,
SignedExchangeHeader* out,
SignedExchangeEnvelope* out,
SignedExchangeDevToolsProxy* devtools_proxy) {
TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("loading"), "ParseRequestMap");
if (!value.is_map()) {
Expand Down Expand Up @@ -165,7 +165,7 @@ bool ParseRequestMap(const cbor::CBORValue& value,
}

bool ParseResponseMap(const cbor::CBORValue& value,
SignedExchangeHeader* out,
SignedExchangeEnvelope* out,
SignedExchangeDevToolsProxy* devtools_proxy) {
TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("loading"), "ParseResponseMap");
if (!value.is_map()) {
Expand Down Expand Up @@ -259,34 +259,34 @@ bool ParseResponseMap(const cbor::CBORValue& value,

} // namespace

constexpr size_t SignedExchangeHeader::kEncodedLengthInBytes;
constexpr size_t SignedExchangeEnvelope::kEncodedLengthInBytes;

// static
size_t SignedExchangeHeader::ParseEncodedLength(
size_t SignedExchangeEnvelope::ParseEncodedLength(
base::span<const uint8_t> input) {
DCHECK_EQ(input.size(), SignedExchangeHeader::kEncodedLengthInBytes);
DCHECK_EQ(input.size(), SignedExchangeEnvelope::kEncodedLengthInBytes);
return static_cast<size_t>(input[0]) << 16 |
static_cast<size_t>(input[1]) << 8 | static_cast<size_t>(input[2]);
}

// static
base::Optional<SignedExchangeHeader> SignedExchangeHeader::Parse(
base::Optional<SignedExchangeEnvelope> SignedExchangeEnvelope::Parse(
base::span<const uint8_t> input,
SignedExchangeDevToolsProxy* devtools_proxy) {
TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("loading"),
"SignedExchangeHeader::Parse");
"SignedExchangeEnvelope::Parse");
cbor::CBORReader::DecoderError error;
base::Optional<cbor::CBORValue> value = cbor::CBORReader::Read(input, &error);
if (!value.has_value()) {
signed_exchange_utils::ReportErrorAndEndTraceEvent(
devtools_proxy, "SignedExchangeHeader::Parse",
devtools_proxy, "SignedExchangeEnvelope::Parse",
base::StringPrintf("Failed to decode CBORValue. CBOR error: %s",
cbor::CBORReader::ErrorCodeToString(error)));
return base::nullopt;
}
if (!value->is_array()) {
signed_exchange_utils::ReportErrorAndEndTraceEvent(
devtools_proxy, "SignedExchangeHeader::Parse",
devtools_proxy, "SignedExchangeEnvelope::Parse",
base::StringPrintf(
"Expected top-level CBORValue to be an array. Actual type : %d",
static_cast<int>(value->type())));
Expand All @@ -297,32 +297,32 @@ base::Optional<SignedExchangeHeader> SignedExchangeHeader::Parse(
constexpr size_t kTopLevelArraySize = 2;
if (top_level_array.size() != kTopLevelArraySize) {
signed_exchange_utils::ReportErrorAndEndTraceEvent(
devtools_proxy, "SignedExchangeHeader::Parse",
devtools_proxy, "SignedExchangeEnvelope::Parse",
base::StringPrintf("Expected top-level array to have 2 elements. "
"Actual element count: %" PRIuS,
top_level_array.size()));
return base::nullopt;
}

SignedExchangeHeader ret;
SignedExchangeEnvelope ret;

if (!ParseRequestMap(top_level_array[0], &ret, devtools_proxy)) {
signed_exchange_utils::ReportErrorAndEndTraceEvent(
devtools_proxy, "SignedExchangeHeader::Parse",
devtools_proxy, "SignedExchangeEnvelope::Parse",
"Failed to parse request map.");
return base::nullopt;
}
if (!ParseResponseMap(top_level_array[1], &ret, devtools_proxy)) {
signed_exchange_utils::ReportErrorAndEndTraceEvent(
devtools_proxy, "SignedExchangeHeader::Parse",
devtools_proxy, "SignedExchangeEnvelope::Parse",
"Failed to parse response map.");
return base::nullopt;
}

auto signature_iter = ret.response_headers_.find(kSignature);
if (signature_iter == ret.response_headers_.end()) {
signed_exchange_utils::ReportErrorAndEndTraceEvent(
devtools_proxy, "SignedExchangeHeader::Parse",
devtools_proxy, "SignedExchangeEnvelope::Parse",
"No signature header found.");
return base::nullopt;
}
Expand All @@ -332,28 +332,29 @@ base::Optional<SignedExchangeHeader> SignedExchangeHeader::Parse(
signature_iter->second, devtools_proxy);
if (!signatures || signatures->empty()) {
signed_exchange_utils::ReportErrorAndEndTraceEvent(
devtools_proxy, "SignedExchangeHeader::Parse",
devtools_proxy, "SignedExchangeEnvelope::Parse",
"Failed to parse signature.");
return base::nullopt;
}

ret.signature_ = (*signatures)[0];

TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("loading"),
"SignedExchangeHeader::Parse");
"SignedExchangeEnvelope::Parse");
return std::move(ret);
}

SignedExchangeHeader::SignedExchangeHeader() = default;
SignedExchangeHeader::SignedExchangeHeader(const SignedExchangeHeader&) =
SignedExchangeEnvelope::SignedExchangeEnvelope() = default;
SignedExchangeEnvelope::SignedExchangeEnvelope(const SignedExchangeEnvelope&) =
default;
SignedExchangeHeader::SignedExchangeHeader(SignedExchangeHeader&&) = default;
SignedExchangeHeader::~SignedExchangeHeader() = default;
SignedExchangeHeader& SignedExchangeHeader::operator=(SignedExchangeHeader&&) =
SignedExchangeEnvelope::SignedExchangeEnvelope(SignedExchangeEnvelope&&) =
default;
SignedExchangeEnvelope::~SignedExchangeEnvelope() = default;
SignedExchangeEnvelope& SignedExchangeEnvelope::operator=(
SignedExchangeEnvelope&&) = default;

bool SignedExchangeHeader::AddResponseHeader(base::StringPiece name,
base::StringPiece value) {
bool SignedExchangeEnvelope::AddResponseHeader(base::StringPiece name,
base::StringPiece value) {
std::string name_str = name.as_string();
DCHECK_EQ(name_str, base::ToLowerASCII(name))
<< "Response header names should be always lower-cased.";
Expand All @@ -365,7 +366,7 @@ bool SignedExchangeHeader::AddResponseHeader(base::StringPiece name,
}

scoped_refptr<net::HttpResponseHeaders>
SignedExchangeHeader::BuildHttpResponseHeaders() const {
SignedExchangeEnvelope::BuildHttpResponseHeaders() const {
std::string header_str("HTTP/1.1 ");
header_str.append(base::NumberToString(response_code()));
header_str.append(" ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_WEB_PACKAGE_SIGNED_EXCHANGE_HEADER_H_
#define CONTENT_BROWSER_WEB_PACKAGE_SIGNED_EXCHANGE_HEADER_H_
#ifndef CONTENT_BROWSER_WEB_PACKAGE_SIGNED_EXCHANGE_ENVELOPE_H_
#define CONTENT_BROWSER_WEB_PACKAGE_SIGNED_EXCHANGE_ENVELOPE_H_

#include <map>
#include <string>
Expand All @@ -23,10 +23,10 @@ namespace content {

class SignedExchangeDevToolsProxy;

// SignedExchangeHeader contains all information captured in signed exchange
// envelope but the payload.
// SignedExchangeEnvelope contains all information captured in
// the "application/signed-exchange" format but the payload.
// https://wicg.github.io/webpackage/draft-yasskin-httpbis-origin-signed-exchanges-impl.html
class CONTENT_EXPORT SignedExchangeHeader {
class CONTENT_EXPORT SignedExchangeEnvelope {
public:
static constexpr size_t kEncodedLengthInBytes = 3;
// Parse encoded length of the variable-length field in the signed exchange.
Expand All @@ -41,14 +41,14 @@ class CONTENT_EXPORT SignedExchangeHeader {
//
// This also performs the step 3 and 4 of "Cross-origin trust" validation.
// https://wicg.github.io/webpackage/draft-yasskin-httpbis-origin-signed-exchanges-impl.html#cross-origin-trust
static base::Optional<SignedExchangeHeader> Parse(
static base::Optional<SignedExchangeEnvelope> Parse(
base::span<const uint8_t> input,
SignedExchangeDevToolsProxy* devtools_proxy);
SignedExchangeHeader();
SignedExchangeHeader(const SignedExchangeHeader&);
SignedExchangeHeader(SignedExchangeHeader&&);
SignedExchangeHeader& operator=(SignedExchangeHeader&&);
~SignedExchangeHeader();
SignedExchangeEnvelope();
SignedExchangeEnvelope(const SignedExchangeEnvelope&);
SignedExchangeEnvelope(SignedExchangeEnvelope&&);
SignedExchangeEnvelope& operator=(SignedExchangeEnvelope&&);
~SignedExchangeEnvelope();

// AddResponseHeader returns false on duplicated keys. |name| must be
// lower-cased.
Expand Down Expand Up @@ -87,4 +87,4 @@ class CONTENT_EXPORT SignedExchangeHeader {

} // namespace content

#endif // CONTENT_BROWSER_WEB_PACKAGE_SIGNED_EXCHANGE_HEADER_H_
#endif // CONTENT_BROWSER_WEB_PACKAGE_SIGNED_EXCHANGE_ENVELOPE_H_
Loading

0 comments on commit f3419f0

Please sign in to comment.