зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1162372 - Load about:neterror when we can't load a uri w/ a custom scheme. r=margaret
This commit is contained in:
Родитель
cd094ce9c9
Коммит
022bcd7498
|
@ -19,9 +19,10 @@ import android.content.Intent;
|
|||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -39,6 +40,9 @@ public final class IntentHelper implements GeckoEventListener {
|
|||
private static String MARKET_INTENT_URI_PACKAGE_PREFIX = "market://details?id=";
|
||||
private static String EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url";
|
||||
|
||||
/** A partial URI to an error page - the encoded error URI should be appended before loading. */
|
||||
private static String UNKNOWN_PROTOCOL_URI_PREFIX = "about:neterror?e=unknownProtocolFound&u=";
|
||||
|
||||
private static IntentHelper instance;
|
||||
|
||||
private final Activity activity;
|
||||
|
@ -133,8 +137,8 @@ public final class IntentHelper implements GeckoEventListener {
|
|||
final String uri = msg.optString("uri");
|
||||
|
||||
if (TextUtils.isEmpty(uri)) {
|
||||
displayToastCannotOpenLink();
|
||||
Log.w(LOGTAG, "Received empty URL. Ignoring...");
|
||||
openUnknownProtocolErrorPage("");
|
||||
Log.w(LOGTAG, "Received empty URL - loading about:neterror");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -143,9 +147,14 @@ public final class IntentHelper implements GeckoEventListener {
|
|||
// 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();
|
||||
try {
|
||||
openUnknownProtocolErrorPage(URLEncoder.encode(uri, "UTF-8"));
|
||||
} catch (final UnsupportedEncodingException encodingE) {
|
||||
openUnknownProtocolErrorPage("");
|
||||
}
|
||||
|
||||
// Don't log the exception to prevent leaking URIs.
|
||||
Log.w(LOGTAG, "Unable to parse Intent URI");
|
||||
Log.w(LOGTAG, "Unable to parse Intent URI - loading about:neterror");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -172,15 +181,21 @@ public final class IntentHelper implements GeckoEventListener {
|
|||
Tabs.getInstance().loadUrl(fallbackUrl);
|
||||
|
||||
} else {
|
||||
displayToastCannotOpenLink();
|
||||
openUnknownProtocolErrorPage(intent.getData().toString());
|
||||
// Don't log the URI to prevent leaking it.
|
||||
Log.w(LOGTAG, "Unable to handle URI");
|
||||
Log.w(LOGTAG, "Unable to open URI, default case - loading about:neterror");
|
||||
}
|
||||
}
|
||||
|
||||
private void displayToastCannotOpenLink() {
|
||||
final String errText = activity.getResources().getString(R.string.intent_uri_cannot_open);
|
||||
Toast.makeText(activity, errText, Toast.LENGTH_LONG).show();
|
||||
/**
|
||||
* Opens about:neterror with the unknownProtocolFound text.
|
||||
* @param encodedUri The encoded uri. While the page does not open correctly without specifying
|
||||
* a uri parameter, it happily accepts the empty String so this argument may
|
||||
* be the empty String.
|
||||
*/
|
||||
private void openUnknownProtocolErrorPage(final String encodedUri) {
|
||||
final String errorUri = UNKNOWN_PROTOCOL_URI_PREFIX + encodedUri;
|
||||
Tabs.getInstance().loadUrl(errorUri);
|
||||
}
|
||||
|
||||
private void openWebActivity(JSONObject message) throws JSONException {
|
||||
|
|
Загрузка…
Ссылка в новой задаче