diff --git a/dom/svg/SVGDocument.cpp b/dom/svg/SVGDocument.cpp index b2f4658ba5ad..b2ab6c28f9c7 100644 --- a/dom/svg/SVGDocument.cpp +++ b/dom/svg/SVGDocument.cpp @@ -167,6 +167,9 @@ SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded() EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet()); EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet()); EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet()); + if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) { + EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoScriptSheet()); + } EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet()); EndUpdate(UPDATE_STYLE); diff --git a/layout/base/nsDocumentViewer.cpp b/layout/base/nsDocumentViewer.cpp index e57877b6c29c..e85f5c337801 100644 --- a/layout/base/nsDocumentViewer.cpp +++ b/layout/base/nsDocumentViewer.cpp @@ -2334,6 +2334,13 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument, styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet); } + if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) { + sheet = nsLayoutStylesheetCache::NoScriptSheet(); + if (sheet) { + styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet); + } + } + sheet = nsLayoutStylesheetCache::HTMLSheet(); if (sheet) { styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet); diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 211fc8e83d34..7377327ca70c 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -8449,3 +8449,14 @@ nsLayoutUtils::TransformToAncestorAndCombineRegions( nsRegion* dest = isPrecise ? aPreciseTargetDest : aImpreciseTargetDest; dest->OrWith(transformed); } + +/* static */ bool +nsLayoutUtils::ShouldUseNoScriptSheet(nsIDocument* aDocument) +{ + // also handle the case where print is done from print preview + // see bug #342439 for more details + if (aDocument->IsStaticDocument()) { + aDocument = aDocument->GetOriginalDocument(); + } + return aDocument->IsScriptEnabled(); +} diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index d6e2b655b0d8..adb8ddf5a608 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -2672,6 +2672,8 @@ public: */ static bool ContainsMetricsWithId(const Layer* aLayer, const ViewID& aScrollId); + static bool ShouldUseNoScriptSheet(nsIDocument* aDocument); + private: static uint32_t sFontSizeInflationEmPerLine; static uint32_t sFontSizeInflationMinTwips; diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index ad568462d2f3..d95b284d6dfd 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -1367,9 +1367,6 @@ PresShell::SetPreferenceStyleRules(bool aForceReflow) if (NS_SUCCEEDED(result)) { result = SetPrefFocusRules(); } - if (NS_SUCCEEDED(result)) { - result = SetPrefNoScriptRule(); - } if (NS_SUCCEEDED(result)) { result = SetPrefNoFramesRule(); } @@ -1451,34 +1448,6 @@ PresShell::CreatePreferenceStyleSheet() // and just "append"? static uint32_t sInsertPrefSheetRulesAt = 2; -nsresult -PresShell::SetPrefNoScriptRule() -{ - nsresult rv = NS_OK; - - // also handle the case where print is done from print preview - // see bug #342439 for more details - nsIDocument* doc = mDocument; - if (doc->IsStaticDocument()) { - doc = doc->GetOriginalDocument(); - } - - bool scriptEnabled = doc->IsScriptEnabled(); - if (scriptEnabled) { - if (!mPrefStyleSheet) { - rv = CreatePreferenceStyleSheet(); - NS_ENSURE_SUCCESS(rv, rv); - } - - uint32_t index = 0; - mPrefStyleSheet-> - InsertRuleInternal(NS_LITERAL_STRING("noscript{display:none!important}"), - sInsertPrefSheetRulesAt, &index); - } - - return rv; -} - nsresult PresShell::SetPrefNoFramesRule(void) { NS_ASSERTION(mPresContext,"null prescontext not allowed"); diff --git a/layout/base/nsPresShell.h b/layout/base/nsPresShell.h index 99b1dad70fb2..2221142d5098 100644 --- a/layout/base/nsPresShell.h +++ b/layout/base/nsPresShell.h @@ -522,7 +522,6 @@ protected: nsresult CreatePreferenceStyleSheet(void); nsresult SetPrefLinkRules(void); nsresult SetPrefFocusRules(void); - nsresult SetPrefNoScriptRule(); nsresult SetPrefNoFramesRule(void); // methods for painting a range to an offscreen buffer diff --git a/layout/style/jar.mn b/layout/style/jar.mn index 3d10bce75a5f..55c6310a363a 100644 --- a/layout/style/jar.mn +++ b/layout/style/jar.mn @@ -10,6 +10,7 @@ toolkit.jar: res/plaintext.css (plaintext.css) res/viewsource.css (viewsource.css) res/counterstyles.css (counterstyles.css) + res/noscript.css (noscript.css) * res/forms.css (forms.css) res/number-control.css (number-control.css) res/arrow.gif (arrow.gif) diff --git a/layout/style/noscript.css b/layout/style/noscript.css new file mode 100644 index 000000000000..f92b42a50c72 --- /dev/null +++ b/layout/style/noscript.css @@ -0,0 +1,9 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* This sheet is added to the style set for documents with script disabled */ + +noscript { + display: none !important; +} diff --git a/layout/style/nsLayoutStylesheetCache.cpp b/layout/style/nsLayoutStylesheetCache.cpp index 28160fce6bd0..efb1598e4887 100644 --- a/layout/style/nsLayoutStylesheetCache.cpp +++ b/layout/style/nsLayoutStylesheetCache.cpp @@ -192,6 +192,19 @@ nsLayoutStylesheetCache::CounterStylesSheet() return gStyleCache->mCounterStylesSheet; } +CSSStyleSheet* +nsLayoutStylesheetCache::NoScriptSheet() +{ + EnsureGlobal(); + + if (!gStyleCache->mNoScriptSheet) { + LoadSheetURL("resource://gre-resources/noscript.css", + gStyleCache->mNoScriptSheet, true); + } + + return gStyleCache->mNoScriptSheet; +} + void nsLayoutStylesheetCache::Shutdown() { @@ -225,6 +238,7 @@ nsLayoutStylesheetCache::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf MEASURE(mHTMLSheet); MEASURE(mMathMLSheet); MEASURE(mMinimalXULSheet); + MEASURE(mNoScriptSheet); MEASURE(mNumberControlSheet); MEASURE(mQuirkSheet); MEASURE(mSVGSheet); diff --git a/layout/style/nsLayoutStylesheetCache.h b/layout/style/nsLayoutStylesheetCache.h index 9b5287006b7b..c9f61a28c3b0 100644 --- a/layout/style/nsLayoutStylesheetCache.h +++ b/layout/style/nsLayoutStylesheetCache.h @@ -48,6 +48,7 @@ class nsLayoutStylesheetCache final static mozilla::CSSStyleSheet* SVGSheet(); static mozilla::CSSStyleSheet* MathMLSheet(); static mozilla::CSSStyleSheet* CounterStylesSheet(); + static mozilla::CSSStyleSheet* NoScriptSheet(); static void Shutdown(); @@ -78,6 +79,7 @@ private: nsRefPtr mHTMLSheet; nsRefPtr mMathMLSheet; nsRefPtr mMinimalXULSheet; + nsRefPtr mNoScriptSheet; nsRefPtr mNumberControlSheet; nsRefPtr mQuirkSheet; nsRefPtr mSVGSheet;