Commit 1a7eaa43 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[Android] Move WebappScopePolicy out of ExternalNavigationHandler.java

This CL is another step toward the componentization of
ExternalNavigationHandler.java for sharing with WebLayer. It removes
the dependence that ExternalNavigationHandler.java currently has on
//chrome's WebappScopePolicy.java. This dependence is to assist in
determining whether the user is navigating within the context of an
installed PWA within which the intent should stay. At this point in
time, this is //chrome-level functionality. Hence, we abstract this
check through ExternalNavigationDelegate.

Bug: 1031465
Change-Id: I65869090553f2cf337db39cfbb9aaac6d341f7e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2087678
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747175}
parent 74dd93df
...@@ -11,7 +11,6 @@ import androidx.annotation.NonNull; ...@@ -11,7 +11,6 @@ import androidx.annotation.NonNull;
import org.chromium.base.PackageManagerUtils; import org.chromium.base.PackageManagerUtils;
import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.OverrideUrlLoadingResult; import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.OverrideUrlLoadingResult;
import org.chromium.chrome.browser.webapps.WebappScopePolicy;
import java.util.List; import java.util.List;
...@@ -33,12 +32,10 @@ interface ExternalNavigationDelegate { ...@@ -33,12 +32,10 @@ interface ExternalNavigationDelegate {
boolean willChromeHandleIntent(Intent intent); boolean willChromeHandleIntent(Intent intent);
/** /**
* If the current activity is a webapp, applies the webapp's scope policy and returns the * Returns whether the context in which the intent is occurring is a webapp in which the
* result. Returns {@link WebappScopePolicy#NavigationDirective#NORMAL_BEHAVIOR} if the current * navigation should stay.
* activity is not a webapp.
*/ */
@WebappScopePolicy.NavigationDirective boolean shouldStayInWebapp(ExternalNavigationParams params);
int applyWebappScopePolicyForUrl(String url);
/** /**
* Returns the number of specialized intent handlers in {@params infos}. Specialized intent * Returns the number of specialized intent handlers in {@params infos}. Specialized intent
......
...@@ -213,8 +213,13 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -213,8 +213,13 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
return willChromeHandleIntent(intent, false); return willChromeHandleIntent(intent, false);
} }
@Override /**
public @WebappScopePolicy.NavigationDirective int applyWebappScopePolicyForUrl(String url) { * If the current activity is a webapp, applies the webapp's scope policy and returns the
* result. Returns {@link WebappScopePolicy#NavigationDirective#NORMAL_BEHAVIOR} if the current
* activity is not a webapp.
* Protected to allow subclasses to customize the logic.
*/
protected @WebappScopePolicy.NavigationDirective int applyWebappScopePolicyForUrl(String url) {
Context context = getAvailableContext(); Context context = getAvailableContext();
if (context instanceof WebappActivity) { if (context instanceof WebappActivity) {
WebappActivity webappActivity = (WebappActivity) context; WebappActivity webappActivity = (WebappActivity) context;
...@@ -224,6 +229,18 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -224,6 +229,18 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
return WebappScopePolicy.NavigationDirective.NORMAL_BEHAVIOR; return WebappScopePolicy.NavigationDirective.NORMAL_BEHAVIOR;
} }
// http://crbug.com/647569 : Stay in a PWA window for a URL within the same scope.
@Override
public boolean shouldStayInWebapp(ExternalNavigationParams params) {
@WebappScopePolicy.NavigationDirective
int webappScopePolicyDirective = applyWebappScopePolicyForUrl(params.getUrl());
if (webappScopePolicyDirective
== WebappScopePolicy.NavigationDirective.IGNORE_EXTERNAL_INTENT_REQUESTS) {
return true;
}
return false;
}
@Override @Override
public int countSpecializedHandlers(List<ResolveInfo> infos) { public int countSpecializedHandlers(List<ResolveInfo> infos) {
return getSpecializedHandlersWithFilter(infos, null).size(); return getSpecializedHandlersWithFilter(infos, null).size();
......
...@@ -30,7 +30,6 @@ import org.chromium.chrome.browser.IntentHandler; ...@@ -30,7 +30,6 @@ import org.chromium.chrome.browser.IntentHandler;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.instantapps.InstantAppsHandler; import org.chromium.chrome.browser.instantapps.InstantAppsHandler;
import org.chromium.chrome.browser.tab.TabRedirectHandler; import org.chromium.chrome.browser.tab.TabRedirectHandler;
import org.chromium.chrome.browser.webapps.WebappScopePolicy;
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.embedder_support.util.UrlUtilities; import org.chromium.components.embedder_support.util.UrlUtilities;
import org.chromium.components.external_intents.ExternalIntentsSwitches; import org.chromium.components.external_intents.ExternalIntentsSwitches;
...@@ -487,12 +486,8 @@ public class ExternalNavigationHandler { ...@@ -487,12 +486,8 @@ public class ExternalNavigationHandler {
return false; return false;
} }
// http://crbug.com/647569 : Stay in a PWA window for a URL within the same scope.
private boolean shouldStayInWebapp(ExternalNavigationParams params) { private boolean shouldStayInWebapp(ExternalNavigationParams params) {
@WebappScopePolicy.NavigationDirective if (mDelegate.shouldStayInWebapp(params)) {
int webappScopePolicyDirective = mDelegate.applyWebappScopePolicyForUrl(params.getUrl());
if (webappScopePolicyDirective
== WebappScopePolicy.NavigationDirective.IGNORE_EXTERNAL_INTENT_REQUESTS) {
if (DEBUG) Log.i(TAG, "Stay in PWA window"); if (DEBUG) Log.i(TAG, "Stay in PWA window");
return true; return true;
} }
......
...@@ -1781,15 +1781,21 @@ public class ExternalNavigationHandlerTest { ...@@ -1781,15 +1781,21 @@ public class ExternalNavigationHandlerTest {
} }
@Override @Override
public @WebappScopePolicy.NavigationDirective int applyWebappScopePolicyForUrl(String url) { public boolean shouldStayInWebapp(ExternalNavigationParams params) {
@WebappScopePolicy.NavigationDirective
int webappScopePolicyDirective = WebappScopePolicy.NavigationDirective.NORMAL_BEHAVIOR;
for (IntentActivity intentActivity : mIntentActivities) { for (IntentActivity intentActivity : mIntentActivities) {
if (intentActivity.packageName().equals(mReferrerWebappPackageName)) { if (intentActivity.packageName().equals(mReferrerWebappPackageName)) {
WebappInfo info = newWebappInfoFromScope(intentActivity.urlPrefix()); WebappInfo info = newWebappInfoFromScope(intentActivity.urlPrefix());
return WebappScopePolicy.applyPolicyForNavigationToUrl( webappScopePolicyDirective = WebappScopePolicy.applyPolicyForNavigationToUrl(
intentActivity.webappScopePolicy(), info, url); intentActivity.webappScopePolicy(), info, params.getUrl());
break;
} }
} }
return WebappScopePolicy.NavigationDirective.NORMAL_BEHAVIOR;
return webappScopePolicyDirective
== WebappScopePolicy.NavigationDirective.IGNORE_EXTERNAL_INTENT_REQUESTS;
} }
@Override @Override
......
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