Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(322)

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.h

Issue 2821553002: Refactor code around ScriptLoader::FetchScript() according to the spec (Closed)
Patch Set: refine Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
38 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>, 41 class CORE_EXPORT ScriptLoader : public GarbageCollectedFinalized<ScriptLoader>,
39 public PendingScriptClient { 42 public PendingScriptClient {
40 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader); 43 USING_GARBAGE_COLLECTED_MIXIN(ScriptLoader);
41 44
42 public: 45 public:
43 static ScriptLoader* Create(ScriptElementBase* element, 46 static ScriptLoader* Create(ScriptElementBase* element,
44 bool created_by_parser, 47 bool created_by_parser,
45 bool is_evaluated, 48 bool is_evaluated,
46 bool created_during_document_write = false) { 49 bool created_during_document_write = false) {
47 return new ScriptLoader(element, created_by_parser, is_evaluated, 50 return new ScriptLoader(element, created_by_parser, is_evaluated,
(...skipping 13 matching lines...) Expand all
61 LegacyTypeSupport support_legacy_types); 64 LegacyTypeSupport support_legacy_types);
62 65
63 // https://html.spec.whatwg.org/#prepare-a-script 66 // https://html.spec.whatwg.org/#prepare-a-script
64 bool PrepareScript(const TextPosition& script_start_position = 67 bool PrepareScript(const TextPosition& script_start_position =
65 TextPosition::MinimumPosition(), 68 TextPosition::MinimumPosition(),
66 LegacyTypeSupport = kDisallowLegacyTypeInTypeAttribute); 69 LegacyTypeSupport = kDisallowLegacyTypeInTypeAttribute);
67 70
68 String ScriptContent() const; 71 String ScriptContent() const;
69 72
70 // Creates a PendingScript for external script whose fetch is started in 73 // Creates a PendingScript for external script whose fetch is started in
71 // fetchScript(). 74 // FetchClassicScript().
72 PendingScript* CreatePendingScript(); 75 PendingScript* CreatePendingScript();
73 76
74 // Returns false if and only if execution was blocked. 77 // Returns false if and only if execution was blocked.
75 bool ExecuteScript(const Script*); 78 bool ExecuteScript(const Script*);
76 virtual void Execute(); 79 virtual void Execute();
77 80
78 // XML parser calls these 81 // XML parser calls these
79 void DispatchLoadEvent(); 82 void DispatchLoadEvent();
80 void DispatchErrorEvent(); 83 void DispatchErrorEvent();
81 bool IsScriptTypeSupported(LegacyTypeSupport) const; 84 bool IsScriptTypeSupported(LegacyTypeSupport) const;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 protected: 124 protected:
122 ScriptLoader(ScriptElementBase*, 125 ScriptLoader(ScriptElementBase*,
123 bool created_by_parser, 126 bool created_by_parser,
124 bool is_evaluated, 127 bool is_evaluated,
125 bool created_during_document_write); 128 bool created_during_document_write);
126 129
127 private: 130 private:
128 bool IgnoresLoadRequest() const; 131 bool IgnoresLoadRequest() const;
129 bool IsScriptForEventSupported() const; 132 bool IsScriptForEventSupported() const;
130 133
131 bool FetchScript(const String& source_url, 134 // FetchClassicScript corresponds to Step 21.6 of
132 const String& encoding, 135 // https://html.spec.whatwg.org/#prepare-a-script
133 FetchParameters::DeferOption); 136 // and must NOT be called from outside of PendingScript().
137 //
138 // https://html.spec.whatwg.org/#fetch-a-classic-script
139 bool FetchClassicScript(const KURL&,
140 ResourceFetcher*,
141 const String& nonce,
142 const IntegrityMetadataSet&,
143 ParserDisposition,
144 CrossOriginAttributeValue,
145 SecurityOrigin*,
146 const String& encoding);
147
134 bool DoExecuteScript(const Script*); 148 bool DoExecuteScript(const Script*);
135 149
136 // Clears the connection to the PendingScript. 150 // Clears the connection to the PendingScript.
137 void DetachPendingScript(); 151 void DetachPendingScript();
138 152
139 // PendingScriptClient 153 // PendingScriptClient
140 void PendingScriptFinished(PendingScript*) override; 154 void PendingScriptFinished(PendingScript*) override;
141 155
142 Member<ScriptElementBase> element_; 156 Member<ScriptElementBase> element_;
143 Member<ScriptResource> resource_; 157 Member<ScriptResource> resource_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 }; 207 };
194 208
195 DocumentWriteIntervention document_write_intervention_; 209 DocumentWriteIntervention document_write_intervention_;
196 210
197 Member<PendingScript> pending_script_; 211 Member<PendingScript> pending_script_;
198 }; 212 };
199 213
200 } // namespace blink 214 } // namespace blink
201 215
202 #endif // ScriptLoader_h 216 #endif // ScriptLoader_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698