Split Cache: Adds frame origin while creating NetworkIsolationKey

This CL constructs the network isolation key using both top-frame-origin
and frame origin. The frame origin is also updated to be a
non-optional argument in the constructor. A follow-up CL will make
top frame origin also a non-optional argument.

Also, updating all of tests to include both parameters when calling
this function.

The new tests in this CL are scoped to Split Cache browser and unit tests
and API unit tests. Other consumers of Network Isolation Key like sockets
etc. will need follow up CLs for any additional tests.

(Initial patches of this CL were done by ericrobinson)

Bug: 950069
Change-Id: Ide1cf9d9f58a768cd22c4b667520a13abf88f9b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1678551
Commit-Queue: Shivani Sharma <[email protected]>
Reviewed-by: Alex Moshchuk <[email protected]>
Reviewed-by: Matt Menke <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Reviewed-by: Josh Karlin <[email protected]>
Reviewed-by: Shivani Sharma <[email protected]>
Cr-Commit-Position: refs/heads/master@{#679435}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 165f4aac..ae1bcfa 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -198,11 +198,17 @@
     scoped_refptr<net::URLRequestContextGetter> request_context,
     const GURL& url,
     const std::string& http_method,
-    const base::Optional<url::Origin>& top_frame_origin) {
+    const base::Optional<url::Origin>& top_frame_origin,
+    const url::Origin& frame_origin) {
   net::HttpCache* cache = request_context->GetURLRequestContext()->
       http_transaction_factory()->GetCache();
-  if (cache)
-    cache->OnExternalCacheHit(url, http_method, top_frame_origin);
+  net::NetworkIsolationKey network_isolation_key;
+  if (cache) {
+    if (top_frame_origin)
+      network_isolation_key =
+          net::NetworkIsolationKey(*top_frame_origin, frame_origin);
+    cache->OnExternalCacheHit(url, http_method, network_isolation_key);
+  }
 }
 
 bool HasMatchingProcess(FrameTree* tree, int render_process_id) {
@@ -4542,12 +4548,13 @@
 
   if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) {
     StoragePartition* partition = source->GetProcess()->GetStoragePartition();
+    const url::Origin& last_committed_origin = source->GetLastCommittedOrigin();
 
     // We require different paths here because there is no NetworkContext
     // for media cache.
     if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
-      partition->GetNetworkContext()->NotifyExternalCacheHit(url, http_method,
-                                                             top_frame_origin);
+      partition->GetNetworkContext()->NotifyExternalCacheHit(
+          url, http_method, top_frame_origin, last_committed_origin);
     } else {
       scoped_refptr<net::URLRequestContextGetter> request_context(
           resource_type == ResourceType::kMedia
@@ -4556,7 +4563,7 @@
       base::PostTaskWithTraits(
           FROM_HERE, {BrowserThread::IO},
           base::BindOnce(&NotifyCacheOnIO, request_context, url, http_method,
-                         top_frame_origin));
+                         top_frame_origin, last_committed_origin));
     }
   }
 }