Bug 790882 - [New Tab Page] Speculatively open connections for sites when hovering them; r=jaws
authorTim Taubert <ttaubert@mozilla.com>
Thu, 21 Mar 2013 15:11:57 +0100
changeset 125842 d6a51ac10751547e646b71a33d388e19bcd054e1
parent 125739 a73a2b5c423b86828060e43b695f95b634721730
child 125843 0e9badd3cf39090e03f4527244521ee0dac14664
push id25120
push userryanvm@gmail.com
push dateThu, 21 Mar 2013 20:48:10 +0000
treeherdermozilla-inbound@cc4fd344ac41 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs790882
milestone22.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 790882 - [New Tab Page] Speculatively open connections for sites when hovering them; r=jaws
browser/base/content/newtab/sites.js
--- a/browser/base/content/newtab/sites.js
+++ b/browser/base/content/newtab/sites.js
@@ -139,36 +139,49 @@ Site.prototype = {
 
   /**
    * Adds event handlers for the site and its buttons.
    */
   _addEventHandlers: function Site_addEventHandlers() {
     // Register drag-and-drop event handlers.
     this._node.addEventListener("dragstart", this, false);
     this._node.addEventListener("dragend", this, false);
+    this._node.addEventListener("mouseenter", this, false);
 
     let controls = this.node.querySelectorAll(".newtab-control");
     for (let i = 0; i < controls.length; i++)
       controls[i].addEventListener("click", this, false);
   },
 
   /**
+   * 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, null, null);
+    sc.speculativeConnect(uri, null);
+  },
+
+  /**
    * Handles all site events.
    */
   handleEvent: function Site_handleEvent(aEvent) {
     switch (aEvent.type) {
       case "click":
         aEvent.preventDefault();
         if (aEvent.target.classList.contains("newtab-control-block"))
           this.block();
         else if (this.isPinned())
           this.unpin();
         else
           this.pin();
         break;
+      case "mouseenter":
+        this._speculativeConnect();
+        break;
       case "dragstart":
         gDrag.start(this, aEvent);
         break;
       case "drag":
         gDrag.drag(this, aEvent);
         break;
       case "dragend":
         gDrag.end(this, aEvent);