OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> | |
3 * | |
4 * This library is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU Library General Public | |
6 * License as published by the Free Software Foundation; either | |
7 * version 2 of the License, or (at your option) any later version. | |
8 * | |
9 * This library is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * Library General Public License for more details. | |
13 * | |
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 | |
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
17 * Boston, MA 02110-1301, USA. | |
18 * | |
19 */ | |
20 | |
21 #ifndef ScriptElement_h | |
22 #define ScriptElement_h | |
23 | |
24 #include "core/loader/cache/CachedResourceClient.h" | |
25 #include "core/loader/cache/CachedResourceHandle.h" | |
26 #include <wtf/text/TextPosition.h> | |
27 #include <wtf/text/WTFString.h> | |
28 | |
29 namespace WebCore { | |
30 | |
31 class CachedScript; | |
32 class ContainerNode; | |
33 class Element; | |
34 class ScriptElement; | |
35 class ScriptSourceCode; | |
36 | |
37 class ScriptElementClient { | |
38 public: | |
39 virtual ~ScriptElementClient() { } | |
40 | |
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 | |
59 Element* element() const { return m_element; } | |
60 | |
61 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI
nTypeAttribute }; | |
62 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m
inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); | |
63 | |
64 String scriptCharset() const { return m_characterEncoding; } | |
65 String scriptContent() const; | |
66 void executeScript(const ScriptSourceCode&); | |
67 void execute(CachedScript*); | |
68 | |
69 // XML parser calls these | |
70 void dispatchLoadEvent(); | |
71 void dispatchErrorEvent(); | |
72 bool isScriptTypeSupported(LegacyTypeSupport) const; | |
73 | |
74 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } | |
75 bool willBeParserExecuted() const { return m_willBeParserExecuted; } | |
76 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } | |
77 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh
enDocumentFinishedParsing; } | |
78 CachedResourceHandle<CachedScript> cachedScript() { return m_cachedScript; } | |
79 | |
80 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired
Load; } | |
81 bool isParserInserted() const { return m_parserInserted; } | |
82 bool alreadyStarted() const { return m_alreadyStarted; } | |
83 bool forceAsync() const { return m_forceAsync; } | |
84 | |
85 // Helper functions used by our parent classes. | |
86 void insertedInto(ContainerNode*); | |
87 void childrenChanged(); | |
88 void handleSourceAttribute(const String& sourceUrl); | |
89 void handleAsyncAttribute(); | |
90 | |
91 private: | |
92 ScriptElement(Element*, bool createdByParser, bool isEvaluated); | |
93 | |
94 bool ignoresLoadRequest() const; | |
95 bool isScriptForEventSupported() const; | |
96 | |
97 bool requestScript(const String& sourceUrl); | |
98 void stopLoadRequest(); | |
99 | |
100 ScriptElementClient* client() const; | |
101 | |
102 // CachedResourceClient | |
103 virtual void notifyFinished(CachedResource*) OVERRIDE; | |
104 | |
105 Element* m_element; | |
106 CachedResourceHandle<CachedScript> m_cachedScript; | |
107 WTF::OrdinalNumber m_startLineNumber; | |
108 bool m_parserInserted : 1; | |
109 bool m_isExternalScript : 1; | |
110 bool m_alreadyStarted : 1; | |
111 bool m_haveFiredLoad : 1; | |
112 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin
g the script." | |
113 bool m_readyToBeParserExecuted : 1; | |
114 bool m_willExecuteWhenDocumentFinishedParsing : 1; | |
115 bool m_forceAsync : 1; | |
116 bool m_willExecuteInOrder : 1; | |
117 String m_characterEncoding; | |
118 String m_fallbackCharacterEncoding; | |
119 }; | |
120 | |
121 ScriptElement* toScriptElementIfPossible(Element*); | |
122 | |
123 inline PassOwnPtr<ScriptElement> ScriptElement::create(Element* element, bool cr
eatedByParser, bool isEvaluated) | |
124 { | |
125 return adoptPtr(new ScriptElement(element, createdByParser, isEvaluated)); | |
126 } | |
127 | |
128 } | |
129 | |
130 | |
131 #endif | |
OLD | NEW |