| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. | 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef HTMLScriptRunner_h | 26 #ifndef HTMLScriptRunner_h |
| 27 #define HTMLScriptRunner_h | 27 #define HTMLScriptRunner_h |
| 28 | 28 |
| 29 #include "bindings/core/v8/ScriptStreamer.h" | 29 #include "bindings/core/v8/ScriptStreamer.h" |
| 30 #include "core/dom/PendingScript.h" | 30 #include "core/dom/PendingScript.h" |
| 31 #include "core/fetch/ResourceClient.h" | 31 #include "core/fetch/ResourceClient.h" |
| 32 #include "core/html/parser/HTMLParserReentryPermit.h" |
| 32 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
| 33 #include "wtf/Deque.h" | 34 #include "wtf/Deque.h" |
| 34 #include "wtf/PassRefPtr.h" | 35 #include "wtf/RefPtr.h" |
| 35 #include "wtf/text/TextPosition.h" | 36 #include "wtf/text/TextPosition.h" |
| 36 | 37 |
| 37 namespace blink { | 38 namespace blink { |
| 38 | 39 |
| 39 class Resource; | 40 class Resource; |
| 40 class Document; | 41 class Document; |
| 41 class Element; | 42 class Element; |
| 42 class HTMLScriptRunnerHost; | 43 class HTMLScriptRunnerHost; |
| 43 | 44 |
| 44 class HTMLScriptRunner final : public GarbageCollectedFinalized<HTMLScriptRunner
>, private ScriptResourceClient { | 45 class HTMLScriptRunner final : public GarbageCollectedFinalized<HTMLScriptRunner
>, private ScriptResourceClient { |
| 45 WTF_MAKE_NONCOPYABLE(HTMLScriptRunner); | 46 WTF_MAKE_NONCOPYABLE(HTMLScriptRunner); |
| 46 USING_GARBAGE_COLLECTED_MIXIN(HTMLScriptRunner); | 47 USING_GARBAGE_COLLECTED_MIXIN(HTMLScriptRunner); |
| 47 USING_PRE_FINALIZER(HTMLScriptRunner, detach); | 48 USING_PRE_FINALIZER(HTMLScriptRunner, detach); |
| 48 public: | 49 public: |
| 49 static HTMLScriptRunner* create(Document* document, HTMLScriptRunnerHost* ho
st) | 50 static HTMLScriptRunner* create(HTMLParserReentryPermit* reentryPermit, Docu
ment* document, HTMLScriptRunnerHost* host) |
| 50 { | 51 { |
| 51 return new HTMLScriptRunner(document, host); | 52 return new HTMLScriptRunner(reentryPermit, document, host); |
| 52 } | 53 } |
| 53 ~HTMLScriptRunner(); | 54 ~HTMLScriptRunner(); |
| 54 | 55 |
| 55 void detach(); | 56 void detach(); |
| 56 | 57 |
| 57 // Processes the passed in script and any pending scripts if possible. | 58 // Processes the passed in script and any pending scripts if possible. |
| 58 void execute(Element* scriptToProcess, const TextPosition& scriptStartPositi
on); | 59 void execute(Element* scriptToProcess, const TextPosition& scriptStartPositi
on); |
| 59 | 60 |
| 60 void executeScriptsWaitingForLoad(Resource*); | 61 void executeScriptsWaitingForLoad(Resource*); |
| 61 bool hasScriptsWaitingForResources() const { return m_hasScriptsWaitingForRe
sources; } | 62 bool hasScriptsWaitingForResources() const { return m_hasScriptsWaitingForRe
sources; } |
| 62 void executeScriptsWaitingForResources(); | 63 void executeScriptsWaitingForResources(); |
| 63 bool executeScriptsWaitingForParsing(); | 64 bool executeScriptsWaitingForParsing(); |
| 64 | 65 |
| 65 bool hasParserBlockingScript() const; | 66 bool hasParserBlockingScript() const; |
| 66 bool isExecutingScript() const { return !!m_scriptNestingLevel; } | 67 bool isExecutingScript() const { return !!m_reentryPermit->scriptNestingLeve
l(); } |
| 67 | 68 |
| 68 // ResourceClient | 69 // ResourceClient |
| 69 void notifyFinished(Resource*) override; | 70 void notifyFinished(Resource*) override; |
| 70 String debugName() const override { return "HTMLScriptRunner"; } | 71 String debugName() const override { return "HTMLScriptRunner"; } |
| 71 | 72 |
| 72 DECLARE_TRACE(); | 73 DECLARE_TRACE(); |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 HTMLScriptRunner(Document*, HTMLScriptRunnerHost*); | 76 HTMLScriptRunner(HTMLParserReentryPermit*, Document*, HTMLScriptRunnerHost*)
; |
| 76 | 77 |
| 77 void executeParsingBlockingScript(); | 78 void executeParsingBlockingScript(); |
| 78 void executePendingScriptAndDispatchEvent(PendingScript*, ScriptStreamer::Ty
pe); | 79 void executePendingScriptAndDispatchEvent(PendingScript*, ScriptStreamer::Ty
pe); |
| 79 void executeParsingBlockingScripts(); | 80 void executeParsingBlockingScripts(); |
| 80 | 81 |
| 81 void requestParsingBlockingScript(Element*); | 82 void requestParsingBlockingScript(Element*); |
| 82 void requestDeferredScript(Element*); | 83 void requestDeferredScript(Element*); |
| 83 bool requestPendingScript(PendingScript*, Element*) const; | 84 bool requestPendingScript(PendingScript*, Element*) const; |
| 84 | 85 |
| 85 void runScript(Element*, const TextPosition& scriptStartPosition); | 86 void runScript(Element*, const TextPosition& scriptStartPosition); |
| 86 | 87 |
| 87 bool isPendingScriptReady(const PendingScript*); | 88 bool isPendingScriptReady(const PendingScript*); |
| 88 | 89 |
| 89 void stopWatchingResourceForLoad(Resource*); | 90 void stopWatchingResourceForLoad(Resource*); |
| 90 | 91 |
| 92 RefPtr<HTMLParserReentryPermit> m_reentryPermit; |
| 91 Member<Document> m_document; | 93 Member<Document> m_document; |
| 92 Member<HTMLScriptRunnerHost> m_host; | 94 Member<HTMLScriptRunnerHost> m_host; |
| 93 Member<PendingScript> m_parserBlockingScript; | 95 Member<PendingScript> m_parserBlockingScript; |
| 94 // http://www.whatwg.org/specs/web-apps/current-work/#list-of-scripts-that-w
ill-execute-when-the-document-has-finished-parsing | 96 // http://www.whatwg.org/specs/web-apps/current-work/#list-of-scripts-that-w
ill-execute-when-the-document-has-finished-parsing |
| 95 HeapDeque<Member<PendingScript>> m_scriptsToExecuteAfterParsing; | 97 HeapDeque<Member<PendingScript>> m_scriptsToExecuteAfterParsing; |
| 96 unsigned m_scriptNestingLevel; | |
| 97 | 98 |
| 98 // We only want stylesheet loads to trigger script execution if script | 99 // We only want stylesheet loads to trigger script execution if script |
| 99 // execution is currently stopped due to stylesheet loads, otherwise we'd | 100 // execution is currently stopped due to stylesheet loads, otherwise we'd |
| 100 // cause nested script execution when parsing <style> tags since </style> | 101 // cause nested script execution when parsing <style> tags since </style> |
| 101 // tags can cause Document to call executeScriptsWaitingForResources. | 102 // tags can cause Document to call executeScriptsWaitingForResources. |
| 102 bool m_hasScriptsWaitingForResources; | 103 bool m_hasScriptsWaitingForResources; |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 } // namespace blink | 106 } // namespace blink |
| 106 | 107 |
| 107 #endif | 108 #endif |
| OLD | NEW |