Skip to content

Commit

Permalink
Add WebBundle-related fields to network::mojom::URLRequest
Browse files Browse the repository at this point in the history
The WebBundle subresource loading POC CL is https://crrev.com/c/2503068.

This CL is a part of the POC, focusing only on updating
URLRequest and other related types so we can land this CL separately.

The design doc: https://docs.google.com/document/d/1_AqUBS4Gr45MPPtXGTUl7Q0DMIEw2zUeWO0zo6Sj0z4/edit#heading=h.5g0nmaz8ctg

This CL itself is no-op; no one is using the added fields.
Follow-up CLs will use the added fields.

Bug: 1082020
Change-Id: I0475aa37d935997bb9487a1705100c4fc6cc0fd9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2560526
Reviewed-by: Karan Bhatia <karandeepb@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kunihiko Sakamoto <ksakamoto@chromium.org>
Commit-Queue: Hayato Ito <hayato@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834125}
  • Loading branch information
hayatoito authored and Chromium LUCI CQ committed Dec 7, 2020
1 parent c3cf1bd commit 823e10f
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 3 deletions.
1 change: 1 addition & 0 deletions chrome/browser/predictors/loading_predictor_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ net::RequestPriority GetRequestPriority(
case network::mojom::RequestDestination::kSharedWorker:
case network::mojom::RequestDestination::kTrack:
case network::mojom::RequestDestination::kVideo:
case network::mojom::RequestDestination::kWebBundle:
case network::mojom::RequestDestination::kWorker:
case network::mojom::RequestDestination::kXslt:
return net::LOWEST;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ WebRequestResourceType ToWebRequestResourceType(
case network::mojom::RequestDestination::kAudioWorklet:
case network::mojom::RequestDestination::kManifest:
case network::mojom::RequestDestination::kPaintWorklet:
case network::mojom::RequestDestination::kWebBundle:
return WebRequestResourceType::OTHER;
}
NOTREACHED();
Expand Down
4 changes: 3 additions & 1 deletion services/network/public/cpp/request_destination.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const char* RequestDestinationToString(
return "track";
case network::mojom::RequestDestination::kVideo:
return "video";
case network::mojom::RequestDestination::kWebBundle:
return "webbundle";
case network::mojom::RequestDestination::kWorker:
return "worker";
case network::mojom::RequestDestination::kXslt:
Expand All @@ -56,4 +58,4 @@ const char* RequestDestinationToString(
return "empty";
}

} // namespace network
} // namespace network
53 changes: 52 additions & 1 deletion services/network/public/cpp/resource_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "net/base/load_flags.h"
#include "services/network/public/mojom/cookie_access_observer.mojom.h"
#include "services/network/public/mojom/web_bundle_handle.mojom.h"

namespace network {

Expand Down Expand Up @@ -34,6 +35,13 @@ bool OptionalTrustedParamsEqualsForTesting(
return (!lhs && !rhs) || (lhs && rhs && lhs->EqualsForTesting(*rhs));
}

bool OptionalWebBundleTokenParamsEqualsForTesting( // IN-TEST
const base::Optional<ResourceRequest::WebBundleTokenParams>& lhs,
const base::Optional<ResourceRequest::WebBundleTokenParams>& rhs) {
return (!lhs && !rhs) ||
(lhs && rhs && lhs->EqualsForTesting(*rhs)); // IN-TEST
}

} // namespace

ResourceRequest::TrustedParams::TrustedParams() = default;
Expand Down Expand Up @@ -63,6 +71,47 @@ bool ResourceRequest::TrustedParams::EqualsForTesting(
client_security_state == trusted_params.client_security_state;
}

ResourceRequest::WebBundleTokenParams::WebBundleTokenParams() = default;
ResourceRequest::WebBundleTokenParams::~WebBundleTokenParams() = default;

ResourceRequest::WebBundleTokenParams::WebBundleTokenParams(
const WebBundleTokenParams& other) {
*this = other;
}

ResourceRequest::WebBundleTokenParams&
ResourceRequest::WebBundleTokenParams::operator=(
const WebBundleTokenParams& other) {
token = other.token;
handle = other.CloneHandle();
return *this;
}

ResourceRequest::WebBundleTokenParams::WebBundleTokenParams(
const base::UnguessableToken& token,
mojo::PendingRemote<mojom::WebBundleHandle> handle)
: token(token), handle(std::move(handle)) {}

bool ResourceRequest::WebBundleTokenParams::EqualsForTesting(
const WebBundleTokenParams& other) const {
return token == other.token &&
((handle && other.handle) || (!handle && !other.handle));
}

mojo::PendingRemote<mojom::WebBundleHandle>
ResourceRequest::WebBundleTokenParams::CloneHandle() const {
if (!handle)
return mojo::NullRemote();
mojo::Remote<network::mojom::WebBundleHandle> remote(std::move(
const_cast<mojo::PendingRemote<network::mojom::WebBundleHandle>&>(
handle)));
mojo::PendingRemote<network::mojom::WebBundleHandle> new_remote;
remote->Clone(new_remote.InitWithNewPipeAndPassReceiver());
const_cast<mojo::PendingRemote<network::mojom::WebBundleHandle>&>(handle) =
remote.Unbind();
return new_remote;
}

ResourceRequest::ResourceRequest() {}
ResourceRequest::ResourceRequest(const ResourceRequest& request) = default;
ResourceRequest::~ResourceRequest() {}
Expand Down Expand Up @@ -122,7 +171,9 @@ bool ResourceRequest::EqualsForTesting(const ResourceRequest& request) const {
recursive_prefetch_token == request.recursive_prefetch_token &&
OptionalTrustedParamsEqualsForTesting(trusted_params,
request.trusted_params) &&
trust_token_params == request.trust_token_params;
trust_token_params == request.trust_token_params &&
OptionalWebBundleTokenParamsEqualsForTesting( // IN-TEST
web_bundle_token_params, request.web_bundle_token_params);
}

bool ResourceRequest::SendsCookies() const {
Expand Down
28 changes: 28 additions & 0 deletions services/network/public/cpp/resource_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "services/network/public/mojom/fetch_api.mojom-shared.h"
#include "services/network/public/mojom/referrer_policy.mojom-shared.h"
#include "services/network/public/mojom/trust_tokens.mojom.h"
#include "services/network/public/mojom/web_bundle_handle.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"

Expand Down Expand Up @@ -57,6 +58,32 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ResourceRequest {
mojom::ClientSecurityStatePtr client_security_state;
};

// Typemapped to network.mojom.WebBundleTokenParams, see comments there
// for details of each field.
struct COMPONENT_EXPORT(NETWORK_CPP_BASE) WebBundleTokenParams {
WebBundleTokenParams();
~WebBundleTokenParams();
// Define a non-default copy-constructor because:
// 1. network::ResourceRequest has a requirement that all of
// the members be trivially copyable.
// 2. mojo::PendingRemote is non-copyable.
WebBundleTokenParams(const WebBundleTokenParams& params);
WebBundleTokenParams& operator=(const WebBundleTokenParams& other);

WebBundleTokenParams(const base::UnguessableToken& token,
mojo::PendingRemote<mojom::WebBundleHandle> handle);

// For testing. Regarding the equality of |handle|, |this| equals |other| if
// both |handle| exists, or neither exists, because we cannot test the
// equality of two mojo handles.
bool EqualsForTesting(const WebBundleTokenParams& other) const;

mojo::PendingRemote<mojom::WebBundleHandle> CloneHandle() const;

base::UnguessableToken token;
mojo::PendingRemote<mojom::WebBundleHandle> handle;
};

ResourceRequest();
ResourceRequest(const ResourceRequest& request);
~ResourceRequest();
Expand Down Expand Up @@ -125,6 +152,7 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ResourceRequest {
// field trivially copyable; see OptionalTrustTokenParams's definition for
// more context.
OptionalTrustTokenParams trust_token_params;
base::Optional<WebBundleTokenParams> web_bundle_token_params;
};

// This does not accept |kDefault| referrer policy.
Expand Down
16 changes: 15 additions & 1 deletion services/network/public/cpp/url_request_mojom_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "services/network/public/mojom/cookie_access_observer.mojom.h"
#include "services/network/public/mojom/trust_tokens.mojom.h"
#include "services/network/public/mojom/url_loader.mojom-shared.h"
#include "services/network/public/mojom/web_bundle_handle.mojom.h"
#include "url/mojom/origin_mojom_traits.h"
#include "url/mojom/url_gurl_mojom_traits.h"

Expand Down Expand Up @@ -162,6 +163,18 @@ bool StructTraits<network::mojom::TrustedUrlRequestParamsDataView,
return true;
}

bool StructTraits<network::mojom::WebBundleTokenParamsDataView,
network::ResourceRequest::WebBundleTokenParams>::
Read(network::mojom::WebBundleTokenParamsDataView data,
network::ResourceRequest::WebBundleTokenParams* out) {
if (!data.ReadToken(&out->token)) {
return false;
}
out->handle = data.TakeWebBundleHandle<
mojo::PendingRemote<network::mojom::WebBundleHandle>>();
return true;
}

bool StructTraits<
network::mojom::URLRequestDataView,
network::ResourceRequest>::Read(network::mojom::URLRequestDataView data,
Expand Down Expand Up @@ -203,7 +216,8 @@ bool StructTraits<
!data.ReadFetchWindowId(&out->fetch_window_id) ||
!data.ReadDevtoolsRequestId(&out->devtools_request_id) ||
!data.ReadDevtoolsStackId(&out->devtools_stack_id) ||
!data.ReadRecursivePrefetchToken(&out->recursive_prefetch_token)) {
!data.ReadRecursivePrefetchToken(&out->recursive_prefetch_token) ||
!data.ReadWebBundleTokenParams(&out->web_bundle_token_params)) {
// Note that data.ReadTrustTokenParams is temporarily handled below.
return false;
}
Expand Down
26 changes: 26 additions & 0 deletions services/network/public/cpp/url_request_mojom_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "services/network/public/mojom/data_pipe_getter.mojom.h"
#include "services/network/public/mojom/trust_tokens.mojom.h"
#include "services/network/public/mojom/url_loader.mojom-shared.h"
#include "services/network/public/mojom/web_bundle_handle.mojom-shared.h"
#include "url/mojom/url_gurl_mojom_traits.h"

namespace mojo {
Expand Down Expand Up @@ -85,6 +86,27 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE)
network::ResourceRequest::TrustedParams* out);
};

template <>
struct COMPONENT_EXPORT(NETWORK_CPP_BASE)
StructTraits<network::mojom::WebBundleTokenParamsDataView,
network::ResourceRequest::WebBundleTokenParams> {
static const base::UnguessableToken& token(
const network::ResourceRequest::WebBundleTokenParams& params) {
return params.token;
}
static mojo::PendingRemote<network::mojom::WebBundleHandle> web_bundle_handle(
const network::ResourceRequest::WebBundleTokenParams& params) {
if (!params.handle)
return mojo::NullRemote();
return std::move(
const_cast<network::ResourceRequest::WebBundleTokenParams&>(params)
.handle);
}

static bool Read(network::mojom::WebBundleTokenParamsDataView data,
network::ResourceRequest::WebBundleTokenParams* out);
};

template <>
struct COMPONENT_EXPORT(NETWORK_CPP_BASE)
StructTraits<network::mojom::URLRequestDataView, network::ResourceRequest> {
Expand Down Expand Up @@ -264,6 +286,10 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE)
const network::ResourceRequest& request) {
return request.trust_token_params.as_ptr();
}
static const base::Optional<network::ResourceRequest::WebBundleTokenParams>&
web_bundle_token_params(const network::ResourceRequest& request) {
return request.web_bundle_token_params;
}

static bool Read(network::mojom::URLRequestDataView data,
network::ResourceRequest* out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "services/network/public/cpp/url_request_mojom_traits.h"

#include "base/optional.h"
#include "base/test/gtest_util.h"
#include "mojo/public/cpp/base/unguessable_token_mojom_traits.h"
#include "mojo/public/cpp/test_support/test_utils.h"
Expand Down Expand Up @@ -101,6 +102,10 @@ TEST(URLRequestMojomTraitsTest, Roundtrips_ResourceRequest) {
mojom::TrustTokenSignRequestData::kInclude;
original.trust_token_params->additional_signed_headers.push_back(
"some_header");
original.web_bundle_token_params =
base::make_optional(ResourceRequest::WebBundleTokenParams(
base::UnguessableToken::Create(),
mojo::PendingRemote<network::mojom::WebBundleHandle>()));

network::ResourceRequest copied;
EXPECT_TRUE(
Expand Down
4 changes: 4 additions & 0 deletions services/network/public/mojom/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ mojom("mojom") {
mojom = "network.mojom.TrustedUrlRequestParams"
cpp = "::network::ResourceRequest::TrustedParams"
},
{
mojom = "network.mojom.WebBundleTokenParams"
cpp = "::network::ResourceRequest::WebBundleTokenParams"
},
{
mojom = "network.mojom.URLRequest"
cpp = "::network::ResourceRequest"
Expand Down
8 changes: 8 additions & 0 deletions services/network/public/mojom/fetch_api.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ enum RequestDestination {
kStyle,
kTrack,
kVideo,
// kWebBundle represents a request for a WebBundle. A <link> element whose
// rel is "webbundle" uses this destination.
//
// e.g. <link rel=webbundle href="example.com/foo.wbn" resources="...">
//
// Fetch specifiction does not define this destination yet.
// Tracking issue: https://github.com/whatwg/fetch/issues/1120
kWebBundle,
kWorker,
kXslt,
};
Expand Down
16 changes: 16 additions & 0 deletions services/network/public/mojom/url_loader.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import "services/network/public/mojom/network_param.mojom";
import "services/network/public/mojom/site_for_cookies.mojom";
import "services/network/public/mojom/trust_tokens.mojom";
import "services/network/public/mojom/url_response_head.mojom";
import "services/network/public/mojom/web_bundle_handle.mojom";
import "url/mojom/origin.mojom";
import "url/mojom/url.mojom";

Expand Down Expand Up @@ -97,6 +98,17 @@ struct TrustedUrlRequestParams {
ClientSecurityState? client_security_state;
};

// Options that may only be set on URLRequests which are related to WebBundle.
struct WebBundleTokenParams {
// Unique token to identify a WebBundle.
mojo_base.mojom.UnguessableToken token;
// Handle for the WebBundle-related communication between the network process
// and the renderer. This is also used as a 'keep-alive' handle. We clean up
// the WebBundle data in the network process when the renderer-side endpoint
// is deleted.
pending_remote<WebBundleHandle>? web_bundle_handle;
};

// Typemapped to network::ResourceRequest.
struct URLRequest {
// The request method: GET, POST, etc.
Expand Down Expand Up @@ -402,6 +414,10 @@ struct URLRequest {
// and the request has set the trustToken Fetch parameter, denoting that it
// wishes to execute a Trust Tokens protocol operation.
TrustTokenParams? trust_token_params;

// Set for WebBundle related requests. See the comment of WebBundleTokenParams
// for details.
WebBundleTokenParams? web_bundle_token_params;
};

// URLRequestBody represents body (i.e. upload data) of a HTTP request.
Expand Down
3 changes: 3 additions & 0 deletions third_party/blink/public/platform/web_url_request.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ class WebURLRequest {
BLINK_PLATFORM_EXPORT network::OptionalTrustTokenParams TrustTokenParams()
const;

BLINK_PLATFORM_EXPORT base::Optional<base::UnguessableToken> WebBundleToken()
const;

#if INSIDE_BLINK
BLINK_PLATFORM_EXPORT ResourceRequest& ToMutableResourceRequest();
BLINK_PLATFORM_EXPORT const ResourceRequest& ToResourceRequest() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ network::OptionalTrustTokenParams WebURLRequest::TrustTokenParams() const {
return ConvertTrustTokenParams(resource_request_->TrustTokenParams());
}

base::Optional<base::UnguessableToken> WebURLRequest::WebBundleToken() const {
if (resource_request_->GetWebBundleTokenParams()) {
return resource_request_->GetWebBundleTokenParams()->token;
}
return base::nullopt;
}

WebURLRequest::WebURLRequest(ResourceRequest& r) : resource_request_(&r) {}

} // namespace blink
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "base/unguessable_token.h"
#include "services/network/public/mojom/ip_address_space.mojom-blink.h"
#include "services/network/public/mojom/web_bundle_handle.mojom-blink.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-blink.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include "third_party/blink/renderer/platform/network/encoded_form_data.h"
Expand All @@ -40,6 +41,38 @@

namespace blink {

ResourceRequestHead::WebBundleTokenParams&
ResourceRequestHead::WebBundleTokenParams::operator=(
const WebBundleTokenParams& other) {
token = other.token;
handle = other.CloneHandle();
return *this;
}

ResourceRequestHead::WebBundleTokenParams::WebBundleTokenParams(
const WebBundleTokenParams& other) {
*this = other;
}

ResourceRequestHead::WebBundleTokenParams::WebBundleTokenParams(
const base::UnguessableToken& web_bundle_token,
mojo::PendingRemote<network::mojom::WebBundleHandle> web_bundle_handle)
: token(web_bundle_token), handle(std::move(web_bundle_handle)) {}

mojo::PendingRemote<network::mojom::WebBundleHandle>
ResourceRequestHead::WebBundleTokenParams::CloneHandle() const {
if (!handle)
return mojo::NullRemote();
mojo::Remote<network::mojom::WebBundleHandle> remote(std::move(
const_cast<mojo::PendingRemote<network::mojom::WebBundleHandle>&>(
handle)));
mojo::PendingRemote<network::mojom::WebBundleHandle> new_remote;
remote->Clone(new_remote.InitWithNewPipeAndPassReceiver());
const_cast<mojo::PendingRemote<network::mojom::WebBundleHandle>&>(handle) =
remote.Unbind();
return new_remote;
}

const base::TimeDelta ResourceRequestHead::default_timeout_interval_ =
base::TimeDelta::Max();

Expand Down
Loading

0 comments on commit 823e10f

Please sign in to comment.