Chromium Code Reviews| 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 namespace { |
| 12 const char* kPerContextDataKey = "Modulator"; | |
|
dcheng
2017/04/05 21:13:29
Drive-by:
const char kPerContextDataKey[] = "Modul
adithyas
2017/04/05 21:45:36
Fixed, nice catch :)
| |
| 13 | |
| 14 V8PerContextData* getPerContextData(LocalFrame* frame) { | |
|
haraken
2017/04/05 02:08:10
I'm not sure if it makes sense to let Modulator ta
kouhei (in TOK)
2017/04/05 02:09:05
Ah. This completely makes sense to me.
adithyas
2017/04/05 21:45:36
Yeah, ScriptState sounds appropriate, and it remov
| |
| 12 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 15 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 13 if (!scriptState) | 16 if (!scriptState) |
| 14 return nullptr; | 17 return nullptr; |
| 15 // TODO(kouhei): setModulator in V8PerContextData when we land ModulatorImpl. | 18 return scriptState->perContextData(); |
| 16 return scriptState->perContextData()->modulator(); | 19 } |
| 20 } // namespace | |
| 21 | |
| 22 Modulator* Modulator::from(LocalFrame* frame) { | |
| 23 return from(getPerContextData(frame)); | |
| 24 } | |
| 25 | |
| 26 Modulator* Modulator::from(V8PerContextData* perContextData) { | |
|
haraken
2017/04/05 02:08:10
Ditto. It would be nicer to pass in a ScriptState*
jbroman
2017/04/05 21:07:00
+1; ScriptState seems nicer here (and it's cheap t
| |
| 27 if (!perContextData) | |
| 28 return nullptr; | |
| 29 return static_cast<Modulator*>(perContextData->getData(kPerContextDataKey)); | |
| 17 } | 30 } |
| 18 | 31 |
| 19 Modulator::~Modulator() {} | 32 Modulator::~Modulator() {} |
| 20 | 33 |
| 34 void Modulator::setModulator(LocalFrame* frame, Modulator* modulator) { | |
| 35 V8PerContextData* perContextData = getPerContextData(frame); | |
| 36 DCHECK(perContextData); | |
| 37 perContextData->addData(kPerContextDataKey, modulator); | |
| 38 } | |
| 39 | |
| 40 void Modulator::clearModulator(LocalFrame* frame) { | |
| 41 V8PerContextData* perContextData = getPerContextData(frame); | |
| 42 DCHECK(perContextData); | |
| 43 perContextData->clearData(kPerContextDataKey); | |
| 44 } | |
| 45 | |
| 21 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest, | 46 KURL Modulator::resolveModuleSpecifier(const String& moduleRequest, |
| 22 const KURL& baseURL) { | 47 const KURL& baseURL) { |
| 23 // Step 1. Apply the URL parser to specifier. If the result is not failure, | 48 // Step 1. Apply the URL parser to specifier. If the result is not failure, |
| 24 // return the result. | 49 // return the result. |
| 25 KURL url(KURL(), moduleRequest); | 50 KURL url(KURL(), moduleRequest); |
| 26 if (url.isValid()) | 51 if (url.isValid()) |
| 27 return url; | 52 return url; |
| 28 | 53 |
| 29 // Step 2. If specifier does not start with the character U+002F SOLIDUS (/), | 54 // Step 2. If specifier does not start with the character U+002F SOLIDUS (/), |
| 30 // the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the | 55 // the two-character sequence U+002E FULL STOP, U+002F SOLIDUS (./), or the |
| 31 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS | 56 // three-character sequence U+002E FULL STOP, U+002E FULL STOP, U+002F SOLIDUS |
| 32 // (../), return failure and abort these steps. | 57 // (../), return failure and abort these steps. |
| 33 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && | 58 if (!moduleRequest.startsWith("/") && !moduleRequest.startsWith("./") && |
| 34 !moduleRequest.startsWith("../")) | 59 !moduleRequest.startsWith("../")) |
| 35 return KURL(); | 60 return KURL(); |
| 36 | 61 |
| 37 // Step 3. Return the result of applying the URL parser to specifier with | 62 // Step 3. Return the result of applying the URL parser to specifier with |
| 38 // script's base URL as the base URL. | 63 // script's base URL as the base URL. |
| 39 DCHECK(baseURL.isValid()); | 64 DCHECK(baseURL.isValid()); |
| 40 KURL absoluteURL(baseURL, moduleRequest); | 65 KURL absoluteURL(baseURL, moduleRequest); |
| 41 if (absoluteURL.isValid()) | 66 if (absoluteURL.isValid()) |
| 42 return absoluteURL; | 67 return absoluteURL; |
| 43 | 68 |
| 44 return KURL(); | 69 return KURL(); |
| 45 } | 70 } |
| 46 | 71 |
| 47 } // namespace blink | 72 } // namespace blink |
| OLD | NEW |