Bug 1348278 - Speculatively connect when mousedown happens on a link r?bz draft
authorNicholas Hurley <hurley@mozilla.com>
Thu, 27 Apr 2017 14:35:09 -0700
changeset 570396 65fe6134ee67071175c8e528450be68cc3b91ff9
parent 570395 c482eb943a2b080851aeb6175c9ae7cdd2ca7cc6
child 626476 f90ec66f2539fd777bde57b60c64ab455ba53158
push id56473
push userbmo:hurley@mozilla.com
push dateFri, 28 Apr 2017 20:01:47 +0000
reviewersbz
bugs1348278
milestone55.0a1
Bug 1348278 - Speculatively connect when mousedown happens on a link r?bz Try to speed up perceived pageload by opening a connection as soon as the user mouses down on a link, instead of waiting for the full click/AsyncOpen process to get there. MozReview-Commit-ID: 4g6mZXWt9H5
dom/base/Element.cpp
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -145,16 +145,18 @@
 #include "mozilla/dom/ElementBinding.h"
 #include "mozilla/dom/VRDisplay.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Preferences.h"
 #include "nsComputedDOMStyle.h"
 #include "nsDOMStringMap.h"
 #include "DOMIntersectionObserver.h"
 
+#include "nsISpeculativeConnect.h"
+
 using namespace mozilla;
 using namespace mozilla::dom;
 
 nsIAtom*
 nsIContent::DoGetID() const
 {
   MOZ_ASSERT(HasID(), "Unexpected call");
   MOZ_ASSERT(IsElement(), "Only elements can have IDs");
@@ -3060,16 +3062,23 @@ Element::PostHandleEventForLinks(EventCh
             aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
             nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(this);
             fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOUSE |
                                nsIFocusManager::FLAG_NOSCROLL);
           }
 
           EventStateManager::SetActiveManager(
             aVisitor.mPresContext->EventStateManager(), this);
+
+          // OK, we're pretty sure we're going to load, so warm up a speculative
+          // connection to be sure we have one ready when we open the channel.
+          nsCOMPtr<nsISpeculativeConnect> sc =
+            do_QueryInterface(nsContentUtils::GetIOService());
+          nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(handler);
+          sc->SpeculativeConnect2(absURI, NodePrincipal(), ir);
         }
       }
     }
     break;
 
   case eMouseClick: {
     WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
     if (mouseEvent->IsLeftClickEvent()) {