| 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; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.app.KeyguardManager; | 7 import android.app.KeyguardManager; |
| 8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
| 9 import android.app.SearchManager; | 9 import android.app.SearchManager; |
| 10 import android.content.ComponentName; | 10 import android.content.ComponentName; |
| 11 import android.content.Context; | 11 import android.content.Context; |
| 12 import android.content.Intent; | 12 import android.content.Intent; |
| 13 import android.content.pm.PackageManager; | 13 import android.content.pm.PackageManager; |
| 14 import android.content.pm.ResolveInfo; | 14 import android.content.pm.ResolveInfo; |
| 15 import android.net.Uri; | 15 import android.net.Uri; |
| 16 import android.os.Bundle; | 16 import android.os.Bundle; |
| 17 import android.os.SystemClock; | 17 import android.os.SystemClock; |
| 18 import android.provider.Browser; | 18 import android.provider.Browser; |
| 19 import android.provider.MediaStore; | 19 import android.provider.MediaStore; |
| 20 import android.speech.RecognizerResultsIntent; | 20 import android.speech.RecognizerResultsIntent; |
| 21 import android.text.TextUtils; | 21 import android.text.TextUtils; |
| 22 import android.util.Pair; | 22 import android.util.Pair; |
| 23 | 23 |
| 24 import org.chromium.base.ApiCompatibilityUtils; | 24 import org.chromium.base.ApiCompatibilityUtils; |
| 25 import org.chromium.base.Log; | 25 import org.chromium.base.Log; |
| 26 import org.chromium.base.VisibleForTesting; | 26 import org.chromium.base.VisibleForTesting; |
| 27 import org.chromium.base.metrics.RecordHistogram; | 27 import org.chromium.base.metrics.RecordHistogram; |
| 28 import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; | 28 //import org.chromium.chrome.browser.externalauth.ExternalAuthUtils; |
| 29 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; | 29 //import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; |
| 30 import org.chromium.chrome.browser.omnibox.AutocompleteController; | 30 //import org.chromium.chrome.browser.omnibox.AutocompleteController; |
| 31 import org.chromium.chrome.browser.search_engines.TemplateUrlService; | 31 import org.chromium.chrome.browser.search_engines.TemplateUrlService; |
| 32 import org.chromium.chrome.browser.tab.Tab; | 32 //import org.chromium.chrome.browser.tab.Tab; |
| 33 import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; | 33 //import org.chromium.chrome.browser.tabmodel.document.ActivityDelegate; |
| 34 import org.chromium.chrome.browser.util.IntentUtils; | 34 import org.chromium.chrome.browser.util.IntentUtils; |
| 35 import org.chromium.content_public.browser.LoadUrlParams; | 35 import org.chromium.content_public.browser.LoadUrlParams; |
| 36 import org.chromium.content_public.common.Referrer; | 36 import org.chromium.content_public.common.Referrer; |
| 37 | 37 |
| 38 import java.util.ArrayList; | 38 import java.util.ArrayList; |
| 39 import java.util.Iterator; | 39 import java.util.Iterator; |
| 40 import java.util.List; | 40 import java.util.List; |
| 41 import java.util.Locale; | 41 import java.util.Locale; |
| 42 | 42 |
| 43 /** | 43 /** |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 282 |
| 283 /** | 283 /** |
| 284 * Handles an Intent after the ChromeTabbedActivity decides that it shouldn'
t ignore the | 284 * Handles an Intent after the ChromeTabbedActivity decides that it shouldn'
t ignore the |
| 285 * Intent. | 285 * Intent. |
| 286 * | 286 * |
| 287 * @return Whether the Intent was successfully handled. | 287 * @return Whether the Intent was successfully handled. |
| 288 * TODO(mariakhomenko): make package protected after ChromeTabbedActivity is
upstreamed. | 288 * TODO(mariakhomenko): make package protected after ChromeTabbedActivity is
upstreamed. |
| 289 */ | 289 */ |
| 290 public boolean onNewIntent(Context context, Intent intent) { | 290 public boolean onNewIntent(Context context, Intent intent) { |
| 291 assert intentHasValidUrl(intent); | 291 assert intentHasValidUrl(intent); |
| 292 String url = getUrlFromIntent(intent); | 292 // String url = getUrlFromIntent(intent); |
| 293 boolean hasUserGesture = | 293 // boolean hasUserGesture = |
| 294 IntentWithGesturesHandler.getInstance().getUserGestureAndClear(i
ntent); | 294 // IntentWithGesturesHandler.getInstance().getUserGestureAndClear
(intent); |
| 295 TabOpenType tabOpenType = getTabOpenType(intent); | 295 // TabOpenType tabOpenType = getTabOpenType(intent); |
| 296 int tabIdToBringToFront = IntentUtils.safeGetIntExtra( | 296 // int tabIdToBringToFront = IntentUtils.safeGetIntExtra( |
| 297 intent, TabOpenType.BRING_TAB_TO_FRONT.name(), Tab.INVALID_TAB_I
D); | 297 // intent, TabOpenType.BRING_TAB_TO_FRONT.name(), Tab.INVALID_TAB
_ID); |
| 298 if (url == null && tabIdToBringToFront == Tab.INVALID_TAB_ID | 298 // if (url == null && tabIdToBringToFront == Tab.INVALID_TAB_ID |
| 299 && tabOpenType != TabOpenType.OPEN_NEW_INCOGNITO_TAB) { | 299 // && tabOpenType != TabOpenType.OPEN_NEW_INCOGNITO_TAB) { |
| 300 return handleWebSearchIntent(intent); | 300 return handleWebSearchIntent(intent); |
| 301 } | 301 // } |
| 302 | 302 |
| 303 String referrerUrl = getReferrerUrlIncludingExtraHeaders(intent, context
); | 303 // String referrerUrl = getReferrerUrlIncludingExtraHeaders(intent, conte
xt); |
| 304 String extraHeaders = getExtraHeadersFromIntent(intent); | 304 // String extraHeaders = getExtraHeadersFromIntent(intent); |
| 305 | 305 // |
| 306 // TODO(joth): Presumably this should check the action too. | 306 // // TODO(joth): Presumably this should check the action too. |
| 307 mDelegate.processUrlViewIntent(url, referrerUrl, extraHeaders, tabOpenTy
pe, | 307 // mDelegate.processUrlViewIntent(url, referrerUrl, extraHeaders, tabOpen
Type, |
| 308 IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATION
_ID), | 308 // IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPLICATI
ON_ID), |
| 309 tabIdToBringToFront, hasUserGesture, intent); | 309 // tabIdToBringToFront, hasUserGesture, intent); |
| 310 recordExternalIntentSourceUMA(intent); | 310 // recordExternalIntentSourceUMA(intent); |
| 311 return true; | 311 // return true; |
| 312 } | 312 } |
| 313 | 313 |
| 314 /** | 314 /** |
| 315 * Extracts referrer Uri from intent, if supplied. | 315 * Extracts referrer Uri from intent, if supplied. |
| 316 * @param intent The intent to use. | 316 * @param intent The intent to use. |
| 317 * @return The referrer Uri. | 317 * @return The referrer Uri. |
| 318 */ | 318 */ |
| 319 private static Uri getReferrer(Intent intent) { | 319 private static Uri getReferrer(Intent intent) { |
| 320 Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); | 320 Uri referrer = intent.getParcelableExtra(Intent.EXTRA_REFERRER); |
| 321 if (referrer != null) { | 321 if (referrer != null) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 if (results == null && sTestIntentsEnabled) { | 414 if (results == null && sTestIntentsEnabled) { |
| 415 String testResult = IntentUtils.safeGetStringExtra( | 415 String testResult = IntentUtils.safeGetStringExtra( |
| 416 intent, RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_ST
RINGS); | 416 intent, RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_ST
RINGS); |
| 417 if (testResult != null) { | 417 if (testResult != null) { |
| 418 results = new ArrayList<String>(); | 418 results = new ArrayList<String>(); |
| 419 results.add(testResult); | 419 results.add(testResult); |
| 420 } | 420 } |
| 421 } | 421 } |
| 422 if (results == null || results.size() == 0) return null; | 422 if (results == null || results.size() == 0) return null; |
| 423 String query = results.get(0); | 423 String query = results.get(0); |
| 424 String url = AutocompleteController.nativeQualifyPartialURLQuery(query); | 424 String url = null; // AutocompleteController.nativeQualifyPartialURLQuer
y(query); |
| 425 if (url == null) { | 425 if (url == null) { |
| 426 List<String> urls = IntentUtils.safeGetStringArrayListExtra( | 426 List<String> urls = IntentUtils.safeGetStringArrayListExtra( |
| 427 intent, RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_UR
LS); | 427 intent, RecognizerResultsIntent.EXTRA_VOICE_SEARCH_RESULT_UR
LS); |
| 428 if (urls != null && urls.size() > 0) { | 428 if (urls != null && urls.size() > 0) { |
| 429 url = urls.get(0); | 429 url = urls.get(0); |
| 430 } else { | 430 } else { |
| 431 url = TemplateUrlService.getInstance().getUrlForVoiceSearchQuery
(query); | 431 url = TemplateUrlService.getInstance().getUrlForVoiceSearchQuery
(query); |
| 432 } | 432 } |
| 433 } | 433 } |
| 434 return url; | 434 return url; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 if (intent == null) return false; | 696 if (intent == null) return false; |
| 697 | 697 |
| 698 PendingIntent token = fetchAuthenticationTokenFromIntent(intent); | 698 PendingIntent token = fetchAuthenticationTokenFromIntent(intent); |
| 699 if (token == null) return false; | 699 if (token == null) return false; |
| 700 | 700 |
| 701 // Do not ignore a valid URL Intent if the sender is Chrome. (If the Pen
dingIntents are | 701 // Do not ignore a valid URL Intent if the sender is Chrome. (If the Pen
dingIntents are |
| 702 // equal, we know that the sender was us.) | 702 // equal, we know that the sender was us.) |
| 703 if (isChromeToken(token, context)) { | 703 if (isChromeToken(token, context)) { |
| 704 return true; | 704 return true; |
| 705 } | 705 } |
| 706 if (ExternalAuthUtils.getInstance().isGoogleSigned( | 706 // if (ExternalAuthUtils.getInstance().isGoogleSigned( |
| 707 context.getPackageManager(), ApiCompatibilityUtils.getCreato
rPackage(token))) { | 707 // context.getPackageManager(), ApiCompatibilityUtils.getCrea
torPackage(token))) { |
| 708 return true; | 708 // return true; |
| 709 } | 709 // } |
| 710 return false; | 710 return false; |
| 711 } | 711 } |
| 712 | 712 |
| 713 private boolean isIntentUserVisible(Context context) { | 713 private boolean isIntentUserVisible(Context context) { |
| 714 // Only process Intents if the screen is on and the device is unlocked; | 714 // Only process Intents if the screen is on and the device is unlocked; |
| 715 // i.e. the user will see what is going on. | 715 // i.e. the user will see what is going on. |
| 716 if (mKeyguardManager == null) { | 716 if (mKeyguardManager == null) { |
| 717 mKeyguardManager = (KeyguardManager) context.getSystemService(Contex
t.KEYGUARD_SERVICE); | 717 mKeyguardManager = (KeyguardManager) context.getSystemService(Contex
t.KEYGUARD_SERVICE); |
| 718 } | 718 } |
| 719 if (!ApiCompatibilityUtils.isInteractive(context)) return false; | 719 if (!ApiCompatibilityUtils.isInteractive(context)) return false; |
| 720 return !ApiCompatibilityUtils.isDeviceProvisioned(context) | 720 return !ApiCompatibilityUtils.isDeviceProvisioned(context) |
| 721 || !mKeyguardManager.inKeyguardRestrictedInputMode(); | 721 || !mKeyguardManager.inKeyguardRestrictedInputMode(); |
| 722 } | 722 } |
| 723 | 723 |
| 724 /* | 724 /* |
| 725 * The default behavior here is to open in a new tab. If this is changed, e
nsure | 725 * The default behavior here is to open in a new tab. If this is changed, e
nsure |
| 726 * intents with action NDEF_DISCOVERED (links beamed over NFC) are handled p
roperly. | 726 * intents with action NDEF_DISCOVERED (links beamed over NFC) are handled p
roperly. |
| 727 */ | 727 */ |
| 728 private TabOpenType getTabOpenType(Intent intent) { | 728 // private TabOpenType getTabOpenType(Intent intent) { |
| 729 if (IntentUtils.safeGetBooleanExtra( | 729 // if (IntentUtils.safeGetBooleanExtra( |
| 730 intent, BookmarkUtils.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, f
alse)) { | 730 // intent, BookmarkUtils.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB,
false)) { |
| 731 return TabOpenType.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB; | 731 // return TabOpenType.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB; |
| 732 } | 732 // } |
| 733 | 733 // |
| 734 if (IntentUtils.safeGetBooleanExtra(intent, EXTRA_OPEN_NEW_INCOGNITO_TAB
, false)) { | 734 // if (IntentUtils.safeGetBooleanExtra(intent, EXTRA_OPEN_NEW_INCOGNITO_T
AB, false)) { |
| 735 return TabOpenType.OPEN_NEW_INCOGNITO_TAB; | 735 // return TabOpenType.OPEN_NEW_INCOGNITO_TAB; |
| 736 } | 736 // } |
| 737 | 737 // |
| 738 if (IntentUtils.safeGetIntExtra(intent, TabOpenType.BRING_TAB_TO_FRONT.n
ame(), | 738 // if (IntentUtils.safeGetIntExtra(intent, TabOpenType.BRING_TAB_TO_FRONT
.name(), |
| 739 Tab.INVALID_TAB_ID) != Tab.INVALID_TAB_ID) { | 739 // Tab.INVALID_TAB_ID) != Tab.INVALID_TAB_ID) { |
| 740 return TabOpenType.BRING_TAB_TO_FRONT; | 740 // return TabOpenType.BRING_TAB_TO_FRONT; |
| 741 } | 741 // } |
| 742 | 742 // |
| 743 String appId = IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_APPL
ICATION_ID); | 743 // String appId = IntentUtils.safeGetStringExtra(intent, Browser.EXTRA_AP
PLICATION_ID); |
| 744 // Due to users complaints, we are NOT reusing tabs for apps that do not
specify an appId. | 744 // // Due to users complaints, we are NOT reusing tabs for apps that do n
ot specify an appId. |
| 745 if (appId == null | 745 // if (appId == null |
| 746 || IntentUtils.safeGetBooleanExtra(intent, Browser.EXTRA_CREATE_
NEW_TAB, false)) { | 746 // || IntentUtils.safeGetBooleanExtra(intent, Browser.EXTRA_CREAT
E_NEW_TAB, false)) { |
| 747 return TabOpenType.OPEN_NEW_TAB; | 747 // return TabOpenType.OPEN_NEW_TAB; |
| 748 } | 748 // } |
| 749 | 749 // |
| 750 // Intents from chrome open in the same tab by default, all others only
clobber | 750 // // Intents from chrome open in the same tab by default, all others onl
y clobber |
| 751 // tabs created by the same app. | 751 // // tabs created by the same app. |
| 752 return mPackageName.equals(appId) ? TabOpenType.CLOBBER_CURRENT_TAB | 752 // return mPackageName.equals(appId) ? TabOpenType.CLOBBER_CURRENT_TAB |
| 753 : TabOpenType.REUSE_APP_ID_MATCHING_TA
B_ELSE_NEW_TAB; | 753 // : TabOpenType.REUSE_APP_ID_MATCHING_
TAB_ELSE_NEW_TAB; |
| 754 } | 754 // } |
| 755 | 755 |
| 756 private boolean isInvalidScheme(String scheme) { | 756 private boolean isInvalidScheme(String scheme) { |
| 757 return scheme != null && (scheme.toLowerCase(Locale.US).equals("javascri
pt") | 757 return scheme != null && (scheme.toLowerCase(Locale.US).equals("javascri
pt") |
| 758 || scheme.toLowerCase(Locale.US).equals
("jar")); | 758 || scheme.toLowerCase(Locale.US).equals
("jar")); |
| 759 } | 759 } |
| 760 | 760 |
| 761 /** | 761 /** |
| 762 * Parses the scheme out of the URL if possible, trimming and getting rid of
unsafe characters. | 762 * Parses the scheme out of the URL if possible, trimming and getting rid of
unsafe characters. |
| 763 * This is useful for determining if a URL has a sneaky, unsafe scheme, e.g.
"java script" or | 763 * This is useful for determining if a URL has a sneaky, unsafe scheme, e.g.
"java script" or |
| 764 * "j$a$r". See: http://crbug.com/248398 | 764 * "j$a$r". See: http://crbug.com/248398 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 800 } |
| 801 | 801 |
| 802 /** | 802 /** |
| 803 * Retrieve the URL from the Intent, which may be in multiple locations. | 803 * Retrieve the URL from the Intent, which may be in multiple locations. |
| 804 * @param intent Intent to examine. | 804 * @param intent Intent to examine. |
| 805 * @return URL from the Intent, or null if a valid URL couldn't be found. | 805 * @return URL from the Intent, or null if a valid URL couldn't be found. |
| 806 */ | 806 */ |
| 807 public static String getUrlFromIntent(Intent intent) { | 807 public static String getUrlFromIntent(Intent intent) { |
| 808 if (intent == null) return null; | 808 if (intent == null) return null; |
| 809 | 809 |
| 810 String url = getUrlFromVoiceSearchResult(intent); | 810 // String url = getUrlFromVoiceSearchResult(intent); |
| 811 if (url == null) url = ActivityDelegate.getInitialUrlForDocument(intent)
; | 811 // if (url == null) url = ActivityDelegate.getInitialUrlForDocument(inten
t); |
| 812 if (url == null) url = intent.getDataString(); | 812 // if (url == null) url = intent.getDataString(); |
| 813 String url = intent.getDataString(); |
| 813 if (url == null) return null; | 814 if (url == null) return null; |
| 814 | 815 |
| 815 url = url.trim(); | 816 url = url.trim(); |
| 816 if (isGoogleChromeScheme(url)) { | 817 if (isGoogleChromeScheme(url)) { |
| 817 url = getUrlFromGoogleChromeSchemeUrl(url); | 818 url = getUrlFromGoogleChromeSchemeUrl(url); |
| 818 } | 819 } |
| 819 return TextUtils.isEmpty(url) ? null : url; | 820 return TextUtils.isEmpty(url) ? null : url; |
| 820 } | 821 } |
| 821 | 822 |
| 822 /** | 823 /** |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 * @param id The referrer id. | 868 * @param id The referrer id. |
| 868 * @return The URL for the referrer or null if none found. | 869 * @return The URL for the referrer or null if none found. |
| 869 */ | 870 */ |
| 870 public static String getPendingReferrerUrl(int id) { | 871 public static String getPendingReferrerUrl(int id) { |
| 871 if (sPendingReferrer != null && (sPendingReferrer.first == id)) { | 872 if (sPendingReferrer != null && (sPendingReferrer.first == id)) { |
| 872 return sPendingReferrer.second; | 873 return sPendingReferrer.second; |
| 873 } | 874 } |
| 874 return null; | 875 return null; |
| 875 } | 876 } |
| 876 } | 877 } |
| OLD | NEW |