Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.tab; | 5 package org.chromium.chrome.browser.tab; |
| 6 | 6 |
| 7 import android.app.Activity; | |
| 7 import android.content.Context; | 8 import android.content.Context; |
| 8 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.pm.PackageManager; | |
| 11 import android.content.pm.ResolveInfo; | |
| 9 import android.net.MailTo; | 12 import android.net.MailTo; |
| 10 import android.net.Uri; | 13 import android.net.Uri; |
| 14 import android.os.AsyncTask; | |
| 15 import android.provider.Browser; | |
| 11 import android.provider.ContactsContract; | 16 import android.provider.ContactsContract; |
| 12 | 17 |
| 13 import org.chromium.base.metrics.RecordUserAction; | 18 import org.chromium.base.metrics.RecordUserAction; |
| 19 import org.chromium.chrome.R; | |
| 14 import org.chromium.chrome.browser.IntentHandler; | 20 import org.chromium.chrome.browser.IntentHandler; |
| 15 import org.chromium.chrome.browser.UrlConstants; | 21 import org.chromium.chrome.browser.UrlConstants; |
| 16 import org.chromium.chrome.browser.contextmenu.ContextMenuItemDelegate; | 22 import org.chromium.chrome.browser.contextmenu.ContextMenuItemDelegate; |
| 23 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | |
| 17 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 24 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
| 18 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; | 25 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
| 19 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 26 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
| 20 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 27 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 21 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 28 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
| 22 import org.chromium.chrome.browser.util.IntentUtils; | 29 import org.chromium.chrome.browser.util.IntentUtils; |
| 23 import org.chromium.chrome.browser.util.UrlUtilities; | 30 import org.chromium.chrome.browser.util.UrlUtilities; |
| 24 import org.chromium.content_public.browser.LoadUrlParams; | 31 import org.chromium.content_public.browser.LoadUrlParams; |
| 25 import org.chromium.content_public.common.Referrer; | 32 import org.chromium.content_public.common.Referrer; |
| 26 import org.chromium.ui.base.Clipboard; | 33 import org.chromium.ui.base.Clipboard; |
| 27 import org.chromium.ui.base.PageTransition; | 34 import org.chromium.ui.base.PageTransition; |
| 28 | 35 |
| 29 import java.net.URI; | 36 import java.net.URI; |
| 30 import java.util.Locale; | 37 import java.util.Locale; |
| 38 import java.util.concurrent.ExecutionException; | |
| 31 | 39 |
| 32 /** | 40 /** |
| 33 * A default {@link ContextMenuItemDelegate} that supports the context menu func tionality in Tab. | 41 * A default {@link ContextMenuItemDelegate} that supports the context menu func tionality in Tab. |
| 34 */ | 42 */ |
| 35 public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { | 43 public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { |
| 36 public static final String PAGESPEED_PASSTHROUGH_HEADERS = | 44 public static final String PAGESPEED_PASSTHROUGH_HEADERS = |
| 37 "Chrome-Proxy: pass-through\nCache-Control: no-cache"; | 45 "Chrome-Proxy: pass-through\nCache-Control: no-cache"; |
| 46 private static final String SAMPLE_URL = "https://www.google.com"; | |
| 38 | 47 |
| 39 private final Clipboard mClipboard; | 48 private final Clipboard mClipboard; |
| 40 private final Tab mTab; | 49 private final Tab mTab; |
| 50 private final AsyncTask<Void, Void, String> mDefaultBrowserFetcher; | |
| 41 | 51 |
| 42 /** | 52 /** |
| 43 * Builds a {@link TabContextMenuItemDelegate} instance. | 53 * Builds a {@link TabContextMenuItemDelegate} instance. |
| 44 */ | 54 */ |
| 45 public TabContextMenuItemDelegate(Tab tab) { | 55 public TabContextMenuItemDelegate(Tab tab) { |
| 46 mTab = tab; | 56 mTab = tab; |
| 47 mClipboard = new Clipboard(mTab.getApplicationContext()); | 57 mClipboard = new Clipboard(mTab.getApplicationContext()); |
| 58 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.
| |
| 59 @Override | |
| 60 protected String doInBackground(Void... params) { | |
| 61 String packageLabel = null; | |
| 62 Activity activity = mTab.getActivity(); | |
| 63 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(SAMPLE_ URL)); | |
| 64 PackageManager pm = activity.getPackageManager(); | |
| 65 ResolveInfo info = pm.resolveActivity(intent, 0); | |
| 66 if (info != null && info.match != 0) { | |
| 67 packageLabel = info.loadLabel(pm).toString(); | |
| 68 } | |
| 69 | |
| 70 return packageLabel == null | |
| 71 ? activity.getString(R.string.menu_open_in_product_defau lt) | |
| 72 : activity.getString(R.string.menu_open_in_product, pack ageLabel); | |
| 73 } | |
| 74 }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); | |
| 48 } | 75 } |
| 49 | 76 |
| 50 @Override | 77 @Override |
| 51 public boolean isIncognito() { | 78 public boolean isIncognito() { |
| 52 return mTab.isIncognito(); | 79 return mTab.isIncognito(); |
| 53 } | 80 } |
| 54 | 81 |
| 55 @Override | 82 @Override |
| 56 public boolean isIncognitoSupported() { | 83 public boolean isIncognitoSupported() { |
| 57 return PrefServiceBridge.getInstance().isIncognitoModeEnabled(); | 84 return PrefServiceBridge.getInstance().isIncognitoModeEnabled(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 } | 252 } |
| 226 | 253 |
| 227 if (!activityStarted) { | 254 if (!activityStarted) { |
| 228 Context context = mTab.getActivity(); | 255 Context context = mTab.getActivity(); |
| 229 if (context == null) context = mTab.getApplicationContext(); | 256 if (context == null) context = mTab.getApplicationContext(); |
| 230 context.startActivity(chromeIntent); | 257 context.startActivity(chromeIntent); |
| 231 activityStarted = true; | 258 activityStarted = true; |
| 232 } | 259 } |
| 233 } | 260 } |
| 234 | 261 |
| 262 @Override | |
| 263 public void onOpenInNewChromeTabFromCCT(String linkUrl, boolean isIncognito) { | |
| 264 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); | |
| 265 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
| 266 intent.setPackage(mTab.getApplicationContext().getPackageName()); | |
| 267 intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PAR ENT, false); | |
| 268 if (isIncognito) { | |
| 269 intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); | |
| 270 intent.putExtra( | |
| 271 Browser.EXTRA_APPLICATION_ID, mTab.getApplicationContext().g etPackageName()); | |
| 272 IntentHandler.addTrustedIntentExtras(intent); | |
| 273 } | |
| 274 IntentUtils.safeStartActivity(mTab.getActivity(), intent); | |
| 275 } | |
| 276 | |
| 277 @Override | |
| 278 public String getTitleForOpenTabInExternalApp() { | |
| 279 try { | |
| 280 return mDefaultBrowserFetcher.get(); | |
| 281 } catch (InterruptedException | ExecutionException e) { | |
| 282 return mTab.getActivity().getString(R.string.menu_open_in_product_de fault); | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 @Override | |
| 287 public void onOpenInDefaultBrowser(String url) { | |
| 288 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.
| |
| 289 IntentUtils.safeStartActivity(mTab.getActivity(), intent); | |
| 290 } | |
| 291 | |
| 235 /** | 292 /** |
| 236 * Checks if spdy proxy is enabled for input url. | 293 * Checks if spdy proxy is enabled for input url. |
| 237 * @param url Input url to check for spdy setting. | 294 * @param url Input url to check for spdy setting. |
| 238 * @return true if url is enabled for spdy proxy. | 295 * @return true if url is enabled for spdy proxy. |
| 239 */ | 296 */ |
| 240 private boolean isSpdyProxyEnabledForUrl(String url) { | 297 private boolean isSpdyProxyEnabledForUrl(String url) { |
| 241 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled () | 298 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled () |
| 242 && url != null && !url.toLowerCase(Locale.US).startsWith( | 299 && url != null && !url.toLowerCase(Locale.US).startsWith( |
| 243 UrlConstants.HTTPS_URL_PREFIX) | 300 UrlConstants.HTTPS_URL_PREFIX) |
| 244 && !isIncognito()) { | 301 && !isIncognito()) { |
| 245 return true; | 302 return true; |
| 246 } | 303 } |
| 247 return false; | 304 return false; |
| 248 } | 305 } |
| 249 | 306 |
| 250 } | 307 } |
| OLD | NEW |