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