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.externalnav; | 5 package org.chromium.chrome.browser.externalnav; |
| 6 | 6 |
| 7 import android.content.ActivityNotFoundException; | 7 import android.content.ActivityNotFoundException; |
| 8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
| 9 import android.content.Intent; | 9 import android.content.Intent; |
| 10 import android.content.pm.PackageManager; | |
| 10 import android.content.pm.ResolveInfo; | 11 import android.content.pm.ResolveInfo; |
| 11 import android.net.Uri; | 12 import android.net.Uri; |
| 12 import android.os.SystemClock; | 13 import android.os.SystemClock; |
| 13 import android.provider.Browser; | 14 import android.provider.Browser; |
| 14 import android.text.TextUtils; | 15 import android.text.TextUtils; |
| 15 import android.webkit.WebView; | 16 import android.webkit.WebView; |
| 16 | 17 |
| 17 import org.chromium.base.CommandLine; | 18 import org.chromium.base.CommandLine; |
| 18 import org.chromium.base.Log; | 19 import org.chromium.base.Log; |
| 19 import org.chromium.base.VisibleForTesting; | 20 import org.chromium.base.VisibleForTesting; |
| 20 import org.chromium.base.metrics.RecordHistogram; | 21 import org.chromium.base.metrics.RecordHistogram; |
| 21 import org.chromium.chrome.browser.ChromeSwitches; | 22 import org.chromium.chrome.browser.ChromeSwitches; |
| 22 import org.chromium.chrome.browser.IntentHandler; | 23 import org.chromium.chrome.browser.IntentHandler; |
| 23 import org.chromium.chrome.browser.UrlConstants; | 24 import org.chromium.chrome.browser.UrlConstants; |
| 24 import org.chromium.chrome.browser.tab.Tab; | 25 import org.chromium.chrome.browser.tab.Tab; |
| 25 import org.chromium.chrome.browser.tab.TabRedirectHandler; | 26 import org.chromium.chrome.browser.tab.TabRedirectHandler; |
| 26 import org.chromium.chrome.browser.util.IntentUtils; | 27 import org.chromium.chrome.browser.util.IntentUtils; |
| 27 import org.chromium.chrome.browser.util.UrlUtilities; | 28 import org.chromium.chrome.browser.util.UrlUtilities; |
| 28 import org.chromium.ui.base.PageTransition; | 29 import org.chromium.ui.base.PageTransition; |
| 29 | 30 |
| 30 import java.net.URI; | 31 import java.net.URI; |
| 32 import java.util.Collections; | |
| 31 import java.util.HashSet; | 33 import java.util.HashSet; |
| 32 import java.util.List; | 34 import java.util.List; |
| 35 import java.util.Set; | |
| 33 import java.util.concurrent.TimeUnit; | 36 import java.util.concurrent.TimeUnit; |
| 34 | 37 |
| 35 /** | 38 /** |
| 36 * Logic related to the URL overriding/intercepting functionality. | 39 * Logic related to the URL overriding/intercepting functionality. |
| 37 * This feature allows Chrome to convert certain navigations to Android Intents allowing | 40 * This feature allows Chrome to convert certain navigations to Android Intents allowing |
| 38 * applications like Youtube to direct users clicking on a http(s) link to their native app. | 41 * applications like Youtube to direct users clicking on a http(s) link to their native app. |
| 39 */ | 42 */ |
| 40 public class ExternalNavigationHandler { | 43 public class ExternalNavigationHandler { |
| 41 private static final String TAG = "UrlHandler"; | 44 private static final String TAG = "UrlHandler"; |
| 42 private static final String SCHEME_WTAI = "wtai://wp/"; | 45 private static final String SCHEME_WTAI = "wtai://wp/"; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 boolean hasBrowserFallbackUrl = false; | 108 boolean hasBrowserFallbackUrl = false; |
| 106 String browserFallbackUrl = | 109 String browserFallbackUrl = |
| 107 IntentUtils.safeGetStringExtra(intent, EXTRA_BROWSER_FALLBACK_UR L); | 110 IntentUtils.safeGetStringExtra(intent, EXTRA_BROWSER_FALLBACK_UR L); |
| 108 if (browserFallbackUrl != null | 111 if (browserFallbackUrl != null |
| 109 && UrlUtilities.isValidForIntentFallbackNavigation(browserFallba ckUrl)) { | 112 && UrlUtilities.isValidForIntentFallbackNavigation(browserFallba ckUrl)) { |
| 110 hasBrowserFallbackUrl = true; | 113 hasBrowserFallbackUrl = true; |
| 111 } else { | 114 } else { |
| 112 browserFallbackUrl = null; | 115 browserFallbackUrl = null; |
| 113 } | 116 } |
| 114 | 117 |
| 118 try { | |
|
please use gerrit instead
2016/07/27 08:29:02
Put this block into a separate function, for examp
| |
| 119 //scheme | |
| 120 String scheme = intent.getData().getScheme(); | |
|
please use gerrit instead
2016/07/27 08:29:02
You don't use "scheme" anywhere except to check th
| |
| 121 String fragment = intent.getData().getFragment(); | |
| 122 if (!TextUtils.isEmpty(scheme) && null != fragment && fragment.conta ins(";")) { | |
|
please use gerrit instead
2016/07/27 08:29:02
Chrome style is to put null after variable:
fragm
| |
| 123 String[] parts = fragment.split(";"); | |
| 124 | |
| 125 Set<Set<String>> allFingerPrint256 = new HashSet<>(); | |
| 126 /** | |
| 127 * same package name , different keystores, generated fingerprin t256 set. | |
| 128 * | |
| 129 * 1.an app's signature may update and change from old, so need config and | |
| 130 * support new and old, but this is optional.(e.g. a.only config new fingerprint | |
| 131 * b. only config old fingerprint. c.config new and old fingerpr int) | |
| 132 * | |
| 133 * 2.one apk itself may contain more than one keystore to sign. | |
| 134 * | |
| 135 * example: suppose apk's new signature is 3A4FXXXXXX,12XXXXXXX, and old signature | |
| 136 * is 1B2AXXXX. you can config the intent like "...;sha256=3A4FX XXXXX,12XXXXXXX;.." | |
| 137 * or "..;sha256=3A4FXXXXXX,12XXXXXXX|1B2AXXXX;.." | |
| 138 */ | |
|
please use gerrit instead
2016/07/27 08:29:02
Chrome style is to use // style comments when insi
| |
| 139 String pkgName = ""; | |
| 140 String fingerPrint256 = ""; | |
| 141 String[] fingerPrint256DifGroups; | |
| 142 for (String each : parts) { | |
| 143 String[] part = each.split("="); | |
|
please use gerrit instead
2016/07/27 08:29:02
Integer loops are more efficient on Android.
for
| |
| 144 if (part[0].equals("sha256")) { | |
|
please use gerrit instead
2016/07/27 08:29:02
This will crash if "each" does not contain "=".
| |
| 145 fingerPrint256 = part[1]; | |
|
please use gerrit instead
2016/07/27 08:29:02
This will crash if "=" is the last character of "e
| |
| 146 | |
| 147 } | |
| 148 if (part[0].equals("package")) { | |
| 149 pkgName = part[1]; | |
| 150 } | |
| 151 } | |
| 152 if (!TextUtils.isEmpty(pkgName) && !TextUtils.isEmpty(fingerPrin t256)) { | |
| 153 fingerPrint256DifGroups = fingerPrint256.split("\\|"); | |
| 154 for (int i = 0; i < fingerPrint256DifGroups.length; ++i) { | |
| 155 Set<String> fingerPrint256GroupSignKeySet = new HashSet< >(); | |
| 156 Collections.addAll(fingerPrint256GroupSignKeySet, finger Print256DifGroups[i] | |
| 157 .split(",")); | |
| 158 allFingerPrint256.add(fingerPrint256GroupSignKeySet); | |
| 159 } | |
| 160 Set<String> fingerPrint256Set = mDelegate.getPackageSHA256Fi ngerprints(pkgName); | |
| 161 if (!allFingerPrint256.contains(fingerPrint256Set)) { | |
| 162 return OverrideUrlLoadingResult.NO_OVERRIDE; | |
| 163 } | |
| 164 } | |
| 165 } | |
| 166 } catch (PackageManager.NameNotFoundException e) { | |
| 167 return OverrideUrlLoadingResult.NO_OVERRIDE; | |
| 168 } catch (Throwable ignore) { | |
| 169 /** | |
| 170 * 1. in method getSha256() , if No SHA-256 implementation found, th is new feature won't | |
| 171 * work, so it should backwards to original way to handle the intent , we should ignore | |
| 172 * ths Throwable. | |
| 173 * | |
| 174 * 2. in the process above, any other exception or error except "Nam eNotFoundException" | |
| 175 * happens, we can consider the feature fail ,and catch the throwabl e and continue next | |
| 176 * work. | |
| 177 */ | |
| 178 } | |
| 179 | |
| 115 long time = SystemClock.elapsedRealtime(); | 180 long time = SystemClock.elapsedRealtime(); |
| 116 OverrideUrlLoadingResult result = shouldOverrideUrlLoadingInternal( | 181 OverrideUrlLoadingResult result = shouldOverrideUrlLoadingInternal( |
| 117 params, intent, hasBrowserFallbackUrl, browserFallbackUrl); | 182 params, intent, hasBrowserFallbackUrl, browserFallbackUrl); |
| 118 RecordHistogram.recordTimesHistogram("Android.StrictMode.OverrideUrlLoad ingTime", | 183 RecordHistogram.recordTimesHistogram("Android.StrictMode.OverrideUrlLoad ingTime", |
| 119 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); | 184 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); |
| 120 | 185 |
| 121 if (result == OverrideUrlLoadingResult.NO_OVERRIDE && hasBrowserFallback Url | 186 if (result == OverrideUrlLoadingResult.NO_OVERRIDE && hasBrowserFallback Url |
| 122 && (params.getRedirectHandler() == null | 187 && (params.getRedirectHandler() == null |
| 123 // For instance, if this is a chained fallback URL, we i gnore it. | 188 // For instance, if this is a chained fallback URL, we i gnore it. |
| 124 || !params.getRedirectHandler().shouldNotOverrideUrlLoad ing())) { | 189 || !params.getRedirectHandler().shouldNotOverrideUrlLoad ing())) { |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 514 if (defaultSmsPackageName == null) return null; | 579 if (defaultSmsPackageName == null) return null; |
| 515 // Makes sure that the default SMS app actually resolves the intent. | 580 // Makes sure that the default SMS app actually resolves the intent. |
| 516 for (ResolveInfo resolveInfo : resolvingComponentNames) { | 581 for (ResolveInfo resolveInfo : resolvingComponentNames) { |
| 517 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam e)) { | 582 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam e)) { |
| 518 return defaultSmsPackageName; | 583 return defaultSmsPackageName; |
| 519 } | 584 } |
| 520 } | 585 } |
| 521 return null; | 586 return null; |
| 522 } | 587 } |
| 523 } | 588 } |
| OLD | NEW |