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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 if (result == OverrideUrlLoadingResult.NO_OVERRIDE && hasBrowserFallback
Url | 115 if (result == OverrideUrlLoadingResult.NO_OVERRIDE && hasBrowserFallback
Url |
116 && (params.getRedirectHandler() == null | 116 && (params.getRedirectHandler() == null |
117 // For instance, if this is a chained fallback URL, we i
gnore it. | 117 // For instance, if this is a chained fallback URL, we i
gnore it. |
118 || !params.getRedirectHandler().shouldNotOverrideUrlLoad
ing())) { | 118 || !params.getRedirectHandler().shouldNotOverrideUrlLoad
ing())) { |
119 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, params); | 119 return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, params); |
120 } | 120 } |
121 return result; | 121 return result; |
122 } | 122 } |
123 | 123 |
124 private boolean intentsHaveSameResolvers(Intent intent, Intent previousInten
t) { | 124 private boolean resolversSubsetOf(List<ResolveInfo> infos, List<ResolveInfo>
container) { |
125 HashSet<ComponentName> previousHandlers = new HashSet<>(); | 125 HashSet<ComponentName> containerSet = new HashSet<>(); |
126 for (ResolveInfo r : mDelegate.queryIntentActivities(previousIntent)) { | 126 for (ResolveInfo info : container) { |
127 previousHandlers.add(new ComponentName(r.activityInfo.packageName, | 127 containerSet.add( |
128 r.activityInfo.name)); | 128 new ComponentName(info.activityInfo.packageName, info.activi
tyInfo.name)); |
129 } | 129 } |
130 for (ResolveInfo r : mDelegate.queryIntentActivities(intent)) { | 130 for (ResolveInfo info : infos) { |
131 if (!previousHandlers.contains(new ComponentName( | 131 if (!containerSet.contains(new ComponentName( |
132 r.activityInfo.packageName, r.activityInfo.name))) { | 132 info.activityInfo.packageName, info.activityInfo.name))) { |
133 return false; | 133 return false; |
134 } | 134 } |
135 } | 135 } |
136 return true; | 136 return true; |
137 } | 137 } |
138 | 138 |
139 private OverrideUrlLoadingResult shouldOverrideUrlLoadingInternal( | 139 private OverrideUrlLoadingResult shouldOverrideUrlLoadingInternal( |
140 ExternalNavigationParams params, Intent intent, boolean hasBrowserFa
llbackUrl, | 140 ExternalNavigationParams params, Intent intent, boolean hasBrowserFa
llbackUrl, |
141 String browserFallbackUrl) { | 141 String browserFallbackUrl) { |
142 // http://crbug.com/441284 : Disallow firing external intent while Chrom
e is in the | 142 // http://crbug.com/441284 : Disallow firing external intent while Chrom
e is in the |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 if (currentUri != null && previousUri != null | 370 if (currentUri != null && previousUri != null |
371 && TextUtils.equals(currentUri.getHost(), previousUri.ge
tHost())) { | 371 && TextUtils.equals(currentUri.getHost(), previousUri.ge
tHost())) { |
372 Intent previousIntent; | 372 Intent previousIntent; |
373 try { | 373 try { |
374 previousIntent = Intent.parseUri( | 374 previousIntent = Intent.parseUri( |
375 params.getReferrerUrl(), Intent.URI_INTENT_SCHEM
E); | 375 params.getReferrerUrl(), Intent.URI_INTENT_SCHEM
E); |
376 } catch (Exception e) { | 376 } catch (Exception e) { |
377 previousIntent = null; | 377 previousIntent = null; |
378 } | 378 } |
379 | 379 |
380 if (previousIntent != null) { | 380 if (previousIntent != null |
381 if (intentsHaveSameResolvers(intent, previousIntent)) { | 381 && resolversSubsetOf(resolvingInfos, |
382 return OverrideUrlLoadingResult.NO_OVERRIDE; | 382 mDelegate.queryIntentActivities(previousI
ntent))) { |
383 } | 383 return OverrideUrlLoadingResult.NO_OVERRIDE; |
384 } | 384 } |
385 } | 385 } |
386 } | 386 } |
387 } | 387 } |
388 | 388 |
389 try { | 389 try { |
390 if (params.isIncognito() && !mDelegate.willChromeHandleIntent(intent
)) { | 390 if (params.isIncognito() && !mDelegate.willChromeHandleIntent(intent
)) { |
391 // This intent may leave Chrome. Warn the user that incognito d
oes not carry over | 391 // This intent may leave Chrome. Warn the user that incognito d
oes not carry over |
392 // to apps out side of Chrome. | 392 // to apps out side of Chrome. |
393 mDelegate.startIncognitoIntent(intent, params.getReferrerUrl(), | 393 mDelegate.startIncognitoIntent(intent, params.getReferrerUrl(), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 if (defaultSmsPackageName == null) return null; | 479 if (defaultSmsPackageName == null) return null; |
480 // Makes sure that the default SMS app actually resolves the intent. | 480 // Makes sure that the default SMS app actually resolves the intent. |
481 for (ResolveInfo resolveInfo : resolvingComponentNames) { | 481 for (ResolveInfo resolveInfo : resolvingComponentNames) { |
482 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam
e)) { | 482 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam
e)) { |
483 return defaultSmsPackageName; | 483 return defaultSmsPackageName; |
484 } | 484 } |
485 } | 485 } |
486 return null; | 486 return null; |
487 } | 487 } |
488 } | 488 } |
OLD | NEW |