From 4e908e2276a9e74e6e9df0c5950048d11af1e2c3 Mon Sep 17 00:00:00 2001 From: antti Date: Mon, 10 Sep 2007 14:55:11 +0000 Subject: [PATCH] WebCore: Reviewed by Kevin. Fix 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 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 | 11 ++++++++ ...lesheet-and-script-load-order-expected.txt | 3 +++ .../stylesheet-and-script-load-order.html | 13 ++++++++++ .../http/tests/local/stylesheet-dependent.js | 1 + WebCore/ChangeLog | 25 +++++++++++++++++++ WebCore/dom/Document.cpp | 3 +++ WebCore/dom/Tokenizer.h | 2 ++ WebCore/html/HTMLTokenizer.cpp | 21 ++++++++++++++++ WebCore/html/HTMLTokenizer.h | 3 +++ 9 files changed, 82 insertions(+) create mode 100644 LayoutTests/http/tests/local/stylesheet-and-script-load-order-expected.txt create mode 100644 LayoutTests/http/tests/local/stylesheet-and-script-load-order.html create mode 100644 LayoutTests/http/tests/local/stylesheet-dependent.js diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 93e70d891e26..e3ba6449c69d 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,14 @@ +2007-09-10 Antti Koivisto + + Reviewed by Kevin. + + Test for + 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 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 index 000000000000..953f9c9ce113 --- /dev/null +++ b/LayoutTests/http/tests/local/stylesheet-and-script-load-order-expected.txt @@ -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 index 000000000000..3c720c97a4f5 --- /dev/null +++ b/LayoutTests/http/tests/local/stylesheet-and-script-load-order.html @@ -0,0 +1,13 @@ + + + + + + +

Test that stylesheet loads complete before external scripts are executed.

+ + + diff --git a/LayoutTests/http/tests/local/stylesheet-dependent.js b/LayoutTests/http/tests/local/stylesheet-dependent.js new file mode 100644 index 000000000000..4e5d9b6be905 --- /dev/null +++ b/LayoutTests/http/tests/local/stylesheet-dependent.js @@ -0,0 +1 @@ +document.write(document.styleSheets[0] ? "PASS" : "FAIL"); diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 22f962f9f2a0..99e47577ddff 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,28 @@ +2007-09-10 Antti Koivisto + + Reviewed by Kevin. + + Fix + 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 Reviewed by Maciej Stachowiak. diff --git a/WebCore/dom/Document.cpp b/WebCore/dom/Document.cpp index 54dd56994281..570c5c2c8b4c 100644 --- a/WebCore/dom/Document.cpp +++ b/WebCore/dom/Document.cpp @@ -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(); diff --git a/WebCore/dom/Tokenizer.h b/WebCore/dom/Tokenizer.h index d9bf69844883..68cb847b9c2f 100644 --- a/WebCore/dom/Tokenizer.h +++ b/WebCore/dom/Tokenizer.h @@ -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 diff --git a/WebCore/html/HTMLTokenizer.cpp b/WebCore/html/HTMLTokenizer.cpp index 3b4b6a8db90f..797cf4c8145e 100644 --- a/WebCore/html/HTMLTokenizer.cpp +++ b/WebCore/html/HTMLTokenizer.cpp @@ -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(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 diff --git a/WebCore/html/HTMLTokenizer.h b/WebCore/html/HTMLTokenizer.h index 70ce8be5d000..f38fca17e506 100644 --- a/WebCore/html/HTMLTokenizer.h +++ b/WebCore/html/HTMLTokenizer.h @@ -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 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. -- 2.36.0