[mparch] Add DidChangeReferrerPolicy() to NCI and RFHO

This CL is a part of the effort to split RFH and FTN.
It adds DidChangeReferrerPolicy() to NavigationControllerImpl and
RenderFrameHostOwner to avoid access to FrameTreeNode from
RenderFrameHostImpl::DidChangeReferrerPolicy(). Changing whether to
protect a URL in the navigation API is moved to
NCI::DidChangeReferrerPolicy().

Bug: 1350575
Change-Id: I9f6d106fb85ea0d3f44eddd276edce4f9c6a2ccd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4019055
Reviewed-by: Charlie Reis <[email protected]>
Commit-Queue: Julie Jeongeun Kim <[email protected]>
Reviewed-by: Kevin McNee <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1077377}
diff --git a/content/browser/renderer_host/navigation_controller_impl.cc b/content/browser/renderer_host/navigation_controller_impl.cc
index 51e339b9..abaf52f0 100644
--- a/content/browser/renderer_host/navigation_controller_impl.cc
+++ b/content/browser/renderer_host/navigation_controller_impl.cc
@@ -4608,4 +4608,17 @@
          frame_tree_node->IsInFencedFrameTree();
 }
 
+void NavigationControllerImpl::DidChangeReferrerPolicy(
+    FrameTreeNode* node,
+    network::mojom::ReferrerPolicy referrer_policy) {
+  FrameNavigationEntry* entry = GetLastCommittedEntry()->GetFrameEntry(node);
+  if (!entry)
+    return;
+
+  // The FrameNavigationEntry may want to change whether to protect its url
+  // in the navigation API when the referrer policy changes.
+  entry->set_protect_url_in_navigation_api(
+      ShouldProtectUrlInNavigationApi(referrer_policy));
+}
+
 }  // namespace content