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
Родитель 06282b2f7c
Коммит 5492e00444
10 изменённых файлов: 49 добавлений и 32 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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");

Просмотреть файл

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

Просмотреть файл

@ -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)

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -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<mozilla::CSSStyleSheet> mHTMLSheet;
nsRefPtr<mozilla::CSSStyleSheet> mMathMLSheet;
nsRefPtr<mozilla::CSSStyleSheet> mMinimalXULSheet;
nsRefPtr<mozilla::CSSStyleSheet> mNoScriptSheet;
nsRefPtr<mozilla::CSSStyleSheet> mNumberControlSheet;
nsRefPtr<mozilla::CSSStyleSheet> mQuirkSheet;
nsRefPtr<mozilla::CSSStyleSheet> mSVGSheet;