[bfcache] Remove BackForwardCache specific IPC and use mojo

This CL removes PutPageIntoBackForwardCache and RestoreFromBackForward
Cache IPCs and use mojo instead.

Now the page state is managed by PageLifecycleStateManager, which is
responsible for sending updates to renderer via mojo messages.

Bug:1057506

Change-Id: I2e1fafe79c758f8d6d56eabd9ee13f288f370bf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2192540
Commit-Queue: Yuzu Saijo <[email protected]>
Reviewed-by: Kinuko Yasuda <[email protected]>
Reviewed-by: Kentaro Hara <[email protected]>
Reviewed-by: Alexander Timin <[email protected]>
Cr-Commit-Position: refs/heads/master@{#773075}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index eae4849..07b8cb1 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -2619,11 +2619,8 @@
     // as soon as they are shown. But the Page and other classes do not expect
     // to be producing frames when the Page is hidden. So we make sure the Page
     // is shown first.
-    // TODO(yuzus): We should include RenderViewHosts in BackForwardCache in
-    // this iteration. Add a special method to get all RenderViewHosts in
-    // BackForwardCache in WebContentsImpl.
-    for (auto& entry : frame_tree_.render_view_hosts()) {
-      entry.second->SetVisibility(page_visibility);
+    for (auto* rvh : GetRenderViewHostsIncludingBackForwardCached()) {
+      rvh->SetVisibility(page_visibility);
     }
   }
 
@@ -2655,8 +2652,8 @@
   if (page_visibility == PageVisibilityState::kHidden) {
     // Similar to when showing the page, we only hide the page after
     // hiding the individual RenderWidgets.
-    for (auto& entry : frame_tree_.render_view_hosts()) {
-      entry.second->SetVisibility(page_visibility);
+    for (auto* rvh : GetRenderViewHostsIncludingBackForwardCached()) {
+      rvh->SetVisibility(page_visibility);
     }
 
   } else {
@@ -7412,4 +7409,23 @@
   return GetMainFrame()->GetPageUkmSourceId();
 }
 
+std::set<RenderViewHostImpl*>
+WebContentsImpl::GetRenderViewHostsIncludingBackForwardCached() {
+  std::set<RenderViewHostImpl*> render_view_hosts;
+
+  // Add RenderViewHostImpls outside of BackForwardCache.
+  for (auto& render_view_host : frame_tree_.render_view_hosts()) {
+    render_view_hosts.insert(render_view_host.second);
+  }
+
+  // Add RenderViewHostImpls in BackForwardCache.
+  const auto& entries = GetController().GetBackForwardCache().GetEntries();
+  for (const auto& entry : entries) {
+    std::set<RenderViewHostImpl*> bfcached_hosts = entry->render_view_hosts;
+    render_view_hosts.insert(bfcached_hosts.begin(), bfcached_hosts.end());
+  }
+
+  return render_view_hosts;
+}
+
 }  // namespace content