Commit 95faad3c authored by Yao Xiao's avatar Yao Xiao Committed by Commit Bot

Split cache: Make Network Isolation Key take non-optional top frame origin

Why: All call sites that create a non-empty network isolation key
must provide a top-frame-origin.

Bug: 984157
Change-Id: I26c15816073a6424fe8bad23c52494114ba08e31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704522
Commit-Queue: Yao Xiao <yaoxia@chromium.org>
Reviewed-by: default avatarShivani Sharma <shivanisha@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMike Pinkerton <pinkerton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678391}
parent a8cc78fa
...@@ -4886,9 +4886,9 @@ void RenderFrameHostImpl::CommitNavigation( ...@@ -4886,9 +4886,9 @@ void RenderFrameHostImpl::CommitNavigation(
// TODO(crbug.com/979296): Consider changing this code to copy an origin // TODO(crbug.com/979296): Consider changing this code to copy an origin
// instead of creating one from a URL which lacks opacity information. // instead of creating one from a URL which lacks opacity information.
if (!is_same_document) { if (!is_same_document) {
base::Optional<url::Origin> top_frame_origin = url::Origin top_frame_origin = frame_tree_node_->IsMainFrame()
frame_tree_node_->IsMainFrame() ? url::Origin::Create(common_params.url) ? url::Origin::Create(common_params.url)
: frame_tree_->root()->current_origin(); : frame_tree_->root()->current_origin();
network_isolation_key_ = net::NetworkIsolationKey(top_frame_origin); network_isolation_key_ = net::NetworkIsolationKey(top_frame_origin);
} }
......
...@@ -1132,7 +1132,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController ...@@ -1132,7 +1132,7 @@ class NavigationURLLoaderImpl::URLLoaderRequestController
base::Optional<url::Origin> origin = base::Optional<url::Origin> origin =
url::Origin::Create(resource_request_->url); url::Origin::Create(resource_request_->url);
resource_request_->trusted_network_isolation_key = resource_request_->trusted_network_isolation_key =
net::NetworkIsolationKey(origin, origin); net::NetworkIsolationKey(origin.value(), origin);
} }
resource_request_->referrer = GURL(redirect_info_.new_referrer); resource_request_->referrer = GURL(redirect_info_.new_referrer);
......
...@@ -223,7 +223,7 @@ class DedicatedWorkerHost : public service_manager::mojom::InterfaceProvider { ...@@ -223,7 +223,7 @@ class DedicatedWorkerHost : public service_manager::mojom::InterfaceProvider {
// creating dedicated workers, as there might be no ancestor frame. // creating dedicated workers, as there might be no ancestor frame.
auto* host = auto* host =
RenderFrameHostImpl::FromID(process_id_, ancestor_render_frame_id_); RenderFrameHostImpl::FromID(process_id_, ancestor_render_frame_id_);
base::Optional<url::Origin> top_frame_origin( url::Origin top_frame_origin(
host->frame_tree_node()->frame_tree()->root()->current_origin()); host->frame_tree_node()->frame_tree()->root()->current_origin());
process->CreateURLLoaderFactory( process->CreateURLLoaderFactory(
......
...@@ -17,7 +17,7 @@ std::string GetOriginDebugString(const base::Optional<url::Origin>& origin) { ...@@ -17,7 +17,7 @@ std::string GetOriginDebugString(const base::Optional<url::Origin>& origin) {
} // namespace } // namespace
NetworkIsolationKey::NetworkIsolationKey( NetworkIsolationKey::NetworkIsolationKey(
const base::Optional<url::Origin>& top_frame_origin, const url::Origin& top_frame_origin,
const base::Optional<url::Origin>& frame_origin) const base::Optional<url::Origin>& frame_origin)
: use_frame_origin_(base::FeatureList::IsEnabled( : use_frame_origin_(base::FeatureList::IsEnabled(
net::features::kAppendFrameOriginToNetworkIsolationKey)), net::features::kAppendFrameOriginToNetworkIsolationKey)),
......
...@@ -21,9 +21,9 @@ class NET_EXPORT NetworkIsolationKey { ...@@ -21,9 +21,9 @@ class NET_EXPORT NetworkIsolationKey {
// Full constructor. When a request is initiated by the top frame, it must // Full constructor. When a request is initiated by the top frame, it must
// also populate the |frame_origin| parameter when calling this constructor. // also populate the |frame_origin| parameter when calling this constructor.
explicit NetworkIsolationKey( explicit NetworkIsolationKey(
// TODO(crbug.com/950069): Make the arguments non-optional once all call // TODO(crbug.com/950069): Make the frame_origin argument non-optional
// sites are updated to include the frame_origin. // once all call sites are updated to include the frame_origin.
const base::Optional<url::Origin>& top_frame_origin, const url::Origin& top_frame_origin,
const base::Optional<url::Origin>& frame_origin = base::nullopt); const base::Optional<url::Origin>& frame_origin = base::nullopt);
// Construct an empty key. // Construct an empty key.
......
...@@ -358,7 +358,12 @@ void HttpCache::OnExternalCacheHit( ...@@ -358,7 +358,12 @@ void HttpCache::OnExternalCacheHit(
HttpRequestInfo request_info; HttpRequestInfo request_info;
request_info.url = url; request_info.url = url;
request_info.method = http_method; request_info.method = http_method;
request_info.network_isolation_key = NetworkIsolationKey(top_frame_origin);
if (top_frame_origin.has_value()) {
request_info.network_isolation_key =
NetworkIsolationKey(top_frame_origin.value());
}
std::string key = GenerateCacheKey(&request_info); std::string key = GenerateCacheKey(&request_info);
disk_cache_->OnExternalCacheHit(key); disk_cache_->OnExternalCacheHit(key);
} }
......
...@@ -19,7 +19,7 @@ bool StructTraits<network::mojom::NetworkIsolationKeyDataView, ...@@ -19,7 +19,7 @@ bool StructTraits<network::mojom::NetworkIsolationKeyDataView,
// given the flags set). The constructor verifies this, so if the top-frame // given the flags set). The constructor verifies this, so if the top-frame
// origin is populated, we call the full constructor, otherwise, the empty. // origin is populated, we call the full constructor, otherwise, the empty.
if (top_frame_origin.has_value()) { if (top_frame_origin.has_value()) {
*out = net::NetworkIsolationKey(top_frame_origin, frame_origin); *out = net::NetworkIsolationKey(top_frame_origin.value(), frame_origin);
} else { } else {
*out = net::NetworkIsolationKey(); *out = net::NetworkIsolationKey();
} }
......
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