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/dom/PendingScript.h" | |
25 #include "core/fetch/FetchRequest.h" | 24 #include "core/fetch/FetchRequest.h" |
26 #include "core/fetch/ResourceClient.h" | 25 #include "core/fetch/ResourceClient.h" |
27 #include "core/fetch/ResourcePtr.h" | 26 #include "core/fetch/ResourcePtr.h" |
28 #include "core/fetch/ScriptResource.h" | 27 #include "core/fetch/ScriptResource.h" |
29 #include "wtf/text/TextPosition.h" | 28 #include "wtf/text/TextPosition.h" |
30 #include "wtf/text/WTFString.h" | 29 #include "wtf/text/WTFString.h" |
31 | 30 |
32 namespace blink { | 31 namespace blink { |
33 | 32 |
34 class Element; | 33 class Element; |
35 class ScriptLoaderClient; | 34 class ScriptLoaderClient; |
36 class ScriptSourceCode; | 35 class ScriptSourceCode; |
37 | 36 |
38 | 37 |
39 class ScriptLoader final : private ScriptResourceClient { | 38 class ScriptLoader final : private ScriptResourceClient { |
40 public: | 39 public: |
41 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool
isEvaluated); | 40 static PassOwnPtr<ScriptLoader> create(Element*, bool createdByParser, bool
isEvaluated); |
42 virtual ~ScriptLoader(); | 41 virtual ~ScriptLoader(); |
43 | 42 |
44 Element* element() const { return m_element; } | 43 Element* element() const { return m_element; } |
45 | 44 |
46 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI
nTypeAttribute }; | 45 enum LegacyTypeSupport { DisallowLegacyTypeInTypeAttribute, AllowLegacyTypeI
nTypeAttribute }; |
47 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m
inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); | 46 bool prepareScript(const TextPosition& scriptStartPosition = TextPosition::m
inimumPosition(), LegacyTypeSupport = DisallowLegacyTypeInTypeAttribute); |
48 | 47 |
49 String scriptCharset() const { return m_characterEncoding; } | 48 String scriptCharset() const { return m_characterEncoding; } |
50 String scriptContent() const; | 49 String scriptContent() const; |
51 void executeScript(const ScriptSourceCode&, double* compilationFinishTime =
0); | 50 void executeScript(const ScriptSourceCode&, double* compilationFinishTime =
0); |
52 void execute(); | 51 void execute(ScriptResource*); |
53 | 52 |
54 // XML parser calls these | 53 // XML parser calls these |
55 void dispatchLoadEvent(); | 54 void dispatchLoadEvent(); |
56 void dispatchErrorEvent(); | 55 void dispatchErrorEvent(); |
57 bool isScriptTypeSupported(LegacyTypeSupport) const; | 56 bool isScriptTypeSupported(LegacyTypeSupport) const; |
58 | 57 |
59 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } | 58 bool haveFiredLoadEvent() const { return m_haveFiredLoad; } |
60 bool willBeParserExecuted() const { return m_willBeParserExecuted; } | 59 bool willBeParserExecuted() const { return m_willBeParserExecuted; } |
61 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } | 60 bool readyToBeParserExecuted() const { return m_readyToBeParserExecuted; } |
62 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh
enDocumentFinishedParsing; } | 61 bool willExecuteWhenDocumentFinishedParsing() const { return m_willExecuteWh
enDocumentFinishedParsing; } |
63 ResourcePtr<ScriptResource> resource() { return m_resource; } | 62 ResourcePtr<ScriptResource> resource() { return m_resource; } |
64 | 63 |
65 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired
Load; } | 64 void setHaveFiredLoadEvent(bool haveFiredLoad) { m_haveFiredLoad = haveFired
Load; } |
66 bool isParserInserted() const { return m_parserInserted; } | 65 bool isParserInserted() const { return m_parserInserted; } |
67 bool alreadyStarted() const { return m_alreadyStarted; } | 66 bool alreadyStarted() const { return m_alreadyStarted; } |
68 bool forceAsync() const { return m_forceAsync; } | 67 bool forceAsync() const { return m_forceAsync; } |
69 | 68 |
70 // Helper functions used by our parent classes. | 69 // Helper functions used by our parent classes. |
71 void didNotifySubtreeInsertionsToDocument(); | 70 void didNotifySubtreeInsertionsToDocument(); |
72 void childrenChanged(); | 71 void childrenChanged(); |
73 void handleSourceAttribute(const String& sourceUrl); | 72 void handleSourceAttribute(const String& sourceUrl); |
74 void handleAsyncAttribute(); | 73 void handleAsyncAttribute(); |
75 | 74 |
76 bool isReady() const { return m_pendingScript.isReady(); } | |
77 | |
78 private: | 75 private: |
79 ScriptLoader(Element*, bool createdByParser, bool isEvaluated); | 76 ScriptLoader(Element*, bool createdByParser, bool isEvaluated); |
80 | 77 |
81 bool ignoresLoadRequest() const; | 78 bool ignoresLoadRequest() const; |
82 bool isScriptForEventSupported() const; | 79 bool isScriptForEventSupported() const; |
83 | 80 |
84 bool fetchScript(const String& sourceUrl, FetchRequest::DeferOption); | 81 bool fetchScript(const String& sourceUrl, FetchRequest::DeferOption); |
| 82 void stopLoadRequest(); |
85 | 83 |
86 ScriptLoaderClient* client() const; | 84 ScriptLoaderClient* client() const; |
87 | 85 |
88 // ResourceClient | 86 // ResourceClient |
89 virtual void notifyFinished(Resource*) override; | 87 virtual void notifyFinished(Resource*) override; |
90 | 88 |
91 // FIXME: Oilpan: This should become a Member once ResourceClient is moved t
o the heap. | 89 // FIXME: Oilpan: This should become a Member once ResourceClient is moved t
o the heap. |
92 Element* m_element; | 90 Element* m_element; |
93 ResourcePtr<ScriptResource> m_resource; | 91 ResourcePtr<ScriptResource> m_resource; |
94 WTF::OrdinalNumber m_startLineNumber; | 92 WTF::OrdinalNumber m_startLineNumber; |
95 bool m_parserInserted : 1; | 93 bool m_parserInserted : 1; |
96 bool m_isExternalScript : 1; | 94 bool m_isExternalScript : 1; |
97 bool m_alreadyStarted : 1; | 95 bool m_alreadyStarted : 1; |
98 bool m_haveFiredLoad : 1; | 96 bool m_haveFiredLoad : 1; |
99 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin
g the script." | 97 bool m_willBeParserExecuted : 1; // Same as "The parser will handle executin
g the script." |
100 bool m_readyToBeParserExecuted : 1; | 98 bool m_readyToBeParserExecuted : 1; |
101 bool m_willExecuteWhenDocumentFinishedParsing : 1; | 99 bool m_willExecuteWhenDocumentFinishedParsing : 1; |
102 bool m_forceAsync : 1; | 100 bool m_forceAsync : 1; |
103 bool m_willExecuteInOrder : 1; | 101 bool m_willExecuteInOrder : 1; |
104 String m_characterEncoding; | 102 String m_characterEncoding; |
105 String m_fallbackCharacterEncoding; | 103 String m_fallbackCharacterEncoding; |
106 | |
107 PendingScript m_pendingScript; | |
108 }; | 104 }; |
109 | 105 |
110 ScriptLoader* toScriptLoaderIfPossible(Element*); | 106 ScriptLoader* toScriptLoaderIfPossible(Element*); |
111 | 107 |
112 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea
tedByParser, bool isEvaluated) | 108 inline PassOwnPtr<ScriptLoader> ScriptLoader::create(Element* element, bool crea
tedByParser, bool isEvaluated) |
113 { | 109 { |
114 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated)); | 110 return adoptPtr(new ScriptLoader(element, createdByParser, isEvaluated)); |
115 } | 111 } |
116 | 112 |
117 } | 113 } |
118 | 114 |
119 | 115 |
120 #endif | 116 #endif |
OLD | NEW |