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 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
11 Modulator* Modulator::from(LocalFrame* frame) { | 11 Modulator* Modulator::from(LocalFrame* frame) { |
12 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 12 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
13 if (!scriptState) | 13 if (!scriptState) |
14 return nullptr; | 14 return nullptr; |
15 // TODO(kouhei): setModulator in V8PerContextData when we land ModulatorImpl. | 15 // TODO(kouhei): setModulator in V8PerContextData when we land ModulatorImpl. |
16 return scriptState->perContextData()->modulator(); | 16 return scriptState->perContextData()->modulator(); |
17 } | 17 } |
18 | 18 |
| 19 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest, |
| 20 const KURL& baseURL) { |
| 21 // Step 1. Apply the URL parser to specifier. If the result is not failure, |
| 22 // return the result. |
| 23 KURL url(KURL(), moduleRequest); |
| 24 if (url.isValid()) |
| 25 return url; |
| 26 |
| 27 // 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 |
| 29 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS |
| 30 // (../), return failure and abort these steps. |
| 31 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && |
| 32 !moduleRequest.startsWith("../")) |
| 33 return KURL(); |
| 34 |
| 35 // Step 3. Return the result of applying the URL parser to specifier with |
| 36 // script's base URL as the base URL. |
| 37 DCHECK(baseURL.isValid()); |
| 38 KURL absoluteURL(baseURL, moduleRequest); |
| 39 if (absoluteURL.isValid()) |
| 40 return absoluteURL; |
| 41 |
| 42 return KURL(); |
| 43 } |
| 44 |
19 } // namespace blink | 45 } // namespace blink |
OLD | NEW |