Bug 1312954 - Part 8: Updating speculativeConnect to speculativeConnect2 for about:newtab. r?Gijs draft
authorTim Huang <tihuang@mozilla.com>
Thu, 19 Jan 2017 16:03:14 +0800
changeset 466002 30516e772f3cf5d9fc0258cf7f9de204443dbb92
parent 466001 3ee0792aff15c78ab6182ff2b054e3f6cf357e65
child 466003 f1229abab447d11347b99f5ace8deca66eb6ebf1
push id42767
push userbmo:tihuang@mozilla.com
push dateWed, 25 Jan 2017 04:18:41 +0000
reviewersGijs
bugs1312954
milestone54.0a1
Bug 1312954 - Part 8: Updating speculativeConnect to speculativeConnect2 for about:newtab. r?Gijs
browser/base/content/newtab/sites.js
--- a/browser/base/content/newtab/sites.js
+++ b/browser/base/content/newtab/sites.js
@@ -305,20 +305,31 @@ Site.prototype = {
   },
 
   /**
    * Speculatively opens a connection to the current site.
    */
   _speculativeConnect: function Site_speculativeConnect() {
     let sc = Services.io.QueryInterface(Ci.nsISpeculativeConnect);
     let uri = Services.io.newURI(this.url);
+
+    if (!uri.schemeIs("http") && !uri.schemeIs("https")) {
+      return;
+    }
+
     try {
       // This can throw for certain internal URLs, when they wind up in
       // about:newtab. Be sure not to propagate the error.
-      sc.speculativeConnect(uri, null);
+
+      // We use the URI's codebase principal here to open its speculative
+      // connection.
+      let originAttributes = document.docShell.getOriginAttributes();
+      let principal = Services.scriptSecurityManager
+                              .createCodebasePrincipal(uri, originAttributes);
+      sc.speculativeConnect2(uri, principal, null);
     } catch (e) {}
   },
 
   /**
    * Record interaction with site using telemetry.
    */
   _recordSiteClicked: function Site_recordSiteClicked(aIndex) {
     if (Services.prefs.prefHasUserValue("browser.newtabpage.rows") ||