Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(617)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappTabDelegate.java

Issue 2969143002: Fixes redirects to external apps when navigating from PWA. (Closed)
Patch Set: Sends intents to specialized apps in WebappTabDelegate (and merge) Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappTabDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappTabDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappTabDelegate.java
index e3e1e9e9a2c74c14e48d61cf70a12c6cf87e00c1..5cf32b45b4f9f0767a0daa8a185dccd0d1f69c99 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappTabDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/WebappTabDelegate.java
@@ -3,9 +3,15 @@
// found in the LICENSE file.
package org.chromium.chrome.browser.webapps;
+import android.content.Intent;
+import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.support.customtabs.CustomTabsIntent;
+import org.chromium.base.Log;
+import org.chromium.chrome.browser.IntentHandler;
+import org.chromium.chrome.browser.customtabs.CustomTabIntentDataProvider;
+import org.chromium.chrome.browser.externalnav.ExternalNavigationDelegateImpl;
import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tab.TabIdManager;
import org.chromium.chrome.browser.tabmodel.AsyncTabParamsManager;
@@ -13,6 +19,9 @@ import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.document.AsyncTabCreationParams;
import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
+import java.net.URISyntaxException;
+import java.util.List;
+
/**
* Asynchronously creates Tabs for navigation originating from an installed PWA.
*
@@ -20,7 +29,10 @@ import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
* {@code _blank} links and {@code window.open(url)} calls instead of creating a new tab in Chrome.
*/
public class WebappTabDelegate extends TabDelegate {
+ private static final String TAG = "WebappTabDelegate";
+
private final WebappActivity mActivity;
+ private ExternalNavigationDelegateImpl mExternalNavigationDelegate; // Initialized lazily
public WebappTabDelegate(WebappActivity activity, boolean incognito) {
super(incognito);
@@ -29,14 +41,49 @@ public class WebappTabDelegate extends TabDelegate {
@Override
public void createNewTab(AsyncTabCreationParams asyncParams, TabLaunchType type, int parentId) {
+ String url = asyncParams.getLoadUrlParams().getUrl();
+ if (maybeStartExternalActivity(url)) {
+ return;
+ }
+
int assignedTabId = TabIdManager.getInstance().generateValidId(Tab.INVALID_TAB_ID);
AsyncTabParamsManager.add(assignedTabId, asyncParams);
- CustomTabsIntent customTabIntent =
- new CustomTabsIntent.Builder().setShowTitle(true).build();
+ Intent intent = new CustomTabsIntent.Builder().setShowTitle(true).build().intent;
+ intent.setData(Uri.parse(url));
+ intent.putExtra(CustomTabIntentDataProvider.EXTRA_SEND_TO_EXTERNAL_DEFAULT_HANDLER, true);
+ intent.putExtra(CustomTabIntentDataProvider.EXTRA_IS_OPENED_BY_CHROME, true);
+ addAsyncTabExtras(asyncParams, parentId, false /* isChromeUI */, assignedTabId, intent);
+
+ IntentHandler.startActivityForTrustedIntent(intent);
+ }
+
+ private boolean maybeStartExternalActivity(String url) {
+ Intent intent;
+ try {
+ intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
+ } catch (URISyntaxException ex) {
+ Log.w(TAG, "Bad URI %s", url, ex);
+ return false;
+ }
+
+ if (shouldStartExternalActivity(intent)) {
+ mActivity.startActivity(intent);
Yusuf 2017/07/19 03:33:37 I think dependence on ExternalNavigationDelegate h
piotrs 2017/07/19 04:06:25 I found isPackageSpecializedHandler, which is what
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean shouldStartExternalActivity(Intent intent) {
+ if (intent.getPackage() != null) return true;
Yusuf 2017/07/19 03:33:37 is this needed? Explicit intents should be covered
piotrs 2017/07/19 04:06:25 Ack, removed.
+
+ if (mExternalNavigationDelegate == null) {
+ mExternalNavigationDelegate =
+ new ExternalNavigationDelegateImpl(mActivity.getActivityTab());
+ }
- customTabIntent.intent.setPackage(mActivity.getPackageName());
- addAsyncTabExtras(asyncParams, parentId, true, assignedTabId, customTabIntent.intent);
- customTabIntent.launchUrl(mActivity, Uri.parse(asyncParams.getLoadUrlParams().getUrl()));
+ List<ResolveInfo> infos = mExternalNavigationDelegate.queryIntentActivities(intent);
+ return mExternalNavigationDelegate.isSpecializedHandlerAvailable(infos);
}
}

Powered by Google App Engine
This is Rietveld 408576698