Bug 1169514 - Part 1: Move noscript rule from the preference style sheet to a cached UA style sheet. r=jwatt

This commit is contained in:
Cameron McCormack 2015-06-16 11:34:47 +10:00
parent 21c7de4127
commit d4b22a556a
10 changed files with 49 additions and 32 deletions

View File

@ -167,6 +167,9 @@ SVGDocument::EnsureNonSVGUserAgentStyleSheetsLoaded()
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet()); EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet());
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet()); EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet());
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet()); EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet());
if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) {
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoScriptSheet());
}
EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet()); EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet());
EndUpdate(UPDATE_STYLE); EndUpdate(UPDATE_STYLE);

View File

@ -2334,6 +2334,13 @@ nsDocumentViewer::CreateStyleSet(nsIDocument* aDocument,
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet); styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
} }
if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) {
sheet = nsLayoutStylesheetCache::NoScriptSheet();
if (sheet) {
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
}
}
sheet = nsLayoutStylesheetCache::HTMLSheet(); sheet = nsLayoutStylesheetCache::HTMLSheet();
if (sheet) { if (sheet) {
styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet); styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);

View File

@ -8449,3 +8449,14 @@ nsLayoutUtils::TransformToAncestorAndCombineRegions(
nsRegion* dest = isPrecise ? aPreciseTargetDest : aImpreciseTargetDest; nsRegion* dest = isPrecise ? aPreciseTargetDest : aImpreciseTargetDest;
dest->OrWith(transformed); 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();
}

View File

@ -2672,6 +2672,8 @@ public:
*/ */
static bool ContainsMetricsWithId(const Layer* aLayer, const ViewID& aScrollId); static bool ContainsMetricsWithId(const Layer* aLayer, const ViewID& aScrollId);
static bool ShouldUseNoScriptSheet(nsIDocument* aDocument);
private: private:
static uint32_t sFontSizeInflationEmPerLine; static uint32_t sFontSizeInflationEmPerLine;
static uint32_t sFontSizeInflationMinTwips; static uint32_t sFontSizeInflationMinTwips;

View File

@ -1367,9 +1367,6 @@ PresShell::SetPreferenceStyleRules(bool aForceReflow)
if (NS_SUCCEEDED(result)) { if (NS_SUCCEEDED(result)) {
result = SetPrefFocusRules(); result = SetPrefFocusRules();
} }
if (NS_SUCCEEDED(result)) {
result = SetPrefNoScriptRule();
}
if (NS_SUCCEEDED(result)) { if (NS_SUCCEEDED(result)) {
result = SetPrefNoFramesRule(); result = SetPrefNoFramesRule();
} }
@ -1451,34 +1448,6 @@ PresShell::CreatePreferenceStyleSheet()
// and just "append"? // and just "append"?
static uint32_t sInsertPrefSheetRulesAt = 2; 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) nsresult PresShell::SetPrefNoFramesRule(void)
{ {
NS_ASSERTION(mPresContext,"null prescontext not allowed"); NS_ASSERTION(mPresContext,"null prescontext not allowed");

View File

@ -522,7 +522,6 @@ protected:
nsresult CreatePreferenceStyleSheet(void); nsresult CreatePreferenceStyleSheet(void);
nsresult SetPrefLinkRules(void); nsresult SetPrefLinkRules(void);
nsresult SetPrefFocusRules(void); nsresult SetPrefFocusRules(void);
nsresult SetPrefNoScriptRule();
nsresult SetPrefNoFramesRule(void); nsresult SetPrefNoFramesRule(void);
// methods for painting a range to an offscreen buffer // methods for painting a range to an offscreen buffer

View File

@ -10,6 +10,7 @@ toolkit.jar:
res/plaintext.css (plaintext.css) res/plaintext.css (plaintext.css)
res/viewsource.css (viewsource.css) res/viewsource.css (viewsource.css)
res/counterstyles.css (counterstyles.css) res/counterstyles.css (counterstyles.css)
res/noscript.css (noscript.css)
* res/forms.css (forms.css) * res/forms.css (forms.css)
res/number-control.css (number-control.css) res/number-control.css (number-control.css)
res/arrow.gif (arrow.gif) res/arrow.gif (arrow.gif)

View File

@ -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;
}

View File

@ -192,6 +192,19 @@ nsLayoutStylesheetCache::CounterStylesSheet()
return gStyleCache->mCounterStylesSheet; return gStyleCache->mCounterStylesSheet;
} }
CSSStyleSheet*
nsLayoutStylesheetCache::NoScriptSheet()
{
EnsureGlobal();
if (!gStyleCache->mNoScriptSheet) {
LoadSheetURL("resource://gre-resources/noscript.css",
gStyleCache->mNoScriptSheet, true);
}
return gStyleCache->mNoScriptSheet;
}
void void
nsLayoutStylesheetCache::Shutdown() nsLayoutStylesheetCache::Shutdown()
{ {
@ -225,6 +238,7 @@ nsLayoutStylesheetCache::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
MEASURE(mHTMLSheet); MEASURE(mHTMLSheet);
MEASURE(mMathMLSheet); MEASURE(mMathMLSheet);
MEASURE(mMinimalXULSheet); MEASURE(mMinimalXULSheet);
MEASURE(mNoScriptSheet);
MEASURE(mNumberControlSheet); MEASURE(mNumberControlSheet);
MEASURE(mQuirkSheet); MEASURE(mQuirkSheet);
MEASURE(mSVGSheet); MEASURE(mSVGSheet);

View File

@ -48,6 +48,7 @@ class nsLayoutStylesheetCache final
static mozilla::CSSStyleSheet* SVGSheet(); static mozilla::CSSStyleSheet* SVGSheet();
static mozilla::CSSStyleSheet* MathMLSheet(); static mozilla::CSSStyleSheet* MathMLSheet();
static mozilla::CSSStyleSheet* CounterStylesSheet(); static mozilla::CSSStyleSheet* CounterStylesSheet();
static mozilla::CSSStyleSheet* NoScriptSheet();
static void Shutdown(); static void Shutdown();
@ -78,6 +79,7 @@ private:
nsRefPtr<mozilla::CSSStyleSheet> mHTMLSheet; nsRefPtr<mozilla::CSSStyleSheet> mHTMLSheet;
nsRefPtr<mozilla::CSSStyleSheet> mMathMLSheet; nsRefPtr<mozilla::CSSStyleSheet> mMathMLSheet;
nsRefPtr<mozilla::CSSStyleSheet> mMinimalXULSheet; nsRefPtr<mozilla::CSSStyleSheet> mMinimalXULSheet;
nsRefPtr<mozilla::CSSStyleSheet> mNoScriptSheet;
nsRefPtr<mozilla::CSSStyleSheet> mNumberControlSheet; nsRefPtr<mozilla::CSSStyleSheet> mNumberControlSheet;
nsRefPtr<mozilla::CSSStyleSheet> mQuirkSheet; nsRefPtr<mozilla::CSSStyleSheet> mQuirkSheet;
nsRefPtr<mozilla::CSSStyleSheet> mSVGSheet; nsRefPtr<mozilla::CSSStyleSheet> mSVGSheet;