Commit 2a5b7140 authored by Patrick McManus's avatar Patrick McManus
Browse files

Bug 453403. Add DNS prefetching, similar to what Google chrome does. r+sr=bzbarsky, a=beltzner

parent a6e187e7
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -102,6 +102,8 @@
#include "nsIDocumentLoader.h"
#include "nsICachingChannel.h"
#include "nsICacheEntryDescriptor.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLDNSPrefetch.h"

PRLogModuleInfo* gContentSinkLogModuleInfo;

@@ -722,6 +724,10 @@ nsContentSink::ProcessLink(nsIContent* aElement,
    PrefetchHref(aHref, aElement, hasPrefetch);
  }

  if ((!aHref.IsEmpty()) && linkTypes.IndexOf(NS_LITERAL_STRING("dns-prefetch")) != -1) {
    PrefetchDNS(aHref);
  }

  // is it a stylesheet link?
  if (linkTypes.IndexOf(NS_LITERAL_STRING("stylesheet")) == -1) {
    return NS_OK;
@@ -853,6 +859,23 @@ nsContentSink::PrefetchHref(const nsAString &aHref,
  }
}

void
nsContentSink::PrefetchDNS(const nsAString &aHref)
{
  nsAutoString hostname;

  if (StringBeginsWith(aHref, NS_LITERAL_STRING("//")))  {
    hostname = Substring(aHref, 2);
  }
  else
    nsGenericHTMLElement::GetHostnameFromHrefString(aHref, hostname);
      
  nsRefPtr<nsHTMLDNSPrefetch> prefetch = new nsHTMLDNSPrefetch(hostname, mDocument);
  if (prefetch) {
    prefetch->PrefetchLow();
  }
}

nsresult
nsContentSink::GetChannelCacheKey(nsIChannel* aChannel, nsACString& aCacheKey)
{
+4 −0
Original line number Diff line number Diff line
@@ -195,6 +195,10 @@ protected:
  void PrefetchHref(const nsAString &aHref, nsIContent *aSource,
                    PRBool aExplicit);

  // aHref can either be the usual URI format or of the form "//www.hostname.com"
  // without a scheme.
  void PrefetchDNS(const nsAString &aHref);

  // Gets the cache key (used to identify items in a cache) of the channel.
  nsresult GetChannelCacheKey(nsIChannel* aChannel, nsACString& aCacheKey);

+1 −0
Original line number Diff line number Diff line
@@ -6572,6 +6572,7 @@ nsDocument::RetrieveRelevantHeaders(nsIChannel *aChannel)
      "content-language",
      "content-disposition",
      "refresh",
      "x-dns-prefetch-control",
      // add more http headers if you need
      // XXXbz don't add content-location support without reading bug
      // 238654 and its dependencies/dups first.
+1 −0
Original line number Diff line number Diff line
@@ -987,6 +987,7 @@ GK_ATOM(headerWindowTarget, "window-target")
GK_ATOM(withParam, "with-param")
GK_ATOM(wizard, "wizard")
GK_ATOM(wrap, "wrap")
GK_ATOM(headerDNSPrefetchControl,"x-dns-prefetch-control")
GK_ATOM(xml, "xml")
GK_ATOM(xmlns, "xmlns")
GK_ATOM(xmp, "xmp")
+1 −0
Original line number Diff line number Diff line
@@ -83,6 +83,7 @@ EXPORTS = \

CPPSRCS		= \
		nsClientRect.cpp \
		nsHTMLDNSPrefetch.cpp \
		nsGenericHTMLElement.cpp \
		nsFormSubmission.cpp \
		nsImageMapUtils.cpp \
Loading