Bug 516422 - Copy link prefetching from nsHTMLContentSink to the HTML5 parser. r=bnewman.

--HG--
extra : rebase_source : c0a5999b05919fa496ddcee94f7be74d004288f3
This commit is contained in:
Henri Sivonen 2010-02-25 13:37:35 +02:00
parent c22899568e
commit f0f3e5872b

View File

@ -44,6 +44,7 @@
#include "nsIContentViewer.h"
#include "nsIDocShellTreeItem.h"
#include "nsIStyleSheetLinkingElement.h"
#include "nsStyleLinkElement.h"
#include "nsIDocShell.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
@ -295,6 +296,32 @@ nsHtml5TreeOpExecutor::UpdateStyleSheet(nsIContent* aElement)
mScriptLoader->AddExecuteBlocker();
}
if (aElement->IsHTML() && aElement->Tag() == nsGkAtoms::link) {
// look for <link rel="next" href="url">
nsAutoString relVal;
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal);
if (!relVal.IsEmpty()) {
// XXX seems overkill to generate this string array
nsAutoTArray<nsString, 4> linkTypes;
nsStyleLinkElement::ParseLinkTypes(relVal, linkTypes);
PRBool hasPrefetch = linkTypes.Contains(NS_LITERAL_STRING("prefetch"));
if (hasPrefetch || linkTypes.Contains(NS_LITERAL_STRING("next"))) {
nsAutoString hrefVal;
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal);
if (!hrefVal.IsEmpty()) {
PrefetchHref(hrefVal, aElement, hasPrefetch);
}
}
if (linkTypes.Contains(NS_LITERAL_STRING("dns-prefetch"))) {
nsAutoString hrefVal;
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::href, hrefVal);
if (!hrefVal.IsEmpty()) {
PrefetchDNS(hrefVal);
}
}
}
}
// Re-open update
BeginDocUpdate();
}