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 ScriptElement_h | 21 #ifndef ScriptLoader_h |
22 #define ScriptElement_h | 22 #define ScriptLoader_h |
23 | 23 |
24 #include "core/loader/cache/CachedResourceClient.h" | 24 #include "core/loader/cache/CachedResourceClient.h" |
25 #include "core/loader/cache/CachedResourceHandle.h" | 25 #include "core/loader/cache/CachedResourceHandle.h" |
26 #include <wtf/text/TextPosition.h> | 26 #include "wtf/text/TextPosition.h" |
27 #include <wtf/text/WTFString.h> | 27 #include "wtf/text/WTFString.h" |
28 | 28 |
29 namespace WebCore { | 29 namespace WebCore { |
30 | 30 |
31 class CachedScript; | 31 class CachedScript; |
32 class ContainerNode; | 32 class ContainerNode; |
33 class Element; | 33 class Element; |
34 class ScriptElement; | 34 class ScriptLoaderClient; |
35 class ScriptSourceCode; | 35 class ScriptSourceCode; |
36 | 36 |
37 class ScriptElementClient { | 37 |
| 38 class ScriptLoader : private CachedResourceClient { |
38 public: | 39 public: |
39 virtual ~ScriptElementClient() { } | 40 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool
isEvaluated); |
40 | 41 virtual ~ScriptLoader(); |
41 virtual void dispatchLoadEvent() = 0; | |
42 | |
43 virtual String sourceAttributeValue() const = 0; | |
44 virtual String charsetAttributeValue() const = 0; | |
45 virtual String typeAttributeValue() const = 0; | |
46 virtual String languageAttributeValue() const = 0; | |
47 virtual String forAttributeValue() const = 0; | |
48 virtual String eventAttributeValue() const = 0; | |
49 virtual bool asyncAttributeValue() const = 0; | |
50 virtual bool deferAttributeValue() const = 0; | |
51 virtual bool hasSourceAttribute() const = 0; | |
52 }; | |
53 | |
54 class ScriptElement : private CachedResourceClient { | |
55 public: | |
56 static PassOwnPtr<ScriptElement> create(Element*, bool createdByParser, bool
isEvaluated); | |
57 virtual ~ScriptElement(); | |
58 | 42 |
59 Element* element() const { return m_element; } | 43 Element* element() const { return m_element; } |
60 | 44 |
61 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI
nTypeAttribute }; | 45 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI
nTypeAttribute }; |
62 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m
inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); | 46 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m
inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); |
63 | 47 |
64 String scriptCharset() const { return m_characterEncoding; } | 48 String scriptCharset() const { return m_characterEncoding; } |
65 String scriptContent() const; | 49 String scriptContent() const; |
66 void executeScript(const ScriptSourceCode&); | 50 void executeScript(const ScriptSourceCode&); |
67 void execute(CachedScript*); | 51 void execute(CachedScript*); |
(...skipping 14 matching lines...) Expand all Loading... |
82 bool alreadyStarted() const { return m_alreadyStarted; } | 66 bool alreadyStarted() const { return m_alreadyStarted; } |
83 bool forceAsync() const { return m_forceAsync; } | 67 bool forceAsync() const { return m_forceAsync; } |
84 | 68 |
85 // Helper functions used by our parent classes. | 69 // Helper functions used by our parent classes. |
86 void insertedInto(ContainerNode*); | 70 void insertedInto(ContainerNode*); |
87 void childrenChanged(); | 71 void childrenChanged(); |
88 void handleSourceAttribute(const String& sourceUrl); | 72 void handleSourceAttribute(const String& sourceUrl); |
89 void handleAsyncAttribute(); | 73 void handleAsyncAttribute(); |
90 | 74 |
91 private: | 75 private: |
92 ScriptElement(Element*, bool createdByParser, bool isEvaluated); | 76 ScriptLoader(Element*, bool createdByParser, bool isEvaluated); |
93 | 77 |
94 bool ignoresLoadRequest() const; | 78 bool ignoresLoadRequest() const; |
95 bool isScriptForEventSupported() const; | 79 bool isScriptForEventSupported() const; |
96 | 80 |
97 bool requestScript(const String& sourceUrl); | 81 bool requestScript(const String& sourceUrl); |
98 void stopLoadRequest(); | 82 void stopLoadRequest(); |
99 | 83 |
100 ScriptElementClient* client() const; | 84 ScriptLoaderClient* client() const; |
101 | 85 |
102 // CachedResourceClient | 86 // CachedResourceClient |
103 virtual void notifyFinished(CachedResource*) OVERRIDE; | 87 virtual void notifyFinished(CachedResource*) OVERRIDE; |
104 | 88 |
105 Element* m_element; | 89 Element* m_element; |
106 CachedResourceHandle<CachedScript> m_cachedScript; | 90 CachedResourceHandle<CachedScript> m_cachedScript; |
107 WTF::OrdinalNumber m_startLineNumber; | 91 WTF::OrdinalNumber m_startLineNumber; |
108 bool m_parserInserted : 1; | 92 bool m_parserInserted : 1; |
109 bool m_isExternalScript : 1; | 93 bool m_isExternalScript : 1; |
110 bool m_alreadyStarted : 1; | 94 bool m_alreadyStarted : 1; |
111 bool m_haveFiredLoad : 1; | 95 bool m_haveFiredLoad : 1; |
112 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin
g the script." | 96 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin
g the script." |
113 bool m_readyToBeParserExecuted : 1; | 97 bool m_readyToBeParserExecuted : 1; |
114 bool m_willExecuteWhenDocumentFinishedParsing : 1; | 98 bool m_willExecuteWhenDocumentFinishedParsing : 1; |
115 bool m_forceAsync : 1; | 99 bool m_forceAsync : 1; |
116 bool m_willExecuteInOrder : 1; | 100 bool m_willExecuteInOrder : 1; |
117 String m_characterEncoding; | 101 String m_characterEncoding; |
118 String m_fallbackCharacterEncoding; | 102 String m_fallbackCharacterEncoding; |
119 }; | 103 }; |
120 | 104 |
121 ScriptElement* toScriptElementIfPossible(Element*); | 105 ScriptLoader* toScriptLoaderIfPossible(Element*); |
122 | 106 |
123 inline PassOwnPtr<ScriptElement> ScriptElement::create(Element* element, bool cr
eatedByParser, bool isEvaluated) | 107 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea
tedByParser, bool isEvaluated) |
124 { | 108 { |
125 return adoptPtr(new ScriptElement(element, createdByParser, isEvaluated)); | 109 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated)); |
126 } | 110 } |
127 | 111 |
128 } | 112 } |
129 | 113 |
130 | 114 |
131 #endif | 115 #endif |
OLD | NEW |