Backing out changeset b47f0de93a82 (bug 457809) due to test failures
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 24 Mar 2009 19:18:25 -0400
changeset 26575 bfea2685b2df23edf92929effa8b3221d6071998
parent 26574 526a987a3b1ee9ceb109bd785f4a16d9a2ccab1e
child 26576 593d36f8c437bc5c1948be05740d0607e1a51eca
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs457809
milestone1.9.2a1pre
Backing out changeset b47f0de93a82 (bug 457809) due to test failures
content/base/public/nsIDocument.h
content/base/src/nsDocument.cpp
parser/htmlparser/src/nsParser.cpp
--- a/content/base/public/nsIDocument.h
+++ b/content/base/public/nsIDocument.h
@@ -1126,23 +1126,16 @@ public:
   virtual void UnsuppressEventHandlingAndFireEvents(PRBool aFireEvents) = 0;
 
   void UnsuppressEventHandling()
   {
     UnsuppressEventHandlingAndFireEvents(PR_TRUE);
   }
 
   PRUint32 EventHandlingSuppressed() { return mEventsSuppressed; }
-  
-  /**
-   * Called by nsParser to preload images. Can be removed and code moved
-   * to nsPreloadURIs::PreloadURIs() in file nsParser.cpp whenever the
-   * parser-module is linked with gklayout-module.
-   */
-  virtual void PreLoadImage(nsIURI* uri);
 protected:
   ~nsIDocument()
   {
     // XXX The cleanup of mNodeInfoManager (calling DropDocumentReference and
     //     releasing it) happens in the nsDocument destructor. We'd prefer to
     //     do it here but nsNodeInfoManager is a concrete class that we don't
     //     want to expose to users of the nsIDocument API outside of Gecko.
   }
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -163,17 +163,16 @@ static NS_DEFINE_CID(kDOMEventGroupCID, 
 #include "nsIContentViewer.h"
 #include "nsIXMLContentSink.h"
 #include "nsContentErrors.h"
 #include "nsIXULDocument.h"
 #include "nsIPrompt.h"
 #include "nsIPropertyBag2.h"
 
 #include "nsFrameLoader.h"
-#include "imgIRequest.h"
 
 #include "mozAutoDocUpdate.h"
 
 #ifdef MOZ_SMIL
 #include "nsSMILAnimationController.h"
 #include "imgIContainer.h"
 #include "nsSVGUtils.h"
 #endif // MOZ_SMIL
@@ -7513,20 +7512,8 @@ nsDocument::UnsuppressEventHandlingAndFi
       nsCOMPtr<nsIPresShell> shell;
       while ((shell = iter.GetNextShell())) {
         shell->FireOrClearDelayedEvents(aFireEvents);
       }
     }
   }
 }
 
-void
-nsIDocument::PreLoadImage(nsIURI* uri)
-{
-  nsCOMPtr<imgIRequest> request;
-  nsContentUtils::LoadImage(uri,
-                            this,
-                            NodePrincipal(),
-                            GetDocumentURI(), // should be ok for referrer
-                            nsnull, // no observer
-                            nsIRequest::LOAD_NORMAL,
-                            getter_AddRefs(request));
-}
--- a/parser/htmlparser/src/nsParser.cpp
+++ b/parser/htmlparser/src/nsParser.cpp
@@ -66,19 +66,16 @@
 #include "nsStreamUtils.h"
 #include "nsHTMLTokenizer.h"
 #include "nsIDocument.h"
 #include "nsNetUtil.h"
 #include "nsScriptLoader.h"
 #include "nsDataHashtable.h"
 #include "nsIThreadPool.h"
 #include "nsXPCOMCIDInternal.h"
-#include "nsICSSStyleSheet.h"
-#include "nsICSSLoaderObserver.h"
-#include "nsICSSLoader.h"
 
 #ifdef MOZ_VIEW_SOURCE
 #include "nsViewSourceHTML.h"
 #endif
 
 #define NS_PARSER_FLAG_PARSER_ENABLED         0x00000002
 #define NS_PARSER_FLAG_OBSERVERS_ENABLED      0x00000004
 #define NS_PARSER_FLAG_PENDING_CONTINUE_EVENT 0x00000008
@@ -219,17 +216,17 @@ public:
   }
 
   NS_DECL_ISUPPORTS
   NS_DECL_NSIRUNNABLE
 
   nsresult StartParsing(nsParser *aParser);
   void StopParsing(PRBool aFromDocWrite);
 
-  enum PrefetchType { NONE, SCRIPT, STYLESHEET, IMAGE };
+  enum PrefetchType { SCRIPT, STYLESHEET, IMAGE };
   struct PrefetchEntry {
     PrefetchType type;
     nsString uri;
     nsString charset;
     nsString elementType;
   };
 
   nsIDocument *GetDocument() {
@@ -289,31 +286,16 @@ private:
 
   // These members are only accessed on the main thread.
   nsCOMPtr<nsIDocument> mDocument;
   CParserContext *mContext;
   PreloadedType mPreloadedURIs;
   PRBool mTerminated;
 };
 
-/**
- * Used if we need to pass an nsICSSLoaderObserver as parameter,
- * but don't really need it's services
- */
-class nsDummyCSSLoaderObserver : public nsICSSLoaderObserver {
-public:
-  NS_IMETHOD
-  StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate, nsresult aStatus) {
-      return NS_OK;
-  }
-  NS_DECL_ISUPPORTS
-};
-
-NS_IMPL_ISUPPORTS1(nsDummyCSSLoaderObserver, nsICSSLoaderObserver)
-
 class nsPreloadURIs : public nsIRunnable {
 public:
   nsPreloadURIs(nsAutoTArray<nsSpeculativeScriptThread::PrefetchEntry, 5> &aURIs,
                 nsSpeculativeScriptThread *aScriptThread)
     : mURIs(aURIs),
       mScriptThread(aScriptThread) {
   }
 
@@ -356,16 +338,20 @@ nsPreloadURIs::PreloadURIs(const nsAutoT
   // the URIs using the document's base URI at the potential cost of being
   // wrong and having to re-load a given relative URI later.
   nsIURI *base = doc->GetBaseURI();
   const nsCString &charset = doc->GetDocumentCharacterSet();
   nsSpeculativeScriptThread::PreloadedType &alreadyPreloaded =
     aScriptThread->GetPreloadedURIs();
   for (PRUint32 i = 0, e = aURIs.Length(); i < e; ++i) {
     const nsSpeculativeScriptThread::PrefetchEntry &pe = aURIs[i];
+    if (pe.type != nsSpeculativeScriptThread::SCRIPT) {
+      continue;
+    }
+
     nsCOMPtr<nsIURI> uri;
     nsresult rv = NS_NewURI(getter_AddRefs(uri), pe.uri, charset.get(), base);
     if (NS_FAILED(rv)) {
       NS_WARNING("Failed to create a URI");
       continue;
     }
 
     nsCAutoString spec;
@@ -373,29 +359,17 @@ nsPreloadURIs::PreloadURIs(const nsAutoT
     PRBool answer;
     if (alreadyPreloaded.Get(spec, &answer)) {
       // Already preloaded. Don't preload again.
       continue;
     }
 
     alreadyPreloaded.Put(spec, PR_TRUE);
 
-    nsCAutoString aReferrer;
-    switch(pe.type) {
-      case nsSpeculativeScriptThread::SCRIPT:
-        doc->ScriptLoader()->PreloadURI(uri, pe.charset, pe.elementType);
-        break; 
-      case nsSpeculativeScriptThread::IMAGE:
-        doc->PreLoadImage(uri);
-        break;
-      case nsSpeculativeScriptThread::STYLESHEET:
-        nsCOMPtr<nsICSSLoaderObserver> obs = new nsDummyCSSLoaderObserver();
-        doc->CSSLoader()->LoadSheet(uri, doc->NodePrincipal(), obs);
-        break;
-    }
+    doc->ScriptLoader()->PreloadURI(uri, pe.charset, pe.elementType);
   }
 }
 
 NS_IMPL_THREADSAFE_ISUPPORTS1(nsSpeculativeScriptThread, nsIRunnable)
 
 NS_IMETHODIMP
 nsSpeculativeScriptThread::Run()
 {
@@ -574,84 +548,99 @@ nsSpeculativeScriptThread::ProcessToken(
     case eToken_start: {
         CStartToken *start = static_cast<CStartToken *>(aToken);
         nsHTMLTag tag = static_cast<nsHTMLTag>(start->GetTypeID());
         PRInt16 attrs = start->GetAttributeCount();
         PRInt16 i = 0;
         nsAutoString src;
         nsAutoString elementType;
         nsAutoString charset;
-        PrefetchType ptype = NONE;
+        PrefetchType ptype = SCRIPT;
 
         switch (tag) {
-          case eHTMLTag_link:
-              ptype = STYLESHEET;
-              break;
-
-          case eHTMLTag_img:
-              ptype = IMAGE;
-              break;
-
-          case eHTMLTag_script:
-              ptype = SCRIPT;
-              break;
-
-          default:
-              break;
-        }
-
-        // We currently handle the following element/attribute combos :
-        //     <link rel="stylesheet" href= charset= type>
-        //     <img src= >
-        //     <script src= charset= type=>
-        if (ptype != NONE) {
-            // Extract attributes
+#if 0 // TODO Support stylesheet and image preloading.
+          case eHTMLTag_link: {
+            // If this is a <link rel=stylesheet> find the src.
+            PRBool isRelStylesheet = PR_FALSE;
             for (; i < attrs; ++i) {
               CAttributeToken *attr = static_cast<CAttributeToken *>(mTokenizer->PopToken());
               NS_ASSERTION(attr->GetTokenType() == eToken_attribute, "Weird token");
-    
-              if (ptype == STYLESHEET && attr->GetKey().EqualsLiteral("rel")) {
-                // early break from loop if this is not a stylesheet
+
+              if (attr->GetKey().EqualsLiteral("rel")) {
                 if (!attr->GetValue().EqualsLiteral("stylesheet")) {
-                  ptype = NONE;
+                  IF_FREE(attr, &mTokenAllocator);
+                  break;
+                }
+                isRelStylesheet = PR_TRUE;
+              } else if (attr->GetKey().EqualsLiteral("src")) {
+                src.Assign(attr->GetValue());
+                if (isRelStylesheet) {
                   IF_FREE(attr, &mTokenAllocator);
                   break;
                 }
-              } else if (ptype == STYLESHEET && attr->GetKey().EqualsLiteral("href")) {
-                src.Assign(attr->GetValue());
-              } else if (ptype != STYLESHEET && attr->GetKey().EqualsLiteral("src")) {
+              }
+
+              IF_FREE(attr, &mTokenAllocator);
+            }
+
+            if (isRelStylesheet && !src.IsEmpty()) {
+              AddToPrefetchList(src, STYLESHEET);
+            }
+            break;
+          }
+
+          case eHTMLTag_style:
+            ptype = STYLESHEET;
+            /* FALL THROUGH */
+          case eHTMLTag_img:
+            if (tag == eHTMLTag_img)
+              ptype = IMAGE;
+            /* FALL THROUGH */
+#endif
+          case eHTMLTag_script:
+            if (tag == eHTMLTag_script)
+              ptype = SCRIPT;
+
+            for (; i < attrs; ++i) {
+              CAttributeToken *attr = static_cast<CAttributeToken *>(mTokenizer->PopToken());
+              NS_ASSERTION(attr->GetTokenType() == eToken_attribute, "Weird token");
+
+              if (attr->GetKey().EqualsLiteral("src")) {
                 src.Assign(attr->GetValue());
               } else if (attr->GetKey().EqualsLiteral("charset")) {
                 charset.Assign(attr->GetValue());
               } else if (attr->GetKey().EqualsLiteral("type")) {
                 elementType.Assign(attr->GetValue());
               }
               IF_FREE(attr, &mTokenAllocator);
             }
 
-            // Add to list if we found the src
             if (!src.IsEmpty()) {
               AddToPrefetchList(src, charset, elementType, ptype);
             }
+            break;
+
+          default:
+            break;
         }
 
         for (; i < attrs; ++i) {
           CToken *attr = mTokenizer->PopToken();
           if (!attr) {
             break;
           }
           NS_ASSERTION(attr->GetTokenType() == eToken_attribute, "Weird token");
           IF_FREE(attr, &mTokenAllocator);
         }
 
         break;
       }
 
-      default:
-        break;
+    default:
+      break;
   }
 
   IF_FREE(aToken, &mTokenAllocator);
 }
 
 void
 nsSpeculativeScriptThread::AddToPrefetchList(const nsAString &src,
                                       const nsAString &charset,