Skip to content

Commit

Permalink
Bug 777293 - Remove NS_NewCSSStyleSheet; r=dbaron
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger committed Aug 4, 2012
1 parent 3c2c2be commit 5aceb72
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 58 deletions.
4 changes: 1 addition & 3 deletions content/base/src/nsTreeSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,7 @@ nsTreeSanitizer::SanitizeStyleSheet(const nsAString& aOriginal,
// -moz-binding is blacklisted.
bool didSanitize = false;
// Create a sheet to hold the parsed CSS
nsRefPtr<nsCSSStyleSheet> sheet;
rv = NS_NewCSSStyleSheet(getter_AddRefs(sheet));
NS_ENSURE_SUCCESS(rv, true);
nsRefPtr<nsCSSStyleSheet> sheet = new nsCSSStyleSheet();
sheet->SetURIs(aDocument->GetDocumentURI(), nullptr, aBaseURI);
sheet->SetPrincipal(aDocument->NodePrincipal());
// Create the CSS parser, and parse the CSS text.
Expand Down
46 changes: 20 additions & 26 deletions layout/base/nsPresShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,39 +1178,33 @@ nsresult PresShell::ClearPreferenceStyleRules(void)
return result;
}

nsresult PresShell::CreatePreferenceStyleSheet(void)
nsresult
PresShell::CreatePreferenceStyleSheet()
{
NS_TIME_FUNCTION_MIN(1.0);

NS_ASSERTION(!mPrefStyleSheet, "prefStyleSheet already exists");
nsresult result = NS_NewCSSStyleSheet(getter_AddRefs(mPrefStyleSheet));
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(mPrefStyleSheet, "null but no error");
nsCOMPtr<nsIURI> uri;
result = NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nullptr);
if (NS_SUCCEEDED(result)) {
NS_ASSERTION(uri, "null but no error");
mPrefStyleSheet->SetURIs(uri, uri, uri);
mPrefStyleSheet->SetComplete();
PRUint32 index;
result =
mPrefStyleSheet->InsertRuleInternal(NS_LITERAL_STRING("@namespace url(http://www.w3.org/1999/xhtml);"),
0, &index);
if (NS_SUCCEEDED(result)) {
mStyleSet->AppendStyleSheet(nsStyleSet::eUserSheet, mPrefStyleSheet);
}
}
}

#ifdef DEBUG_attinasi
printf("CreatePrefStyleSheet completed: error=%ld\n",(long)result);
#endif

if (NS_FAILED(result)) {
mPrefStyleSheet = new nsCSSStyleSheet();
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nullptr);
if (NS_FAILED(rv)) {
mPrefStyleSheet = nullptr;
return rv;
}
NS_ASSERTION(uri, "null but no error");
mPrefStyleSheet->SetURIs(uri, uri, uri);
mPrefStyleSheet->SetComplete();
PRUint32 index;
rv =
mPrefStyleSheet->InsertRuleInternal(NS_LITERAL_STRING("@namespace url(http://www.w3.org/1999/xhtml);"),
0, &index);
if (NS_FAILED(rv)) {
mPrefStyleSheet = nullptr;
return rv;
}

return result;
mStyleSet->AppendStyleSheet(nsStyleSet::eUserSheet, mPrefStyleSheet);
return NS_OK;
}

// XXX We want these after the @namespace rule. Does order matter
Expand Down
7 changes: 3 additions & 4 deletions layout/style/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,6 @@ Loader::CreateSheet(nsIURI* aURI,
mPendingDatas.Init();
}

nsresult rv = NS_OK;
*aSheet = nullptr;
aSheetState = eSheetStateUnknown;

Expand Down Expand Up @@ -1199,9 +1198,9 @@ Loader::CreateSheet(nsIURI* aURI,
originalURI = aURI;
}

rv = NS_NewCSSStyleSheet(aSheet);
NS_ENSURE_SUCCESS(rv, rv);
(*aSheet)->SetURIs(sheetURI, originalURI, baseURI);
nsRefPtr<nsCSSStyleSheet> sheet = new nsCSSStyleSheet();
sheet->SetURIs(sheetURI, originalURI, baseURI);
sheet.forget(aSheet);
}

NS_ASSERTION(*aSheet, "We should have a sheet by now!");
Expand Down
24 changes: 3 additions & 21 deletions layout/style/nsCSSStyleSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsCSSStyleSheet* aPrimarySheet)
mSheets.AppendElement(aPrimarySheet);

mPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
if (!mPrincipal) {
NS_RUNTIMEABORT("OOM");
}
}

static bool SetStyleSheetReference(css::Rule* aRule, void* aSheet)
Expand Down Expand Up @@ -2161,24 +2164,3 @@ nsCSSStyleSheet::GetOriginalURI() const
{
return mInner->mOriginalSheetURI;
}

nsresult
NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult)
{
*aInstancePtrResult = nullptr;
nsCSSStyleSheet *it = new nsCSSStyleSheet();

if (!it) {
return NS_ERROR_OUT_OF_MEMORY;
}

NS_ADDREF(it);

if (!it->mInner || !it->mInner->mPrincipal) {
NS_RELEASE(it);
return NS_ERROR_OUT_OF_MEMORY;
}

*aInstancePtrResult = it;
return NS_OK;
}
4 changes: 0 additions & 4 deletions layout/style/nsCSSStyleSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class nsCSSStyleSheetInner {
public:
friend class nsCSSStyleSheet;
friend class nsCSSRuleProcessor;
friend nsresult NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult);
private:
nsCSSStyleSheetInner(nsCSSStyleSheet* aPrimarySheet);
nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy,
Expand Down Expand Up @@ -282,12 +281,9 @@ class nsCSSStyleSheet MOZ_FINAL : public nsIStyleSheet,

friend class nsMediaList;
friend class nsCSSRuleProcessor;
friend nsresult NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult);
friend struct ChildSheetListBuilder;
};

NS_DEFINE_STATIC_IID_ACCESSOR(nsCSSStyleSheet, NS_CSS_STYLE_SHEET_IMPL_CID)

nsresult NS_NewCSSStyleSheet(nsCSSStyleSheet** aInstancePtrResult);

#endif /* !defined(nsCSSStyleSheet_h_) */

0 comments on commit 5aceb72

Please sign in to comment.