OLD | NEW |
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 Loading... |
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/ClassicPendingScript.h" | 31 #include "core/dom/ClassicPendingScript.h" |
32 #include "core/dom/ClassicScript.h" | 32 #include "core/dom/ClassicScript.h" |
33 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
34 #include "core/dom/DocumentParserTiming.h" | 34 #include "core/dom/DocumentParserTiming.h" |
35 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 35 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
36 #include "core/dom/Script.h" | 36 #include "core/dom/Script.h" |
| 37 #include "core/dom/Modulator.h" |
| 38 #include "core/dom/ModuleScript.h" |
37 #include "core/dom/ScriptElementBase.h" | 39 #include "core/dom/ScriptElementBase.h" |
38 #include "core/dom/ScriptRunner.h" | 40 #include "core/dom/ScriptRunner.h" |
39 #include "core/dom/ScriptableDocumentParser.h" | 41 #include "core/dom/ScriptableDocumentParser.h" |
40 #include "core/dom/Text.h" | 42 #include "core/dom/Text.h" |
41 #include "core/events/Event.h" | 43 #include "core/events/Event.h" |
42 #include "core/frame/LocalFrame.h" | 44 #include "core/frame/LocalFrame.h" |
43 #include "core/frame/SubresourceIntegrity.h" | 45 #include "core/frame/SubresourceIntegrity.h" |
44 #include "core/frame/csp/ContentSecurityPolicy.h" | 46 #include "core/frame/csp/ContentSecurityPolicy.h" |
45 #include "core/html/CrossOriginAttribute.h" | 47 #include "core/html/CrossOriginAttribute.h" |
46 #include "core/html/imports/HTMLImport.h" | 48 #include "core/html/imports/HTMLImport.h" |
47 #include "core/html/parser/HTMLParserIdioms.h" | 49 #include "core/html/parser/HTMLParserIdioms.h" |
| 50 #include "core/loader/modulescript/ModuleScriptFetchRequest.h" |
48 #include "platform/WebFrameScheduler.h" | 51 #include "platform/WebFrameScheduler.h" |
49 #include "platform/loader/fetch/AccessControlStatus.h" | 52 #include "platform/loader/fetch/AccessControlStatus.h" |
50 #include "platform/loader/fetch/FetchRequest.h" | 53 #include "platform/loader/fetch/FetchRequest.h" |
51 #include "platform/loader/fetch/MemoryCache.h" | 54 #include "platform/loader/fetch/MemoryCache.h" |
52 #include "platform/loader/fetch/ResourceFetcher.h" | 55 #include "platform/loader/fetch/ResourceFetcher.h" |
53 #include "platform/network/mime/MIMETypeRegistry.h" | 56 #include "platform/network/mime/MIMETypeRegistry.h" |
54 #include "platform/weborigin/SecurityOrigin.h" | 57 #include "platform/weborigin/SecurityOrigin.h" |
55 #include "public/platform/WebCachePolicy.h" | 58 #include "public/platform/WebCachePolicy.h" |
56 #include "wtf/StdLibExtras.h" | 59 #include "wtf/StdLibExtras.h" |
57 #include "wtf/text/StringBuilder.h" | 60 #include "wtf/text/StringBuilder.h" |
58 #include "wtf/text/StringHash.h" | 61 #include "wtf/text/StringHash.h" |
59 | 62 |
60 namespace blink { | 63 namespace blink { |
61 | 64 |
| 65 class ScriptElementModuleClient |
| 66 : public GarbageCollectedFinalized<ScriptElementModuleClient>, |
| 67 public ModuleTreeClient { |
| 68 USING_GARBAGE_COLLECTED_MIXIN(ScriptElementModuleClient); |
| 69 |
| 70 public: |
| 71 static ScriptElementModuleClient* create(LocalFrame* frame) { |
| 72 return new ScriptElementModuleClient(frame); |
| 73 } |
| 74 virtual ~ScriptElementModuleClient() = default; |
| 75 |
| 76 DECLARE_TRACE(); |
| 77 |
| 78 private: |
| 79 ScriptElementModuleClient(LocalFrame* frame) : m_frame(frame) {} |
| 80 |
| 81 // Implements ModuleTreeClient |
| 82 void notifyModuleTreeLoadFinished(ModuleScript*) override; |
| 83 |
| 84 Member<LocalFrame> m_frame; |
| 85 }; |
| 86 |
| 87 void ScriptElementModuleClient::notifyModuleTreeLoadFinished( |
| 88 ModuleScript* moduleScript) { |
| 89 printf("notifyFinishedModuleTree!!! moduleScript: %p\n", moduleScript); |
| 90 if (!moduleScript) |
| 91 return; |
| 92 DCHECK_EQ(moduleScript->instantiationState(), |
| 93 ModuleInstantiationState::Instantiated); |
| 94 |
| 95 // TODO(kouhei): Actually we should just return w/ the prepared script here. |
| 96 // In this prototype, we will execute the module immediately just for fun. :) |
| 97 Modulator::from(m_frame.get())->executeModule(moduleScript->record()); |
| 98 } |
| 99 |
| 100 DEFINE_TRACE(ScriptElementModuleClient) { |
| 101 visitor->trace(m_frame); |
| 102 ModuleTreeClient::trace(visitor); |
| 103 } |
| 104 |
62 ScriptLoader::ScriptLoader(ScriptElementBase* element, | 105 ScriptLoader::ScriptLoader(ScriptElementBase* element, |
63 bool parserInserted, | 106 bool parserInserted, |
64 bool alreadyStarted, | 107 bool alreadyStarted, |
65 bool createdDuringDocumentWrite) | 108 bool createdDuringDocumentWrite) |
66 : m_element(element), | 109 : m_element(element), |
67 m_startLineNumber(WTF::OrdinalNumber::beforeFirst()), | 110 m_startLineNumber(WTF::OrdinalNumber::beforeFirst()), |
68 m_haveFiredLoad(false), | 111 m_haveFiredLoad(false), |
69 m_willBeParserExecuted(false), | 112 m_willBeParserExecuted(false), |
70 m_willExecuteWhenDocumentFinishedParsing(false), | 113 m_willExecuteWhenDocumentFinishedParsing(false), |
71 m_createdDuringDocumentWrite(createdDuringDocumentWrite), | 114 m_createdDuringDocumentWrite(createdDuringDocumentWrite), |
(...skipping 26 matching lines...) Expand all Loading... |
98 m_startLineNumber = | 141 m_startLineNumber = |
99 m_element->document().scriptableDocumentParser()->lineNumber(); | 142 m_element->document().scriptableDocumentParser()->lineNumber(); |
100 } | 143 } |
101 } | 144 } |
102 | 145 |
103 ScriptLoader::~ScriptLoader() {} | 146 ScriptLoader::~ScriptLoader() {} |
104 | 147 |
105 DEFINE_TRACE(ScriptLoader) { | 148 DEFINE_TRACE(ScriptLoader) { |
106 visitor->trace(m_element); | 149 visitor->trace(m_element); |
107 visitor->trace(m_resource); | 150 visitor->trace(m_resource); |
| 151 visitor->trace(m_elementModuleClient); |
108 visitor->trace(m_pendingScript); | 152 visitor->trace(m_pendingScript); |
109 PendingScriptClient::trace(visitor); | 153 PendingScriptClient::trace(visitor); |
110 } | 154 } |
111 | 155 |
112 void ScriptLoader::setFetchDocWrittenScriptDeferIdle() { | 156 void ScriptLoader::setFetchDocWrittenScriptDeferIdle() { |
113 DCHECK(!m_createdDuringDocumentWrite); | 157 DCHECK(!m_createdDuringDocumentWrite); |
114 m_documentWriteIntervention = | 158 m_documentWriteIntervention = |
115 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle; | 159 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle; |
116 } | 160 } |
117 | 161 |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 const String& encoding, | 528 const String& encoding, |
485 FetchRequest::DeferOption defer) { | 529 FetchRequest::DeferOption defer) { |
486 Document* elementDocument = &(m_element->document()); | 530 Document* elementDocument = &(m_element->document()); |
487 if (!m_element->isConnected() || m_element->document() != elementDocument) | 531 if (!m_element->isConnected() || m_element->document() != elementDocument) |
488 return false; | 532 return false; |
489 | 533 |
490 DCHECK(!m_resource); | 534 DCHECK(!m_resource); |
491 // 21. "If the element has a src content attribute, run these substeps:" | 535 // 21. "If the element has a src content attribute, run these substeps:" |
492 if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) { | 536 if (!stripLeadingAndTrailingHTMLSpaces(sourceUrl).isEmpty()) { |
493 // 21.4. "Parse src relative to the element's node document." | 537 // 21.4. "Parse src relative to the element's node document." |
494 ResourceRequest resourceRequest(elementDocument->completeURL(sourceUrl)); | 538 KURL url = elementDocument->completeURL(sourceUrl); |
| 539 ResourceRequest resourceRequest(url); |
495 | 540 |
496 // [Intervention] | 541 // [Intervention] |
497 if (m_documentWriteIntervention == | 542 if (m_documentWriteIntervention == |
498 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) { | 543 DocumentWriteIntervention::FetchDocWrittenScriptDeferIdle) { |
499 resourceRequest.setHTTPHeaderField( | 544 resourceRequest.setHTTPHeaderField( |
500 "Intervention", | 545 "Intervention", |
501 "<https://www.chromestatus.com/feature/5718547946799104>"); | 546 "<https://www.chromestatus.com/feature/5718547946799104>"); |
502 } | 547 } |
503 | 548 |
504 FetchRequest request(resourceRequest, m_element->initiatorName()); | 549 FetchRequest request(resourceRequest, m_element->initiatorName()); |
505 | 550 |
506 // 15. "Let CORS setting be the current state of the element's | 551 // 15. "Let CORS setting be the current state of the element's |
507 // crossorigin content attribute." | 552 // crossorigin content attribute." |
508 CrossOriginAttributeValue crossOrigin = | 553 CrossOriginAttributeValue crossOrigin = |
509 crossOriginAttributeValue(m_element->crossOriginAttributeValue()); | 554 crossOriginAttributeValue(m_element->crossOriginAttributeValue()); |
510 | 555 |
511 // 16. "Let module script credentials mode be determined by switching | 556 // 16. "Let module script credentials mode be determined by switching |
512 // on CORS setting:" | 557 // on CORS setting:" |
513 // TODO(hiroshige): Implement this step for "module". | 558 // TODO(hiroshige): Implement this step for "module". |
| 559 if (RuntimeEnabledFeatures::moduleScriptsEnabled() && |
| 560 m_element->typeAttributeValue() == "module") { |
| 561 m_elementModuleClient = ScriptElementModuleClient::create( |
| 562 elementDocument->contextDocument()->frame()); |
| 563 |
| 564 String nonce; |
| 565 if (m_element->isNonceableElement()) |
| 566 nonce = m_element->nonce(); |
| 567 ParserDisposition parserState = |
| 568 isParserInserted() ? ParserInserted : NotParserInserted; |
| 569 |
| 570 // 16. "Let module script credentials mode be determined by switching |
| 571 // on CORS setting:" |
| 572 WebURLRequest::FetchCredentialsMode credentialsMode; |
| 573 switch (crossOrigin) { |
| 574 case CrossOriginAttributeNotSet: |
| 575 credentialsMode = WebURLRequest::FetchCredentialsModeOmit; |
| 576 break; |
| 577 case CrossOriginAttributeAnonymous: |
| 578 credentialsMode = WebURLRequest::FetchCredentialsModeSameOrigin; |
| 579 break; |
| 580 case CrossOriginAttributeUseCredentials: |
| 581 credentialsMode = WebURLRequest::FetchCredentialsModeInclude; |
| 582 break; |
| 583 default: |
| 584 NOTREACHED(); |
| 585 } |
| 586 |
| 587 ModuleScriptFetchRequest moduleRequest(url, nonce, parserState, |
| 588 credentialsMode); |
| 589 Modulator::from(elementDocument->frame()) |
| 590 ->fetchTree(moduleRequest, m_elementModuleClient); |
| 591 return true; |
| 592 } |
514 | 593 |
515 // 21.6, "classic": "Fetch a classic script given ... CORS setting | 594 // 21.6, "classic": "Fetch a classic script given ... CORS setting |
516 // ... and encoding." | 595 // ... and encoding." |
517 if (crossOrigin != CrossOriginAttributeNotSet) | 596 if (crossOrigin != CrossOriginAttributeNotSet) |
518 request.setCrossOriginAccessControl(elementDocument->getSecurityOrigin(), | 597 request.setCrossOriginAccessControl(elementDocument->getSecurityOrigin(), |
519 crossOrigin); | 598 crossOrigin); |
520 | 599 |
521 request.setCharset(encoding); | 600 request.setCharset(encoding); |
522 | 601 |
523 // 17. "If the script element has a nonce attribute, | 602 // 17. "If the script element has a nonce attribute, |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 // then abort these steps at this point. The script is not executed. | 855 // then abort these steps at this point. The script is not executed. |
777 return equalIgnoringCase(eventAttribute, "onload") || | 856 return equalIgnoringCase(eventAttribute, "onload") || |
778 equalIgnoringCase(eventAttribute, "onload()"); | 857 equalIgnoringCase(eventAttribute, "onload()"); |
779 } | 858 } |
780 | 859 |
781 String ScriptLoader::scriptContent() const { | 860 String ScriptLoader::scriptContent() const { |
782 return m_element->textFromChildren(); | 861 return m_element->textFromChildren(); |
783 } | 862 } |
784 | 863 |
785 } // namespace blink | 864 } // namespace blink |
OLD | NEW |