Commit 7e7767a3 authored by Kevin McNee's avatar Kevin McNee Committed by Commit Bot

Consider inner WebContents when choosing whether to snapshot for offline pages

RecentTabHelper::WebContentsWasHidden has several conditions for saving
a snapshot. One of which is to not snapshot for custom tabs. We try to
determine if a WebContents is a custom tab, but for inner WebContents,
such as portals, we DCHECK as they are not directly associated with a
tab.

We now use the outermost WebContents to determine whether we are in a
custom tab.

Bug: 958825
Change-Id: Ia7e2ebe93e3a73741c5d0df467f20bc8bc9c38ba
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635969Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarDmitry Titov <dimich@chromium.org>
Commit-Queue: Kevin McNee <mcnee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664746}
parent b0ef5b0c
...@@ -130,4 +130,38 @@ public class PortalsTest { ...@@ -130,4 +130,38 @@ public class PortalsTest {
executeScriptAndAwaitSwap(tab, "activatePortal();"); executeScriptAndAwaitSwap(tab, "activatePortal();");
executeScriptAndAwaitSwap(tab, "reactivatePredecessor();"); executeScriptAndAwaitSwap(tab, "reactivatePredecessor();");
} }
/**
* Tests that an adopted predecessor can be destroyed.
*/
@Test
@MediumTest
@Feature({"Portals"})
public void testRemovePredecessor() throws Exception {
mActivityTestRule.startMainActivityWithURL(
mTestServer.getURL("/chrome/test/data/android/portals/predecessor-adoption.html"));
final Tab tab = mActivityTestRule.getActivity().getActivityTab();
executeScriptAndAwaitSwap(tab, "activatePortal();");
JavaScriptUtils.executeJavaScriptAndWaitForResult(
tab.getWebContents(), "removePredecessor();");
}
/**
* Tests that a previously activated portal can be destroyed.
*/
@Test
@MediumTest
@Feature({"Portals"})
public void testRemovePreviouslyActivePortal() throws Exception {
mActivityTestRule.startMainActivityWithURL(
mTestServer.getURL("/chrome/test/data/android/portals/predecessor-adoption.html"));
final Tab tab = mActivityTestRule.getActivity().getActivityTab();
executeScriptAndAwaitSwap(tab, "activatePortal();");
executeScriptAndAwaitSwap(tab, "reactivatePredecessor();");
JavaScriptUtils.executeJavaScriptAndWaitForResult(tab.getWebContents(), "removePortal();");
}
} }
...@@ -312,12 +312,17 @@ void RecentTabHelper::WebContentsWasHidden() { ...@@ -312,12 +312,17 @@ void RecentTabHelper::WebContentsWasHidden() {
// - A last_n snapshot is currently being saved. // - A last_n snapshot is currently being saved.
// - The tab is in the process of being closed. // - The tab is in the process of being closed.
// - The tab is currently presented as a custom tab. // - The tab is currently presented as a custom tab.
// Note that a WebContents may be embedded in another WebContents. The
// outermost WebContents is the one associated with the tab.
if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_ || if (!last_n_listen_to_tab_hidden_ || last_n_ongoing_snapshot_info_ ||
tab_is_closing_ || delegate_->IsCustomTab(web_contents())) { tab_is_closing_ ||
delegate_->IsCustomTab(web_contents()->GetOutermostWebContents())) {
DVLOG(1) << "Will not snapshot for last_n (reasons: " DVLOG(1) << "Will not snapshot for last_n (reasons: "
<< !last_n_listen_to_tab_hidden_ << ", " << !last_n_listen_to_tab_hidden_ << ", "
<< !!last_n_ongoing_snapshot_info_ << ", " << tab_is_closing_ << !!last_n_ongoing_snapshot_info_ << ", " << tab_is_closing_
<< ", " << delegate_->IsCustomTab(web_contents()) << ", "
<< delegate_->IsCustomTab(
web_contents()->GetOutermostWebContents())
<< ") for: " << web_contents()->GetLastCommittedURL().spec(); << ") for: " << web_contents()->GetLastCommittedURL().spec();
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment