Commit 78c06092 authored by Yusuf Ozuysal's avatar Yusuf Ozuysal Committed by Commit Bot

Fail gracefully on a URI with no handlers

In openInChrome, we had a past fix to check if Chrome can handle a VIEW
intent and pass back to the system if not. But this seems to have come
back with a smaller crash segment that fails because there are no
handlers. This CL handles that one last exception and lets Chrome do
nothing as a graceful failure.

BUG=891640

Change-Id: I9ad7146c5cf8a77e59527b909521460668717818
Reviewed-on: https://chromium-review.googlesource.com/c/1300104Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Yusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605737}
parent 3e7cb938
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.tab;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.MailTo;
import android.net.Uri;
import android.provider.Browser;
......@@ -227,11 +228,15 @@ public class TabContextMenuItemDelegate implements ContextMenuItemDelegate {
Intent chromeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(linkUrl));
chromeIntent.setPackage(applicationContext.getPackageName());
chromeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (applicationContext.getPackageManager()
.queryIntentActivities(chromeIntent, 0)
.isEmpty()) {
PackageManager packageManager = applicationContext.getPackageManager();
if (packageManager.queryIntentActivities(chromeIntent, 0).isEmpty()) {
// If Chrome can't handle intent fallback to using any other VIEW handlers.
chromeIntent.setPackage(null);
// Query again without the package name set and if there are still no handlers for the
// URI fail gracefully, and do nothing, since this will still cause a crash if launched.
if (packageManager.queryIntentActivities(chromeIntent, 0).isEmpty()) return;
}
// For "Open in Chrome" from the context menu in FullscreenActivity we want to bypass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment