Bug 1278581 - Part 3 - Don't load neterror page manually when protocol couldn't be handled. r=snorp

Our current way is somewhat convoluted - we manually create an about:neterror
URL in the Android UI and then load it from the ContentDispatchChooser by simply
setting window.location.href, which means that the page URL won't reflect the
actual URL we were trying to load and the rest of Gecko will think that the page
load succeeded (unless they're explicitly checking the URL for the presence of
about:neterror).

MozReview-Commit-ID: Z0LSSE6AGU

--HG--
extra : rebase_source : 95b390ca30e08222f140f5d6d790ca93a49363ba
This commit is contained in:
Jan Henning 2018-03-21 22:47:17 +01:00
parent 136f1713c4
commit a740007379
3 changed files with 3 additions and 25 deletions

View File

@ -63,9 +63,6 @@ public final class IntentHelper implements BundleEventListener {
private static final String MARKET_INTENT_URI_PACKAGE_PREFIX = "market://details?id=";
private static final 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 final String UNKNOWN_PROTOCOL_URI_PREFIX = "about:neterror?e=unknownProtocolFound&u=";
private static IntentHelper instance;
private IntentHelper() {
@ -505,7 +502,6 @@ public final class IntentHelper implements BundleEventListener {
if (TextUtils.isEmpty(uri)) {
Log.w(LOGTAG, "Received empty URL - loading about:neterror");
errorResponse.putString("uri", getUnknownProtocolErrorPageUri(""));
errorResponse.putBoolean("isFallback", false);
callback.sendError(errorResponse);
return;
@ -516,16 +512,8 @@ public final class IntentHelper implements BundleEventListener {
// TODO (bug 1173626): This will not handle android-app uris on non 5.1 devices.
intent = Intent.parseUri(uri, 0);
} catch (final URISyntaxException e) {
String errorUri;
try {
errorUri = getUnknownProtocolErrorPageUri(URLEncoder.encode(uri, "UTF-8"));
} catch (final UnsupportedEncodingException encodingE) {
errorUri = getUnknownProtocolErrorPageUri("");
}
// Don't log the exception to prevent leaking URIs.
Log.w(LOGTAG, "Unable to parse Intent URI - loading about:neterror");
errorResponse.putString("uri", errorUri);
errorResponse.putBoolean("isFallback", false);
callback.sendError(errorResponse);
return;
@ -575,7 +563,6 @@ public final class IntentHelper implements BundleEventListener {
//
// Don't log the URI to prevent leaking it.
Log.w(LOGTAG, "Unable to open URI, maybe showing neterror");
errorResponse.putString("uri", getUnknownProtocolErrorPageUri(intent.getData().toString()));
errorResponse.putBoolean("isFallback", false);
callback.sendError(errorResponse);
}
@ -601,16 +588,6 @@ public final class IntentHelper implements BundleEventListener {
return false;
}
/**
* Returns an about:neterror uri with the unknownProtocolFound text as a parameter.
* @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 String getUnknownProtocolErrorPageUri(final String encodedUri) {
return UNKNOWN_PROTOCOL_URI_PREFIX + encodedUri;
}
private static class ResultHandler implements ActivityResultHandler {
private final EventCallback callback;

View File

@ -4570,7 +4570,8 @@ Tab.prototype = {
}
if ((!aRequest || Components.isSuccessCode(aRequest.status)) &&
!fixedURI.displaySpec.startsWith("about:neterror") && !this.isSearch) {
!(aFlags & Ci.nsIWebProgressListener.LOCATION_CHANGE_ERROR_PAGE) &&
!this.isSearch) {
// If this won't end up in an error page and the user isn't searching,
// don't retain the typed entry.
this.userRequested = "";

View File

@ -86,7 +86,7 @@ ContentDispatchChooser.prototype =
let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
let millis = dwu.millisSinceLastUserInput;
if (millis < 0 || millis >= 1000) {
window.location.href = data.uri;
window.document.docShell.displayLoadError(Cr.NS_ERROR_UNKNOWN_PROTOCOL, aURI, null);
} else {
this._closeBlankWindow(window);
}