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
--- 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()) {