WebCore:
authorantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Sep 2007 14:55:11 +0000 (14:55 +0000)
committerantti <antti@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 10 Sep 2007 14:55:11 +0000 (14:55 +0000)
        Reviewed by Kevin.

        Fix <rdar://problem/5444866>
        REGRESSION: missing text in Acrobat "Getting Started" screen due to change in load ordering of large resources

        Make external scripts loaded using file: wait until all style sheet loads have completed before executing.
        Fixes a class of problems where there is a dependency between script and stylesheet and results would effectively
        get randomized based on which order the resources arrived. In Tiger file loads were effectively serialized by
        lower level components, which is why this regressed.

        Test: http/tests/local/stylesheet-and-script-load-order.html

        * dom/Document.cpp:
        (WebCore::Document::removePendingSheet):
        * dom/Tokenizer.h:
        (WebCore::Tokenizer::executeScriptsWaitingForStylesheets):
        * html/HTMLTokenizer.cpp:
        (WebCore::HTMLTokenizer::HTMLTokenizer):
        (WebCore::HTMLTokenizer::begin):
        (WebCore::HTMLTokenizer::executeScriptsWaitingForStylesheets):
        (WebCore::HTMLTokenizer::notifyFinished):
        * html/HTMLTokenizer.h:

LayoutTests:

        Reviewed by Kevin.

        Test for <rdar://problem/5444866>
        REGRESSION: missing text in Acrobat "Getting Started" screen due to change in load ordering of large resources

        * http/tests/local/stylesheet-and-script-load-order-expected.txt: Added.
        * http/tests/local/stylesheet-and-script-load-order.html: Added.
        * http/tests/local/stylesheet-dependent.js: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@25466 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/local/stylesheet-and-script-load-order-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/local/stylesheet-and-script-load-order.html [new file with mode: 0644]
LayoutTests/http/tests/local/stylesheet-dependent.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/dom/Document.cpp
WebCore/dom/Tokenizer.h
WebCore/html/HTMLTokenizer.cpp
WebCore/html/HTMLTokenizer.h

index 93e70d891e26e7f79371de9d635e4f0deba89ef7..e3ba6449c69d6cb8b7c74e053baeb111b45db751 100644 (file)
@@ -1,3 +1,14 @@
+2007-09-10  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Kevin.
+        
+        Test for <rdar://problem/5444866>
+        REGRESSION: missing text in Acrobat "Getting Started" screen due to change in load ordering of large resources
+
+        * http/tests/local/stylesheet-and-script-load-order-expected.txt: Added.
+        * http/tests/local/stylesheet-and-script-load-order.html: Added.
+        * http/tests/local/stylesheet-dependent.js: Added.
+
 2007-09-09  Sam Weinig  <sam@webkit.org>
 
         Disable more occasionally failing tests.
diff --git a/LayoutTests/http/tests/local/stylesheet-and-script-load-order-expected.txt b/LayoutTests/http/tests/local/stylesheet-and-script-load-order-expected.txt
new file mode 100644 (file)
index 0000000..953f9c9
--- /dev/null
@@ -0,0 +1,3 @@
+Test that stylesheet loads complete before external scripts are executed.
+
+PASS
diff --git a/LayoutTests/http/tests/local/stylesheet-and-script-load-order.html b/LayoutTests/http/tests/local/stylesheet-and-script-load-order.html
new file mode 100644 (file)
index 0000000..3c720c9
--- /dev/null
@@ -0,0 +1,13 @@
+<html>
+<head>
+    <script>  
+        if (window.layoutTestController)
+            layoutTestController.dumpAsText();
+    </script>
+    <link rel=stylesheet href="http://127.0.0.1:8000/local/slow-css-pass.cgi">
+</head>
+<body>
+    <p>Test that stylesheet loads complete before external scripts are executed.</p>
+    <script src=stylesheet-dependent.js></script>
+</body>
+</html>
diff --git a/LayoutTests/http/tests/local/stylesheet-dependent.js b/LayoutTests/http/tests/local/stylesheet-dependent.js
new file mode 100644 (file)
index 0000000..4e5d9b6
--- /dev/null
@@ -0,0 +1 @@
+document.write(document.styleSheets[0] ? "PASS" : "FAIL");
index 22f962f9f2a030a9ebacef831103fabb582318db..99e47577ddffff1b11828ad14f33db10a4cc84bd 100644 (file)
@@ -1,3 +1,28 @@
+2007-09-10  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Kevin.
+
+        Fix <rdar://problem/5444866>
+        REGRESSION: missing text in Acrobat "Getting Started" screen due to change in load ordering of large resources
+        
+        Make external scripts loaded using file: wait until all style sheet loads have completed before executing. 
+        Fixes a class of problems where there is a dependency between script and stylesheet and results would effectively 
+        get randomized based on which order the resources arrived. In Tiger file loads were effectively serialized by
+        lower level components, which is why this regressed. 
+
+        Test: http/tests/local/stylesheet-and-script-load-order.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::removePendingSheet):
+        * dom/Tokenizer.h:
+        (WebCore::Tokenizer::executeScriptsWaitingForStylesheets):
+        * html/HTMLTokenizer.cpp:
+        (WebCore::HTMLTokenizer::HTMLTokenizer):
+        (WebCore::HTMLTokenizer::begin):
+        (WebCore::HTMLTokenizer::executeScriptsWaitingForStylesheets):
+        (WebCore::HTMLTokenizer::notifyFinished):
+        * html/HTMLTokenizer.h:
+
 2007-09-08  David Smith  <catfish.man@gmail.com>
 
         Reviewed by Maciej Stachowiak.
index 54dd569942812092f38f97e81a2456fb7c0931f3..570c5c2c8b4cc9c8ab6459df71acf71f75c06bae 100644 (file)
@@ -1950,6 +1950,9 @@ void Document::removePendingSheet()
 #endif
 
     updateStyleSelector();
+    
+    if (!m_pendingStylesheets && m_tokenizer)
+        m_tokenizer->executeScriptsWaitingForStylesheets();
 
     if (!m_pendingStylesheets && m_gotoAnchorNeededAfterStylesheetsLoad && m_frame)
         m_frame->loader()->gotoAnchor();
index d9bf69844883301c9869ed79896f31d922cf80ea..68cb847b9c2fb8627270b1756b4b9ce057a5db33 100644 (file)
@@ -60,6 +60,8 @@ namespace WebCore {
 
         virtual int lineNumber() const { return -1; }
         virtual int columnNumber() const { return -1; }
+        
+        virtual void executeScriptsWaitingForStylesheets() {}
 
     protected:
         // The tokenizer has buffers, so parsing may continue even after
index 3b4b6a8db90ff56844b166cdbbc27238a55261af..797cf4c8145eb4fc3cd4e1ab7b5dba5c4902abaa 100644 (file)
@@ -151,6 +151,7 @@ HTMLTokenizer::HTMLTokenizer(HTMLDocument* doc, bool reportErrors)
     , scriptCodeResync(0)
     , m_executingScript(0)
     , m_requestingScript(false)
+    , m_hasScriptsWaitingForStylesheets(false)
     , m_timer(this, &HTMLTokenizer::timerFired)
     , m_doc(doc)
     , parser(new HTMLParser(doc, reportErrors))
@@ -169,6 +170,7 @@ HTMLTokenizer::HTMLTokenizer(HTMLViewSourceDocument* doc)
     , scriptCodeResync(0)
     , m_executingScript(0)
     , m_requestingScript(false)
+    , m_hasScriptsWaitingForStylesheets(false)
     , m_timer(this, &HTMLTokenizer::timerFired)
     , m_doc(doc)
     , parser(0)
@@ -186,6 +188,7 @@ HTMLTokenizer::HTMLTokenizer(DocumentFragment* frag)
     , scriptCodeResync(0)
     , m_executingScript(0)
     , m_requestingScript(false)
+    , m_hasScriptsWaitingForStylesheets(false)
     , m_timer(this, &HTMLTokenizer::timerFired)
     , m_doc(frag->document())
     , inWrite(false)
@@ -224,6 +227,7 @@ void HTMLTokenizer::begin()
 {
     m_executingScript = 0;
     m_requestingScript = false;
+    m_hasScriptsWaitingForStylesheets = false;
     m_state.setLoadingExtScript(false);
     reset();
     size = 254;
@@ -1678,6 +1682,14 @@ void HTMLTokenizer::enlargeScriptBuffer(int len)
     scriptCode = static_cast<UChar*>(fastRealloc(scriptCode, newSize * sizeof(UChar)));
     scriptCodeMaxSize = newSize;
 }
+    
+void HTMLTokenizer::executeScriptsWaitingForStylesheets()
+{
+    ASSERT(m_doc->haveStylesheetsLoaded());
+
+    if (m_hasScriptsWaitingForStylesheets)
+        notifyFinished(0);
+}
 
 void HTMLTokenizer::notifyFinished(CachedResource*)
 {
@@ -1687,6 +1699,15 @@ void HTMLTokenizer::notifyFinished(CachedResource*)
 #endif
 
     ASSERT(!pendingScripts.isEmpty());
+
+    // Make scripts loaded from file URLs wait for stylesheets to match Tiger behavior where
+    // file loads were serialized in lower level.
+    // FIXME: this should really be done for all script loads or the same effect should be achieved by other
+    // means, like javascript suspend/resume
+    m_hasScriptsWaitingForStylesheets = !m_doc->haveStylesheetsLoaded() && pendingScripts.head()->url().startsWith("file:", false);
+    if (m_hasScriptsWaitingForStylesheets)
+        return;
+
     bool finished = false;
     while (!finished && pendingScripts.head()->isLoaded()) {
 #ifdef TOKEN_DEBUG
index 70ce8be5d000e6fcc228425c5392aa0de246d14f..f38fca17e5065672e6e3646188c2a8f72fd34c50 100644 (file)
@@ -106,6 +106,8 @@ public:
     int* lineNumberPtr() { return &lineno; }
 
     bool processingContentWrittenByScript() const { return src.excludeLineNumbers(); }
+    
+    virtual void executeScriptsWaitingForStylesheets();
 
 private:
     class State;
@@ -322,6 +324,7 @@ private:
     RefPtr<Node> scriptNode;
 
     bool m_requestingScript;
+    bool m_hasScriptsWaitingForStylesheets;
 
     // if we found one broken comment, there are most likely others as well
     // store a flag to get rid of the O(n^2) behaviour in such a case.