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