Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: third_party/WebKit/Source/core/dom/ScriptLoader.cpp

Issue 2555653002: [WIP Prototype] ES6 https://html.spec.whatwg.org/#fetch-a-single-module-script implementation (Closed)
Patch Set: WIP: ModuleLoaderClient && crafts to make it work even if notifyFinished adds another ModuleLoaderC… Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 7 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 16 matching lines...) Expand all
27 #include "bindings/core/v8/ScriptController.h" 27 #include "bindings/core/v8/ScriptController.h"
28 #include "bindings/core/v8/ScriptSourceCode.h" 28 #include "bindings/core/v8/ScriptSourceCode.h"
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/SVGNames.h" 30 #include "core/SVGNames.h"
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/dom/DocumentParserTiming.h" 32 #include "core/dom/DocumentParserTiming.h"
33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" 33 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h"
34 #include "core/dom/ScriptLoaderClient.h" 34 #include "core/dom/ScriptLoaderClient.h"
35 #include "core/dom/ScriptRunner.h" 35 #include "core/dom/ScriptRunner.h"
36 #include "core/dom/ScriptableDocumentParser.h" 36 #include "core/dom/ScriptableDocumentParser.h"
37 #include "core/dom/ModuleMap.h"
37 #include "core/dom/Text.h" 38 #include "core/dom/Text.h"
38 #include "core/events/Event.h" 39 #include "core/events/Event.h"
39 #include "core/fetch/AccessControlStatus.h" 40 #include "core/fetch/AccessControlStatus.h"
40 #include "core/fetch/FetchRequest.h" 41 #include "core/fetch/FetchRequest.h"
41 #include "core/fetch/MemoryCache.h" 42 #include "core/fetch/MemoryCache.h"
42 #include "core/fetch/ResourceFetcher.h" 43 #include "core/fetch/ResourceFetcher.h"
43 #include "core/frame/LocalFrame.h" 44 #include "core/frame/LocalFrame.h"
44 #include "core/frame/SubresourceIntegrity.h" 45 #include "core/frame/SubresourceIntegrity.h"
45 #include "core/frame/UseCounter.h" 46 #include "core/frame/UseCounter.h"
46 #include "core/frame/csp/ContentSecurityPolicy.h" 47 #include "core/frame/csp/ContentSecurityPolicy.h"
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 m_characterEncoding = elementDocument.characterSet(); 254 m_characterEncoding = elementDocument.characterSet();
254 255
255 if (client->hasSourceAttribute()) { 256 if (client->hasSourceAttribute()) {
256 FetchRequest::DeferOption defer = FetchRequest::NoDefer; 257 FetchRequest::DeferOption defer = FetchRequest::NoDefer;
257 if (!m_parserInserted || client->asyncAttributeValue() || 258 if (!m_parserInserted || client->asyncAttributeValue() ||
258 client->deferAttributeValue()) 259 client->deferAttributeValue())
259 defer = FetchRequest::LazyLoad; 260 defer = FetchRequest::LazyLoad;
260 if (m_documentWriteIntervention == 261 if (m_documentWriteIntervention ==
261 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) 262 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle)
262 defer = FetchRequest::IdleLoad; 263 defer = FetchRequest::IdleLoad;
264
263 if (!fetchScript(client->sourceAttributeValue(), defer)) 265 if (!fetchScript(client->sourceAttributeValue(), defer))
264 return false; 266 return false;
265 } 267 }
266 268
267 // Since the asynchronous, low priority fetch for doc.written blocked 269 // Since the asynchronous, low priority fetch for doc.written blocked
268 // script is not for execution, return early from here. Watch for its 270 // script is not for execution, return early from here. Watch for its
269 // completion to be able to remove it from the memory cache. 271 // completion to be able to remove it from the memory cache.
270 if (m_documentWriteIntervention == 272 if (m_documentWriteIntervention ==
271 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) { 273 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) {
272 m_pendingScript = PendingScript::create(m_element, m_resource.get()); 274 m_pendingScript = PendingScript::create(m_element, m_resource.get());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 330
329 bool ScriptLoader::fetchScript(const String& sourceUrl, 331 bool ScriptLoader::fetchScript(const String& sourceUrl,
330 FetchRequest::DeferOption defer) { 332 FetchRequest::DeferOption defer) {
331 DCHECK(m_element); 333 DCHECK(m_element);
332 334
333 Document* elementDocument = &(m_element->document()); 335 Document* elementDocument = &(m_element->document());
334 if (!m_element->isConnected() || m_element->document() != elementDocument) 336 if (!m_element->isConnected() || m_element->document() != elementDocument)
335 return false; 337 return false;
336 338
337 DCHECK(!m_resource); 339 DCHECK(!m_resource);
340
338 if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) { 341 if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) {
339 FetchRequest request( 342 KURL url = elementDocument->completeURL(sourceUrl);
340 ResourceRequest(elementDocument->completeURL(sourceUrl)), 343
341 m_element->localName()); 344 if (RuntimeEnabledFeatures::moduleScriptsEnabled() &&
345 client()->typeAttributeValue() == "module") {
346 elementDocument->ensureModuleMap()->fetch(url);
347 return true;
348 }
349
350 FetchRequest request(ResourceRequest(url), m_element->localName());
342 351
343 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue( 352 CrossOriginAttributeValue crossOrigin = crossOriginAttributeValue(
344 m_element->fastGetAttribute(HTMLNames::crossoriginAttr)); 353 m_element->fastGetAttribute(HTMLNames::crossoriginAttr));
345 if (crossOrigin != CrossOriginAttributeNotSet) 354 if (crossOrigin != CrossOriginAttributeNotSet)
346 request.setCrossOriginAccessControl(elementDocument->getSecurityOrigin(), 355 request.setCrossOriginAccessControl(elementDocument->getSecurityOrigin(),
347 crossOrigin); 356 crossOrigin);
348 request.setCharset(scriptCharset()); 357 request.setCharset(scriptCharset());
349 358
350 if (ContentSecurityPolicy::isNonceableElement(m_element.get())) { 359 if (ContentSecurityPolicy::isNonceableElement(m_element.get())) {
351 request.setContentSecurityPolicyNonce( 360 request.setContentSecurityPolicyNonce(
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 if (isHTMLScriptLoader(element)) 655 if (isHTMLScriptLoader(element))
647 return toHTMLScriptElement(element)->loader(); 656 return toHTMLScriptElement(element)->loader();
648 657
649 if (isSVGScriptLoader(element)) 658 if (isSVGScriptLoader(element))
650 return toSVGScriptElement(element)->loader(); 659 return toSVGScriptElement(element)->loader();
651 660
652 return 0; 661 return 0;
653 } 662 }
654 663
655 } // namespace blink 664 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698