| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU Library General Public License | 14 * You should have received a copy of the GNU Library General Public License |
| 15 * along with this library; see the file COPYING.LIB. If not, write to | 15 * along with this library; see the file COPYING.LIB. If not, write to |
| 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
| 18 * | 18 * |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 #ifndef ScriptLoader_h | 21 #ifndef ScriptLoader_h |
| 22 #define ScriptLoader_h | 22 #define ScriptLoader_h |
| 23 | 23 |
| 24 #include "core/CoreExport.h" | 24 #include "core/CoreExport.h" |
| 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/fetch/AccessControlStatus.h" |
| 27 #include "core/fetch/FetchRequest.h" | 28 #include "core/fetch/FetchRequest.h" |
| 28 #include "core/fetch/ResourceClient.h" | 29 #include "core/fetch/ResourceClient.h" |
| 29 #include "core/loader/resource/ScriptResource.h" | 30 #include "core/loader/resource/ScriptResource.h" |
| 31 #include "wtf/Functional.h" |
| 30 #include "wtf/text/TextPosition.h" | 32 #include "wtf/text/TextPosition.h" |
| 31 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
| 32 | 34 |
| 33 namespace blink { | 35 namespace blink { |
| 34 | 36 |
| 37 class CompiledScript; |
| 35 class Element; | 38 class Element; |
| 36 class ScriptLoaderClient; | 39 class ScriptLoaderClient; |
| 37 class ScriptSourceCode; | 40 class ScriptSourceCode; |
| 38 class LocalFrame; | 41 class LocalFrame; |
| 39 | 42 |
| 40 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, | 43 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, |
| 41 public ScriptResourceClient { | 44 public ScriptResourceClient { |
| 42 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); | 45 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); |
| 43 | 46 |
| 44 public: | 47 public: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 const String& typeAttributeValue, | 66 const String& typeAttributeValue, |
| 64 const String& languageAttributeValue, | 67 const String& languageAttributeValue, |
| 65 LegacyTypeSupport supportLegacyTypes); | 68 LegacyTypeSupport supportLegacyTypes); |
| 66 | 69 |
| 67 bool prepareScript( | 70 bool prepareScript( |
| 68 const TextPosition& scriptStartPosition = TextPosition::minimumPosition(), | 71 const TextPosition& scriptStartPosition = TextPosition::minimumPosition(), |
| 69 LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); | 72 LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); |
| 70 | 73 |
| 71 String scriptCharset() const { return m_characterEncoding; } | 74 String scriptCharset() const { return m_characterEncoding; } |
| 72 String scriptContent() const; | 75 String scriptContent() const; |
| 76 |
| 73 // Returns false if and only if execution was blocked. | 77 // Returns false if and only if execution was blocked. |
| 74 bool executeScript(const ScriptSourceCode&); | 78 bool executeScript(const ScriptSourceCode&); |
| 79 |
| 80 // Similar to executeScript, except that the actual execution of the script |
| 81 // may be scheduled to run asynchronously. The provided callback will be |
| 82 // invoked immediately after execution completes (or immediately, if there is |
| 83 // nothing to do), with true iff the execution completed without error |
| 84 // (including if there is nothing to do). Only policy errors (that should |
| 85 // produce an error event) are reported this way; compile errors are still OK. |
| 86 using ExecuteScriptAsyncCallback = |
| 87 WTF::Function<void(bool completedWithoutError)>; |
| 88 void executeScriptAsync(const ScriptSourceCode&, |
| 89 std::unique_ptr<ExecuteScriptAsyncCallback>); |
| 90 |
| 75 virtual void execute(); | 91 virtual void execute(); |
| 76 | 92 |
| 77 // XML parser calls these | 93 // XML parser calls these |
| 78 void dispatchLoadEvent(); | 94 void dispatchLoadEvent(); |
| 79 void dispatchErrorEvent(); | 95 void dispatchErrorEvent(); |
| 80 bool isScriptTypeSupported(LegacyTypeSupport) const; | 96 bool isScriptTypeSupported(LegacyTypeSupport) const; |
| 81 | 97 |
| 82 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } | 98 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } |
| 83 bool willBeParserExecuted() const { return m_willBeParserExecuted; } | 99 bool willBeParserExecuted() const { return m_willBeParserExecuted; } |
| 84 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } | 100 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 bool createdByParser, | 139 bool createdByParser, |
| 124 bool isEvaluated, | 140 bool isEvaluated, |
| 125 bool createdDuringDocumentWrite); | 141 bool createdDuringDocumentWrite); |
| 126 | 142 |
| 127 private: | 143 private: |
| 128 bool ignoresLoadRequest() const; | 144 bool ignoresLoadRequest() const; |
| 129 bool isScriptForEventSupported() const; | 145 bool isScriptForEventSupported() const; |
| 130 void logScriptMIMEType(LocalFrame*, ScriptResource*, const String&); | 146 void logScriptMIMEType(LocalFrame*, ScriptResource*, const String&); |
| 131 | 147 |
| 132 bool fetchScript(const String& sourceUrl, FetchRequest::DeferOption); | 148 bool fetchScript(const String& sourceUrl, FetchRequest::DeferOption); |
| 133 bool doExecuteScript(const ScriptSourceCode&); | 149 |
| 150 // Separate stages of executeScript/executeScriptAsync. |
| 151 |
| 152 // Called asynchronously after script compilation, to actually execute the |
| 153 // script, after executeScriptAsync is invoked. |
| 154 void continueExecuteScriptAsync(CompiledScript*, |
| 155 Document* elementDocumentWhenCompiled, |
| 156 std::unique_ptr<ExecuteScriptAsyncCallback>); |
| 157 |
| 158 // Determines whether the script should be proceed to execution. |
| 159 // Includes Content Security Policy and MIME type checks. |
| 160 // Must be called directly before execution, to ensure that current policy is |
| 161 // applied. |
| 162 enum class CheckScriptResult { NothingToDo, Proceed, Abort }; |
| 163 CheckScriptResult checkScript(const ScriptSourceCode&); |
| 164 |
| 165 // Called before script compilation, to determine the extent to which cached |
| 166 // data about the script is sharable. |
| 167 AccessControlStatus computeAccessControlStatus(const ScriptSourceCode&); |
| 168 |
| 169 // Invokes the functor with the ScriptController, in a context where it script |
| 170 // can run. Applies (and unapplies) state such as document.currentScript. |
| 171 // This should be used to wrap the actual execution of the script. |
| 172 template <typename Functor> |
| 173 void asCurrentScript(const Functor&); |
| 174 |
| 175 // Records time that the parser has been blocked on script execution. |
| 176 void recordParserBlockedOnScriptExecutionSince(double startTime); |
| 177 |
| 178 // End stages of executeScript/executeScriptAsync. |
| 134 | 179 |
| 135 ScriptLoaderClient* client() const; | 180 ScriptLoaderClient* client() const; |
| 136 | 181 |
| 137 // ResourceClient | 182 // ResourceClient |
| 138 void notifyFinished(Resource*) override; | 183 void notifyFinished(Resource*) override; |
| 139 String debugName() const override { return "ScriptLoader"; } | 184 String debugName() const override { return "ScriptLoader"; } |
| 140 | 185 |
| 141 Member<Element> m_element; | 186 Member<Element> m_element; |
| 142 Member<ScriptResource> m_resource; | 187 Member<ScriptResource> m_resource; |
| 143 WTF::OrdinalNumber m_startLineNumber; | 188 WTF::OrdinalNumber m_startLineNumber; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 172 DocumentWriteIntervention m_documentWriteIntervention; | 217 DocumentWriteIntervention m_documentWriteIntervention; |
| 173 | 218 |
| 174 Member<PendingScript> m_pendingScript; | 219 Member<PendingScript> m_pendingScript; |
| 175 }; | 220 }; |
| 176 | 221 |
| 177 ScriptLoader* toScriptLoaderIfPossible(Element*); | 222 ScriptLoader* toScriptLoaderIfPossible(Element*); |
| 178 | 223 |
| 179 } // namespace blink | 224 } // namespace blink |
| 180 | 225 |
| 181 #endif // ScriptLoader_h | 226 #endif // ScriptLoader_h |
| OLD | NEW |