| 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/fetch/ResourceClient.h" | 24 #include "core/fetch/ResourceClient.h" |
| 25 #include "core/fetch/ResourceOwner.h" | |
| 26 #include "core/fetch/ResourcePtr.h" | 25 #include "core/fetch/ResourcePtr.h" |
| 27 #include "core/fetch/ScriptResource.h" | |
| 28 #include "wtf/text/TextPosition.h" | 26 #include "wtf/text/TextPosition.h" |
| 29 #include "wtf/text/WTFString.h" | 27 #include "wtf/text/WTFString.h" |
| 30 | 28 |
| 31 namespace WebCore { | 29 namespace WebCore { |
| 32 | 30 |
| 33 class ScriptResource; | 31 class ScriptResource; |
| 34 class ContainerNode; | 32 class ContainerNode; |
| 35 class Document; | 33 class Document; |
| 36 class Element; | 34 class Element; |
| 37 class ScriptLoaderClient; | 35 class ScriptLoaderClient; |
| 38 class ScriptRunner; | |
| 39 class ScriptSourceCode; | 36 class ScriptSourceCode; |
| 40 | 37 |
| 41 class ScriptPrep FINAL { | |
| 42 public: | |
| 43 ScriptPrep(bool succeeded, const ResourcePtr<ScriptResource>& resource) | |
| 44 : m_succeeded(succeeded) | |
| 45 , m_resource(resource) | |
| 46 { } | |
| 47 | 38 |
| 48 bool succeeded() const { return m_succeeded; } | 39 class ScriptLoader FINAL : private ResourceClient { |
| 49 ScriptResource* resource() const { return m_resource.get(); } | |
| 50 | |
| 51 static ScriptPrep failed() { return ScriptPrep(); } | |
| 52 | |
| 53 private: | |
| 54 ScriptPrep() | |
| 55 : m_succeeded(false) | |
| 56 { } | |
| 57 | |
| 58 bool m_succeeded; | |
| 59 ResourcePtr<ScriptResource> m_resource; | |
| 60 }; | |
| 61 | |
| 62 class ScriptLoader FINAL : public ResourceOwner<ScriptResource> { | |
| 63 public: | 40 public: |
| 64 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool
isEvaluated); | 41 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool
isEvaluated); |
| 65 virtual ~ScriptLoader(); | 42 virtual ~ScriptLoader(); |
| 66 | 43 |
| 67 Element* element() const { return m_element; } | 44 Element* element() const { return m_element; } |
| 68 | 45 |
| 69 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI
nTypeAttribute }; | 46 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI
nTypeAttribute }; |
| 70 ScriptPrep prepareScript(const TextPosition& scriptStartPosition = TextPosit
ion::minimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); | 47 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m
inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); |
| 71 | 48 |
| 72 String scriptCharset() const { return m_characterEncoding; } | 49 String scriptCharset() const { return m_characterEncoding; } |
| 73 String scriptContent() const; | 50 String scriptContent() const; |
| 74 void executeScript(const ScriptSourceCode&); | 51 void executeScript(const ScriptSourceCode&); |
| 75 void execute(ScriptResource*); | 52 void execute(ScriptResource*); |
| 76 | 53 |
| 77 // XML parser calls these | 54 // XML parser calls these |
| 78 void dispatchLoadEvent(); | 55 void dispatchLoadEvent(); |
| 79 void dispatchErrorEvent(); | 56 void dispatchErrorEvent(); |
| 80 bool isScriptTypeSupported(LegacyTypeSupport) const; | 57 bool isScriptTypeSupported(LegacyTypeSupport) const; |
| 81 | 58 |
| 82 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } | 59 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } |
| 83 bool willBeParserExecuted() const { return m_willBeParserExecuted; } | 60 bool willBeParserExecuted() const { return m_willBeParserExecuted; } |
| 84 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } | 61 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } |
| 85 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh
enDocumentFinishedParsing; } | 62 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh
enDocumentFinishedParsing; } |
| 63 ResourcePtr<ScriptResource> resource() { return m_resource; } |
| 86 | 64 |
| 87 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired
Load; } | 65 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired
Load; } |
| 88 bool isParserInserted() const { return m_parserInserted; } | 66 bool isParserInserted() const { return m_parserInserted; } |
| 89 bool alreadyStarted() const { return m_alreadyStarted; } | 67 bool alreadyStarted() const { return m_alreadyStarted; } |
| 90 bool forceAsync() const { return m_forceAsync; } | 68 bool forceAsync() const { return m_forceAsync; } |
| 91 | 69 |
| 92 // Helper functions used by our parent classes. | 70 // Helper functions used by our parent classes. |
| 93 void didNotifySubtreeInsertionsToDocument(); | 71 void didNotifySubtreeInsertionsToDocument(); |
| 94 void childrenChanged(); | 72 void childrenChanged(); |
| 95 void handleSourceAttribute(const String& sourceUrl); | 73 void handleSourceAttribute(const String& sourceUrl); |
| 96 void handleAsyncAttribute(); | 74 void handleAsyncAttribute(); |
| 97 void cancel(Document* contextDocument); | 75 void cancel(Document* contextDocument); |
| 98 | 76 |
| 99 private: | 77 private: |
| 100 ScriptLoader(Element*, bool createdByParser, bool isEvaluated); | 78 ScriptLoader(Element*, bool createdByParser, bool isEvaluated); |
| 101 | 79 |
| 102 bool ignoresLoadRequest() const; | 80 bool ignoresLoadRequest() const; |
| 103 bool isScriptForEventSupported() const; | 81 bool isScriptForEventSupported() const; |
| 104 | 82 |
| 105 ResourcePtr<ScriptResource> fetchScript(const String& sourceUrl); | 83 bool fetchScript(const String& sourceUrl); |
| 84 void stopLoadRequest(); |
| 106 | 85 |
| 107 ScriptLoaderClient* client() const; | 86 ScriptLoaderClient* client() const; |
| 108 | 87 |
| 109 // ResourceClient | 88 // ResourceClient |
| 110 virtual void notifyFinished(Resource*) OVERRIDE; | 89 virtual void notifyFinished(Resource*) OVERRIDE; |
| 111 | 90 |
| 112 enum FinishType { | 91 enum FinishType { |
| 113 FinishSuccessfully, | 92 FinishSuccessfully, |
| 114 FinishWithCancel, | 93 FinishWithCancel, |
| 115 FinishWithError | 94 FinishWithError |
| 116 }; | 95 }; |
| 117 | 96 |
| 118 void finishLoading(Document* contextDocument, FinishType); | 97 void finishLoading(Document* contextDocument, FinishType); |
| 119 void notifyRunnerFinishLoading(ScriptRunner*, FinishType); | |
| 120 | 98 |
| 121 Element* m_element; | 99 Element* m_element; |
| 100 ResourcePtr<ScriptResource> m_resource; |
| 122 WTF::OrdinalNumber m_startLineNumber; | 101 WTF::OrdinalNumber m_startLineNumber; |
| 123 bool m_parserInserted : 1; | 102 bool m_parserInserted : 1; |
| 124 bool m_isExternalScript : 1; | 103 bool m_isExternalScript : 1; |
| 125 bool m_alreadyStarted : 1; | 104 bool m_alreadyStarted : 1; |
| 126 bool m_haveFiredLoad : 1; | 105 bool m_haveFiredLoad : 1; |
| 127 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin
g the script." | 106 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin
g the script." |
| 128 bool m_readyToBeParserExecuted : 1; | 107 bool m_readyToBeParserExecuted : 1; |
| 129 bool m_willExecuteWhenDocumentFinishedParsing : 1; | 108 bool m_willExecuteWhenDocumentFinishedParsing : 1; |
| 130 bool m_forceAsync : 1; | 109 bool m_forceAsync : 1; |
| 131 bool m_willExecuteInOrder : 1; | 110 bool m_willExecuteInOrder : 1; |
| 132 String m_characterEncoding; | 111 String m_characterEncoding; |
| 133 String m_fallbackCharacterEncoding; | 112 String m_fallbackCharacterEncoding; |
| 134 }; | 113 }; |
| 135 | 114 |
| 136 ScriptLoader* toScriptLoaderIfPossible(Element*); | 115 ScriptLoader* toScriptLoaderIfPossible(Element*); |
| 137 | 116 |
| 138 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea
tedByParser, bool isEvaluated) | 117 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea
tedByParser, bool isEvaluated) |
| 139 { | 118 { |
| 140 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated)); | 119 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated)); |
| 141 } | 120 } |
| 142 | 121 |
| 143 } | 122 } |
| 144 | 123 |
| 145 | 124 |
| 146 #endif | 125 #endif |
| OLD | NEW |