Bug 1293252 - Transfer document quirkiness via the speculative load queue. r=wchen a=ritu
authorHenri Sivonen <hsivonen@hsivonen.fi>
Thu, 25 Aug 2016 12:20:58 +0300
changeset 350725 bc14a6826c3200ff5c6342b4005e15879a7d129a
parent 350724 2f3602ef7f015df38f0aed5c6d33864f47762e4f
child 350726 2bcf7a0d6dd030237bb11532a5a9d7be0ecdbcef
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen, ritu
bugs1293252
milestone50.0
Bug 1293252 - Transfer document quirkiness via the speculative load queue. r=wchen a=ritu MozReview-Commit-ID: 4lTbxSSrCf4
parser/html/nsHtml5SpeculativeLoad.cpp
parser/html/nsHtml5SpeculativeLoad.h
parser/html/nsHtml5TreeBuilderCppSupplement.h
--- a/parser/html/nsHtml5SpeculativeLoad.cpp
+++ b/parser/html/nsHtml5SpeculativeLoad.cpp
@@ -38,43 +38,51 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5T
       break;
     case eSpeculativeLoadOpenPicture:
       aExecutor->PreloadOpenPicture();
       break;
     case eSpeculativeLoadEndPicture:
       aExecutor->PreloadEndPicture();
       break;
     case eSpeculativeLoadPictureSource:
-      aExecutor->PreloadPictureSource(mSrcset, mSizes, mTypeOrCharsetSource,
+      aExecutor->PreloadPictureSource(mSrcset, mSizes, mTypeOrCharsetSourceOrDocumentMode,
                                       mMedia);
       break;
     case eSpeculativeLoadScript:
-      aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSource,
+      aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
                                mCrossOrigin, mIntegrity, false);
       break;
     case eSpeculativeLoadScriptFromHead:
-      aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSource,
+      aExecutor->PreloadScript(mUrl, mCharset, mTypeOrCharsetSourceOrDocumentMode,
                                mCrossOrigin, mIntegrity, true);
       break;
     case eSpeculativeLoadStyle:
       aExecutor->PreloadStyle(mUrl, mCharset, mCrossOrigin, mIntegrity);
       break;
     case eSpeculativeLoadManifest:  
       aExecutor->ProcessOfflineManifest(mUrl);
       break;
     case eSpeculativeLoadSetDocumentCharset: {
         nsAutoCString narrowName;
         CopyUTF16toUTF8(mCharset, narrowName);
-        NS_ASSERTION(mTypeOrCharsetSource.Length() == 1,
+        NS_ASSERTION(mTypeOrCharsetSourceOrDocumentMode.Length() == 1,
             "Unexpected charset source string");
-        int32_t intSource = (int32_t)mTypeOrCharsetSource.First();
+        int32_t intSource = (int32_t)mTypeOrCharsetSourceOrDocumentMode.First();
         aExecutor->SetDocumentCharsetAndSource(narrowName,
                                                intSource);
       }
       break;
+    case eSpeculativeLoadSetDocumentMode: {
+        NS_ASSERTION(mTypeOrCharsetSourceOrDocumentMode.Length() == 1,
+            "Unexpected document mode string");
+        nsHtml5DocumentMode mode =
+            (nsHtml5DocumentMode)mTypeOrCharsetSourceOrDocumentMode.First();
+        aExecutor->SetDocumentMode(mode);
+      }
+      break;
     case eSpeculativeLoadPreconnect:
       aExecutor->Preconnect(mUrl, mCrossOrigin);
       break;
     default:
       NS_NOTREACHED("Bogus speculative load.");
       break;
   }
 }
--- a/parser/html/nsHtml5SpeculativeLoad.h
+++ b/parser/html/nsHtml5SpeculativeLoad.h
@@ -21,16 +21,17 @@ enum eHtml5SpeculativeLoad {
   eSpeculativeLoadOpenPicture,
   eSpeculativeLoadEndPicture,
   eSpeculativeLoadPictureSource,
   eSpeculativeLoadScript,
   eSpeculativeLoadScriptFromHead,
   eSpeculativeLoadStyle,
   eSpeculativeLoadManifest,
   eSpeculativeLoadSetDocumentCharset,
+  eSpeculativeLoadSetDocumentMode,
   eSpeculativeLoadPreconnect
 };
 
 class nsHtml5SpeculativeLoad {
   public:
     nsHtml5SpeculativeLoad();
     ~nsHtml5SpeculativeLoad();
 
@@ -101,34 +102,34 @@ class nsHtml5SpeculativeLoad {
                                   const nsAString& aType,
                                   const nsAString& aMedia)
     {
       NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
                       "Trying to reinitialize a speculative load!");
       mOpCode = eSpeculativeLoadPictureSource;
       mSrcset.Assign(aSrcset);
       mSizes.Assign(aSizes);
-      mTypeOrCharsetSource.Assign(aType);
+      mTypeOrCharsetSourceOrDocumentMode.Assign(aType);
       mMedia.Assign(aMedia);
     }
 
     inline void InitScript(const nsAString& aUrl,
                            const nsAString& aCharset,
                            const nsAString& aType,
                            const nsAString& aCrossOrigin,
                            const nsAString& aIntegrity,
                            bool aParserInHead)
     {
       NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
                       "Trying to reinitialize a speculative load!");
       mOpCode = aParserInHead ?
           eSpeculativeLoadScriptFromHead : eSpeculativeLoadScript;
       mUrl.Assign(aUrl);
       mCharset.Assign(aCharset);
-      mTypeOrCharsetSource.Assign(aType);
+      mTypeOrCharsetSourceOrDocumentMode.Assign(aType);
       mCrossOrigin.Assign(aCrossOrigin);
       mIntegrity.Assign(aIntegrity);
     }
 
     inline void InitStyle(const nsAString& aUrl, const nsAString& aCharset,
                           const nsAString& aCrossOrigin,
                           const nsAString& aIntegrity)
     {
@@ -172,17 +173,31 @@ class nsHtml5SpeculativeLoad {
      */
     inline void InitSetDocumentCharset(nsACString& aCharset,
                                        int32_t aCharsetSource)
     {
       NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
                       "Trying to reinitialize a speculative load!");
       mOpCode = eSpeculativeLoadSetDocumentCharset;
       CopyUTF8toUTF16(aCharset, mCharset);
-      mTypeOrCharsetSource.Assign((char16_t)aCharsetSource);
+      mTypeOrCharsetSourceOrDocumentMode.Assign((char16_t)aCharsetSource);
+    }
+
+    /**
+     * Speculative document mode setting isn't really speculative. Once it
+     * happens, we are committed to it. However, this information needs to
+     * travel in the speculation queue in order to have this information
+     * available before parsing the speculatively loaded style sheets.
+     */
+    inline void InitSetDocumentMode(nsHtml5DocumentMode aMode)
+    {
+      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
+                      "Trying to reinitialize a speculative load!");
+      mOpCode = eSpeculativeLoadSetDocumentMode;
+      mTypeOrCharsetSourceOrDocumentMode.Assign((char16_t)aMode);
     }
 
     inline void InitPreconnect(const nsAString& aUrl,
                                const nsAString& aCrossOrigin)
     {
       NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
                       "Trying to reinitialize a speculative load!");
       mOpCode = eSpeculativeLoadPreconnect;
@@ -203,20 +218,23 @@ class nsHtml5SpeculativeLoad {
      * then this is the value of the "charset" attribute. For
      * eSpeculativeLoadSetDocumentCharset it is the charset that the
      * document's charset is being set to. Otherwise it's empty.
      */
     nsString mCharset;
     /**
      * If mOpCode is eSpeculativeLoadSetDocumentCharset, this is a
      * one-character string whose single character's code point is to be
-     * interpreted as a charset source integer. Otherwise, it is empty or
-     * the value of the type attribute.
+     * interpreted as a charset source integer. If mOpCode is
+     * eSpeculativeLoadSetDocumentMode, this is a one-character string whose
+     * single character's code point is to be interpreted as an
+     * nsHtml5DocumentMode. Otherwise, it is empty or the value of the type
+     * attribute.
      */
-    nsString mTypeOrCharsetSource;
+    nsString mTypeOrCharsetSourceOrDocumentMode;
     /**
      * If mOpCode is eSpeculativeLoadImage or eSpeculativeLoadScript[FromHead]
      * or eSpeculativeLoadPreconnect this is the value of the "crossorigin"
      * attribute.  If the attribute is not set, this will be a void string.
      */
     nsString mCrossOrigin;
     /**
      * If mOpCode is eSpeculativeLoadImage or eSpeculativeLoadPictureSource,
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -1218,16 +1218,20 @@ nsHtml5TreeBuilder::StartPlainTextBody()
 // DocumentModeHandler
 void
 nsHtml5TreeBuilder::documentMode(nsHtml5DocumentMode m)
 {
   if (mBuilder) {
     mBuilder->SetDocumentMode(m);
     return;
   }
+  if (mSpeculativeLoadStage) {
+    mSpeculativeLoadQueue.AppendElement()->InitSetDocumentMode(m);
+    return;
+  }
   nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
   NS_ASSERTION(treeOp, "Tree op allocation failed.");
   treeOp->Init(m);
 }
 
 nsIContentHandle*
 nsHtml5TreeBuilder::getDocumentFragmentForTemplate(nsIContentHandle* aTemplate)
 {