Portals: Fix accessibility crash

Currently, after activation and adoption, both AX trees for the newly
activated page and the portal have their parent_tree_id set to each
other, which can lead to a stack overflow when trying to retrieve
the root BrowserAccessibilityManager. This CL breaks this cycle by
unsetting the parent_tree_id of the detached WebContents' AX tree.

Bug: 1033999
Change-Id: Ibd0b6f4f9af28df2795574728800438a7ec5dd12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972234
Reviewed-by: Lucas Gadani <[email protected]>
Reviewed-by: Nasko Oskov <[email protected]>
Commit-Queue: Adithya Srinivasan <[email protected]>
Cr-Commit-Position: refs/heads/master@{#726194}
diff --git a/content/browser/web_contents/web_contents_impl.cc b/content/browser/web_contents/web_contents_impl.cc
index acb1a5fa..4dd67e8 100644
--- a/content/browser/web_contents/web_contents_impl.cc
+++ b/content/browser/web_contents/web_contents_impl.cc
@@ -1844,6 +1844,10 @@
   node_.SetFocusedWebContents(this);
   CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost());
   RecursivelyRegisterFrameSinkIds();
+  // TODO(adithyas): |browser_plugin_embedder_ax_tree_id| should either not be
+  // used for portals, or it should get a different name.
+  GetMainFrame()->set_browser_plugin_embedder_ax_tree_id(ui::AXTreeIDUnknown());
+  GetMainFrame()->UpdateAXTreeData();
   return web_contents;
 }