| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | 2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 * | 3 * |
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
| 8 * | 8 * |
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "core/dom/PendingScript.h" | 25 #include "core/dom/PendingScript.h" |
| 26 #include "core/dom/ScriptRunner.h" | 26 #include "core/dom/ScriptRunner.h" |
| 27 #include "core/loader/resource/ScriptResource.h" | 27 #include "core/loader/resource/ScriptResource.h" |
| 28 #include "platform/loader/fetch/FetchRequest.h" | 28 #include "platform/loader/fetch/FetchRequest.h" |
| 29 #include "platform/loader/fetch/ResourceClient.h" | 29 #include "platform/loader/fetch/ResourceClient.h" |
| 30 #include "wtf/text/TextPosition.h" | 30 #include "wtf/text/TextPosition.h" |
| 31 #include "wtf/text/WTFString.h" | 31 #include "wtf/text/WTFString.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 class Element; | 35 class LocalFrame; |
| 36 class ScriptLoaderClient; | 36 class ScriptLoaderClient; |
| 37 class ScriptSourceCode; | 37 class ScriptSourceCode; |
| 38 class LocalFrame; | |
| 39 | 38 |
| 40 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, | 39 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, |
| 41 public PendingScriptClient { | 40 public PendingScriptClient { |
| 42 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); | 41 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); |
| 43 | 42 |
| 44 public: | 43 public: |
| 45 static ScriptLoader* create(Element* element, | 44 static ScriptLoader* create(ScriptLoaderClient* client, |
| 46 bool createdByParser, | 45 bool createdByParser, |
| 47 bool isEvaluated, | 46 bool isEvaluated, |
| 48 bool createdDuringDocumentWrite = false) { | 47 bool createdDuringDocumentWrite = false) { |
| 49 return new ScriptLoader(element, createdByParser, isEvaluated, | 48 return new ScriptLoader(client, createdByParser, isEvaluated, |
| 50 createdDuringDocumentWrite); | 49 createdDuringDocumentWrite); |
| 51 } | 50 } |
| 52 | 51 |
| 53 ~ScriptLoader() override; | 52 ~ScriptLoader() override; |
| 54 DECLARE_VIRTUAL_TRACE(); | 53 DECLARE_VIRTUAL_TRACE(); |
| 55 | 54 |
| 56 Element* element() const { return m_element; } | |
| 57 | |
| 58 enum LegacyTypeSupport { | 55 enum LegacyTypeSupport { |
| 59 DisallowLegacyTypeInTypeAttribute, | 56 DisallowLegacyTypeInTypeAttribute, |
| 60 AllowLegacyTypeInTypeAttribute | 57 AllowLegacyTypeInTypeAttribute |
| 61 }; | 58 }; |
| 62 static bool isValidScriptTypeAndLanguage( | 59 static bool isValidScriptTypeAndLanguage( |
| 63 const String& typeAttributeValue, | 60 const String& typeAttributeValue, |
| 64 const String& languageAttributeValue, | 61 const String& languageAttributeValue, |
| 65 LegacyTypeSupport supportLegacyTypes); | 62 LegacyTypeSupport supportLegacyTypes); |
| 66 | 63 |
| 67 // https://html.spec.whatwg.org/#prepare-a-script | 64 // https://html.spec.whatwg.org/#prepare-a-script |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 106 |
| 110 bool wasCreatedDuringDocumentWrite() { return m_createdDuringDocumentWrite; } | 107 bool wasCreatedDuringDocumentWrite() { return m_createdDuringDocumentWrite; } |
| 111 | 108 |
| 112 bool disallowedFetchForDocWrittenScript() { | 109 bool disallowedFetchForDocWrittenScript() { |
| 113 return m_documentWriteIntervention == | 110 return m_documentWriteIntervention == |
| 114 DocumentWriteIntervention::DoNotFetchDocWrittenScript; | 111 DocumentWriteIntervention::DoNotFetchDocWrittenScript; |
| 115 } | 112 } |
| 116 void setFetchDocWrittenScriptDeferIdle(); | 113 void setFetchDocWrittenScriptDeferIdle(); |
| 117 | 114 |
| 118 protected: | 115 protected: |
| 119 ScriptLoader(Element*, | 116 ScriptLoader(ScriptLoaderClient*, |
| 120 bool createdByParser, | 117 bool createdByParser, |
| 121 bool isEvaluated, | 118 bool isEvaluated, |
| 122 bool createdDuringDocumentWrite); | 119 bool createdDuringDocumentWrite); |
| 123 | 120 |
| 124 private: | 121 private: |
| 125 bool ignoresLoadRequest() const; | 122 bool ignoresLoadRequest() const; |
| 126 bool isScriptForEventSupported() const; | 123 bool isScriptForEventSupported() const; |
| 127 void logScriptMIMEType(LocalFrame*, ScriptResource*, const String&); | 124 void logScriptMIMEType(LocalFrame*, ScriptResource*, const String&); |
| 128 | 125 |
| 129 bool fetchScript(const String& sourceUrl, | 126 bool fetchScript(const String& sourceUrl, |
| 130 const String& encoding, | 127 const String& encoding, |
| 131 FetchRequest::DeferOption); | 128 FetchRequest::DeferOption); |
| 132 bool doExecuteScript(const ScriptSourceCode&); | 129 bool doExecuteScript(const ScriptSourceCode&); |
| 133 | 130 |
| 134 ScriptLoaderClient* client() const; | |
| 135 | |
| 136 // Clears the connection to the PendingScript. | 131 // Clears the connection to the PendingScript. |
| 137 void detachPendingScript(); | 132 void detachPendingScript(); |
| 138 | 133 |
| 139 // PendingScriptClient | 134 // PendingScriptClient |
| 140 void pendingScriptFinished(PendingScript*) override; | 135 void pendingScriptFinished(PendingScript*) override; |
| 141 | 136 |
| 142 Member<Element> m_element; | 137 Member<ScriptLoaderClient> m_client; |
| 143 Member<ScriptResource> m_resource; | 138 Member<ScriptResource> m_resource; |
| 144 WTF::OrdinalNumber m_startLineNumber; | 139 WTF::OrdinalNumber m_startLineNumber; |
| 145 | 140 |
| 146 // https://html.spec.whatwg.org/#script-processing-model | 141 // https://html.spec.whatwg.org/#script-processing-model |
| 147 // "A script element has several associated pieces of state.": | 142 // "A script element has several associated pieces of state.": |
| 148 | 143 |
| 149 // https://html.spec.whatwg.org/#already-started | 144 // https://html.spec.whatwg.org/#already-started |
| 150 // "Initially, script elements must have this flag unset" | 145 // "Initially, script elements must have this flag unset" |
| 151 bool m_alreadyStarted = false; | 146 bool m_alreadyStarted = false; |
| 152 | 147 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // will be using DeferOption::IdleLoad to keep it out of the critical | 185 // will be using DeferOption::IdleLoad to keep it out of the critical |
| 191 // path. | 186 // path. |
| 192 FetchDocWrittenScriptDeferIdle, | 187 FetchDocWrittenScriptDeferIdle, |
| 193 }; | 188 }; |
| 194 | 189 |
| 195 DocumentWriteIntervention m_documentWriteIntervention; | 190 DocumentWriteIntervention m_documentWriteIntervention; |
| 196 | 191 |
| 197 Member<PendingScript> m_pendingScript; | 192 Member<PendingScript> m_pendingScript; |
| 198 }; | 193 }; |
| 199 | 194 |
| 200 ScriptLoader* toScriptLoaderIfPossible(Element*); | |
| 201 | |
| 202 } // namespace blink | 195 } // namespace blink |
| 203 | 196 |
| 204 #endif // ScriptLoader_h | 197 #endif // ScriptLoader_h |
| OLD | NEW |