Back out cf876b6ac843 (bug 1168980) for Android xpcshell crashes in test_redirect-caching_failure.js and test_redirect_failure.js
CLOSED TREE
This commit is contained in:
@@ -16,12 +16,8 @@ import org.json.JSONObject;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -31,14 +27,8 @@ public final class IntentHelper implements GeckoEventListener {
|
||||
"Intent:GetHandlers",
|
||||
"Intent:Open",
|
||||
"Intent:OpenForResult",
|
||||
"Intent:OpenNoHandler",
|
||||
"WebActivity:Open"
|
||||
};
|
||||
|
||||
// via http://developer.android.com/distribute/tools/promote/linking.html
|
||||
private static String MARKET_INTENT_URI_PACKAGE_PREFIX = "market://details?id=";
|
||||
private static String EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url";
|
||||
|
||||
private static IntentHelper instance;
|
||||
|
||||
private final Activity activity;
|
||||
@@ -74,8 +64,6 @@ public final class IntentHelper implements GeckoEventListener {
|
||||
open(message);
|
||||
} else if (event.equals("Intent:OpenForResult")) {
|
||||
openForResult(message);
|
||||
} else if (event.equals("Intent:OpenNoHandler")) {
|
||||
openNoHandler(message);
|
||||
} else if (event.equals("WebActivity:Open")) {
|
||||
openWebActivity(message);
|
||||
}
|
||||
@@ -123,66 +111,6 @@ public final class IntentHelper implements GeckoEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a URI without any valid handlers on device. In the best case, a package is specified
|
||||
* and we can bring the user directly to the application page in an app market. If a package is
|
||||
* not specified and there is a fallback url in the intent extras, we open that url. If neither
|
||||
* is present, we alert the user that we were unable to open the link.
|
||||
*/
|
||||
private void openNoHandler(final JSONObject msg) {
|
||||
final String uri = msg.optString("uri");
|
||||
|
||||
if (TextUtils.isEmpty(uri)) {
|
||||
displayToastCannotOpenLink();
|
||||
Log.w(LOGTAG, "Received empty URL. Ignoring...");
|
||||
return;
|
||||
}
|
||||
|
||||
final Intent intent;
|
||||
try {
|
||||
// TODO (bug 1173626): This will not handle android-app uris on non 5.1 devices.
|
||||
intent = Intent.parseUri(uri, 0);
|
||||
} catch (final URISyntaxException e) {
|
||||
displayToastCannotOpenLink();
|
||||
// Don't log the exception to prevent leaking URIs.
|
||||
Log.w(LOGTAG, "Unable to parse Intent URI");
|
||||
return;
|
||||
}
|
||||
|
||||
// For this flow, we follow Chrome's lead:
|
||||
// https://developer.chrome.com/multidevice/android/intents
|
||||
//
|
||||
// Note on alternative flows: we could get the intent package from a component, however, for
|
||||
// security reasons, components are ignored when opening URIs (bug 1168998) so we should
|
||||
// ignore it here too.
|
||||
//
|
||||
// Our old flow used to prompt the user to search for their app in the market by scheme and
|
||||
// while this could help the user find a new app, there is not always a correlation in
|
||||
// scheme to application name and we could end up steering the user wrong (potentially to
|
||||
// malicious software). Better to leave that one alone.
|
||||
if (intent.getPackage() != null) {
|
||||
final String marketUri = MARKET_INTENT_URI_PACKAGE_PREFIX + intent.getPackage();
|
||||
final Intent marketIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(marketUri));
|
||||
marketIntent.addCategory(Intent.CATEGORY_BROWSABLE);
|
||||
marketIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
activity.startActivity(marketIntent);
|
||||
|
||||
} else if (intent.hasExtra(EXTRA_BROWSER_FALLBACK_URL)) {
|
||||
final String fallbackUrl = intent.getStringExtra(EXTRA_BROWSER_FALLBACK_URL);
|
||||
Tabs.getInstance().loadUrl(fallbackUrl);
|
||||
|
||||
} else {
|
||||
displayToastCannotOpenLink();
|
||||
// Don't log the URI to prevent leaking it.
|
||||
Log.w(LOGTAG, "Unable to handle URI");
|
||||
}
|
||||
}
|
||||
|
||||
private void displayToastCannotOpenLink() {
|
||||
final String errText = activity.getResources().getString(R.string.intent_uri_cannot_open);
|
||||
Toast.makeText(activity, errText, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void openWebActivity(JSONObject message) throws JSONException {
|
||||
final Intent intent = WebActivityMapper.getIntentForWebActivity(message.getJSONObject("activity"));
|
||||
ActivityHandlerHelper.startIntentForActivity(activity, intent, new ResultHandler(message));
|
||||
|
||||
Reference in New Issue
Block a user