Commit a37f2257 authored by Brandon Wylie's avatar Brandon Wylie Committed by Chromium LUCI CQ

Stop tab loading during reparenting

Bug: 1056147
Change-Id: Ib13cb84cc38791afa12b92a3ea4ce12a33a1c434
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2590653
Commit-Queue: Brandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837420}
parent 9ec828c0
......@@ -71,6 +71,10 @@ public class TabReparentingController {
mDelegate.getTabModelSelector().enterReparentingMode();
for (int i = 0; i < tabs.size(); i++) {
Tab tab = tabs.get(i);
if (tab.isLoading()) {
tab.stopLoading();
tab.getWebContents().getNavigationController().setNeedsReload();
}
// The current tab has already been detached/stored and is waiting for andorid to
// recreate the activity.
......
......@@ -398,10 +398,13 @@ public class ChromeTabCreator extends TabCreator {
mActivity.getCompositorViewHolder(), mActivity.getWindowAndroid(),
createDefaultTabDelegateFactory()),
params.getFinalizeCallback());
// TODO(crbug.com/1108562): This is a temporary fix for RBS issue crbug.com/1105810,
// TODO(crbug.com/1108562): Photos/videos viewed in custom tabs aren't displayed
// properly after reparenting. This is a temporary fix for RBS issue crbug.com/1105810,
// investigate and fix the root cause.
if (tab.getUrl().getScheme().equals(UrlConstants.FILE_SCHEME)) {
tab.reloadIgnoringCache();
} else if (tab.needsReload()) {
tab.reload();
}
}
if (tab == null) {
......
......@@ -31,6 +31,8 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabReparentingParams;
import org.chromium.chrome.test.util.browser.tabmodel.MockTabModel;
import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.content_public.browser.NavigationController;
import org.chromium.content_public.browser.WebContents;
import java.util.HashMap;
import java.util.Map;
......@@ -209,6 +211,18 @@ public class TabReparentingControllerTest {
verify(mTask, times(3)).detach();
}
@Test
public void testReparenting_stopLoadingIfNeeded() {
// New tab pages aren't reparented intentionally.
mForegroundTab = createAndAddMockTab(1, false, "https://www.google.com");
doReturn(true).when(mForegroundTab).isLoading();
mController.prepareTabsForReparenting();
verify(mForegroundTab).stopLoading();
verify(mForegroundTab.getWebContents().getNavigationController()).setNeedsReload();
}
/**
* Adds a tab to the correct model and sets the index in the mapping.
*
......@@ -219,7 +233,11 @@ public class TabReparentingControllerTest {
*/
private Tab createAndAddMockTab(int id, boolean incognito, String url) {
Tab tab = Mockito.mock(Tab.class);
WebContents wc = Mockito.mock(WebContents.class);
NavigationController nc = Mockito.mock(NavigationController.class);
doReturn(url).when(tab).getUrlString();
doReturn(wc).when(tab).getWebContents();
doReturn(nc).when(wc).getNavigationController();
UserDataHost udh = new UserDataHost();
udh.setUserData(ReparentingTask.class, mTask);
doReturn(udh).when(tab).getUserDataHost();
......
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