Propagate a stylesheet's principal to the URI and Image CSSValues derived fromthat sheet. Bug 377091, r+sr=dbaron

This commit is contained in:
bzbarsky@mit.edu 2007-05-02 18:15:53 -07:00
parent c984b81071
commit 51671d60c6
14 changed files with 173 additions and 53 deletions

View File

@ -1999,6 +1999,7 @@ nsGenericHTMLElement::ParseStyleAttribute(nsIContent* aContent,
nsCOMPtr<nsICSSStyleRule> rule;
result = cssParser->ParseStyleAttribute(aValue, doc->GetDocumentURI(),
baseURI,
aContent->NodePrincipal(),
getter_AddRefs(rule));
cssLoader->RecycleParser(cssParser);
@ -2248,7 +2249,7 @@ nsGenericHTMLElement::MapImageBorderAttributeInto(const nsMappedAttributes* aAtt
void
nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes,
nsRuleData* aData)
nsRuleData* aData)
{
if (aData->mSID != eStyleStruct_Background)
return;
@ -2275,9 +2276,12 @@ nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes,
// accessor on nsAttrValue?
nsStringBuffer* buffer = nsCSSValue::BufferFromString(spec);
if (NS_LIKELY(buffer != 0)) {
// XXXbz it would be nice to assert that doc->NodePrincipal() is
// the same as the principal of the node (which we'd need to store
// in the mapped attrs or something?)
nsCSSValue::Image *img =
new nsCSSValue::Image(uri, buffer, doc->GetDocumentURI(),
doc, PR_TRUE);
doc->NodePrincipal(), doc, PR_TRUE);
buffer->Release();
if (NS_LIKELY(img != 0)) {
aData->mColorData->mBackImage.SetImageValue(img);

View File

@ -642,7 +642,6 @@ nsSVGElement::DidModifySVGObservable(nsISVGValue* aObservable,
nsContentUtils::HasMutationListeners(this,
NS_EVENT_BITS_MUTATION_ATTRMODIFIED);
nsIDocument* document = GetCurrentDoc();
if (hasListeners || IsInDoc()) {
modification = !!mAttrsAndChildren.GetAttr(attrName->LocalName(),
attrName->NamespaceID());
@ -730,7 +729,7 @@ nsSVGElement::UpdateContentStyleRule()
PRBool changed;
parser->ParseProperty(nsCSSProps::LookupProperty(name), value,
docURI, baseURI,
docURI, baseURI, NodePrincipal(),
declaration, &changed);
}

View File

@ -829,6 +829,11 @@ nsXULElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
(!aBindingParent && aParent &&
aParent->GetBindingParent() == GetBindingParent()),
"Already have a binding parent. Unbind first!");
// XXXbz XUL's SetNativeAnonymous is all weird, so can't assert
// anything here
// NS_PRECONDITION(aBindingParent != this || IsNativeAnonymous(),
// "Only native anonymous content should have itself as its "
// "own binding parent");
if (!aBindingParent && aParent) {
aBindingParent = aParent->GetBindingParent();
@ -2706,6 +2711,10 @@ nsXULPrototypeElement::SetAttrAt(PRUint32 aPos, const nsAString& aValue,
// XXX Get correct Base URI (need GetBaseURI on *prototype* element)
parser->ParseStyleAttribute(aValue, aDocumentURI, aDocumentURI,
// This is basically duplicating what
// nsINode::NodePrincipal() does
mNodeInfo->NodeInfoManager()->
DocumentPrincipal(),
getter_AddRefs(rule));
if (rule) {
mAttributes[aPos].mValue.SetTo(rule);

View File

@ -1511,7 +1511,8 @@ CSSLoaderImpl::ParseSheet(nsIUnicharInputStream* aStream,
nsCOMPtr<nsIURI> sheetURI, baseURI;
aLoadData->mSheet->GetSheetURI(getter_AddRefs(sheetURI));
aLoadData->mSheet->GetBaseURI(getter_AddRefs(baseURI));
rv = parser->Parse(aStream, sheetURI, baseURI, aLoadData->mLineNumber,
rv = parser->Parse(aStream, sheetURI, baseURI,
aLoadData->mSheet->Principal(), aLoadData->mLineNumber,
aLoadData->mAllowUnsafeRules,
*getter_AddRefs(dummySheet));
mParsingDatas.RemoveElementAt(mParsingDatas.Count() - 1);

View File

@ -79,6 +79,7 @@
#include "nsIMediaList.h"
#include "nsILookAndFeel.h"
#include "nsStyleUtil.h"
#include "nsIPrincipal.h"
#include "prprf.h"
#include "math.h"
@ -108,6 +109,7 @@ public:
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
PRUint32 aLineNumber,
PRBool aAllowUnsafeRules,
nsICSSStyleSheet*& aResult);
@ -115,11 +117,13 @@ public:
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aDocURL,
nsIURI* aBaseURL,
nsIPrincipal* aNodePrincipal,
nsICSSStyleRule** aResult);
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSDeclaration* aDeclaration,
PRBool aParseOnlyOneDecl,
PRBool* aChanged,
@ -128,12 +132,14 @@ public:
NS_IMETHOD ParseRule(const nsAString& aRule,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCOMArray<nsICSSRule>& aResult);
NS_IMETHOD ParseProperty(const nsCSSProperty aPropID,
const nsAString& aPropValue,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSDeclaration* aDeclaration,
PRBool* aChanged);
@ -176,10 +182,12 @@ protected:
};
nsresult InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
PRUint32 aLineNumber, nsIURI* aBaseURI);
PRUint32 aLineNumber, nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal);
// the caller must hold on to aBuffer until parsing is done
nsresult InitScanner(const nsString& aString, nsIURI* aSheetURI,
PRUint32 aLineNumber, nsIURI* aBaseURI);
PRUint32 aLineNumber, nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal);
nsresult ReleaseScanner(void);
nsresult DoParseMediaList(const nsSubstring& aBuffer,
@ -403,6 +411,9 @@ protected:
// The URI to be used as an HTTP "Referer" and for error reporting.
nsCOMPtr<nsIURI> mSheetURL;
// The principal of the sheet involved
nsCOMPtr<nsIPrincipal> mSheetPrincipal;
// The sheet we're parsing into
nsCOMPtr<nsICSSStyleSheet> mSheet;
@ -617,7 +628,8 @@ CSSParserImpl::SetChildLoader(nsICSSLoader* aChildLoader)
nsresult
CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
PRUint32 aLineNumber, nsIURI* aBaseURI)
PRUint32 aLineNumber, nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal)
{
NS_ASSERTION(! mScannerInited, "already have scanner");
@ -627,6 +639,7 @@ CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
#endif
mBaseURL = aBaseURI;
mSheetURL = aSheetURI;
mSheetPrincipal = aSheetPrincipal;
mHavePushBack = PR_FALSE;
@ -635,7 +648,8 @@ CSSParserImpl::InitScanner(nsIUnicharInputStream* aInput, nsIURI* aSheetURI,
nsresult
CSSParserImpl::InitScanner(const nsString& aString, nsIURI* aSheetURI,
PRUint32 aLineNumber, nsIURI* aBaseURI)
PRUint32 aLineNumber, nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal)
{
// Having it not own the string is OK since the caller will hold on to
// the stream until we're done parsing.
@ -648,6 +662,7 @@ CSSParserImpl::InitScanner(const nsString& aString, nsIURI* aSheetURI,
#endif
mBaseURL = aBaseURI;
mSheetURL = aSheetURI;
mSheetPrincipal = aSheetPrincipal;
mHavePushBack = PR_FALSE;
@ -671,10 +686,13 @@ NS_IMETHODIMP
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
nsIURI* aSheetURI,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
PRUint32 aLineNumber,
PRBool aAllowUnsafeRules,
nsICSSStyleSheet*& aResult)
{
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
NS_ASSERTION(nsnull != aBaseURI, "need base URL");
NS_ASSERTION(nsnull != aSheetURI, "need sheet URL");
@ -683,6 +701,7 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
NS_ENSURE_TRUE(mSheet, NS_ERROR_OUT_OF_MEMORY);
mSheet->SetURIs(aSheetURI, aBaseURI);
mSheet->SetPrincipal(aSheetPrincipal);
mNameSpaceMap = nsnull;
}
#ifdef DEBUG
@ -690,14 +709,19 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
nsCOMPtr<nsIURI> uri;
mSheet->GetSheetURI(getter_AddRefs(uri));
PRBool equal;
aSheetURI->Equals(uri, &equal);
NS_ASSERTION(equal, "Sheet URI does not match passed URI");
NS_ASSERTION(NS_SUCCEEDED(aSheetURI->Equals(uri, &equal)) && equal,
"Sheet URI does not match passed URI");
NS_ASSERTION(NS_SUCCEEDED(mSheet->Principal()->Equals(aSheetPrincipal,
&equal)) &&
equal,
"Sheet principal does not match passed principal");
}
#endif
nsresult errorCode = NS_OK;
nsresult result = InitScanner(aInput, aSheetURI, aLineNumber, aBaseURI);
nsresult result = InitScanner(aInput, aSheetURI, aLineNumber, aBaseURI,
aSheetPrincipal);
if (! NS_SUCCEEDED(result)) {
return result;
}
@ -764,12 +788,16 @@ NS_IMETHODIMP
CSSParserImpl::ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aDocURL,
nsIURI* aBaseURL,
nsIPrincipal* aNodePrincipal,
nsICSSStyleRule** aResult)
{
NS_PRECONDITION(aNodePrincipal, "Must have principal here!");
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
const nsAFlatString& flat = PromiseFlatString(aAttributeValue);
nsresult rv = InitScanner(flat, aDocURL, 0, aBaseURL); // XXX line number
// XXX line number?
nsresult rv = InitScanner(flat, aDocURL, 0, aBaseURL, aNodePrincipal);
if (! NS_SUCCEEDED(rv)) {
return rv;
}
@ -815,16 +843,19 @@ NS_IMETHODIMP
CSSParserImpl::ParseAndAppendDeclaration(const nsAString& aBuffer,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSDeclaration* aDeclaration,
PRBool aParseOnlyOneDecl,
PRBool* aChanged,
PRBool aClearOldDecl)
{
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
// NS_ASSERTION(nsnull != aBaseURL, "need base URL");
*aChanged = PR_FALSE;
const nsAFlatString& flat = PromiseFlatString(aBuffer);
nsresult rv = InitScanner(flat, aSheetURL, 0, aBaseURL);
nsresult rv = InitScanner(flat, aSheetURL, 0, aBaseURL, aSheetPrincipal);
if (! NS_SUCCEEDED(rv)) {
return rv;
}
@ -869,12 +900,15 @@ NS_IMETHODIMP
CSSParserImpl::ParseRule(const nsAString& aRule,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCOMArray<nsICSSRule>& aResult)
{
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
const nsAFlatString& flat = PromiseFlatString(aRule);
nsresult rv = InitScanner(flat, aSheetURL, 0, aBaseURL);
nsresult rv = InitScanner(flat, aSheetURL, 0, aBaseURL, aSheetPrincipal);
if (NS_FAILED(rv)) {
return rv;
}
@ -908,15 +942,18 @@ CSSParserImpl::ParseProperty(const nsCSSProperty aPropID,
const nsAString& aPropValue,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSDeclaration* aDeclaration,
PRBool* aChanged)
{
NS_PRECONDITION(aSheetPrincipal, "Must have principal here!");
NS_ASSERTION(nsnull != aBaseURL, "need base URL");
NS_ASSERTION(nsnull != aDeclaration, "Need declaration to parse into!");
*aChanged = PR_FALSE;
const nsAFlatString& flat = PromiseFlatString(aPropValue);
nsresult rv = InitScanner(flat, aSheetURL, 0, aBaseURL);
nsresult rv = InitScanner(flat, aSheetURL, 0, aBaseURL, aSheetPrincipal);
if (NS_FAILED(rv)) {
return rv;
}
@ -1024,7 +1061,7 @@ CSSParserImpl::DoParseMediaList(const nsSubstring& aBuffer,
const nsAFlatString& flat = PromiseFlatString(aBuffer);
// fake base URL since media lists don't have URLs in them
nsresult rv = InitScanner(flat, aURL, aLineNumber, aURL);
nsresult rv = InitScanner(flat, aURL, aLineNumber, aURL, nsnull);
if (NS_FAILED(rv)) {
return rv;
}
@ -1047,7 +1084,7 @@ CSSParserImpl::ParseColorString(const nsSubstring& aBuffer,
NS_ASSERTION(aHandleAlphaColors == PR_TRUE || aHandleAlphaColors == PR_FALSE, "bad PRBool value");
const nsAFlatString& flat = PromiseFlatString(aBuffer);
nsresult rv = InitScanner(flat, aURL, aLineNumber, aURL);
nsresult rv = InitScanner(flat, aURL, aLineNumber, aURL, nsnull);
if (NS_FAILED(rv))
return rv;
@ -4016,6 +4053,12 @@ PRBool CSSParserImpl::ParseAttr(nsresult& aErrorCode, nsCSSValue& aValue)
PRBool CSSParserImpl::ParseURL(nsresult& aErrorCode, nsCSSValue& aValue)
{
if (!mSheetPrincipal) {
NS_NOTREACHED("Codepaths that expect to parse URLs MUST pass in an "
"origin principal");
return PR_FALSE;
}
if (ExpectSymbol(aErrorCode, '(', PR_FALSE)) {
if (! GetURLToken(aErrorCode, PR_TRUE)) {
return PR_FALSE;
@ -4035,7 +4078,8 @@ PRBool CSSParserImpl::ParseURL(nsresult& aErrorCode, nsCSSValue& aValue)
return PR_FALSE;
}
nsCSSValue::URL *url = new nsCSSValue::URL(uri, buffer, mSheetURL);
nsCSSValue::URL *url =
new nsCSSValue::URL(uri, buffer, mSheetURL, mSheetPrincipal);
buffer->Release();
if (NS_UNLIKELY(!url)) {
aErrorCode = NS_ERROR_OUT_OF_MEMORY;

View File

@ -72,6 +72,8 @@
#include "nsRuleNode.h"
#include "nsUnicharUtils.h"
#include "nsCSSPseudoElements.h"
#include "nsIPrincipal.h"
#include "nsComponentManagerUtils.h"
#include "nsContentUtils.h"
#include "nsContentErrors.h"
@ -810,6 +812,7 @@ public:
PRBool aAllocate);
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader,
nsICSSParser** aCSSParser);
virtual nsresult DeclarationChanged();
@ -911,12 +914,14 @@ DOMCSSDeclarationImpl::GetCSSDeclaration(nsCSSDeclaration **aDecl,
nsresult
DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader,
nsICSSParser** aCSSParser)
{
// null out the out params since some of them may not get initialized below
*aSheetURI = nsnull;
*aBaseURI = nsnull;
*aSheetPrincipal = nsnull;
*aCSSLoader = nsnull;
*aCSSParser = nsnull;
nsresult result;
@ -926,6 +931,12 @@ DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aSheetURI,
if (sheet) {
sheet->GetSheetURI(aSheetURI);
sheet->GetBaseURI(aBaseURI);
nsCOMPtr<nsICSSStyleSheet> cssSheet(do_QueryInterface(sheet));
if (cssSheet) {
NS_ADDREF(*aSheetPrincipal = cssSheet->Principal());
}
nsCOMPtr<nsIDocument> document;
sheet->GetOwningDocument(*getter_AddRefs(document));
if (document) {
@ -940,6 +951,11 @@ DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aSheetURI,
result = NS_NewCSSParser(aCSSParser);
}
if (NS_SUCCEEDED(result) && !*aSheetPrincipal) {
result = CallCreateInstance("@mozilla.org/nullprincipal;1",
aSheetPrincipal);
}
return result;
}

View File

@ -1543,7 +1543,8 @@ nsCSSStyleSheet::InsertRule(const nsAString& aRule,
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
nsCOMArray<nsICSSRule> rules;
result = css->ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI, rules);
result = css->ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
mInner->mPrincipal, rules);
if (NS_FAILED(result))
return result;
@ -1783,7 +1784,8 @@ nsCSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule,
NS_ENSURE_SUCCESS(result, result);
nsCOMArray<nsICSSRule> rules;
result = css->ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI, rules);
result = css->ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
mInner->mPrincipal, rules);
NS_ENSURE_SUCCESS(result, result);
PRInt32 rulecount = rules.Count();

View File

@ -44,6 +44,7 @@
#include "imgIRequest.h"
#include "nsIDocument.h"
#include "nsContentUtils.h"
#include "nsIPrincipal.h"
// Paint forcing
#include "prenv.h"
@ -355,6 +356,7 @@ void nsCSSValue::StartImageLoad(nsIDocument* aDocument, PRBool aIsBGImage) const
new nsCSSValue::Image(mValue.mURL->mURI,
mValue.mURL->mString,
mValue.mURL->mReferrer,
mValue.mURL->mOriginPrincipal,
aDocument, aIsBGImage);
if (image) {
nsCSSValue* writable = NS_CONST_CAST(nsCSSValue*, this);
@ -384,10 +386,45 @@ nsCSSValue::BufferFromString(const nsString& aValue)
return buffer;
}
nsCSSValue::URL::URL(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
nsIPrincipal* aOriginPrincipal)
: mURI(aURI),
mString(aString),
mReferrer(aReferrer),
mOriginPrincipal(aOriginPrincipal),
mRefCnt(0)
{
NS_PRECONDITION(aOriginPrincipal, "Must have an origin principal");
mString->AddRef();
MOZ_COUNT_CTOR(nsCSSValue::URL);
}
nsCSSValue::URL::~URL()
{
mString->Release();
MOZ_COUNT_DTOR(nsCSSValue::URL);
}
PRBool
nsCSSValue::URL::operator==(const URL& aOther) const
{
PRBool eq;
return NS_strcmp(GetBufferValue(mString),
GetBufferValue(aOther.mString)) == 0 &&
(mURI == aOther.mURI || // handles null == null
(mURI && aOther.mURI &&
NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
eq)) &&
NS_SUCCEEDED(mOriginPrincipal->Equals(aOther.mOriginPrincipal,
&eq)) &&
eq;
}
nsCSSValue::Image::Image(nsIURI* aURI, nsStringBuffer* aString,
nsIURI* aReferrer, nsIDocument* aDocument,
PRBool aIsBGImage)
: URL(aURI, aString, aReferrer)
nsIURI* aReferrer, nsIPrincipal* aOriginPrincipal,
nsIDocument* aDocument, PRBool aIsBGImage)
: URL(aURI, aString, aReferrer, aOriginPrincipal)
{
MOZ_COUNT_CTOR(nsCSSValue::Image);

View File

@ -53,6 +53,7 @@
class imgIRequest;
class nsIDocument;
class nsIPrincipal;
enum nsCSSUnit {
eCSSUnit_Null = 0, // (n/a) null unit, value is not specified
@ -376,38 +377,24 @@ public:
};
struct URL {
// Methods are not inline because using an nsIPrincipal means requiring
// caps, which leads to REQUIRES hell, since this header is included all
// over.
// aString must not be null.
URL(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer)
: mURI(aURI),
mString(aString),
mReferrer(aReferrer),
mRefCnt(0)
{
mString->AddRef();
MOZ_COUNT_CTOR(nsCSSValue::URL);
}
// aOriginPrincipal must not be null.
URL(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
nsIPrincipal* aOriginPrincipal) NS_HIDDEN;
~URL()
{
mString->Release();
MOZ_COUNT_DTOR(nsCSSValue::URL);
}
~URL() NS_HIDDEN;
PRBool operator==(const URL& aOther) const
{
PRBool eq;
return NS_strcmp(GetBufferValue(mString),
GetBufferValue(aOther.mString)) == 0 &&
(mURI == aOther.mURI || // handles null == null
(mURI && aOther.mURI &&
NS_SUCCEEDED(mURI->Equals(aOther.mURI, &eq)) &&
eq));
}
NS_HIDDEN_(PRBool) operator==(const URL& aOther) const;
nsCOMPtr<nsIURI> mURI; // null == invalid URL
nsStringBuffer* mString; // Could use nsRefPtr, but it'd add useless
// null-checks; this is never null.
nsCOMPtr<nsIURI> mReferrer;
nsCOMPtr<nsIPrincipal> mOriginPrincipal;
void AddRef() { ++mRefCnt; }
void Release() { if (--mRefCnt == 0) delete this; }
@ -421,7 +408,8 @@ public:
// this header is included all over.
// aString must not be null.
Image(nsIURI* aURI, nsStringBuffer* aString, nsIURI* aReferrer,
nsIDocument* aDocument, PRBool aIsBGImage = PR_FALSE) NS_HIDDEN;
nsIPrincipal* aOriginPrincipal, nsIDocument* aDocument,
PRBool aIsBGImage = PR_FALSE) NS_HIDDEN;
~Image() NS_HIDDEN;
// Inherit operator== from nsCSSValue::URL

View File

@ -49,6 +49,7 @@
#include "nsStyleConsts.h"
#include "nsContentUtils.h"
#include "nsIContent.h"
#include "nsIPrincipal.h"
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIContent *aContent)
{
@ -136,6 +137,7 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
nsresult
nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader,
nsICSSParser** aCSSParser)
{
@ -143,6 +145,7 @@ nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
// null out the out params since some of them may not get initialized below
*aSheetURI = nsnull;
*aBaseURI = nsnull;
*aSheetPrincipal = nsnull;
*aCSSLoader = nsnull;
*aCSSParser = nsnull;
@ -168,6 +171,7 @@ nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
baseURI.swap(*aBaseURI);
sheetURI.swap(*aSheetURI);
NS_ADDREF(*aSheetPrincipal = mContent->NodePrincipal());
return NS_OK;
}

View File

@ -66,6 +66,7 @@ public:
PRBool aAllocate);
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader,
nsICSSParser** aCSSParser);
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);

View File

@ -48,6 +48,7 @@
#include "nsCOMPtr.h"
#include "nsIURL.h"
#include "nsReadableUtils.h"
#include "nsIPrincipal.h"
#include "nsContentUtils.h"
@ -253,9 +254,11 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSProperty aPropID,
nsCOMPtr<nsICSSLoader> cssLoader;
nsCOMPtr<nsICSSParser> cssParser;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;
result = GetCSSParsingEnvironment(getter_AddRefs(sheetURI),
getter_AddRefs(baseURI),
getter_AddRefs(sheetPrincipal),
getter_AddRefs(cssLoader),
getter_AddRefs(cssParser));
if (NS_FAILED(result)) {
@ -264,7 +267,7 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSProperty aPropID,
PRBool changed;
result = cssParser->ParseProperty(aPropID, aPropValue, sheetURI, baseURI,
decl, &changed);
sheetPrincipal, decl, &changed);
if (NS_SUCCEEDED(result) && changed) {
result = DeclarationChanged();
}
@ -290,9 +293,11 @@ nsDOMCSSDeclaration::ParseDeclaration(const nsAString& aDecl,
nsCOMPtr<nsICSSLoader> cssLoader;
nsCOMPtr<nsICSSParser> cssParser;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;
result = GetCSSParsingEnvironment(getter_AddRefs(sheetURI),
getter_AddRefs(baseURI),
getter_AddRefs(sheetPrincipal),
getter_AddRefs(cssLoader),
getter_AddRefs(cssParser));
@ -301,7 +306,8 @@ nsDOMCSSDeclaration::ParseDeclaration(const nsAString& aDecl,
}
PRBool changed;
result = cssParser->ParseAndAppendDeclaration(aDecl, sheetURI, baseURI, decl,
result = cssParser->ParseAndAppendDeclaration(aDecl, sheetURI, baseURI,
sheetPrincipal, decl,
aParseOnlyOneDecl,
&changed,
aClearOldDecl);

View File

@ -47,6 +47,7 @@ class nsCSSDeclaration;
class nsICSSParser;
class nsICSSLoader;
class nsIURI;
class nsIPrincipal;
class CSS2PropertiesTearoff : public nsIDOMNSCSS2Properties
{
@ -101,10 +102,12 @@ protected:
PRBool aAllocate) = 0;
virtual nsresult DeclarationChanged() = 0;
// This will only fail if it can't get a parser. This means it can
// return NS_OK without aURI or aCSSLoader being initialized.
// This will only fail if it can't get a parser or a principal.
// This means it can return NS_OK without aURI or aCSSLoader being
// initialized.
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
nsICSSLoader** aCSSLoader,
nsICSSParser** aCSSParser) = 0;

View File

@ -54,6 +54,7 @@ class nsCSSDeclaration;
class nsICSSLoader;
class nsICSSRule;
class nsMediaList;
class nsIPrincipal;
#define NS_ICSS_PARSER_IID \
{ 0x2cb34728, 0x0f17, 0x4753, \
@ -92,6 +93,7 @@ public:
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURI* aSheetURL,
nsIURI* aBaseURI,
nsIPrincipal* aSheetPrincipal,
PRUint32 aLineNumber,
PRBool aAllowUnsafeRules,
nsICSSStyleSheet*& aResult) = 0;
@ -102,11 +104,13 @@ public:
NS_IMETHOD ParseStyleAttribute(const nsAString& aAttributeValue,
nsIURI* aDocURL,
nsIURI* aBaseURL,
nsIPrincipal* aNodePrincipal,
nsICSSStyleRule** aResult) = 0;
NS_IMETHOD ParseAndAppendDeclaration(const nsAString& aBuffer,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSDeclaration* aDeclaration,
PRBool aParseOnlyOneDecl,
PRBool* aChanged,
@ -115,12 +119,14 @@ public:
NS_IMETHOD ParseRule(const nsAString& aRule,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCOMArray<nsICSSRule>& aResult) = 0;
NS_IMETHOD ParseProperty(const nsCSSProperty aPropID,
const nsAString& aPropValue,
nsIURI* aSheetURL,
nsIURI* aBaseURL,
nsIPrincipal* aSheetPrincipal,
nsCSSDeclaration* aDeclaration,
PRBool* aChanged) = 0;