Commit 671b9d02 authored by dominickn's avatar dominickn Committed by Commit bot

Prevent navigations within fullscreen webapps from being intercepted.

If a native app and a PWA are installed which handle the same URLs,
a navigation within the PWA may open the intent picker to ask the user
if they wish to browse in the native app.

This CL stops the picker from appearing if the user is browsing within
the fullscreen PWA. It does not do so if the user is browsing the PWA
outside of the fullscreen standalone (i.e. launched from homescreen)
mode.

BUG=647569

Review-Url: https://codereview.chromium.org/2348853002
Cr-Commit-Position: refs/heads/master@{#419406}
parent 7eb600a0
......@@ -34,6 +34,12 @@ interface ExternalNavigationDelegate {
*/
boolean isSpecializedHandlerAvailable(List<ResolveInfo> infos);
/**
* Returns true if the current activity is a webapp and {@params url} lies within the scope of
* that webapp.
*/
boolean isWithinCurrentWebappScope(String url);
/**
* Returns the number of specialized intent handlers in {@params infos}. Specialized intent
* handlers are intent handlers which handle only a few URLs (e.g. google maps or youtube).
......
......@@ -41,6 +41,7 @@ import org.chromium.chrome.browser.document.ChromeLauncherActivity;
import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.OverrideUrlLoadingResult;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.util.UrlUtilities;
import org.chromium.chrome.browser.webapps.WebappActivity;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.common.Referrer;
import org.chromium.ui.base.PageTransition;
......@@ -239,6 +240,16 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
return countSpecializedHandlers(infos) > 0;
}
@Override
public boolean isWithinCurrentWebappScope(String url) {
Context context = getAvailableContext();
if (context instanceof WebappActivity) {
String scope = ((WebappActivity) context).getWebappScope();
return url.startsWith(scope);
}
return false;
}
@Override
public int countSpecializedHandlers(List<ResolveInfo> infos) {
return getSpecializedHandlersWithFilter(infos, null).size();
......
......@@ -216,6 +216,11 @@ public class ExternalNavigationHandler {
}
}
// http://crbug.com/647569 : Stay in a PWA window for a URL within the same scope.
if (mDelegate.isWithinCurrentWebappScope(params.getUrl())) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
// http://crbug.com/149218: We want to show the intent picker for ordinary links, providing
// the link is not an incoming intent from another application, unless it's a redirect (see
// below).
......
......@@ -233,6 +233,13 @@ public class WebappActivity extends FullScreenActivity {
return mWebappInfo;
}
/**
* @return A string containing the scope of the webapp opened in this activity.
*/
public String getWebappScope() {
return mWebappInfo.scopeUri().toString();
}
private void initializeWebappData() {
final int backgroundColor = ColorUtils.getOpaqueColor(mWebappInfo.backgroundColor(
ApiCompatibilityUtils.getColor(getResources(), R.color.webapp_default_bg)));
......
......@@ -228,6 +228,14 @@ public class ExternalNavigationHandlerTest extends NativeLibraryTestBase {
.expecting(OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE);
}
@SmallTest
public void testInWebapp() {
// Don't override if the URL is within the current webapp scope.
mDelegate.setIsWithinCurrentWebappScope(true);
checkUrl("http://youtube.com/")
.expecting(OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE);
}
@SmallTest
public void testWtai() {
// Start the telephone application with the given number.
......@@ -994,6 +1002,11 @@ public class ExternalNavigationHandlerTest extends NativeLibraryTestBase {
return countSpecializedHandlers(resolveInfos) > 0;
}
@Override
public boolean isWithinCurrentWebappScope(String url) {
return mIsWithinCurrentWebappScope;
}
@Override
public int countSpecializedHandlers(List<ResolveInfo> resolveInfos) {
return getSpecializedHandlers(resolveInfos).size();
......@@ -1120,6 +1133,10 @@ public class ExternalNavigationHandlerTest extends NativeLibraryTestBase {
mIsChromeAppInForeground = value;
}
public void setIsWithinCurrentWebappScope(boolean value) {
mIsWithinCurrentWebappScope = value;
}
public Intent startActivityIntent = null;
public boolean startIncognitoIntentCalled = false;
......@@ -1129,6 +1146,7 @@ public class ExternalNavigationHandlerTest extends NativeLibraryTestBase {
private String mNewUrlAfterClobbering;
private String mReferrerUrlForClobbering;
public boolean mIsChromeAppInForeground = true;
public boolean mIsWithinCurrentWebappScope;
public boolean shouldRequestFileAccess;
public boolean startFileIntentCalled;
......
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