Bug 1169514 - Part 2: Move noframes rules from the preferences style sheet to a cached UA style sheet. r=jwatt
authorCameron McCormack <cam@mcc.id.au>
Tue, 16 Jun 2015 11:34:47 +1000
changeset 267108 fca18f7bf521de38df05680ea36663836dc3413d
parent 267107 44e4a6479eb15ea2e28dc81c7a63d61ca4720f59
child 267109 8f69f20370b7adbfc2ec2c608711369c36b6e3e5
push idunknown
push userunknown
push dateunknown
reviewersjwatt
bugs1169514
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1169514 - Part 2: Move noframes rules from the preferences style sheet to a cached UA style sheet. r=jwatt
dom/svg/SVGDocument.cpp
layout/base/nsDocumentViewer.cpp
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
layout/base/nsPresShell.cpp
layout/base/nsPresShell.h
layout/style/jar.mn
layout/style/noframes.css
layout/style/nsLayoutStylesheetCache.cpp
layout/style/nsLayoutStylesheetCache.h
--- a/dom/svg/SVGDocument.cpp
+++ b/dom/svg/SVGDocument.cpp
@@ -162,16 +162,19 @@ SVGDocument::EnsureNonSVGUserAgentStyleS
   CSSStyleSheet* sheet = nsLayoutStylesheetCache::NumberControlSheet();
   if (sheet) {
     // number-control.css can be behind a pref
     EnsureOnDemandBuiltInUASheet(sheet);
   }
   EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::FormsSheet());
   EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::CounterStylesSheet());
   EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::HTMLSheet());
+  if (nsLayoutUtils::ShouldUseNoFramesSheet(this)) {
+    EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoFramesSheet());
+  }
   if (nsLayoutUtils::ShouldUseNoScriptSheet(this)) {
     EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::NoScriptSheet());
   }
   EnsureOnDemandBuiltInUASheet(nsLayoutStylesheetCache::UASheet());
 
   EndUpdate(UPDATE_STYLE);
 }
 
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -2336,16 +2336,23 @@ nsDocumentViewer::CreateStyleSet(nsIDocu
 
     if (nsLayoutUtils::ShouldUseNoScriptSheet(aDocument)) {
       sheet = nsLayoutStylesheetCache::NoScriptSheet();
       if (sheet) {
         styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
       }
     }
 
+    if (nsLayoutUtils::ShouldUseNoFramesSheet(aDocument)) {
+      sheet = nsLayoutStylesheetCache::NoFramesSheet();
+      if (sheet) {
+        styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
+      }
+    }
+
     sheet = nsLayoutStylesheetCache::HTMLSheet();
     if (sheet) {
       styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet, sheet);
     }
 
     styleSet->PrependStyleSheet(nsStyleSet::eAgentSheet,
                                 nsLayoutStylesheetCache::UASheet());
   } else {
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -8455,8 +8455,19 @@ nsLayoutUtils::ShouldUseNoScriptSheet(ns
 {
   // 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();
 }
+
+/* static */ bool
+nsLayoutUtils::ShouldUseNoFramesSheet(nsIDocument* aDocument)
+{
+  bool allowSubframes = true;
+  nsIDocShell* docShell = aDocument->GetDocShell();
+  if (docShell) {
+    docShell->GetAllowSubframes(&allowSubframes);
+  }
+  return !allowSubframes;
+}
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2668,16 +2668,17 @@ public:
 
   /**
    * Looks in the layer subtree rooted at aLayer for a metrics with scroll id
    * aScrollId. Returns true if such is found.
    */
   static bool ContainsMetricsWithId(const Layer* aLayer, const ViewID& aScrollId);
 
   static bool ShouldUseNoScriptSheet(nsIDocument* aDocument);
+  static bool ShouldUseNoFramesSheet(nsIDocument* aDocument);
 
 private:
   static uint32_t sFontSizeInflationEmPerLine;
   static uint32_t sFontSizeInflationMinTwips;
   static uint32_t sFontSizeInflationLineThreshold;
   static int32_t  sFontSizeInflationMappingIntercept;
   static uint32_t sFontSizeInflationMaxRatio;
   static bool sFontSizeInflationForceEnabled;
--- a/layout/base/nsPresShell.cpp
+++ b/layout/base/nsPresShell.cpp
@@ -1362,19 +1362,16 @@ PresShell::SetPreferenceStyleRules(bool 
     // XXX - when there is both an override and agent pref stylesheet this won't matter,
     //       as the color rules will be overrides and the links rules will be agent
     if (NS_SUCCEEDED(result)) {
       result = SetPrefLinkRules();
     }
     if (NS_SUCCEEDED(result)) {
       result = SetPrefFocusRules();
     }
-    if (NS_SUCCEEDED(result)) {
-      result = SetPrefNoFramesRule();
-    }
 #ifdef DEBUG_attinasi
     printf( "Preference Style Rules set: error=%ld\n", (long)result);
 #endif
 
     // Note that this method never needs to force any calculation; the caller
     // will recalculate style if needed
 
     return result;
@@ -1443,50 +1440,16 @@ PresShell::CreatePreferenceStyleSheet()
   return NS_OK;
 }
 
 // XXX We want these after the @namespace rules.  Does order matter
 // for these rules, or can we call StyleRule::StyleRuleCount()
 // and just "append"?
 static uint32_t sInsertPrefSheetRulesAt = 2;
 
-nsresult PresShell::SetPrefNoFramesRule(void)
-{
-  NS_ASSERTION(mPresContext,"null prescontext not allowed");
-  if (!mPresContext) {
-    return NS_ERROR_FAILURE;
-  }
-
-  nsresult rv = NS_OK;
-
-  if (!mPrefStyleSheet) {
-    rv = CreatePreferenceStyleSheet();
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-
-  NS_ASSERTION(mPrefStyleSheet, "prefstylesheet should not be null");
-
-  bool allowSubframes = true;
-  nsCOMPtr<nsIDocShell> docShell(mPresContext->GetDocShell());
-  if (docShell) {
-    docShell->GetAllowSubframes(&allowSubframes);
-  }
-  if (!allowSubframes) {
-    uint32_t index = 0;
-    rv = mPrefStyleSheet->
-      InsertRuleInternal(NS_LITERAL_STRING("noframes{display:block}"),
-                         sInsertPrefSheetRulesAt, &index);
-    NS_ENSURE_SUCCESS(rv, rv);
-    rv = mPrefStyleSheet->
-      InsertRuleInternal(NS_LITERAL_STRING("frame, frameset, iframe {display:none!important}"),
-                         sInsertPrefSheetRulesAt, &index);
-  }
-  return rv;
-}
-
 nsresult PresShell::SetPrefLinkRules(void)
 {
   NS_ASSERTION(mPresContext,"null prescontext not allowed");
   if (!mPresContext) {
     return NS_ERROR_FAILURE;
   }
 
   nsresult rv = NS_OK;
--- a/layout/base/nsPresShell.h
+++ b/layout/base/nsPresShell.h
@@ -517,17 +517,16 @@ protected:
     /**
     * methods that manage rules that are used to implement the associated preferences
     *  - initially created for bugs 31816, 20760, 22963
     */
   nsresult ClearPreferenceStyleRules(void);
   nsresult CreatePreferenceStyleSheet(void);
   nsresult SetPrefLinkRules(void);
   nsresult SetPrefFocusRules(void);
-  nsresult SetPrefNoFramesRule(void);
 
   // methods for painting a range to an offscreen buffer
 
   // given a display list, clip the items within the list to
   // the range
   nsRect ClipListToRange(nsDisplayListBuilder *aBuilder,
                          nsDisplayList* aList,
                          nsRange* aRange);
--- a/layout/style/jar.mn
+++ b/layout/style/jar.mn
@@ -6,14 +6,15 @@ toolkit.jar:
 *  res/ua.css    (ua.css)
    res/html.css    (html.css)
    res/quirk.css    (quirk.css)
    res/full-screen-override.css    (full-screen-override.css)
    res/plaintext.css     (plaintext.css)
    res/viewsource.css    (viewsource.css)
    res/counterstyles.css (counterstyles.css)
    res/noscript.css (noscript.css)
+   res/noframes.css (noframes.css)
 *  res/forms.css    (forms.css)
    res/number-control.css    (number-control.css)
    res/arrow.gif    (arrow.gif)
    res/arrowd.gif   (arrowd.gif)
 
 % resource gre-resources %res/
new file mode 100644
--- /dev/null
+++ b/layout/style/noframes.css
@@ -0,0 +1,13 @@
+/* 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 frames disabled */
+
+noframes {
+  display: block;
+}
+
+frame, frameset, iframe {
+  display: none !important;
+}
--- a/layout/style/nsLayoutStylesheetCache.cpp
+++ b/layout/style/nsLayoutStylesheetCache.cpp
@@ -200,16 +200,29 @@ nsLayoutStylesheetCache::NoScriptSheet()
   if (!gStyleCache->mNoScriptSheet) {
     LoadSheetURL("resource://gre-resources/noscript.css",
                  gStyleCache->mNoScriptSheet, true);
   }
 
   return gStyleCache->mNoScriptSheet;
 }
 
+CSSStyleSheet*
+nsLayoutStylesheetCache::NoFramesSheet()
+{
+  EnsureGlobal();
+
+  if (!gStyleCache->mNoFramesSheet) {
+    LoadSheetURL("resource://gre-resources/noframes.css",
+                 gStyleCache->mNoFramesSheet, true);
+  }
+
+  return gStyleCache->mNoFramesSheet;
+}
+
 void
 nsLayoutStylesheetCache::Shutdown()
 {
   NS_IF_RELEASE(gCSSLoader);
   gStyleCache = nullptr;
 }
 
 MOZ_DEFINE_MALLOC_SIZE_OF(LayoutStylesheetCacheMallocSizeOf)
@@ -233,16 +246,17 @@ nsLayoutStylesheetCache::SizeOfIncluding
   #define MEASURE(s) n += s ? s->SizeOfIncludingThis(aMallocSizeOf) : 0;
 
   MEASURE(mCounterStylesSheet);
   MEASURE(mFormsSheet);
   MEASURE(mFullScreenOverrideSheet);
   MEASURE(mHTMLSheet);
   MEASURE(mMathMLSheet);
   MEASURE(mMinimalXULSheet);
+  MEASURE(mNoFramesSheet);
   MEASURE(mNoScriptSheet);
   MEASURE(mNumberControlSheet);
   MEASURE(mQuirkSheet);
   MEASURE(mSVGSheet);
   MEASURE(mScrollbarsSheet);
   MEASURE(mUASheet);
   MEASURE(mUserChromeSheet);
   MEASURE(mUserContentSheet);
--- a/layout/style/nsLayoutStylesheetCache.h
+++ b/layout/style/nsLayoutStylesheetCache.h
@@ -44,16 +44,17 @@ class nsLayoutStylesheetCache final
   static mozilla::CSSStyleSheet* MinimalXULSheet();
   static mozilla::CSSStyleSheet* XULSheet();
   static mozilla::CSSStyleSheet* QuirkSheet();
   static mozilla::CSSStyleSheet* FullScreenOverrideSheet();
   static mozilla::CSSStyleSheet* SVGSheet();
   static mozilla::CSSStyleSheet* MathMLSheet();
   static mozilla::CSSStyleSheet* CounterStylesSheet();
   static mozilla::CSSStyleSheet* NoScriptSheet();
+  static mozilla::CSSStyleSheet* NoFramesSheet();
 
   static void Shutdown();
 
   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
 private:
   nsLayoutStylesheetCache();
   ~nsLayoutStylesheetCache();
@@ -74,16 +75,17 @@ private:
   static mozilla::StaticRefPtr<nsLayoutStylesheetCache> gStyleCache;
   static mozilla::css::Loader* gCSSLoader;
   nsRefPtr<mozilla::CSSStyleSheet> mCounterStylesSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mFormsSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mFullScreenOverrideSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mHTMLSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mMathMLSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mMinimalXULSheet;
+  nsRefPtr<mozilla::CSSStyleSheet> mNoFramesSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mNoScriptSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mNumberControlSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mQuirkSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mSVGSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mScrollbarsSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mUASheet;
   nsRefPtr<mozilla::CSSStyleSheet> mUserChromeSheet;
   nsRefPtr<mozilla::CSSStyleSheet> mUserContentSheet;