Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java |
| index 9dbaa3fcb0af14cab4db36c5894e37394b15987c..0792ed808bbd796a9b24851fa30d29ddbd4597d6 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/tab/TabContextMenuItemDelegate.java |
| @@ -4,16 +4,23 @@ |
| package org.chromium.chrome.browser.tab; |
| +import android.app.Activity; |
| import android.content.Context; |
| import android.content.Intent; |
| +import android.content.pm.PackageManager; |
| +import android.content.pm.ResolveInfo; |
| import android.net.MailTo; |
| import android.net.Uri; |
| +import android.os.AsyncTask; |
| +import android.provider.Browser; |
| import android.provider.ContactsContract; |
| import org.chromium.base.metrics.RecordUserAction; |
| +import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.IntentHandler; |
| import org.chromium.chrome.browser.UrlConstants; |
| import org.chromium.chrome.browser.contextmenu.ContextMenuItemDelegate; |
| +import org.chromium.chrome.browser.document.ChromeLauncherActivity; |
| import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
| import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
| import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| @@ -28,6 +35,7 @@ import org.chromium.ui.base.PageTransition; |
| import java.net.URI; |
| import java.util.Locale; |
| +import java.util.concurrent.ExecutionException; |
| /** |
| * A default {@link ContextMenuItemDelegate} that supports the context menu functionality in Tab. |
| @@ -35,9 +43,11 @@ import java.util.Locale; |
| public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { |
| public static final String PAGESPEED_PASSTHROUGH_HEADERS = |
| "Chrome-Proxy: pass-through\nCache-Control: no-cache"; |
| + private static final String SAMPLE_URL = "https://www.google.com"; |
| private final Clipboard mClipboard; |
| private final Tab mTab; |
| + private final AsyncTask<Void, Void, String> mDefaultBrowserFetcher; |
| /** |
| * Builds a {@link TabContextMenuItemDelegate} instance. |
| @@ -45,6 +55,23 @@ public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { |
| public TabContextMenuItemDelegate(Tab tab) { |
| mTab = tab; |
| mClipboard = new Clipboard(mTab.getApplicationContext()); |
| + mDefaultBrowserFetcher = new AsyncTask<Void, Void, String>() { |
|
Ted C
2017/02/11 00:08:46
This is the same as in CustomTabAppMenuPropertiesD
Maria
2017/02/11 00:55:57
I agree that having this in one place would be nic
ltian
2017/02/14 01:43:44
Done.
|
| + @Override |
| + protected String doInBackground(Void... params) { |
| + String packageLabel = null; |
| + Activity activity = mTab.getActivity(); |
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(SAMPLE_URL)); |
| + PackageManager pm = activity.getPackageManager(); |
| + ResolveInfo info = pm.resolveActivity(intent, 0); |
| + if (info != null && info.match != 0) { |
| + packageLabel = info.loadLabel(pm).toString(); |
| + } |
| + |
| + return packageLabel == null |
| + ? activity.getString(R.string.menu_open_in_product_default) |
| + : activity.getString(R.string.menu_open_in_product, packageLabel); |
| + } |
| + }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
| } |
| @Override |
| @@ -232,6 +259,36 @@ public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { |
| } |
| } |
| + @Override |
| + public void onOpenInNewChromeTabFromCCT(String linkUrl, boolean isIncognito) { |
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); |
| + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| + intent.setPackage(mTab.getApplicationContext().getPackageName()); |
| + intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PARENT, false); |
| + if (isIncognito) { |
| + intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); |
| + intent.putExtra( |
| + Browser.EXTRA_APPLICATION_ID, mTab.getApplicationContext().getPackageName()); |
| + IntentHandler.addTrustedIntentExtras(intent); |
| + } |
| + IntentUtils.safeStartActivity(mTab.getActivity(), intent); |
| + } |
| + |
| + @Override |
| + public String getTitleForOpenTabInExternalApp() { |
| + try { |
| + return mDefaultBrowserFetcher.get(); |
| + } catch (InterruptedException | ExecutionException e) { |
| + return mTab.getActivity().getString(R.string.menu_open_in_product_default); |
| + } |
| + } |
| + |
| + @Override |
| + public void onOpenInDefaultBrowser(String url) { |
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); |
|
Ted C
2017/02/11 00:08:46
I think we want NEW_TASK here too
ltian
2017/02/14 01:43:44
Done.
|
| + IntentUtils.safeStartActivity(mTab.getActivity(), intent); |
| + } |
| + |
| /** |
| * Checks if spdy proxy is enabled for input url. |
| * @param url Input url to check for spdy setting. |