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.content.Context; | 7 import android.content.Context; |
8 import android.content.Intent; | 8 import android.content.Intent; |
9 import android.net.MailTo; | 9 import android.net.MailTo; |
10 import android.net.Uri; | 10 import android.net.Uri; |
11 import android.provider.Browser; | |
11 import android.provider.ContactsContract; | 12 import android.provider.ContactsContract; |
12 | 13 |
13 import org.chromium.base.metrics.RecordUserAction; | 14 import org.chromium.base.metrics.RecordUserAction; |
15 import org.chromium.chrome.R; | |
16 import org.chromium.chrome.browser.DefaultBrowserInfo; | |
14 import org.chromium.chrome.browser.IntentHandler; | 17 import org.chromium.chrome.browser.IntentHandler; |
15 import org.chromium.chrome.browser.UrlConstants; | 18 import org.chromium.chrome.browser.UrlConstants; |
16 import org.chromium.chrome.browser.contextmenu.ContextMenuItemDelegate; | 19 import org.chromium.chrome.browser.contextmenu.ContextMenuItemDelegate; |
20 import org.chromium.chrome.browser.document.ChromeLauncherActivity; | |
17 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 21 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
18 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; | 22 import org.chromium.chrome.browser.net.spdyproxy.DataReductionProxySettings; |
19 import org.chromium.chrome.browser.preferences.PrefServiceBridge; | 23 import org.chromium.chrome.browser.preferences.PrefServiceBridge; |
20 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; | 24 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
21 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; | 25 import org.chromium.chrome.browser.tabmodel.document.TabDelegate; |
22 import org.chromium.chrome.browser.util.IntentUtils; | 26 import org.chromium.chrome.browser.util.IntentUtils; |
23 import org.chromium.chrome.browser.util.UrlUtilities; | 27 import org.chromium.chrome.browser.util.UrlUtilities; |
24 import org.chromium.content_public.browser.LoadUrlParams; | 28 import org.chromium.content_public.browser.LoadUrlParams; |
25 import org.chromium.content_public.common.Referrer; | 29 import org.chromium.content_public.common.Referrer; |
26 import org.chromium.ui.base.Clipboard; | 30 import org.chromium.ui.base.Clipboard; |
27 import org.chromium.ui.base.PageTransition; | 31 import org.chromium.ui.base.PageTransition; |
28 | 32 |
29 import java.net.URI; | 33 import java.net.URI; |
30 import java.util.Locale; | 34 import java.util.Locale; |
35 import java.util.concurrent.ExecutionException; | |
31 | 36 |
32 /** | 37 /** |
33 * A default {@link ContextMenuItemDelegate} that supports the context menu func tionality in Tab. | 38 * A default {@link ContextMenuItemDelegate} that supports the context menu func tionality in Tab. |
34 */ | 39 */ |
35 public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { | 40 public class TabContextMenuItemDelegate implements ContextMenuItemDelegate { |
36 public static final String PAGESPEED_PASSTHROUGH_HEADERS = | 41 public static final String PAGESPEED_PASSTHROUGH_HEADERS = |
37 "Chrome-Proxy: pass-through\nCache-Control: no-cache"; | 42 "Chrome-Proxy: pass-through\nCache-Control: no-cache"; |
43 private static final String SAMPLE_URL = "https://www.google.com"; | |
Ted C
2017/02/14 19:02:00
no longer needed
ltian
2017/02/16 05:05:10
Done.
| |
38 | 44 |
39 private final Clipboard mClipboard; | 45 private final Clipboard mClipboard; |
40 private final Tab mTab; | 46 private final Tab mTab; |
41 | 47 |
42 /** | 48 /** |
43 * Builds a {@link TabContextMenuItemDelegate} instance. | 49 * Builds a {@link TabContextMenuItemDelegate} instance. |
44 */ | 50 */ |
45 public TabContextMenuItemDelegate(Tab tab) { | 51 public TabContextMenuItemDelegate(Tab tab) { |
46 mTab = tab; | 52 mTab = tab; |
47 mClipboard = new Clipboard(mTab.getApplicationContext()); | 53 mClipboard = new Clipboard(mTab.getApplicationContext()); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 } | 231 } |
226 | 232 |
227 if (!activityStarted) { | 233 if (!activityStarted) { |
228 Context context = mTab.getActivity(); | 234 Context context = mTab.getActivity(); |
229 if (context == null) context = mTab.getApplicationContext(); | 235 if (context == null) context = mTab.getApplicationContext(); |
230 context.startActivity(chromeIntent); | 236 context.startActivity(chromeIntent); |
231 activityStarted = true; | 237 activityStarted = true; |
232 } | 238 } |
233 } | 239 } |
234 | 240 |
241 @Override | |
242 public void onOpenInNewChromeTabFromCCT(String linkUrl, boolean isIncognito) { | |
243 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl)); | |
244 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
245 intent.setPackage(mTab.getApplicationContext().getPackageName()); | |
246 intent.putExtra(ChromeLauncherActivity.EXTRA_IS_ALLOWED_TO_RETURN_TO_PAR ENT, false); | |
247 if (isIncognito) { | |
248 intent.putExtra(IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, true); | |
249 intent.putExtra( | |
250 Browser.EXTRA_APPLICATION_ID, mTab.getApplicationContext().g etPackageName()); | |
251 IntentHandler.addTrustedIntentExtras(intent); | |
252 } | |
253 IntentUtils.safeStartActivity(mTab.getActivity(), intent); | |
254 } | |
255 | |
256 @Override | |
257 public String getTitleForOpenTabInExternalApp() { | |
258 try { | |
259 return DefaultBrowserInfo.getTitleOpenInDefaultBrowser(mTab.getActiv ity(), false); | |
260 } catch (InterruptedException | ExecutionException e) { | |
261 return mTab.getActivity().getString(R.string.menu_open_in_product_de fault); | |
262 } | |
263 } | |
264 | |
265 @Override | |
266 public void onOpenInDefaultBrowser(String url) { | |
267 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
268 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
269 IntentUtils.safeStartActivity(mTab.getActivity(), intent); | |
270 } | |
271 | |
235 /** | 272 /** |
236 * Checks if spdy proxy is enabled for input url. | 273 * Checks if spdy proxy is enabled for input url. |
237 * @param url Input url to check for spdy setting. | 274 * @param url Input url to check for spdy setting. |
238 * @return true if url is enabled for spdy proxy. | 275 * @return true if url is enabled for spdy proxy. |
239 */ | 276 */ |
240 private boolean isSpdyProxyEnabledForUrl(String url) { | 277 private boolean isSpdyProxyEnabledForUrl(String url) { |
241 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled () | 278 if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled () |
242 && url != null && !url.toLowerCase(Locale.US).startsWith( | 279 && url != null && !url.toLowerCase(Locale.US).startsWith( |
243 UrlConstants.HTTPS_URL_PREFIX) | 280 UrlConstants.HTTPS_URL_PREFIX) |
244 && !isIncognito()) { | 281 && !isIncognito()) { |
245 return true; | 282 return true; |
246 } | 283 } |
247 return false; | 284 return false; |
248 } | 285 } |
249 | 286 |
250 } | 287 } |
OLD | NEW |