| 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 19 matching lines...) Expand all Loading... |
| 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 "core/html/parser/HTMLParserReentryPermit.h" |
| 33 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
| 34 #include "wtf/Deque.h" | 34 #include "wtf/Deque.h" |
| 35 #include "wtf/RefPtr.h" | 35 #include "wtf/RefPtr.h" |
| 36 #include "wtf/text/TextPosition.h" | 36 #include "wtf/text/TextPosition.h" |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class Resource; | |
| 41 class Document; | 40 class Document; |
| 42 class Element; | 41 class Element; |
| 43 class HTMLParserScriptRunnerHost; | 42 class HTMLParserScriptRunnerHost; |
| 44 | 43 |
| 45 // HTMLParserScriptRunner is responsible for for arranging the execution of | 44 // HTMLParserScriptRunner is responsible for for arranging the execution of |
| 46 // script elements inserted by the parser, according to the rules for | 45 // script elements inserted by the parser, according to the rules for |
| 47 // 'An end tag whose tag name is "script"': | 46 // 'An end tag whose tag name is "script"': |
| 48 // https://html.spec.whatwg.org/multipage/syntax.html#scriptEndTag | 47 // https://html.spec.whatwg.org/multipage/syntax.html#scriptEndTag |
| 49 // | 48 // |
| 50 // If a script blocks parsing, this class is responsible for holding it, and | 49 // If a script blocks parsing, this class is responsible for holding it, and |
| 51 // executing it when required. | 50 // executing it when required. |
| 52 // | 51 // |
| 53 // An HTMLParserScriptRunner is owned by its host, an HTMLDocumentParser. | 52 // An HTMLParserScriptRunner is owned by its host, an HTMLDocumentParser. |
| 54 class HTMLParserScriptRunner final | 53 class HTMLParserScriptRunner final |
| 55 : public GarbageCollectedFinalized<HTMLParserScriptRunner>, | 54 : public GarbageCollectedFinalized<HTMLParserScriptRunner>, |
| 56 private ScriptResourceClient { | 55 private PendingScriptClient { |
| 57 WTF_MAKE_NONCOPYABLE(HTMLParserScriptRunner); | 56 WTF_MAKE_NONCOPYABLE(HTMLParserScriptRunner); |
| 58 USING_GARBAGE_COLLECTED_MIXIN(HTMLParserScriptRunner); | 57 USING_GARBAGE_COLLECTED_MIXIN(HTMLParserScriptRunner); |
| 59 USING_PRE_FINALIZER(HTMLParserScriptRunner, detach); | 58 USING_PRE_FINALIZER(HTMLParserScriptRunner, detach); |
| 60 | 59 |
| 61 public: | 60 public: |
| 62 static HTMLParserScriptRunner* create(HTMLParserReentryPermit* reentryPermit, | 61 static HTMLParserScriptRunner* create(HTMLParserReentryPermit* reentryPermit, |
| 63 Document* document, | 62 Document* document, |
| 64 HTMLParserScriptRunnerHost* host) { | 63 HTMLParserScriptRunnerHost* host) { |
| 65 return new HTMLParserScriptRunner(reentryPermit, document, host); | 64 return new HTMLParserScriptRunner(reentryPermit, document, host); |
| 66 } | 65 } |
| 67 ~HTMLParserScriptRunner(); | 66 ~HTMLParserScriptRunner(); |
| 68 | 67 |
| 69 // Prepares this object to be destroyed. Invoked when the parser is detached, | 68 // Prepares this object to be destroyed. Invoked when the parser is detached, |
| 70 // or failing that, as a pre-finalizer. | 69 // or failing that, as a pre-finalizer. |
| 71 void detach(); | 70 void detach(); |
| 72 | 71 |
| 73 // Processes the passed in script and any pending scripts if possible. | 72 // Processes the passed in script and any pending scripts if possible. |
| 74 // This does not necessarily run the script immediately. For instance, | 73 // This does not necessarily run the script immediately. For instance, |
| 75 // execution may not happen until the script loads from the network, or after | 74 // execution may not happen until the script loads from the network, or after |
| 76 // the document finishes parsing. | 75 // the document finishes parsing. |
| 77 void processScriptElement(Element*, const TextPosition& scriptStartPosition); | 76 void processScriptElement(Element*, const TextPosition& scriptStartPosition); |
| 78 | 77 |
| 79 // Invoked when the parsing-blocking script resource has loaded, to execute | 78 // Invoked when the parsing-blocking script resource has loaded, to execute |
| 80 // parsing-blocking scripts. | 79 // parsing-blocking scripts. |
| 81 void executeScriptsWaitingForLoad(Resource*); | 80 void executeScriptsWaitingForLoad(PendingScript*); |
| 82 | 81 |
| 83 // Invoked when all script-blocking resources (e.g., stylesheets) have loaded, | 82 // Invoked when all script-blocking resources (e.g., stylesheets) have loaded, |
| 84 // to execute parsing-blocking scripts. | 83 // to execute parsing-blocking scripts. |
| 85 void executeScriptsWaitingForResources(); | 84 void executeScriptsWaitingForResources(); |
| 86 | 85 |
| 87 // Invoked when parsing is stopping, to execute any deferred scripts. | 86 // Invoked when parsing is stopping, to execute any deferred scripts. |
| 88 bool executeScriptsWaitingForParsing(); | 87 bool executeScriptsWaitingForParsing(); |
| 89 | 88 |
| 90 bool hasParserBlockingScript() const; | 89 bool hasParserBlockingScript() const; |
| 91 bool isExecutingScript() const { | 90 bool isExecutingScript() const { |
| 92 return !!m_reentryPermit->scriptNestingLevel(); | 91 return !!m_reentryPermit->scriptNestingLevel(); |
| 93 } | 92 } |
| 94 | 93 |
| 95 // ResourceClient | |
| 96 void notifyFinished(Resource*) override; | |
| 97 String debugName() const override { return "HTMLParserScriptRunner"; } | |
| 98 | |
| 99 DECLARE_TRACE(); | 94 DECLARE_TRACE(); |
| 100 | 95 |
| 101 private: | 96 private: |
| 102 HTMLParserScriptRunner(HTMLParserReentryPermit*, | 97 HTMLParserScriptRunner(HTMLParserReentryPermit*, |
| 103 Document*, | 98 Document*, |
| 104 HTMLParserScriptRunnerHost*); | 99 HTMLParserScriptRunnerHost*); |
| 105 | 100 |
| 101 // PendingScriptClient |
| 102 void pendingScriptFinished(PendingScript*) override; |
| 103 |
| 106 void executePendingScriptAndDispatchEvent(PendingScript*, | 104 void executePendingScriptAndDispatchEvent(PendingScript*, |
| 107 ScriptStreamer::Type); | 105 ScriptStreamer::Type); |
| 108 void executeParsingBlockingScripts(); | 106 void executeParsingBlockingScripts(); |
| 109 | 107 |
| 110 void requestParsingBlockingScript(Element*); | 108 void requestParsingBlockingScript(Element*); |
| 111 void requestDeferredScript(Element*); | 109 void requestDeferredScript(Element*); |
| 112 bool requestPendingScript(PendingScript*, Element*) const; | 110 bool requestPendingScript(PendingScript*, Element*) const; |
| 113 | 111 |
| 114 // Processes the provided script element, but does not execute any | 112 // Processes the provided script element, but does not execute any |
| 115 // parsing-blocking scripts that may remain after execution. | 113 // parsing-blocking scripts that may remain after execution. |
| 116 void processScriptElementInternal(Element*, | 114 void processScriptElementInternal(Element*, |
| 117 const TextPosition& scriptStartPosition); | 115 const TextPosition& scriptStartPosition); |
| 118 | 116 |
| 119 bool isParserBlockingScriptReady(); | 117 bool isParserBlockingScriptReady(); |
| 120 | 118 |
| 121 void stopWatchingResourceForLoad(Resource*); | 119 void possiblyFetchBlockedDocWriteScript(PendingScript*); |
| 122 | |
| 123 void possiblyFetchBlockedDocWriteScript(Resource*); | |
| 124 | 120 |
| 125 RefPtr<HTMLParserReentryPermit> m_reentryPermit; | 121 RefPtr<HTMLParserReentryPermit> m_reentryPermit; |
| 126 Member<Document> m_document; | 122 Member<Document> m_document; |
| 127 Member<HTMLParserScriptRunnerHost> m_host; | 123 Member<HTMLParserScriptRunnerHost> m_host; |
| 128 Member<PendingScript> m_parserBlockingScript; | 124 Member<PendingScript> m_parserBlockingScript; |
| 129 // http://www.whatwg.org/specs/web-apps/current-work/#list-of-scripts-that-wil
l-execute-when-the-document-has-finished-parsing | 125 // http://www.whatwg.org/specs/web-apps/current-work/#list-of-scripts-that-wil
l-execute-when-the-document-has-finished-parsing |
| 130 HeapDeque<Member<PendingScript>> m_scriptsToExecuteAfterParsing; | 126 HeapDeque<Member<PendingScript>> m_scriptsToExecuteAfterParsing; |
| 131 }; | 127 }; |
| 132 | 128 |
| 133 } // namespace blink | 129 } // namespace blink |
| 134 | 130 |
| 135 #endif | 131 #endif |
| OLD | NEW |