OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "core/dom/ModuleMap.h" |
| 6 #include "core/fetch/ResourceFetcher.h" |
| 7 #include "core/loader/resource/ScriptResource.h" |
| 8 |
| 9 namespace blink { |
| 10 |
| 11 ModuleMap::ModuleMap(ResourceFetcher* fetcher) |
| 12 : m_fetcher(fetcher) |
| 13 { |
| 14 DCHECK(m_fetcher); |
| 15 } |
| 16 |
| 17 void ModuleMap::fetch(const KURL& url) { |
| 18 printf("ModuleMap::fetch(%s)\n", url.getString().utf8().data()); |
| 19 |
| 20 MapImpl::AddResult result = m_map.set(url, Entry()); |
| 21 Entry& entry = result.storedValue->value; |
| 22 if (!result.isNewEntry) { |
| 23 printf("not new entry\n"); |
| 24 // FIXME: If moduleMap[url] is "fetching", wait (in parallel) until that |
| 25 // entry's value changes, then proceed to the next step. |
| 26 if (entry.isFetching()) { |
| 27 // return promise? |
| 28 } |
| 29 // FIXME: If moduleMap[url] exists, asynchronously complete this algorithm |
| 30 // with moduleMap[url], and abort these steps. |
| 31 return; |
| 32 } |
| 33 |
| 34 // Step 4. Set moduleMap[url] to "fetching". => Initial entry state is |
| 35 // fetching |
| 36 |
| 37 // Step 5. Let request be a new request whose url is url, destination is |
| 38 // destination, type is "script", mode is "cors", credentials mode is |
| 39 // credentials mode, cryptographic nonce metadata is cryptographic nonce, |
| 40 // parser metadata is parser state, referrer is referrer, and client is fetch |
| 41 // client settings object. |
| 42 FetchRequest request(ResourceRequest(url), "module"); |
| 43 // request.setDefer(FetchRequest::LazyLoad); //? always async -> defer? |
| 44 Member<ScriptResource> resource = ScriptResource::fetch(request, m_fetcher.get
()); |
| 45 resource->script(); |
| 46 |
| 47 // Step 6. If the caller specified custom steps to perform the fetch, perform |
| 48 // them on request, setting the is top-level flag if the top-level module |
| 49 // fetch flag is set. Return from this algorithm, and when the custom perform |
| 50 // the fetch steps complete with response response, run the remaining steps. |
| 51 // Otherwise, fetch request. Return from this algorithm, and run the remaining |
| 52 // steps as part of the fetch's process response for the response response. |
| 53 // Note: response is always CORS-same-origin. |
| 54 |
| 55 // TODO(kouhei): yokuwakaran |
| 56 |
| 57 // Step 7. If any of the following conditions are met, set moduleMap[url] to |
| 58 // null, asynchronously complete this algorithm with null, and abort these |
| 59 // steps: |
| 60 // - response's type is "error" |
| 61 // - response's status is not an ok status |
| 62 // The result of extracting a MIME type from response's header list (ignoring |
| 63 // parameters) is not a JavaScript MIME type |
| 64 // Note: For historical reasons, fetching a classic script does not include |
| 65 // MIME type checking. In contrast, module scripts will fail to load if they |
| 66 // are not of a correct MIME type. |
| 67 |
| 68 // Step 8. Let source text be the result of UTF-8 decoding response's body. |
| 69 |
| 70 // Step 9. Let module script be the result of creating a module script given |
| 71 // source text, module map settings object, response's url, cryptographic |
| 72 // nonce, parser state, and credentials mode. |
| 73 |
| 74 // Step 10. Set moduleMap[url] to module script, and asynchronously complete |
| 75 // this algorithm with module script. |
| 76 } |
| 77 |
| 78 DEFINE_TRACE(ModuleMap) { |
| 79 visitor->trace(m_map); |
| 80 visitor->trace(m_fetcher); |
| 81 } |
| 82 |
| 83 } // namespace blink |
OLD | NEW |