Update browser history on portal activation

When a portal contents is activated, we swap it with its predecessor,
so to the user it appears that the tab has navigated. However, we did
not notify the history service about this, so the page the user is now
viewing does not appear in chrome://history/.

Now upon portal activation, we have the history service add a page visit
for the portal's last committed entry.

Bug: 944198
Change-Id: Iebb0c66a2afddefc5172c84158ea2d01511c8309
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2080832
Commit-Queue: Kevin McNee <[email protected]>
Reviewed-by: Charlie Reis <[email protected]>
Reviewed-by: Lucas Gadani <[email protected]>
Cr-Commit-Position: refs/heads/master@{#761141}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index 44a80d2..57f7b6f4 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1942,6 +1942,14 @@
   GetMainFrame()->UpdateAXTreeData();
 }
 
+void WebContentsImpl::DidActivatePortal(WebContents* predecessor_contents) {
+  DCHECK(predecessor_contents);
+  NotifyInsidePortal(false);
+  GetDelegate()->WebContentsBecamePortal(predecessor_contents);
+  for (auto& observer : observers_)
+    observer.DidActivatePortal(predecessor_contents);
+}
+
 void WebContentsImpl::NotifyInsidePortal(bool inside_portal) {
   SendPageMessage(new PageMsg_SetInsidePortal(MSG_ROUTING_NONE, inside_portal));
 }