| 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/dom/Modulator.h" | 5 #include "core/dom/Modulator.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/V8PerContextData.h" |
| 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/ModulatorImpl.h" |
| 11 #include "core/frame/LocalFrame.h" |
| 8 | 12 |
| 9 namespace blink { | 13 namespace blink { |
| 10 | 14 |
| 11 Modulator* Modulator::from(LocalFrame* frame) { | 15 Modulator* Modulator::from(LocalFrame* frame) { |
| 12 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 16 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 13 if (!scriptState) | 17 if (!scriptState) |
| 14 return nullptr; | 18 return nullptr; |
| 15 // TODO(kouhei): setModulator in V8PerContextData when we land ModulatorImpl. | 19 Modulator* modulator = scriptState->perContextData()->modulator(); |
| 16 return scriptState->perContextData()->modulator(); | 20 if (!modulator) { |
| 21 if (Document* document = frame->document()) { |
| 22 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 23 modulator = ModulatorImpl::create(scriptState, *document); |
| 24 scriptState->perContextData()->setModulator(modulator); |
| 25 } |
| 26 } |
| 27 return modulator; |
| 17 } | 28 } |
| 18 | 29 |
| 19 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest, | 30 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest0, |
| 20 const KURL& baseURL) { | 31 const KURL& baseURL) { |
| 32 String moduleRequest = moduleRequest0.isolatedCopy(); |
| 33 if (!moduleRequest.endsWith(".js") && !moduleRequest.endsWith(".glsl")) { |
| 34 moduleRequest.append('.'); |
| 35 moduleRequest.append('j'); |
| 36 moduleRequest.append('s'); |
| 37 } |
| 38 if (moduleRequest.endsWith(".glsl")) { |
| 39 moduleRequest = |
| 40 KURL(KURL(), "data:text/javascript, export default 'glslsrc';"); |
| 41 } |
| 21 // Step 1. Apply the URL parser to specifier. If the result is not failure, | 42 // Step 1. Apply the URL parser to specifier. If the result is not failure, |
| 22 // return the result. | 43 // return the result. |
| 23 KURL url(KURL(), moduleRequest); | 44 KURL url(KURL(), moduleRequest); |
| 24 if (url.isValid()) | 45 if (url.isValid()) |
| 25 return url; | 46 return url; |
| 26 | 47 |
| 27 // Step 2. If specifier does not start with the character U+002F SOLIDUS (/), | 48 // Step 2. If specifier does not start with the character U+002F SOLIDUS (/), |
| 28 // the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the | 49 // the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the |
| 29 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS | 50 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS |
| 30 // (../), return failure and abort these steps. | 51 // (../), return failure and abort these steps. |
| 31 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && | 52 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && |
| 32 !moduleRequest.startsWith("../")) | 53 !moduleRequest.startsWith("../")) |
| 33 return KURL(); | 54 return KURL(); |
| 34 | 55 |
| 35 // Step 3. Return the result of applying the URL parser to specifier with | 56 // Step 3. Return the result of applying the URL parser to specifier with |
| 36 // script's base URL as the base URL. | 57 // script's base URL as the base URL. |
| 37 DCHECK(baseURL.isValid()); | 58 DCHECK(baseURL.isValid()); |
| 38 KURL absoluteURL(baseURL, moduleRequest); | 59 KURL absoluteURL(baseURL, moduleRequest); |
| 39 if (absoluteURL.isValid()) | 60 if (absoluteURL.isValid()) |
| 40 return absoluteURL; | 61 return absoluteURL; |
| 41 | 62 |
| 42 return KURL(); | 63 return KURL(); |
| 43 } | 64 } |
| 44 | 65 |
| 45 } // namespace blink | 66 } // namespace blink |
| OLD | NEW |