Bug 649163. Stop refcounting the return values from GetCSSParsingEnvironment, where possible. r=dbaron

--HG--
extra : rebase_source : 13d75f3954dd1597d58f7741ac8cfc4de51ebe46
This commit is contained in:
Boris Zbarsky 2011-04-27 16:53:49 -04:00
Родитель c21d922d80
Коммит 6fe7aab98c
9 изменённых файлов: 71 добавлений и 145 удалений

Просмотреть файл

@ -953,10 +953,7 @@ public:
void DropReference(void);
virtual css::Declaration* GetCSSDeclaration(PRBool aAllocate);
virtual nsresult SetCSSDeclaration(css::Declaration* aDecl);
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
css::Loader** aCSSLoader);
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv);
virtual nsIDocument* DocToUpdate();
// Override |AddRef| and |Release| for being a member of
@ -1055,19 +1052,10 @@ DOMCSSDeclarationImpl::GetCSSDeclaration(PRBool aAllocate)
}
}
/*
* This is a utility function. It will only fail if it can't get a
* parser. This means it can return NS_OK without aURI or aCSSLoader
* being initialized.
*/
nsresult
DOMCSSDeclarationImpl::GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
css::Loader** aCSSLoader)
void
DOMCSSDeclarationImpl::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
{
return GetCSSParsingEnvironmentForRule(mRule, aSheetURI, aBaseURI,
aSheetPrincipal, aCSSLoader);
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
}
NS_IMETHODIMP

Просмотреть файл

@ -1721,19 +1721,10 @@ nsCSSKeyframeStyleDeclaration::GetCSSDeclaration(PRBool aAllocate)
}
}
/*
* This is a utility function. It will only fail if it can't get a
* parser. This means it can return NS_OK without aURI or aCSSLoader
* being initialized.
*/
nsresult
nsCSSKeyframeStyleDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
css::Loader** aCSSLoader)
void
nsCSSKeyframeStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
{
return GetCSSParsingEnvironmentForRule(mRule, aSheetURI, aBaseURI,
aSheetPrincipal, aCSSLoader);
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
}
NS_IMETHODIMP

Просмотреть файл

@ -329,10 +329,7 @@ public:
void DropReference() { mRule = nsnull; }
virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool aAllocate);
virtual nsresult SetCSSDeclaration(mozilla::css::Declaration* aDecl);
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
mozilla::css::Loader** aCSSLoader);
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv);
virtual nsIDocument* DocToUpdate();
NS_IMETHOD_(nsrefcnt) AddRef();

Просмотреть файл

@ -436,12 +436,12 @@ nsComputedDOMStyle::DocToUpdate()
return nsnull;
}
nsresult
nsComputedDOMStyle::GetCSSParsingEnvironment(nsIURI**, nsIURI**, nsIPrincipal**,
css::Loader**)
void
nsComputedDOMStyle::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
{
NS_RUNTIMEABORT("called nsComputedDOMStyle::GetCSSParsingEnvironment");
return NS_ERROR_FAILURE;
// Just in case NS_RUNTIMEABORT ever stops killing us for some reason
aCSSParseEnv.mPrincipal = nsnull;
}
NS_IMETHODIMP

Просмотреть файл

@ -107,8 +107,7 @@ public:
virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool);
virtual nsresult SetCSSDeclaration(mozilla::css::Declaration*);
virtual nsIDocument* DocToUpdate();
virtual nsresult GetCSSParsingEnvironment(nsIURI**, nsIURI**, nsIPrincipal**,
mozilla::css::Loader**);
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv);
private:
void AssertFlushedPendingReflows() {

Просмотреть файл

@ -170,40 +170,22 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(PRBool aAllocate)
return decl;
}
/*
* This is a utility function. It will only fail if it can't get a
* parser. This means it can return NS_OK without aURI or aCSSLoader
* being initialized.
*/
nsresult
nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
mozilla::css::Loader** aCSSLoader)
void
nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
{
NS_ASSERTION(mElement, "Something is severely broken -- there should be an Element here!");
// null out the out params since some of them may not get initialized below
*aSheetURI = nsnull;
*aBaseURI = nsnull;
*aSheetPrincipal = nsnull;
*aCSSLoader = nsnull;
nsIDocument* doc = mElement->GetOwnerDoc();
if (!doc) {
// document has been destroyed
return NS_ERROR_NOT_AVAILABLE;
aCSSParseEnv.mPrincipal = nsnull;
return;
}
nsCOMPtr<nsIURI> baseURI = mElement->GetBaseURI();
nsCOMPtr<nsIURI> sheetURI = doc->GetDocumentURI();
NS_ADDREF(*aCSSLoader = doc->CSSLoader());
baseURI.swap(*aBaseURI);
sheetURI.swap(*aSheetURI);
NS_ADDREF(*aSheetPrincipal = mElement->NodePrincipal());
return NS_OK;
aCSSParseEnv.mSheetURI = doc->GetDocumentURI();
aCSSParseEnv.mBaseURI = mElement->GetBaseURI();
aCSSParseEnv.mPrincipal = mElement->NodePrincipal();
aCSSParseEnv.mCSSLoader = doc->CSSLoader();
}
NS_IMETHODIMP

Просмотреть файл

@ -76,10 +76,7 @@ public:
// If GetCSSDeclaration returns non-null, then the decl it returns
// is owned by our current style rule.
virtual mozilla::css::Declaration* GetCSSDeclaration(PRBool aAllocate);
virtual nsresult GetCSSParsingEnvironment(nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
mozilla::css::Loader** aCSSLoader);
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv);
NS_IMETHOD GetParentRule(nsIDOMCSSRule **aParent);
virtual nsINode* GetParentObject();

Просмотреть файл

@ -125,18 +125,10 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
return NS_ERROR_FAILURE;
}
nsresult result;
nsRefPtr<css::Loader> cssLoader;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;
result = GetCSSParsingEnvironment(getter_AddRefs(sheetURI),
getter_AddRefs(baseURI),
getter_AddRefs(sheetPrincipal),
getter_AddRefs(cssLoader));
if (NS_FAILED(result)) {
return result;
CSSParsingEnvironment env;
GetCSSParsingEnvironment(env);
if (!env.mPrincipal) {
return NS_ERROR_NOT_AVAILABLE;
}
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
@ -148,10 +140,11 @@ nsDOMCSSDeclaration::SetCssText(const nsAString& aCssText)
nsAutoPtr<css::Declaration> decl(new css::Declaration());
decl->InitializeEmpty();
nsCSSParser cssParser(cssLoader);
nsCSSParser cssParser(env.mCSSLoader);
PRBool changed;
result = cssParser.ParseDeclarations(aCssText, sheetURI, baseURI,
sheetPrincipal, decl, &changed);
nsresult result = cssParser.ParseDeclarations(aCssText, env.mSheetURI,
env.mBaseURI,
env.mPrincipal, decl, &changed);
if (NS_FAILED(result) || !changed) {
return result;
}
@ -271,43 +264,22 @@ nsDOMCSSDeclaration::RemoveProperty(const nsAString& aPropertyName,
return RemoveProperty(propID);
}
/* static */ nsresult
nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(
nsICSSRule* aRule, nsIURI** aSheetURI,
nsIURI** aBaseURI, nsIPrincipal** aSheetPrincipal,
mozilla::css::Loader** aCSSLoader)
/* static */ void
nsDOMCSSDeclaration::GetCSSParsingEnvironmentForRule(nsICSSRule* aRule,
CSSParsingEnvironment& aCSSParseEnv)
{
// null out the out params since some of them may not get initialized below
*aSheetURI = nsnull;
*aBaseURI = nsnull;
*aSheetPrincipal = nsnull;
*aCSSLoader = nsnull;
if (aRule) {
nsIStyleSheet* sheet = aRule->GetStyleSheet();
if (sheet) {
NS_IF_ADDREF(*aSheetURI = sheet->GetSheetURI());
NS_IF_ADDREF(*aBaseURI = sheet->GetBaseURI());
nsRefPtr<nsCSSStyleSheet> cssSheet(do_QueryObject(sheet));
if (cssSheet) {
NS_ADDREF(*aSheetPrincipal = cssSheet->Principal());
}
nsIDocument* document = sheet->GetOwningDocument();
if (document) {
NS_ADDREF(*aCSSLoader = document->CSSLoader());
}
}
nsIStyleSheet* sheet = aRule ? aRule->GetStyleSheet() : nsnull;
nsRefPtr<nsCSSStyleSheet> cssSheet(do_QueryObject(sheet));
if (!cssSheet) {
aCSSParseEnv.mPrincipal = nsnull;
return;
}
nsresult result = NS_OK;
if (!*aSheetPrincipal) {
result = CallCreateInstance("@mozilla.org/nullprincipal;1",
aSheetPrincipal);
}
return result;
nsIDocument* document = sheet->GetOwningDocument();
aCSSParseEnv.mSheetURI = sheet->GetSheetURI();
aCSSParseEnv.mBaseURI = sheet->GetBaseURI();
aCSSParseEnv.mPrincipal = cssSheet->Principal();
aCSSParseEnv.mCSSLoader = document ? document->CSSLoader() : nsnull;
}
nsresult
@ -320,17 +292,10 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSProperty aPropID,
return NS_ERROR_FAILURE;
}
nsresult result;
nsRefPtr<css::Loader> cssLoader;
nsCOMPtr<nsIURI> baseURI, sheetURI;
nsCOMPtr<nsIPrincipal> sheetPrincipal;
result = GetCSSParsingEnvironment(getter_AddRefs(sheetURI),
getter_AddRefs(baseURI),
getter_AddRefs(sheetPrincipal),
getter_AddRefs(cssLoader));
if (NS_FAILED(result)) {
return result;
CSSParsingEnvironment env;
GetCSSParsingEnvironment(env);
if (!env.mPrincipal) {
return NS_ERROR_NOT_AVAILABLE;
}
// For nsDOMCSSAttributeDeclaration, SetCSSDeclaration will lead to
@ -341,11 +306,11 @@ nsDOMCSSDeclaration::ParsePropertyValue(const nsCSSProperty aPropID,
mozAutoDocConditionalContentUpdateBatch autoUpdate(DocToUpdate(), PR_TRUE);
css::Declaration* decl = olddecl->EnsureMutable();
nsCSSParser cssParser(cssLoader);
nsCSSParser cssParser(env.mCSSLoader);
PRBool changed;
result = cssParser.ParseProperty(aPropID, aPropValue, sheetURI, baseURI,
sheetPrincipal, decl, &changed,
aIsImportant);
nsresult result = cssParser.ParseProperty(aPropID, aPropValue, env.mSheetURI,
env.mBaseURI, env.mPrincipal, decl,
&changed, aIsImportant);
if (NS_FAILED(result) || !changed) {
if (decl != olddecl) {
delete decl;

Просмотреть файл

@ -100,22 +100,29 @@ protected:
// to it.
virtual nsIDocument* DocToUpdate() = 0;
// 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,
mozilla::css::Loader** aCSSLoader) = 0;
// Information neded to parse a declaration. We need the mSheetURI
// for error reporting, mBaseURI to resolve relative URIs,
// mPrincipal for subresource loads, and mCSSLoader for determining
// whether we're in quirks mode. mBaseURI needs to be a strong
// pointer because of xml:base possibly creating base URIs on the
// fly. This is why we don't use CSSParsingEnvironment as a return
// value, to avoid multiple-refcounting of mBaseURI.
struct CSSParsingEnvironment {
nsIURI* mSheetURI;
nsCOMPtr<nsIURI> mBaseURI;
nsIPrincipal* mPrincipal;
mozilla::css::Loader* mCSSLoader;
};
// On failure, mPrincipal should be set to null in aCSSParseEnv.
// If mPrincipal is null, the other members may not be set to
// anything meaningful.
virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) = 0;
// An implementation for GetCSSParsingEnvironment for callers wrapping
// an nsICSSRule.
static nsresult
GetCSSParsingEnvironmentForRule(nsICSSRule* aRule,
nsIURI** aSheetURI,
nsIURI** aBaseURI,
nsIPrincipal** aSheetPrincipal,
mozilla::css::Loader** aCSSLoader);
static void GetCSSParsingEnvironmentForRule(nsICSSRule* aRule,
CSSParsingEnvironment& aCSSParseEnv);
nsresult ParsePropertyValue(const nsCSSProperty aPropID,
const nsAString& aPropValue,