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 Modulator::~Modulator() {} |
| 20 |
19 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest, | 21 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest, |
20 const KURL& baseURL) { | 22 const KURL& baseURL) { |
21 // Step 1. Apply the URL parser to specifier. If the result is not failure, | 23 // Step 1. Apply the URL parser to specifier. If the result is not failure, |
22 // return the result. | 24 // return the result. |
23 KURL url(KURL(), moduleRequest); | 25 KURL url(KURL(), moduleRequest); |
24 if (url.isValid()) | 26 if (url.isValid()) |
25 return url; | 27 return url; |
26 | 28 |
27 // Step 2. If specifier does not start with the character U+002F SOLIDUS (/), | 29 // 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 | 30 // 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 | 31 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS |
30 // (../), return failure and abort these steps. | 32 // (../), return failure and abort these steps. |
31 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && | 33 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && |
32 !moduleRequest.startsWith("../")) | 34 !moduleRequest.startsWith("../")) |
33 return KURL(); | 35 return KURL(); |
34 | 36 |
35 // Step 3. Return the result of applying the URL parser to specifier with | 37 // Step 3. Return the result of applying the URL parser to specifier with |
36 // script's base URL as the base URL. | 38 // script's base URL as the base URL. |
37 DCHECK(baseURL.isValid()); | 39 DCHECK(baseURL.isValid()); |
38 KURL absoluteURL(baseURL, moduleRequest); | 40 KURL absoluteURL(baseURL, moduleRequest); |
39 if (absoluteURL.isValid()) | 41 if (absoluteURL.isValid()) |
40 return absoluteURL; | 42 return absoluteURL; |
41 | 43 |
42 return KURL(); | 44 return KURL(); |
43 } | 45 } |
44 | 46 |
45 } // namespace blink | 47 } // namespace blink |
OLD | NEW |