| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // null, asynchronously complete this algorithm with null, and abort these | 193 // null, asynchronously complete this algorithm with null, and abort these |
| 194 // steps. | 194 // steps. |
| 195 if (!wasModuleLoadSuccessful(resource())) { | 195 if (!wasModuleLoadSuccessful(resource())) { |
| 196 advanceState(State::Finished); | 196 advanceState(State::Finished); |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 | 199 |
| 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 sourceText = resource()->script(); | 201 String sourceText = resource()->script(); |
| 202 | 202 |
| 203 AccessControlStatus accessControlStatus = |
| 204 resource()->calculateAccessControlStatus(m_modulator->securityOrigin()); |
| 205 |
| 203 // Step 9. Let module script be the result of creating a module script given | 206 // Step 9. Let module script be the result of creating a module script given |
| 204 // source text, module map settings object, response's url, cryptographic | 207 // source text, module map settings object, response's url, cryptographic |
| 205 // nonce, parser state, and credentials mode. | 208 // nonce, parser state, and credentials mode. |
| 206 m_moduleScript = createModuleScript( | 209 m_moduleScript = createModuleScript( |
| 207 sourceText, resource()->response().url(), m_modulator, m_nonce, | 210 sourceText, resource()->response().url(), m_modulator, m_nonce, |
| 208 m_parserState, resource()->resourceRequest().fetchCredentialsMode()); | 211 m_parserState, resource()->resourceRequest().fetchCredentialsMode(), |
| 212 accessControlStatus); |
| 209 | 213 |
| 210 advanceState(State::Finished); | 214 advanceState(State::Finished); |
| 211 } | 215 } |
| 212 | 216 |
| 213 // https://html.spec.whatwg.org/#creating-a-module-script | 217 // https://html.spec.whatwg.org/#creating-a-module-script |
| 214 ModuleScript* ModuleScriptLoader::createModuleScript( | 218 ModuleScript* ModuleScriptLoader::createModuleScript( |
| 215 const String& sourceText, | 219 const String& sourceText, |
| 216 const KURL& url, | 220 const KURL& url, |
| 217 Modulator* modulator, | 221 Modulator* modulator, |
| 218 const String& nonce, | 222 const String& nonce, |
| 219 ParserDisposition parserState, | 223 ParserDisposition parserState, |
| 220 WebURLRequest::FetchCredentialsMode credentialsMode) { | 224 WebURLRequest::FetchCredentialsMode credentialsMode, |
| 225 AccessControlStatus accessControlStatus) { |
| 221 // Step 1. Let script be a new module script that this algorithm will | 226 // Step 1. Let script be a new module script that this algorithm will |
| 222 // subsequently initialize. | 227 // subsequently initialize. |
| 223 // Step 2. Set script's settings object to the environment settings object | 228 // Step 2. Set script's settings object to the environment settings object |
| 224 // provided. | 229 // provided. |
| 225 // Note: "script's settings object" will be "modulator". | 230 // Note: "script's settings object" will be "modulator". |
| 226 | 231 |
| 227 // Delegate to Modulator::compileModule to process Steps 3-6. | 232 // Delegate to Modulator::compileModule to process Steps 3-6. |
| 228 ScriptModule result = modulator->compileModule(sourceText, url.getString()); | 233 ScriptModule result = modulator->compileModule(sourceText, url.getString(), |
| 234 accessControlStatus); |
| 229 // Step 6: "...return null, and abort these steps." | 235 // Step 6: "...return null, and abort these steps." |
| 230 if (result.isNull()) | 236 if (result.isNull()) |
| 231 return nullptr; | 237 return nullptr; |
| 232 // Step 7. Set script's module record to result. | 238 // Step 7. Set script's module record to result. |
| 233 // Step 8. Set script's base URL to the script base URL provided. | 239 // Step 8. Set script's base URL to the script base URL provided. |
| 234 // Step 9. Set script's cryptographic nonce to the cryptographic nonce | 240 // Step 9. Set script's cryptographic nonce to the cryptographic nonce |
| 235 // provided. | 241 // provided. |
| 236 // Step 10. Set script's parser state to the parser state. | 242 // Step 10. Set script's parser state to the parser state. |
| 237 // Step 11. Set script's credentials mode to the credentials mode provided. | 243 // Step 11. Set script's credentials mode to the credentials mode provided. |
| 238 // Step 12. Return script. | 244 // Step 12. Return script. |
| 239 return ModuleScript::create(result, url, nonce, parserState, credentialsMode); | 245 return ModuleScript::create(result, url, nonce, parserState, credentialsMode); |
| 240 } | 246 } |
| 241 | 247 |
| 242 DEFINE_TRACE(ModuleScriptLoader) { | 248 DEFINE_TRACE(ModuleScriptLoader) { |
| 243 visitor->trace(m_modulator); | 249 visitor->trace(m_modulator); |
| 244 visitor->trace(m_moduleScript); | 250 visitor->trace(m_moduleScript); |
| 245 visitor->trace(m_registry); | 251 visitor->trace(m_registry); |
| 246 visitor->trace(m_client); | 252 visitor->trace(m_client); |
| 247 ResourceOwner<ScriptResource>::trace(visitor); | 253 ResourceOwner<ScriptResource>::trace(visitor); |
| 248 } | 254 } |
| 249 | 255 |
| 250 } // namespace blink | 256 } // namespace blink |
| OLD | NEW |