Bug 1325878: Use dom::MediaList in the CSS Loader. r=xidorn
authorEmilio Cobos Álvarez <emilio@crisal.io>
Mon, 10 Apr 2017 10:38:42 +0800
changeset 352725 80f9f184eb4058ee8fbe922cb1d62409dc52062d
parent 352724 73bc24a5bf253c0b268c32c13eec5315d44ea855
child 352726 2ea02e45d8fd7aab5bccebb5ea0b15d38ad54139
push id89122
push userkwierso@gmail.com
push dateThu, 13 Apr 2017 01:24:36 +0000
treeherdermozilla-inbound@b31c8835bfc3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1325878
milestone55.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 1325878: Use dom::MediaList in the CSS Loader. r=xidorn MozReview-Commit-ID: 8KcKYrkk3jI Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
layout/style/Loader.cpp
layout/style/Loader.h
layout/style/MediaList.cpp
layout/style/MediaList.h
--- a/layout/style/Loader.cpp
+++ b/layout/style/Loader.cpp
@@ -48,30 +48,30 @@
 #include "nsIStyleSheetLinkingElement.h"
 #include "nsICSSLoaderObserver.h"
 #include "nsCSSParser.h"
 #include "mozilla/css/ImportRule.h"
 #include "nsThreadUtils.h"
 #include "nsGkAtoms.h"
 #include "nsIThreadInternal.h"
 #include "nsINetworkPredictor.h"
+#include "mozilla/dom/MediaList.h"
 #include "mozilla/dom/ShadowRoot.h"
 #include "mozilla/dom/URL.h"
 #include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/ServoBindings.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/ConsoleReportCollector.h"
 #include "mozilla/ServoUtils.h"
 
 #ifdef MOZ_XUL
 #include "nsXULPrototypeCache.h"
 #endif
 
-#include "nsMediaList.h"
 #include "nsIDOMStyleSheet.h"
 #include "nsError.h"
 
 #include "nsIContentSecurityPolicy.h"
 #include "mozilla/dom/SRICheck.h"
 
 #include "mozilla/dom/EncodingUtils.h"
 using mozilla::dom::EncodingUtils;
@@ -1276,34 +1276,28 @@ Loader::CreateSheet(nsIURI* aURI,
  * PrepareSheet() handles setting the media and title on the sheet, as
  * well as setting the enabled state based on the title and whether
  * the sheet had "alternate" in its rel.
  */
 void
 Loader::PrepareSheet(StyleSheet* aSheet,
                      const nsSubstring& aTitle,
                      const nsSubstring& aMediaString,
-                     nsMediaList* aMediaList,
+                     MediaList* aMediaList,
                      Element* aScopeElement,
                      bool aIsAlternate)
 {
   NS_PRECONDITION(aSheet, "Must have a sheet!");
 
-  RefPtr<nsMediaList> mediaList(aMediaList);
+  RefPtr<MediaList> mediaList(aMediaList);
 
   if (!aMediaString.IsEmpty()) {
     NS_ASSERTION(!aMediaList,
                  "must not provide both aMediaString and aMediaList");
-    mediaList = new nsMediaList();
-
-    nsCSSParser mediumParser(this);
-
-    // We have aMediaString only when linked from link elements, style
-    // elements, or PIs, so pass true.
-    mediumParser.ParseMediaList(aMediaString, nullptr, 0, mediaList);
+    mediaList = MediaList::Create(GetStyleBackendType(), aMediaString);
   }
 
   aSheet->SetMedia(mediaList);
 
   aSheet->SetTitle(aTitle);
   aSheet->SetEnabled(!aIsAlternate);
 
   if (aSheet->IsGecko()) {
@@ -2197,17 +2191,17 @@ HaveAncestorDataWithURI(SheetLoadData *a
   }
 
   return false;
 }
 
 nsresult
 Loader::LoadChildSheet(StyleSheet* aParentSheet,
                        nsIURI* aURL,
-                       nsMediaList* aMedia,
+                       dom::MediaList* aMedia,
                        ImportRule* aGeckoParentRule,
                        const RawServoStyleSheet* aServoChildSheet,
                        LoaderReusableStyleSheets* aReusableSheets)
 {
   LOG(("css::Loader::LoadChildSheet"));
   NS_PRECONDITION(aURL, "Must have a URI to load");
   NS_PRECONDITION(aParentSheet, "Must have a parent sheet");
 
--- a/layout/style/Loader.h
+++ b/layout/style/Loader.h
@@ -26,17 +26,16 @@
 #include "mozilla/StyleBackendType.h"
 #include "mozilla/StyleSheet.h"
 #include "mozilla/net/ReferrerPolicy.h"
 
 class nsICSSLoaderObserver;
 class nsIConsoleReportCollector;
 class nsIContent;
 class nsIDocument;
-class nsMediaList;
 class nsIStyleSheetLinkingElement;
 
 namespace mozilla {
 namespace dom {
 class DocGroup;
 class Element;
 } // namespace dom
 } // namespace mozilla
@@ -295,17 +294,17 @@ public:
    *                         order the child sheet list of aParentSheet.
    * @param aServoChildSheet the child stylesheet of the @import rule, when
    *                         using Servo's style system.
    * @param aSavedSheets any saved style sheets which could be reused
    *              for this load
    */
   nsresult LoadChildSheet(StyleSheet* aParentSheet,
                           nsIURI* aURL,
-                          nsMediaList* aMedia,
+                          dom::MediaList* aMedia,
                           ImportRule* aGeckoParentRule,
                           const RawServoStyleSheet* aServoChildSheet,
                           LoaderReusableStyleSheets* aSavedSheets);
 
   /**
    * Synchronously load and return the stylesheet at aURL.  Any child sheets
    * will also be loaded synchronously.  Note that synchronous loads over some
    * protocols may involve spinning up a new event loop, so use of this method
@@ -498,23 +497,24 @@ private:
                        const nsAString& aIntegrity,
                        bool aSyncLoad,
                        bool aHasAlternateRel,
                        const nsAString& aTitle,
                        StyleSheetState& aSheetState,
                        bool *aIsAlternate,
                        RefPtr<StyleSheet>* aSheet);
 
-  // Pass in either a media string or the nsMediaList from the
-  // CSSParser.  Don't pass both.
+  // Pass in either a media string or the MediaList from the CSSParser.  Don't
+  // pass both.
+  //
   // This method will set the sheet's enabled state based on aIsAlternate
   void PrepareSheet(StyleSheet* aSheet,
                     const nsAString& aTitle,
                     const nsAString& aMediaString,
-                    nsMediaList* aMediaList,
+                    dom::MediaList* aMediaList,
                     dom::Element* aScopeElement,
                     bool aIsAlternate);
 
   nsresult InsertSheetInDoc(StyleSheet* aSheet,
                             nsIContent* aLinkingContent,
                             nsIDocument* aDocument);
 
   nsresult InsertChildSheet(StyleSheet* aSheet,
--- a/layout/style/MediaList.cpp
+++ b/layout/style/MediaList.cpp
@@ -70,17 +70,24 @@ MediaList::DoMediaChange(Func aCallback)
   }
   return rv;
 }
 
 /* static */ already_AddRefed<MediaList>
 MediaList::Create(const nsIDocument& aDocument,
                   const nsAString& aMedia)
 {
-  if (aDocument.IsStyledByServo()) {
+  return Create(aDocument.GetStyleBackendType(), aMedia);
+}
+
+/* static */ already_AddRefed<MediaList>
+MediaList::Create(StyleBackendType aBackendType,
+                  const nsAString& aMedia)
+{
+  if (aBackendType == StyleBackendType::Servo) {
     RefPtr<ServoMediaList> mediaList = new ServoMediaList(aMedia);
     return mediaList.forget();
   }
 
   nsCSSParser parser;
   RefPtr<nsMediaList> mediaList = new nsMediaList();
   parser.ParseMediaList(aMedia, nullptr, 0, mediaList);
   return mediaList.forget();
--- a/layout/style/MediaList.h
+++ b/layout/style/MediaList.h
@@ -6,16 +6,17 @@
 
 /* base class for representation of media lists */
 
 #ifndef mozilla_dom_MediaList_h
 #define mozilla_dom_MediaList_h
 
 #include "mozilla/ErrorResult.h"
 #include "mozilla/ServoUtils.h"
+#include "mozilla/StyleBackendType.h"
 
 #include "nsIDOMMediaList.h"
 #include "nsWrapperCache.h"
 
 class nsIDocument;
 class nsPresContext;
 class nsMediaQueryResultCacheKey;
 
@@ -37,16 +38,22 @@ class MediaList : public nsIDOMMediaList
 {
 public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(MediaList)
 
   /**
    * Creates a MediaList backed by the StyleBackendType of the document.
    */
+  static already_AddRefed<MediaList> Create(StyleBackendType,
+                                            const nsAString& aMedia);
+
+  /**
+   * Creates a MediaList backed by the StyleBackendType of the document.
+   */
   static already_AddRefed<MediaList> Create(const nsIDocument& aDocument,
                                             const nsAString& aMedia);
 
   virtual already_AddRefed<MediaList> Clone() = 0;
 
   JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
   nsISupports* GetParentObject() const { return nullptr; }