| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 340 |
| 341 if (params.getReferrerUrl() != null) { | 341 if (params.getReferrerUrl() != null) { |
| 342 IntentHandler.setPendingReferrer(intent, params.getReferrerUrl()); | 342 IntentHandler.setPendingReferrer(intent, params.getReferrerUrl()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 // Make sure webkit can handle it internally before checking for special
ized | 345 // Make sure webkit can handle it internally before checking for special
ized |
| 346 // handlers. If webkit can't handle it internally, we need to call | 346 // handlers. If webkit can't handle it internally, we need to call |
| 347 // startActivityIfNeeded or startActivity. | 347 // startActivityIfNeeded or startActivity. |
| 348 if (!isExternalProtocol) { | 348 if (!isExternalProtocol) { |
| 349 if (!mDelegate.isSpecializedHandlerAvailable(resolvingInfos)) { | 349 if (!mDelegate.isSpecializedHandlerAvailable(resolvingInfos)) { |
| 350 if (params.isWebApk()) { | 350 if (params.webApkPackageName() != null) { |
| 351 intent.setPackage(mDelegate.getPackageName()); | 351 intent.setPackage(mDelegate.getPackageName()); |
| 352 mDelegate.startActivity(intent); | 352 mDelegate.startActivity(intent); |
| 353 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T; | 353 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T; |
| 354 } | 354 } |
| 355 return OverrideUrlLoadingResult.NO_OVERRIDE; | 355 return OverrideUrlLoadingResult.NO_OVERRIDE; |
| 356 } else if (params.getReferrerUrl() != null && (isLink || isFormSubmi
t)) { | 356 } else if (params.getReferrerUrl() != null && (isLink || isFormSubmi
t)) { |
| 357 // Current URL has at least one specialized handler available. F
or navigations | 357 // Current URL has at least one specialized handler available. F
or navigations |
| 358 // within the same host, keep the navigation inside the browser
unless the set of | 358 // within the same host, keep the navigation inside the browser
unless the set of |
| 359 // available apps to handle the new navigation is different. htt
p://crbug.com/463138 | 359 // available apps to handle the new navigation is different. htt
p://crbug.com/463138 |
| 360 URI currentUri; | 360 URI currentUri; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 && !params.getRedirectHandler().hasNewResolver(inten
t)) { | 405 && !params.getRedirectHandler().hasNewResolver(inten
t)) { |
| 406 return OverrideUrlLoadingResult.NO_OVERRIDE; | 406 return OverrideUrlLoadingResult.NO_OVERRIDE; |
| 407 } | 407 } |
| 408 } | 408 } |
| 409 // The intent can be used to launch Chrome itself, record the us
er | 409 // The intent can be used to launch Chrome itself, record the us
er |
| 410 // gesture here so that it can be used later. | 410 // gesture here so that it can be used later. |
| 411 if (params.hasUserGesture()) { | 411 if (params.hasUserGesture()) { |
| 412 IntentWithGesturesHandler.getInstance().onNewIntentWithGestu
re(intent); | 412 IntentWithGesturesHandler.getInstance().onNewIntentWithGestu
re(intent); |
| 413 } | 413 } |
| 414 | 414 |
| 415 // If the only specialized intent handler is a WebAPK, set the i
ntent's package |
| 416 // to launch the WebAPK without showing the intent picker. |
| 417 String targetWebApkPackageName = |
| 418 mDelegate.findValidWebApkPackageName(resolvingInfos); |
| 419 if (targetWebApkPackageName != null |
| 420 && mDelegate.countSpecializedHandlers(resolvingInfos) ==
1) { |
| 421 intent.setPackage(targetWebApkPackageName); |
| 422 } |
| 423 |
| 415 if (mDelegate.startActivityIfNeeded(intent)) { | 424 if (mDelegate.startActivityIfNeeded(intent)) { |
| 416 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T; | 425 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTEN
T; |
| 417 } else { | 426 } else { |
| 418 return OverrideUrlLoadingResult.NO_OVERRIDE; | 427 return OverrideUrlLoadingResult.NO_OVERRIDE; |
| 419 } | 428 } |
| 420 } | 429 } |
| 421 } catch (ActivityNotFoundException ex) { | 430 } catch (ActivityNotFoundException ex) { |
| 422 // Ignore the error. If no application can handle the URL, | 431 // Ignore the error. If no application can handle the URL, |
| 423 // assume the browser can handle it. | 432 // assume the browser can handle it. |
| 424 } | 433 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 if (defaultSmsPackageName == null) return null; | 488 if (defaultSmsPackageName == null) return null; |
| 480 // Makes sure that the default SMS app actually resolves the intent. | 489 // Makes sure that the default SMS app actually resolves the intent. |
| 481 for (ResolveInfo resolveInfo : resolvingComponentNames) { | 490 for (ResolveInfo resolveInfo : resolvingComponentNames) { |
| 482 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam
e)) { | 491 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam
e)) { |
| 483 return defaultSmsPackageName; | 492 return defaultSmsPackageName; |
| 484 } | 493 } |
| 485 } | 494 } |
| 486 return null; | 495 return null; |
| 487 } | 496 } |
| 488 } | 497 } |
| OLD | NEW |