From eacd7374101e7a29fd9974691a1a763137bd5081 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 4 Aug 2012 09:44:01 +0200 Subject: [PATCH] Bug 777293 - Remove NS_NewCSSStyleSheet; r=dbaron --- content/base/src/nsTreeSanitizer.cpp | 4 +-- layout/base/nsPresShell.cpp | 46 ++++++++++++---------------- layout/style/Loader.cpp | 7 ++--- layout/style/nsCSSStyleSheet.cpp | 24 ++------------- layout/style/nsCSSStyleSheet.h | 4 --- 5 files changed, 27 insertions(+), 58 deletions(-) diff --git a/content/base/src/nsTreeSanitizer.cpp b/content/base/src/nsTreeSanitizer.cpp index 8d8a1abacb5..20a004da5fc 100644 --- a/content/base/src/nsTreeSanitizer.cpp +++ b/content/base/src/nsTreeSanitizer.cpp @@ -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 sheet; - rv = NS_NewCSSStyleSheet(getter_AddRefs(sheet)); - NS_ENSURE_SUCCESS(rv, true); + nsRefPtr sheet = new nsCSSStyleSheet(); sheet->SetURIs(aDocument->GetDocumentURI(), nullptr, aBaseURI); sheet->SetPrincipal(aDocument->NodePrincipal()); // Create the CSS parser, and parse the CSS text. diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 65a1f677ef1..6a9380b8a09 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -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 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 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 diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index cb8db37baa5..6dcd7346bb0 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1080,7 +1080,6 @@ Loader::CreateSheet(nsIURI* aURI, mPendingDatas.Init(); } - nsresult rv = NS_OK; *aSheet = nullptr; aSheetState = eSheetStateUnknown; @@ -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 sheet = new nsCSSStyleSheet(); + sheet->SetURIs(sheetURI, originalURI, baseURI); + sheet.forget(aSheet); } NS_ASSERTION(*aSheet, "We should have a sheet by now!"); diff --git a/layout/style/nsCSSStyleSheet.cpp b/layout/style/nsCSSStyleSheet.cpp index bc088d52197..da929111c1c 100644 --- a/layout/style/nsCSSStyleSheet.cpp +++ b/layout/style/nsCSSStyleSheet.cpp @@ -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) @@ -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; -} diff --git a/layout/style/nsCSSStyleSheet.h b/layout/style/nsCSSStyleSheet.h index f2b1cbdc071..ace2667e40d 100644 --- a/layout/style/nsCSSStyleSheet.h +++ b/layout/style/nsCSSStyleSheet.h @@ -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, @@ -282,12 +281,9 @@ protected: 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_) */