Commit 084a0c64 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

PreviewTab: Handle not viewable content

This CL handles web contents that is not viewable in the preview
tab such as those supposed to be downloaded instead. Shows a toast
message about the occasion and closes the tab.

Screenshot: https://storage.cloud.google.com/chromium-translation-screenshots/b77f7e044e4dec1b76791882126fc33e673e7f17

Bug: 981258
Change-Id: I144f953b14638901cf3846273a2c70e393066500
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2483546Reviewed-by: default avatarDonn Denman <donnd@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818785}
parent 3b47a814
...@@ -9,6 +9,7 @@ import android.os.Handler; ...@@ -9,6 +9,7 @@ import android.os.Handler;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.components.browser_ui.bottomsheet.BottomSheetController; import org.chromium.components.browser_ui.bottomsheet.BottomSheetController;
...@@ -22,6 +23,7 @@ import org.chromium.content_public.browser.NavigationHandle; ...@@ -22,6 +23,7 @@ import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver; import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.content_public.common.ResourceRequestBody; import org.chromium.content_public.common.ResourceRequestBody;
import org.chromium.ui.widget.Toast;
import org.chromium.url.GURL; import org.chromium.url.GURL;
/** /**
...@@ -125,9 +127,17 @@ public class EphemeralTabMediator { ...@@ -125,9 +127,17 @@ public class EphemeralTabMediator {
@Override @Override
public void didFinishNavigation(NavigationHandle navigation) { public void didFinishNavigation(NavigationHandle navigation) {
if (navigation.hasCommitted() && navigation.isInMainFrame()) { if (navigation.isInMainFrame()) {
mIsOnErrorPage = navigation.isErrorPage(); if (navigation.hasCommitted()) {
mSheetContent.updateURL(mWebContents.get().getVisibleUrl()); mIsOnErrorPage = navigation.isErrorPage();
mSheetContent.updateURL(mWebContents.get().getVisibleUrl());
} else {
// Not viewable contents such as download. Show a toast and close the tab.
Toast.makeText(ContextUtils.getApplicationContext(),
R.string.ephemeral_tab_sheet_not_viewable, Toast.LENGTH_SHORT)
.show();
mBottomSheetController.hideContent(mSheetContent, /* animate= */ true);
}
} }
} }
}; };
......
...@@ -3403,6 +3403,9 @@ Data from your Incognito session will only be cleared from Chrome when you <ph n ...@@ -3403,6 +3403,9 @@ Data from your Incognito session will only be cleared from Chrome when you <ph n
<message name="IDS_EPHEMERAL_TAB_SHEET_DESCRIPTION" desc="The content description of the preview tab bottom sheet."> <message name="IDS_EPHEMERAL_TAB_SHEET_DESCRIPTION" desc="The content description of the preview tab bottom sheet.">
Preview tab Preview tab
</message> </message>
<message name="IDS_EPHEMERAL_TAB_SHEET_NOT_VIEWABLE" desc="Notifies the user that the link they are trying to preview cannot be viewed.">
Preview tab content is not viewable.
</message>
<message name="IDS_EPHEMERAL_TAB_SHEET_OPENED_HALF" desc="Accessibility string read when the preview tab bottom sheet is opened at half height. The sheet will occupy up to half the screen."> <message name="IDS_EPHEMERAL_TAB_SHEET_OPENED_HALF" desc="Accessibility string read when the preview tab bottom sheet is opened at half height. The sheet will occupy up to half the screen.">
Preview tab is half-opened Preview tab is half-opened
</message> </message>
......
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