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.ResolveInfo; | 10 import android.content.pm.ResolveInfo; |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 && (params.getRedirectHandler() == null | 126 && (params.getRedirectHandler() == null |
| 127 // For instance, if this is a chained fallback URL, we i gnore it. | 127 // For instance, if this is a chained fallback URL, we i gnore it. |
| 128 || !params.getRedirectHandler().shouldNotOverrideUrlLoad ing())) { | 128 || !params.getRedirectHandler().shouldNotOverrideUrlLoad ing())) { |
| 129 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, params); | 129 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, params); |
| 130 } | 130 } |
| 131 return result; | 131 return result; |
| 132 } | 132 } |
| 133 | 133 |
| 134 private boolean resolversSubsetOf(List<ResolveInfo> infos, List<ResolveInfo> container) { | 134 private boolean resolversSubsetOf(List<ResolveInfo> infos, List<ResolveInfo> container) { |
| 135 HashSet<ComponentName> containerSet = new HashSet<>(); | 135 HashSet<ComponentName> containerSet = new HashSet<>(); |
| 136 if (container == null) return false; | |
|
Maria
2016/10/10 22:56:56
I would move this check above the hash set allocat
Ted C
2016/10/10 23:05:45
Done.
| |
| 137 | |
| 136 for (ResolveInfo info : container) { | 138 for (ResolveInfo info : container) { |
| 137 containerSet.add( | 139 containerSet.add( |
| 138 new ComponentName(info.activityInfo.packageName, info.activi tyInfo.name)); | 140 new ComponentName(info.activityInfo.packageName, info.activi tyInfo.name)); |
| 139 } | 141 } |
| 140 for (ResolveInfo info : infos) { | 142 for (ResolveInfo info : infos) { |
| 141 if (!containerSet.contains(new ComponentName( | 143 if (!containerSet.contains(new ComponentName( |
| 142 info.activityInfo.packageName, info.activityInfo.name))) { | 144 info.activityInfo.packageName, info.activityInfo.name))) { |
| 143 return false; | 145 return false; |
| 144 } | 146 } |
| 145 } | 147 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 // security (only access to BROWSABLE activities). | 304 // security (only access to BROWSABLE activities). |
| 303 intent.addCategory(Intent.CATEGORY_BROWSABLE); | 305 intent.addCategory(Intent.CATEGORY_BROWSABLE); |
| 304 intent.setComponent(null); | 306 intent.setComponent(null); |
| 305 Intent selector = intent.getSelector(); | 307 Intent selector = intent.getSelector(); |
| 306 if (selector != null) { | 308 if (selector != null) { |
| 307 selector.addCategory(Intent.CATEGORY_BROWSABLE); | 309 selector.addCategory(Intent.CATEGORY_BROWSABLE); |
| 308 selector.setComponent(null); | 310 selector.setComponent(null); |
| 309 } | 311 } |
| 310 | 312 |
| 311 List<ResolveInfo> resolvingInfos = mDelegate.queryIntentActivities(inten t); | 313 List<ResolveInfo> resolvingInfos = mDelegate.queryIntentActivities(inten t); |
| 314 if (resolvingInfos == null) return OverrideUrlLoadingResult.NO_OVERRIDE; | |
| 315 | |
| 312 boolean canResolveActivity = resolvingInfos.size() > 0; | 316 boolean canResolveActivity = resolvingInfos.size() > 0; |
| 313 // check whether the intent can be resolved. If not, we will see | 317 // check whether the intent can be resolved. If not, we will see |
| 314 // whether we can download it from the Market. | 318 // whether we can download it from the Market. |
| 315 if (!canResolveActivity) { | 319 if (!canResolveActivity) { |
| 316 if (hasBrowserFallbackUrl) { | 320 if (hasBrowserFallbackUrl) { |
| 317 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, para ms); | 321 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, para ms); |
| 318 } | 322 } |
| 319 | 323 |
| 320 String packagename = intent.getPackage(); | 324 String packagename = intent.getPackage(); |
| 321 if (packagename != null) { | 325 if (packagename != null) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 Intent previousIntent; | 430 Intent previousIntent; |
| 427 try { | 431 try { |
| 428 previousIntent = Intent.parseUri( | 432 previousIntent = Intent.parseUri( |
| 429 params.getReferrerUrl(), Intent.URI_INTENT_SCHEM E); | 433 params.getReferrerUrl(), Intent.URI_INTENT_SCHEM E); |
| 430 } catch (Exception e) { | 434 } catch (Exception e) { |
| 431 previousIntent = null; | 435 previousIntent = null; |
| 432 } | 436 } |
| 433 | 437 |
| 434 if (previousIntent != null | 438 if (previousIntent != null |
| 435 && resolversSubsetOf(resolvingInfos, | 439 && resolversSubsetOf(resolvingInfos, |
| 436 mDelegate.queryIntentActivities(previousI ntent))) { | 440 mDelegate.queryIntentActivities(previousInte nt))) { |
| 437 return OverrideUrlLoadingResult.NO_OVERRIDE; | 441 return OverrideUrlLoadingResult.NO_OVERRIDE; |
| 438 } | 442 } |
| 439 } | 443 } |
| 440 } | 444 } |
| 441 } | 445 } |
| 442 | 446 |
| 443 boolean shouldProxyForInstantApps = isExternalProtocol | 447 boolean shouldProxyForInstantApps = isExternalProtocol |
| 444 && SUPERVISOR_PKG.equals(intent.getPackage()) | 448 && SUPERVISOR_PKG.equals(intent.getPackage()) |
| 445 && mDelegate.isSerpReferrer(params.getReferrerUrl(), params.getT ab()); | 449 && mDelegate.isSerpReferrer(params.getReferrerUrl(), params.getT ab()); |
| 446 | 450 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 browserFallbackUrl, params.getReferrerUrl(), params.getTab()); | 539 browserFallbackUrl, params.getReferrerUrl(), params.getTab()); |
| 536 } | 540 } |
| 537 | 541 |
| 538 /** | 542 /** |
| 539 * @return Whether the |url| could be handled by an external application on the system. | 543 * @return Whether the |url| could be handled by an external application on the system. |
| 540 */ | 544 */ |
| 541 public boolean canExternalAppHandleUrl(String url) { | 545 public boolean canExternalAppHandleUrl(String url) { |
| 542 if (url.startsWith(SCHEME_WTAI_MC)) return true; | 546 if (url.startsWith(SCHEME_WTAI_MC)) return true; |
| 543 try { | 547 try { |
| 544 Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); | 548 Intent intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME); |
| 545 return intent.getPackage() != null | 549 if (intent.getPackage() != null) return true; |
| 546 || mDelegate.queryIntentActivities(intent).size() > 0; | 550 |
| 551 List<ResolveInfo> resolvingInfos = mDelegate.queryIntentActivities(i ntent); | |
| 552 if (resolvingInfos != null && resolvingInfos.size() > 0) return true ; | |
| 547 } catch (Exception ex) { | 553 } catch (Exception ex) { |
| 548 // Ignore the error. | 554 // Ignore the error. |
| 549 Log.w(TAG, "Bad URI %s", url, ex); | 555 Log.w(TAG, "Bad URI %s", url, ex); |
| 550 } | 556 } |
| 551 return false; | 557 return false; |
| 552 } | 558 } |
| 553 | 559 |
| 554 /** | 560 /** |
| 555 * Dispatch SMS intents to the default SMS application if applicable. | 561 * Dispatch SMS intents to the default SMS application if applicable. |
| 556 * Most SMS apps refuse to send SMS if not set as default SMS application. | 562 * Most SMS apps refuse to send SMS if not set as default SMS application. |
| 557 * | 563 * |
| 558 * @param resolvingComponentNames The list of ComponentName that resolves th e current intent. | 564 * @param resolvingComponentNames The list of ComponentName that resolves th e current intent. |
| 559 */ | 565 */ |
| 560 private String getDefaultSmsPackageName(List<ResolveInfo> resolvingComponent Names) { | 566 private String getDefaultSmsPackageName(List<ResolveInfo> resolvingComponent Names) { |
| 561 String defaultSmsPackageName = mDelegate.getDefaultSmsPackageName(); | 567 String defaultSmsPackageName = mDelegate.getDefaultSmsPackageName(); |
| 562 if (defaultSmsPackageName == null) return null; | 568 if (defaultSmsPackageName == null) return null; |
| 563 // Makes sure that the default SMS app actually resolves the intent. | 569 // Makes sure that the default SMS app actually resolves the intent. |
| 564 for (ResolveInfo resolveInfo : resolvingComponentNames) { | 570 for (ResolveInfo resolveInfo : resolvingComponentNames) { |
| 565 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam e)) { | 571 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam e)) { |
| 566 return defaultSmsPackageName; | 572 return defaultSmsPackageName; |
| 567 } | 573 } |
| 568 } | 574 } |
| 569 return null; | 575 return null; |
| 570 } | 576 } |
| 571 } | 577 } |
| OLD | NEW |