Skip to content

Commit

Permalink
Add signed_exchange_utils::ShouldAdvertiseAcceptHeader
Browse files Browse the repository at this point in the history
This CL introduces signed_exchange_utils::ShouldAdvertiseAcceptHeader,
which can be used to query if a origin should be sent
"Accept: application/signed-exchange" header.

The origins list is managed by the feature "SignedHTTPExchangeAcceptHeader",
and a Finch param attached to it.

Note: Use the below args to test this:
--enable-features=SignedHTTPExchangeAcceptHeader<AcceptHeaderStudy
--force-fieldtrials=AcceptHeaderStudy/Group
--force-fieldtrial-params=AcceptHeaderStudy.Group:OriginsList/www%2eexample%2ecom

The subsequent CL will actually plumb this to the navigation loaders.

Bug: 887201
Change-Id: I06cc991e396b28ab0d02e2bbba3a117fd53d4fe5
Reviewed-on: https://chromium-review.googlesource.com/1235473
Reviewed-by: Tsuyoshi Horo <horo@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Kunihiko Sakamoto <ksakamoto@chromium.org>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594572}
  • Loading branch information
nyaxt authored and Commit Bot committed Sep 27, 2018
1 parent ec2de78 commit 17843f4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
29 changes: 29 additions & 0 deletions content/browser/web_package/signed_exchange_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
#include "content/browser/web_package/signed_exchange_utils.h"

#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/no_destructor.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "content/browser/web_package/origins_list.h"
#include "content/browser/web_package/signed_exchange_devtools_proxy.h"
#include "content/browser/web_package/signed_exchange_error.h"
#include "content/browser/web_package/signed_exchange_request_handler.h"
Expand All @@ -30,6 +34,31 @@ void ReportErrorAndTraceEvent(
devtools_proxy->ReportError(error_message, std::move(error_field));
}

namespace {

OriginsList CreateAdvertiseAcceptHeaderOriginsList() {
std::string param = base::GetFieldTrialParamValueByFeature(
features::kSignedHTTPExchangeAcceptHeader,
features::kSignedHTTPExchangeAcceptHeaderFieldTrialParamName);
if (param.empty())
DLOG(ERROR) << "The Accept-SXG origins list param is empty.";

return OriginsList(param);
}

} // namespace

bool ShouldAdvertiseAcceptHeader(const url::Origin& origin) {
if (!base::FeatureList::IsEnabled(features::kSignedHTTPExchangeAcceptHeader))
return false;

// |origins_list| is initialized in a thread-safe manner.
// Querying OriginsList::Match() should be safe since it's read-only access.
static base::NoDestructor<OriginsList> origins_list(
CreateAdvertiseAcceptHeaderOriginsList());
return origins_list->Match(origin);
}

bool IsSignedExchangeHandlingEnabled() {
return base::FeatureList::IsEnabled(features::kSignedHTTPExchange) ||
base::FeatureList::IsEnabled(features::kSignedHTTPExchangeOriginTrial);
Expand Down
9 changes: 9 additions & 0 deletions content/browser/web_package/signed_exchange_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
#include <string>

#include "base/optional.h"
#include "content/browser/web_package/origins_list.h"
#include "content/browser/web_package/signed_exchange_consts.h"
#include "content/browser/web_package/signed_exchange_error.h"
#include "content/common/content_export.h"

class GURL;

namespace url {
class Origin;
} // namespace url

namespace network {
struct ResourceResponseHead;
} // namespace network
Expand All @@ -33,6 +38,10 @@ void ReportErrorAndTraceEvent(
base::Optional<SignedExchangeError::FieldIndexPair> error_field =
base::nullopt);

// Returns true if Accept headers should be sent with
// "application/signed-exchange".
bool ShouldAdvertiseAcceptHeader(const url::Origin& origin);

// Returns true when SignedHTTPExchange feature or SignedHTTPExchangeOriginTrial
// feature is enabled.
bool IsSignedExchangeHandlingEnabled();
Expand Down
7 changes: 7 additions & 0 deletions content/public/common/content_features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,13 @@ const base::Feature kSharedArrayBuffer {
const base::Feature kSignedHTTPExchange{"SignedHTTPExchange",
base::FEATURE_DISABLED_BY_DEFAULT};

// Send "Accept: application/signed-exchange" header to origins who opt-in.
const base::Feature kSignedHTTPExchangeAcceptHeader{
"SignedHTTPExchangeAcceptHeader", base::FEATURE_DISABLED_BY_DEFAULT};
// Field trial parameter containing the list of origins that opted-in to receive
// "Accept: application/signed-exchange" header.
const char kSignedHTTPExchangeAcceptHeaderFieldTrialParamName[] = "OriginsList";

// Origin Trial of Origin-Signed HTTP Exchanges (for WebPackage Loading)
const base::Feature kSignedHTTPExchangeOriginTrial{
"SignedHTTPExchangeOriginTrial", base::FEATURE_DISABLED_BY_DEFAULT};
Expand Down
3 changes: 3 additions & 0 deletions content/public/common/content_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ CONTENT_EXPORT extern const base::Feature kServiceWorkerPaymentApps;
CONTENT_EXPORT extern const base::Feature kServiceWorkerScriptFullCodeCache;
CONTENT_EXPORT extern const base::Feature kSharedArrayBuffer;
CONTENT_EXPORT extern const base::Feature kSignedHTTPExchange;
CONTENT_EXPORT extern const base::Feature kSignedHTTPExchangeAcceptHeader;
CONTENT_EXPORT extern const char
kSignedHTTPExchangeAcceptHeaderFieldTrialParamName[];
CONTENT_EXPORT extern const base::Feature kSignedHTTPExchangeOriginTrial;
CONTENT_EXPORT extern const base::Feature kSpareRendererForSitePerProcess;
CONTENT_EXPORT extern const base::Feature kTimerThrottlingForHiddenFrames;
Expand Down

0 comments on commit 17843f4

Please sign in to comment.