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/CoreExport.h" | 24 #include "core/CoreExport.h" |
25 #include "core/dom/PendingScript.h" | 25 #include "core/dom/PendingScript.h" |
26 #include "core/dom/ScriptRunner.h" | 26 #include "core/dom/ScriptRunner.h" |
27 #include "core/loader/resource/ScriptResource.h" | 27 #include "core/html/CrossOriginAttribute.h" |
28 #include "platform/loader/fetch/FetchParameters.h" | 28 #include "platform/loader/fetch/ResourceLoaderOptions.h" |
29 #include "platform/loader/fetch/ResourceClient.h" | |
30 #include "platform/wtf/text/TextPosition.h" | 29 #include "platform/wtf/text/TextPosition.h" |
31 #include "platform/wtf/text/WTFString.h" | 30 #include "platform/wtf/text/WTFString.h" |
| 31 #include "public/platform/WebURLRequest.h" |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 class ScriptElementBase; | 35 class ScriptElementBase; |
36 class Script; | 36 class Script; |
37 | 37 |
| 38 class ResourceFetcher; |
| 39 class ScriptResource; |
| 40 |
| 41 class Modulator; |
| 42 class ModulePendingScriptTreeClient; |
| 43 |
38 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, | 44 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, |
39 public PendingScriptClient { | 45 public PendingScriptClient { |
40 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); | 46 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); |
41 | 47 |
42 public: | 48 public: |
43 static ScriptLoader* Create(ScriptElementBase* element, | 49 static ScriptLoader* Create(ScriptElementBase* element, |
44 bool created_by_parser, | 50 bool created_by_parser, |
45 bool is_evaluated, | 51 bool is_evaluated, |
46 bool created_during_document_write = false) { | 52 bool created_during_document_write = false) { |
47 return new ScriptLoader(element, created_by_parser, is_evaluated, | 53 return new ScriptLoader(element, created_by_parser, is_evaluated, |
48 created_during_document_write); | 54 created_during_document_write); |
49 } | 55 } |
50 | 56 |
51 ~ScriptLoader() override; | 57 ~ScriptLoader() override; |
52 DECLARE_VIRTUAL_TRACE(); | 58 DECLARE_VIRTUAL_TRACE(); |
53 | 59 |
54 enum LegacyTypeSupport { | 60 enum LegacyTypeSupport { |
55 kDisallowLegacyTypeInTypeAttribute, | 61 kDisallowLegacyTypeInTypeAttribute, |
56 kAllowLegacyTypeInTypeAttribute | 62 kAllowLegacyTypeInTypeAttribute |
57 }; | 63 }; |
58 static bool IsValidScriptTypeAndLanguage( | 64 static bool IsValidScriptTypeAndLanguage( |
59 const String& type_attribute_value, | 65 const String& type_attribute_value, |
60 const String& language_attribute_value, | 66 const String& language_attribute_value, |
61 LegacyTypeSupport support_legacy_types); | 67 LegacyTypeSupport support_legacy_types, |
| 68 ScriptType& out_script_type); |
62 | 69 |
63 // https://html.spec.whatwg.org/#prepare-a-script | 70 // https://html.spec.whatwg.org/#prepare-a-script |
64 bool PrepareScript(const TextPosition& script_start_position = | 71 bool PrepareScript(const TextPosition& script_start_position = |
65 TextPosition::MinimumPosition(), | 72 TextPosition::MinimumPosition(), |
66 LegacyTypeSupport = kDisallowLegacyTypeInTypeAttribute); | 73 LegacyTypeSupport = kDisallowLegacyTypeInTypeAttribute); |
67 | 74 |
68 String ScriptContent() const; | 75 String ScriptContent() const; |
69 | 76 |
70 // Creates a PendingScript for external script whose fetch is started in | 77 // Creates a PendingScript for external script whose fetch is started in |
71 // fetchScript(). | 78 // FetchClassicScript()/FetchModuleScriptTree(). |
72 PendingScript* CreatePendingScript(); | 79 PendingScript* CreatePendingScript(); |
73 | 80 |
74 // Returns false if and only if execution was blocked. | 81 // Returns false if and only if execution was blocked. |
75 bool ExecuteScript(const Script*); | 82 bool ExecuteScript(const Script*); |
76 virtual void Execute(); | 83 virtual void Execute(); |
77 | 84 |
78 // XML parser calls these | 85 // XML parser calls these |
79 void DispatchLoadEvent(); | 86 void DispatchLoadEvent(); |
80 void DispatchErrorEvent(); | 87 void DispatchErrorEvent(); |
81 bool IsScriptTypeSupported(LegacyTypeSupport) const; | 88 bool IsScriptTypeSupported(LegacyTypeSupport, |
| 89 ScriptType& out_script_type) const; |
82 | 90 |
83 bool HaveFiredLoadEvent() const { return have_fired_load_; } | 91 bool HaveFiredLoadEvent() const { return have_fired_load_; } |
84 bool WillBeParserExecuted() const { return will_be_parser_executed_; } | 92 bool WillBeParserExecuted() const { return will_be_parser_executed_; } |
85 bool ReadyToBeParserExecuted() const { return ready_to_be_parser_executed_; } | 93 bool ReadyToBeParserExecuted() const { return ready_to_be_parser_executed_; } |
86 bool WillExecuteWhenDocumentFinishedParsing() const { | 94 bool WillExecuteWhenDocumentFinishedParsing() const { |
87 return will_execute_when_document_finished_parsing_; | 95 return will_execute_when_document_finished_parsing_; |
88 } | 96 } |
89 ScriptResource* GetResource() { return resource_.Get(); } | 97 ScriptResource* GetResource() { return resource_.Get(); } |
90 | 98 |
91 void SetHaveFiredLoadEvent(bool have_fired_load) { | 99 void SetHaveFiredLoadEvent(bool have_fired_load) { |
92 have_fired_load_ = have_fired_load; | 100 have_fired_load_ = have_fired_load; |
93 } | 101 } |
94 bool IsParserInserted() const { return parser_inserted_; } | 102 bool IsParserInserted() const { return parser_inserted_; } |
95 bool AlreadyStarted() const { return already_started_; } | 103 bool AlreadyStarted() const { return already_started_; } |
96 bool IsNonBlocking() const { return non_blocking_; } | 104 bool IsNonBlocking() const { return non_blocking_; } |
| 105 ScriptType GetScriptType() const { return script_type_; } |
97 | 106 |
98 // Helper functions used by our parent classes. | 107 // Helper functions used by our parent classes. |
99 void DidNotifySubtreeInsertionsToDocument(); | 108 void DidNotifySubtreeInsertionsToDocument(); |
100 void ChildrenChanged(); | 109 void ChildrenChanged(); |
101 void HandleSourceAttribute(const String& source_url); | 110 void HandleSourceAttribute(const String& source_url); |
102 void HandleAsyncAttribute(); | 111 void HandleAsyncAttribute(); |
103 | 112 |
104 virtual bool IsReady() const { | 113 virtual bool IsReady() const { |
105 return pending_script_ && pending_script_->IsReady(); | 114 return pending_script_ && pending_script_->IsReady(); |
106 } | 115 } |
(...skipping 14 matching lines...) Expand all Loading... |
121 protected: | 130 protected: |
122 ScriptLoader(ScriptElementBase*, | 131 ScriptLoader(ScriptElementBase*, |
123 bool created_by_parser, | 132 bool created_by_parser, |
124 bool is_evaluated, | 133 bool is_evaluated, |
125 bool created_during_document_write); | 134 bool created_during_document_write); |
126 | 135 |
127 private: | 136 private: |
128 bool IgnoresLoadRequest() const; | 137 bool IgnoresLoadRequest() const; |
129 bool IsScriptForEventSupported() const; | 138 bool IsScriptForEventSupported() const; |
130 | 139 |
131 bool FetchScript(const String& source_url, | 140 // FetchClassicScript corresponds to Step 21.6 of |
132 const String& encoding, | 141 // https://html.spec.whatwg.org/#prepare-a-script |
133 FetchParameters::DeferOption); | 142 // and must NOT be called from outside of PendingScript(). |
| 143 // |
| 144 // https://html.spec.whatwg.org/#fetch-a-classic-script |
| 145 bool FetchClassicScript(const KURL&, |
| 146 ResourceFetcher*, |
| 147 const String& nonce, |
| 148 const IntegrityMetadataSet&, |
| 149 ParserDisposition, |
| 150 CrossOriginAttributeValue, |
| 151 SecurityOrigin*, |
| 152 const String& encoding); |
| 153 // https://html.spec.whatwg.org/#fetch-a-module-script-tree |
| 154 void FetchModuleScriptTree(const KURL&, |
| 155 Modulator*, |
| 156 const String& nonce, |
| 157 ParserDisposition, |
| 158 WebURLRequest::FetchCredentialsMode); |
| 159 |
134 bool DoExecuteScript(const Script*); | 160 bool DoExecuteScript(const Script*); |
135 | 161 |
136 // Clears the connection to the PendingScript. | 162 // Clears the connection to the PendingScript. |
137 void DetachPendingScript(); | 163 void DetachPendingScript(); |
138 | 164 |
139 // PendingScriptClient | 165 // PendingScriptClient |
140 void PendingScriptFinished(PendingScript*) override; | 166 void PendingScriptFinished(PendingScript*) override; |
141 | 167 |
142 Member<ScriptElementBase> element_; | 168 Member<ScriptElementBase> element_; |
143 Member<ScriptResource> resource_; | 169 Member<ScriptResource> resource_; |
(...skipping 12 matching lines...) Expand all Loading... |
156 | 182 |
157 // https://html.spec.whatwg.org/#non-blocking | 183 // https://html.spec.whatwg.org/#non-blocking |
158 // "Initially, script elements must have this flag set." | 184 // "Initially, script elements must have this flag set." |
159 bool non_blocking_ = true; | 185 bool non_blocking_ = true; |
160 | 186 |
161 // https://html.spec.whatwg.org/#ready-to-be-parser-executed | 187 // https://html.spec.whatwg.org/#ready-to-be-parser-executed |
162 // "Initially, script elements must have this flag unset" | 188 // "Initially, script elements must have this flag unset" |
163 bool ready_to_be_parser_executed_ = false; | 189 bool ready_to_be_parser_executed_ = false; |
164 | 190 |
165 // https://html.spec.whatwg.org/#concept-script-type | 191 // https://html.spec.whatwg.org/#concept-script-type |
166 // TODO(hiroshige): Implement "script's type". | 192 // "It is determined when the script is prepared" |
| 193 ScriptType script_type_ = ScriptType::kClassic; |
167 | 194 |
168 // https://html.spec.whatwg.org/#concept-script-external | 195 // https://html.spec.whatwg.org/#concept-script-external |
169 // "It is determined when the script is prepared" | 196 // "It is determined when the script is prepared" |
170 bool is_external_script_ = false; | 197 bool is_external_script_ = false; |
171 | 198 |
172 bool have_fired_load_; | 199 bool have_fired_load_; |
173 | 200 |
174 // Same as "The parser will handle executing the script." | 201 // Same as "The parser will handle executing the script." |
175 bool will_be_parser_executed_; | 202 bool will_be_parser_executed_; |
176 | 203 |
(...skipping 11 matching lines...) Expand all Loading... |
188 // present in the http cache, send a GET for it with an interventions | 215 // present in the http cache, send a GET for it with an interventions |
189 // header to allow the server to know of the intervention. This fetch | 216 // header to allow the server to know of the intervention. This fetch |
190 // will be using DeferOption::IdleLoad to keep it out of the critical | 217 // will be using DeferOption::IdleLoad to keep it out of the critical |
191 // path. | 218 // path. |
192 kFetchDocWrittenScriptDeferIdle, | 219 kFetchDocWrittenScriptDeferIdle, |
193 }; | 220 }; |
194 | 221 |
195 DocumentWriteIntervention document_write_intervention_; | 222 DocumentWriteIntervention document_write_intervention_; |
196 | 223 |
197 Member<PendingScript> pending_script_; | 224 Member<PendingScript> pending_script_; |
| 225 Member<ModulePendingScriptTreeClient> module_tree_client_; |
198 }; | 226 }; |
199 | 227 |
200 } // namespace blink | 228 } // namespace blink |
201 | 229 |
202 #endif // ScriptLoader_h | 230 #endif // ScriptLoader_h |
OLD | NEW |