| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/loader/modulescript/ModuleScriptLoader.h" | 5 #include "core/loader/modulescript/ModuleScriptLoader.h" |
| 6 | 6 |
| 7 #include "core/dom/Modulator.h" | 7 #include "core/dom/Modulator.h" |
| 8 #include "core/dom/ModuleScript.h" | 8 #include "core/dom/ModuleScript.h" |
| 9 #include "core/loader/modulescript/ModuleScriptLoaderClient.h" | 9 #include "core/loader/modulescript/ModuleScriptLoaderClient.h" |
| 10 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h" | 10 #include "core/loader/modulescript/ModuleScriptLoaderRegistry.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 // Step 8. Let source text be the result of UTF-8 decoding response's body. | 200 // Step 8. Let source text be the result of UTF-8 decoding response's body. |
| 201 String source_text = GetResource()->SourceText(); | 201 String source_text = GetResource()->SourceText(); |
| 202 | 202 |
| 203 AccessControlStatus access_control_status = | 203 AccessControlStatus access_control_status = |
| 204 GetResource()->CalculateAccessControlStatus( | 204 GetResource()->CalculateAccessControlStatus( |
| 205 modulator_->GetSecurityOrigin()); | 205 modulator_->GetSecurityOrigin()); |
| 206 | 206 |
| 207 // Step 9. Let module script be the result of creating a module script given | 207 // Step 9. Let module script be the result of creating a module script given |
| 208 // source text, module map settings object, response's url, cryptographic | 208 // source text, module map settings object, response's url, cryptographic |
| 209 // nonce, parser state, and credentials mode. | 209 // nonce, parser state, and credentials mode. |
| 210 module_script_ = CreateModuleScript( | 210 module_script_ = ModuleScript::Create( |
| 211 source_text, GetResource()->GetResponse().Url(), modulator_, nonce_, | 211 source_text, modulator_, GetResource()->GetResponse().Url(), nonce_, |
| 212 parser_state_, | 212 parser_state_, |
| 213 GetResource()->GetResourceRequest().GetFetchCredentialsMode(), | 213 GetResource()->GetResourceRequest().GetFetchCredentialsMode(), |
| 214 access_control_status); | 214 access_control_status); |
| 215 | 215 |
| 216 AdvanceState(State::kFinished); | 216 AdvanceState(State::kFinished); |
| 217 } | 217 } |
| 218 | 218 |
| 219 // https://html.spec.whatwg.org/#creating-a-module-script | |
| 220 ModuleScript* ModuleScriptLoader::CreateModuleScript( | |
| 221 const String& source_text, | |
| 222 const KURL& url, | |
| 223 Modulator* modulator, | |
| 224 const String& nonce, | |
| 225 ParserDisposition parser_state, | |
| 226 WebURLRequest::FetchCredentialsMode credentials_mode, | |
| 227 AccessControlStatus access_control_status) { | |
| 228 // Step 1. Let script be a new module script that this algorithm will | |
| 229 // subsequently initialize. | |
| 230 // Step 2. Set script's settings object to the environment settings object | |
| 231 // provided. | |
| 232 // Note: "script's settings object" will be "modulator". | |
| 233 | |
| 234 // Delegate to Modulator::compileModule to process Steps 3-6. | |
| 235 ScriptModule result = modulator->CompileModule(source_text, url.GetString(), | |
| 236 access_control_status); | |
| 237 // Step 6: "...return null, and abort these steps." | |
| 238 if (result.IsNull()) | |
| 239 return nullptr; | |
| 240 // Step 7. Set script's module record to result. | |
| 241 // Step 8. Set script's base URL to the script base URL provided. | |
| 242 // Step 9. Set script's cryptographic nonce to the cryptographic nonce | |
| 243 // provided. | |
| 244 // Step 10. Set script's parser state to the parser state. | |
| 245 // Step 11. Set script's credentials mode to the credentials mode provided. | |
| 246 // Step 12. Return script. | |
| 247 return ModuleScript::Create(modulator, result, url, nonce, parser_state, | |
| 248 credentials_mode); | |
| 249 } | |
| 250 | |
| 251 DEFINE_TRACE(ModuleScriptLoader) { | 219 DEFINE_TRACE(ModuleScriptLoader) { |
| 252 visitor->Trace(modulator_); | 220 visitor->Trace(modulator_); |
| 253 visitor->Trace(module_script_); | 221 visitor->Trace(module_script_); |
| 254 visitor->Trace(registry_); | 222 visitor->Trace(registry_); |
| 255 visitor->Trace(client_); | 223 visitor->Trace(client_); |
| 256 ResourceOwner<ScriptResource>::Trace(visitor); | 224 ResourceOwner<ScriptResource>::Trace(visitor); |
| 257 } | 225 } |
| 258 | 226 |
| 259 } // namespace blink | 227 } // namespace blink |
| OLD | NEW |