Bug 672014. Pass the crossorigin attribute through to image preloading code. r=joe,hsivonen

This commit is contained in:
Boris Zbarsky 2011-07-29 14:30:00 -04:00
parent ed28a9a6e4
commit 8983ada153
13 changed files with 262 additions and 226 deletions

View File

@ -126,8 +126,8 @@ class Element;
#define NS_IDOCUMENT_IID \
{ 0x18e4d4bd, 0x006b, 0x4008, \
{ 0x90, 0x05, 0x27, 0x57, 0x35, 0xf0, 0xd4, 0x85 } }
{ 0xe4bc7342, 0x6528, 0x4979, \
{ 0x9e, 0xb5, 0x12, 0xef, 0x4a, 0x97, 0xe1, 0xea } }
// Flag for AddStyleSheet().
#define NS_STYLESHEET_FROM_CATALOG (1 << 0)
@ -1386,7 +1386,8 @@ public:
* to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
* parser-module is linked with gklayout-module.
*/
virtual void MaybePreLoadImage(nsIURI* uri) = 0;
virtual void MaybePreLoadImage(nsIURI* uri,
const nsAString& aCrossOriginAttr) = 0;
/**
* Called by nsParser to preload style sheets. Can also be merged into

View File

@ -203,6 +203,8 @@
#include "mozilla/Preferences.h"
#include "imgILoader.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -7668,7 +7670,7 @@ FireOrClearDelayedEvents(nsTArray<nsCOMPtr<nsIDocument> >& aDocuments,
}
void
nsDocument::MaybePreLoadImage(nsIURI* uri)
nsDocument::MaybePreLoadImage(nsIURI* uri, const nsAString &aCrossOriginAttr)
{
// Early exit if the img is already present in the img-cache
// which indicates that the "real" load has already started and
@ -7680,6 +7682,16 @@ nsDocument::MaybePreLoadImage(nsIURI* uri)
return;
}
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
if (aCrossOriginAttr.LowerCaseEqualsLiteral("anonymous")) {
loadFlags |= imgILoader::LOAD_CORS_ANONYMOUS;
} else if (aCrossOriginAttr.LowerCaseEqualsLiteral("use-credentials")) {
loadFlags |= imgILoader::LOAD_CORS_USE_CREDENTIALS;
}
// else should we err on the side of not doing the preload if
// aCrossOriginAttr is nonempty? Let's err on the side of doing the
// preload as CORS_NONE.
// Image not in cache - trigger preload
nsCOMPtr<imgIRequest> request;
nsresult rv =
@ -7688,7 +7700,7 @@ nsDocument::MaybePreLoadImage(nsIURI* uri)
NodePrincipal(),
mDocumentURI, // uri of document used as referrer
nsnull, // no observer
nsIRequest::LOAD_NORMAL,
loadFlags,
getter_AddRefs(request));
// Pin image-reference to avoid evicting it from the img-cache before

View File

@ -885,7 +885,8 @@ public:
void MaybeEndOutermostXBLUpdate();
virtual void MaybePreLoadImage(nsIURI* uri);
virtual void MaybePreLoadImage(nsIURI* uri,
const nsAString &aCrossOriginAttr);
virtual void PreloadStyle(nsIURI* uri, const nsAString& charset);

View File

@ -1094,6 +1094,7 @@ public final class AttributeName
public static final AttributeName CELLPADDING = new AttributeName(ALL_NO_NS, SAME_LOCAL("cellpadding"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName CELLSPACING = new AttributeName(ALL_NO_NS, SAME_LOCAL("cellspacing"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName COLUMNWIDTH = new AttributeName(ALL_NO_NS, SAME_LOCAL("columnwidth"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName CROSSORIGIN = new AttributeName(ALL_NO_NS, SAME_LOCAL("crossorigin"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName COLUMNALIGN = new AttributeName(ALL_NO_NS, SAME_LOCAL("columnalign"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName COLUMNLINES = new AttributeName(ALL_NO_NS, SAME_LOCAL("columnlines"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
public static final AttributeName CONTEXTMENU = new AttributeName(ALL_NO_NS, SAME_LOCAL("contextmenu"), ALL_NO_PREFIX, NCNAME_HTML | NCNAME_FOREIGN | NCNAME_LANG);
@ -1676,6 +1677,7 @@ public final class AttributeName
CELLPADDING,
CELLSPACING,
COLUMNWIDTH,
CROSSORIGIN,
COLUMNALIGN,
COLUMNLINES,
CONTEXTMENU,
@ -2259,6 +2261,7 @@ public final class AttributeName
371448425,
371448430,
371545055,
371593469,
371596922,
371758751,
371964792,

View File

@ -458,6 +458,7 @@ HTML5_ATOM(arabic_form, "arabic-form")
HTML5_ATOM(cellpadding, "cellpadding")
HTML5_ATOM(cellspacing, "cellspacing")
HTML5_ATOM(columnwidth, "columnwidth")
HTML5_ATOM(crossorigin, "crossorigin")
HTML5_ATOM(columnalign, "columnalign")
HTML5_ATOM(columnlines, "columnlines")
HTML5_ATOM(contextmenu, "contextmenu")

File diff suppressed because one or more lines are too long

View File

@ -473,6 +473,7 @@ class nsHtml5AttributeName
static nsHtml5AttributeName* ATTR_CELLPADDING;
static nsHtml5AttributeName* ATTR_CELLSPACING;
static nsHtml5AttributeName* ATTR_COLUMNWIDTH;
static nsHtml5AttributeName* ATTR_CROSSORIGIN;
static nsHtml5AttributeName* ATTR_COLUMNALIGN;
static nsHtml5AttributeName* ATTR_COLUMNLINES;
static nsHtml5AttributeName* ATTR_CONTEXTMENU;

View File

@ -61,13 +61,13 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor)
aExecutor->SetSpeculationBase(mUrl);
break;
case eSpeculativeLoadImage:
aExecutor->PreloadImage(mUrl);
aExecutor->PreloadImage(mUrl, mCharsetOrCrossOrigin);
break;
case eSpeculativeLoadScript:
aExecutor->PreloadScript(mUrl, mCharset, mType);
aExecutor->PreloadScript(mUrl, mCharsetOrCrossOrigin, mType);
break;
case eSpeculativeLoadStyle:
aExecutor->PreloadStyle(mUrl, mCharset);
aExecutor->PreloadStyle(mUrl, mCharsetOrCrossOrigin);
break;
case eSpeculativeLoadManifest:
aExecutor->ProcessOfflineManifest(mUrl);

View File

@ -65,11 +65,13 @@ class nsHtml5SpeculativeLoad {
mUrl.Assign(aUrl);
}
inline void InitImage(const nsAString& aUrl) {
inline void InitImage(const nsAString& aUrl,
const nsAString& aCrossOrigin) {
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
"Trying to reinitialize a speculative load!");
mOpCode = eSpeculativeLoadImage;
mUrl.Assign(aUrl);
mCharsetOrCrossOrigin.Assign(aCrossOrigin);
}
inline void InitScript(const nsAString& aUrl,
@ -79,7 +81,7 @@ class nsHtml5SpeculativeLoad {
"Trying to reinitialize a speculative load!");
mOpCode = eSpeculativeLoadScript;
mUrl.Assign(aUrl);
mCharset.Assign(aCharset);
mCharsetOrCrossOrigin.Assign(aCharset);
mType.Assign(aType);
}
@ -88,7 +90,7 @@ class nsHtml5SpeculativeLoad {
"Trying to reinitialize a speculative load!");
mOpCode = eSpeculativeLoadStyle;
mUrl.Assign(aUrl);
mCharset.Assign(aCharset);
mCharsetOrCrossOrigin.Assign(aCharset);
}
/**
@ -114,7 +116,11 @@ class nsHtml5SpeculativeLoad {
private:
eHtml5SpeculativeLoad mOpCode;
nsString mUrl;
nsString mCharset;
// If mOpCode is eSpeculativeLoadImage, this is the value of the
// "crossorigin" attribute. If mOpCode is eSpeculativeLoadStyle
// or eSpeculativeLoadScript then this is the value of the
// "charset" attribute. Otherwise it's empty.
nsString mCharsetOrCrossOrigin;
nsString mType;
};

View File

@ -105,7 +105,13 @@ nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5Htm
if (nsHtml5Atoms::img == aName) {
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_SRC);
if (url) {
mSpeculativeLoadQueue.AppendElement()->InitImage(*url);
nsString* crossOrigin =
aAttributes->getValue(nsHtml5AttributeName::ATTR_CROSSORIGIN);
if (crossOrigin) {
mSpeculativeLoadQueue.AppendElement()->InitImage(*url, *crossOrigin);
} else {
mSpeculativeLoadQueue.AppendElement()->InitImage(*url, EmptyString());
}
}
} else if (nsHtml5Atoms::script == aName) {
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
@ -138,7 +144,7 @@ nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5Htm
} else if (nsHtml5Atoms::video == aName) {
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_POSTER);
if (url) {
mSpeculativeLoadQueue.AppendElement()->InitImage(*url);
mSpeculativeLoadQueue.AppendElement()->InitImage(*url, EmptyString());
}
} else if (nsHtml5Atoms::style == aName) {
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
@ -163,7 +169,7 @@ nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5Htm
if (nsHtml5Atoms::image == aName) {
nsString* url = aAttributes->getValue(nsHtml5AttributeName::ATTR_XLINK_HREF);
if (url) {
mSpeculativeLoadQueue.AppendElement()->InitImage(*url);
mSpeculativeLoadQueue.AppendElement()->InitImage(*url, EmptyString());
}
} else if (nsHtml5Atoms::script == aName) {
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();

View File

@ -891,13 +891,14 @@ nsHtml5TreeOpExecutor::PreloadStyle(const nsAString& aURL,
}
void
nsHtml5TreeOpExecutor::PreloadImage(const nsAString& aURL)
nsHtml5TreeOpExecutor::PreloadImage(const nsAString& aURL,
const nsAString& aCrossOrigin)
{
nsCOMPtr<nsIURI> uri = ConvertIfNotPreloadedYet(aURL);
if (!uri) {
return;
}
mDocument->MaybePreLoadImage(uri);
mDocument->MaybePreLoadImage(uri, aCrossOrigin);
}
void

View File

@ -401,7 +401,7 @@ class nsHtml5TreeOpExecutor : public nsContentSink,
void PreloadStyle(const nsAString& aURL, const nsAString& aCharset);
void PreloadImage(const nsAString& aURL);
void PreloadImage(const nsAString& aURL, const nsAString& aCrossOrigin);
void SetSpeculationBase(const nsAString& aURL);

View File

@ -362,7 +362,7 @@ nsPreloadURIs::PreloadURIs(const nsAutoTArray<nsSpeculativeScriptThread::Prefetc
doc->ScriptLoader()->PreloadURI(uri, pe.charset, pe.elementType);
break;
case nsSpeculativeScriptThread::IMAGE:
doc->MaybePreLoadImage(uri);
doc->MaybePreLoadImage(uri, EmptyString());
break;
case nsSpeculativeScriptThread::STYLESHEET:
doc->PreloadStyle(uri, pe.charset);