Commit 879635b2 authored by Sebastian Streich's avatar Sebastian Streich
Browse files

Bug 1539853 - Throw Exceptions on null Principal within...

Bug 1539853 - Throw Exceptions on null Principal within SpeculativeConnectInternal and Handle on Callsite  r=ckerschb,Gijs

***
++Linting

Differential Revision: https://phabricator.services.mozilla.com/D25725

--HG--
extra : moz-landing-system : lando
parent 65c7dcde
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -3818,8 +3818,14 @@ var SessionStoreInternal = {
      });
      let sc = Services.io.QueryInterface(Ci.nsISpeculativeConnect);
      let uri = Services.io.newURI(url);
      try {
        sc.speculativeConnect(uri, principal, null);
        return true;
      } catch (error) {
         // Can't setup speculative connection for this url.
         Cu.reportError(error);
        return false;
      }
    }
    return false;
  },
+1 −5
Original line number Diff line number Diff line
@@ -1766,11 +1766,7 @@ nsresult nsIOService::SpeculativeConnectInternal(
  MOZ_ASSERT(aPrincipal, "We expect passing a principal here.");

  if (!aPrincipal) {
    // Bug 1537883, fail silently in case aPrincipal is null rather
    // than having the browser crash because we cannot create a
    // loadInfo without a principal. Within Bug 1539853 we should
    // resolve why aPrincipal is null here and remove the silent fail.
    return NS_OK;
    return NS_ERROR_INVALID_ARG;
  }

  // dummy channel used to create a TCP connection.
+12 −2
Original line number Diff line number Diff line
@@ -2481,12 +2481,22 @@ Engine.prototype = {
    let principal = Services.scriptSecurityManager
                            .createCodebasePrincipal(searchURI, attrs);

    try {
      connector.speculativeConnect(searchURI, principal, callbacks);
    } catch (e) {
      // Can't setup speculative connection for this url, just ignore it.
      Cu.reportError(e);
    }

    if (this.supportsResponseType(URLTYPE_SUGGEST_JSON)) {
      let suggestURI = this.getSubmission("dummy", URLTYPE_SUGGEST_JSON).uri;
      if (suggestURI.prePath != searchURI.prePath)
        try {
          connector.speculativeConnect(suggestURI, principal, callbacks);
        } catch (e) {
          // Can't setup speculative connection for this url, just ignore it.
          Cu.reportError(e);
        }
    }
  },
};