From f892fa1b7652c63d467d47b9ea228107cda4f86a Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Thu, 14 Apr 2016 09:55:47 +1000 Subject: [PATCH] Bug 1247150 - Consistently use StyleSheetHandle::RefPtr* for outparams in nsLayoutStylesheetCache. r=dholbert --- layout/style/nsLayoutStylesheetCache.cpp | 70 ++++++++++++------------ layout/style/nsLayoutStylesheetCache.h | 8 +-- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index af7c2bd1507c..66f25ac34f0d 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -75,7 +75,7 @@ nsLayoutStylesheetCache::ScrollbarsSheet() if (!mScrollbarsSheet) { // Scrollbars don't need access to unsafe rules LoadSheetURL("chrome://global/skin/scrollbars.css", - mScrollbarsSheet, eAuthorSheetFeatures); + &mScrollbarsSheet, eAuthorSheetFeatures); } return mScrollbarsSheet; @@ -87,7 +87,7 @@ nsLayoutStylesheetCache::FormsSheet() if (!mFormsSheet) { // forms.css needs access to unsafe rules LoadSheetURL("resource://gre-resources/forms.css", - mFormsSheet, eAgentSheetFeatures); + &mFormsSheet, eAgentSheetFeatures); } return mFormsSheet; @@ -102,7 +102,7 @@ nsLayoutStylesheetCache::NumberControlSheet() if (!mNumberControlSheet) { LoadSheetURL("resource://gre-resources/number-control.css", - mNumberControlSheet, eAgentSheetFeatures); + &mNumberControlSheet, eAgentSheetFeatures); } return mNumberControlSheet; @@ -125,7 +125,7 @@ nsLayoutStylesheetCache::UASheet() { if (!mUASheet) { LoadSheetURL("resource://gre-resources/ua.css", - mUASheet, eAgentSheetFeatures); + &mUASheet, eAgentSheetFeatures); } return mUASheet; @@ -136,7 +136,7 @@ nsLayoutStylesheetCache::HTMLSheet() { if (!mHTMLSheet) { LoadSheetURL("resource://gre-resources/html.css", - mHTMLSheet, eAgentSheetFeatures); + &mHTMLSheet, eAgentSheetFeatures); } return mHTMLSheet; @@ -171,7 +171,7 @@ nsLayoutStylesheetCache::MathMLSheet() { if (!mMathMLSheet) { LoadSheetURL("resource://gre-resources/mathml.css", - mMathMLSheet, eAgentSheetFeatures); + &mMathMLSheet, eAgentSheetFeatures); } return mMathMLSheet; @@ -188,7 +188,7 @@ nsLayoutStylesheetCache::NoScriptSheet() { if (!mNoScriptSheet) { LoadSheetURL("resource://gre-resources/noscript.css", - mNoScriptSheet, eAgentSheetFeatures); + &mNoScriptSheet, eAgentSheetFeatures); } return mNoScriptSheet; @@ -199,7 +199,7 @@ nsLayoutStylesheetCache::NoFramesSheet() { if (!mNoFramesSheet) { LoadSheetURL("resource://gre-resources/noframes.css", - mNoFramesSheet, eAgentSheetFeatures); + &mNoFramesSheet, eAgentSheetFeatures); } return mNoFramesSheet; @@ -209,7 +209,7 @@ StyleSheetHandle nsLayoutStylesheetCache::ChromePreferenceSheet(nsPresContext* aPresContext) { if (!mChromePreferenceSheet) { - BuildPreferenceSheet(mChromePreferenceSheet, aPresContext); + BuildPreferenceSheet(&mChromePreferenceSheet, aPresContext); } return mChromePreferenceSheet; @@ -219,7 +219,7 @@ StyleSheetHandle nsLayoutStylesheetCache::ContentPreferenceSheet(nsPresContext* aPresContext) { if (!mContentPreferenceSheet) { - BuildPreferenceSheet(mContentPreferenceSheet, aPresContext); + BuildPreferenceSheet(&mContentPreferenceSheet, aPresContext); } return mContentPreferenceSheet; @@ -230,7 +230,7 @@ nsLayoutStylesheetCache::ContentEditableSheet() { if (!mContentEditableSheet) { LoadSheetURL("resource://gre/res/contenteditable.css", - mContentEditableSheet, eAgentSheetFeatures); + &mContentEditableSheet, eAgentSheetFeatures); } return mContentEditableSheet; @@ -241,7 +241,7 @@ nsLayoutStylesheetCache::DesignModeSheet() { if (!mDesignModeSheet) { LoadSheetURL("resource://gre/res/designmode.css", - mDesignModeSheet, eAgentSheetFeatures); + &mDesignModeSheet, eAgentSheetFeatures); } return mDesignModeSheet; @@ -323,15 +323,15 @@ nsLayoutStylesheetCache::nsLayoutStylesheetCache(StyleBackendType aType) // And make sure that we load our UA sheets. No need to do this // per-profile, since they're profile-invariant. LoadSheetURL("resource://gre-resources/counterstyles.css", - mCounterStylesSheet, eAgentSheetFeatures); + &mCounterStylesSheet, eAgentSheetFeatures); LoadSheetURL("chrome://global/content/minimal-xul.css", - mMinimalXULSheet, eAgentSheetFeatures); + &mMinimalXULSheet, eAgentSheetFeatures); LoadSheetURL("resource://gre-resources/quirk.css", - mQuirkSheet, eAgentSheetFeatures); + &mQuirkSheet, eAgentSheetFeatures); LoadSheetURL("resource://gre/res/svg.css", - mSVGSheet, eAgentSheetFeatures); + &mSVGSheet, eAgentSheetFeatures); LoadSheetURL("chrome://global/content/xul.css", - mXULSheet, eAgentSheetFeatures); + &mXULSheet, eAgentSheetFeatures); // The remaining sheets are created on-demand do to their use being rarer // (which helps save memory for Firefox OS apps) or because they need to @@ -411,13 +411,13 @@ nsLayoutStylesheetCache::InitFromProfile() contentFile->Append(NS_LITERAL_STRING("userContent.css")); chromeFile->Append(NS_LITERAL_STRING("userChrome.css")); - LoadSheetFile(contentFile, mUserContentSheet, eUserSheetFeatures); - LoadSheetFile(chromeFile, mUserChromeSheet, eUserSheetFeatures); + LoadSheetFile(contentFile, &mUserContentSheet, eUserSheetFeatures); + LoadSheetFile(chromeFile, &mUserChromeSheet, eUserSheetFeatures); } void nsLayoutStylesheetCache::LoadSheetURL(const char* aURL, - StyleSheetHandle::RefPtr& aSheet, + StyleSheetHandle::RefPtr* aSheet, SheetParsingMode aParsingMode) { nsCOMPtr uri; @@ -430,7 +430,7 @@ nsLayoutStylesheetCache::LoadSheetURL(const char* aURL, void nsLayoutStylesheetCache::LoadSheetFile(nsIFile* aFile, - StyleSheetHandle::RefPtr& aSheet, + StyleSheetHandle::RefPtr* aSheet, SheetParsingMode aParsingMode) { bool exists = false; @@ -736,7 +736,7 @@ ErrorLoadingBuiltinSheet(nsIURI* aURI, const char* aMsg) void nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, - StyleSheetHandle::RefPtr& aSheet, + StyleSheetHandle::RefPtr* aSheet, SheetParsingMode aParsingMode) { if (!aURI) { @@ -759,7 +759,7 @@ nsLayoutStylesheetCache::LoadSheet(nsIURI* aURI, #ifdef MOZ_CRASHREPORTER nsZipArchive::sFileCorruptedReason = nullptr; #endif - nsresult rv = loader->LoadSheetSync(aURI, aParsingMode, true, &aSheet); + nsresult rv = loader->LoadSheetSync(aURI, aParsingMode, true, aSheet); if (NS_FAILED(rv)) { ErrorLoadingBuiltinSheet(aURI, nsPrintfCString("LoadSheetSync failed with error %x", rv).get()); @@ -842,24 +842,26 @@ nsLayoutStylesheetCache::InvalidatePreferenceSheets() } void -nsLayoutStylesheetCache::BuildPreferenceSheet(StyleSheetHandle::RefPtr& aSheet, +nsLayoutStylesheetCache::BuildPreferenceSheet(StyleSheetHandle::RefPtr* aSheet, nsPresContext* aPresContext) { if (mBackendType == StyleBackendType::Gecko) { - aSheet = new CSSStyleSheet(CORS_NONE, mozilla::net::RP_Default); + *aSheet = new CSSStyleSheet(CORS_NONE, mozilla::net::RP_Default); } else { - aSheet = new ServoStyleSheet(CORS_NONE, mozilla::net::RP_Default, - dom::SRIMetadata()); + *aSheet = new ServoStyleSheet(CORS_NONE, mozilla::net::RP_Default, + dom::SRIMetadata()); } - aSheet->SetParsingMode(eAgentSheetFeatures); + StyleSheetHandle sheet = *aSheet; + + sheet->SetParsingMode(eAgentSheetFeatures); nsCOMPtr uri; NS_NewURI(getter_AddRefs(uri), "about:PreferenceStyleSheet", nullptr); MOZ_ASSERT(uri, "URI creation shouldn't fail"); - aSheet->SetURIs(uri, uri, uri); - aSheet->AsStyleSheet()->SetComplete(); + sheet->SetURIs(uri, uri, uri); + sheet->AsStyleSheet()->SetComplete(); static const uint32_t kPreallocSize = 1024; @@ -946,11 +948,11 @@ nsLayoutStylesheetCache::BuildPreferenceSheet(StyleSheetHandle::RefPtr& aSheet, "kPreallocSize should be big enough to build preference style " "sheet without reallocation"); - if (aSheet->IsGecko()) { - aSheet->AsGecko()->ReparseSheet(sheetText); + if (sheet->IsGecko()) { + sheet->AsGecko()->ReparseSheet(sheetText); } else { - aSheet->AsServo()->ParseSheet(sheetText, uri, uri, nullptr, 0, - SheetParsingMode::eAuthorSheetFeatures); + sheet->AsServo()->ParseSheet(sheetText, uri, uri, nullptr, 0, + SheetParsingMode::eAuthorSheetFeatures); } #undef NS_GET_R_G_B diff --git a/layout/style/nsLayoutStylesheetCache.h b/layout/style/nsLayoutStylesheetCache.h index 3d7ff1cd3c4f..eb9f0ad112ed 100644 --- a/layout/style/nsLayoutStylesheetCache.h +++ b/layout/style/nsLayoutStylesheetCache.h @@ -76,17 +76,17 @@ private: void InitFromProfile(); void InitMemoryReporter(); void LoadSheetURL(const char* aURL, - mozilla::StyleSheetHandle::RefPtr& aSheet, + mozilla::StyleSheetHandle::RefPtr* aSheet, mozilla::css::SheetParsingMode aParsingMode); void LoadSheetFile(nsIFile* aFile, - mozilla::StyleSheetHandle::RefPtr& aSheet, + mozilla::StyleSheetHandle::RefPtr* aSheet, mozilla::css::SheetParsingMode aParsingMode); - void LoadSheet(nsIURI* aURI, mozilla::StyleSheetHandle::RefPtr& aSheet, + void LoadSheet(nsIURI* aURI, mozilla::StyleSheetHandle::RefPtr* aSheet, mozilla::css::SheetParsingMode aParsingMode); static void InvalidateSheet(mozilla::StyleSheetHandle::RefPtr* aGeckoSheet, mozilla::StyleSheetHandle::RefPtr* aServoSheet); static void DependentPrefChanged(const char* aPref, void* aData); - void BuildPreferenceSheet(mozilla::StyleSheetHandle::RefPtr& aSheet, + void BuildPreferenceSheet(mozilla::StyleSheetHandle::RefPtr* aSheet, nsPresContext* aPresContext); static mozilla::StaticRefPtr gStyleCache_Gecko;