| 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 11 matching lines...) Expand all Loading... |
| 22 * Boston, MA 02110-1301, USA. | 22 * Boston, MA 02110-1301, USA. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #include "core/dom/ScriptLoader.h" | 25 #include "core/dom/ScriptLoader.h" |
| 26 | 26 |
| 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 "bindings/core/v8/V8Binding.h" | 29 #include "bindings/core/v8/V8Binding.h" |
| 30 #include "core/HTMLNames.h" | 30 #include "core/HTMLNames.h" |
| 31 #include "core/SVGNames.h" | 31 #include "core/SVGNames.h" |
| 32 #include "core/dom/ClassicScript.h" |
| 32 #include "core/dom/Document.h" | 33 #include "core/dom/Document.h" |
| 33 #include "core/dom/DocumentParserTiming.h" | 34 #include "core/dom/DocumentParserTiming.h" |
| 34 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" | 35 #include "core/dom/IgnoreDestructiveWriteCountIncrementer.h" |
| 36 #include "core/dom/Script.h" |
| 35 #include "core/dom/ScriptElementBase.h" | 37 #include "core/dom/ScriptElementBase.h" |
| 36 #include "core/dom/ScriptRunner.h" | 38 #include "core/dom/ScriptRunner.h" |
| 37 #include "core/dom/ScriptableDocumentParser.h" | 39 #include "core/dom/ScriptableDocumentParser.h" |
| 38 #include "core/dom/Text.h" | 40 #include "core/dom/Text.h" |
| 39 #include "core/events/Event.h" | 41 #include "core/events/Event.h" |
| 40 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
| 41 #include "core/frame/SubresourceIntegrity.h" | 43 #include "core/frame/SubresourceIntegrity.h" |
| 42 #include "core/frame/UseCounter.h" | |
| 43 #include "core/frame/csp/ContentSecurityPolicy.h" | 44 #include "core/frame/csp/ContentSecurityPolicy.h" |
| 44 #include "core/html/CrossOriginAttribute.h" | 45 #include "core/html/CrossOriginAttribute.h" |
| 45 #include "core/html/imports/HTMLImport.h" | 46 #include "core/html/imports/HTMLImport.h" |
| 46 #include "core/html/parser/HTMLParserIdioms.h" | 47 #include "core/html/parser/HTMLParserIdioms.h" |
| 47 #include "core/inspector/ConsoleMessage.h" | |
| 48 #include "platform/WebFrameScheduler.h" | 48 #include "platform/WebFrameScheduler.h" |
| 49 #include "platform/loader/fetch/AccessControlStatus.h" | 49 #include "platform/loader/fetch/AccessControlStatus.h" |
| 50 #include "platform/loader/fetch/FetchRequest.h" | 50 #include "platform/loader/fetch/FetchRequest.h" |
| 51 #include "platform/loader/fetch/MemoryCache.h" | 51 #include "platform/loader/fetch/MemoryCache.h" |
| 52 #include "platform/loader/fetch/ResourceFetcher.h" | 52 #include "platform/loader/fetch/ResourceFetcher.h" |
| 53 #include "platform/network/mime/MIMETypeRegistry.h" | 53 #include "platform/network/mime/MIMETypeRegistry.h" |
| 54 #include "platform/weborigin/SecurityOrigin.h" | 54 #include "platform/weborigin/SecurityOrigin.h" |
| 55 #include "public/platform/WebCachePolicy.h" | 55 #include "public/platform/WebCachePolicy.h" |
| 56 #include "wtf/StdLibExtras.h" | 56 #include "wtf/StdLibExtras.h" |
| 57 #include "wtf/text/StringBuilder.h" | 57 #include "wtf/text/StringBuilder.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 m_nonBlocking = false; | 140 m_nonBlocking = false; |
| 141 } | 141 } |
| 142 | 142 |
| 143 void ScriptLoader::detachPendingScript() { | 143 void ScriptLoader::detachPendingScript() { |
| 144 if (!m_pendingScript) | 144 if (!m_pendingScript) |
| 145 return; | 145 return; |
| 146 m_pendingScript->dispose(); | 146 m_pendingScript->dispose(); |
| 147 m_pendingScript = nullptr; | 147 m_pendingScript = nullptr; |
| 148 } | 148 } |
| 149 | 149 |
| 150 static bool isLegacySupportedJavaScriptLanguage(const String& language) { | |
| 151 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only | |
| 152 // javascript1.1 - javascript1.3. | |
| 153 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. | |
| 154 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. | |
| 155 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. | |
| 156 // We want to accept all the values that either of these browsers accept, but | |
| 157 // not other values. | |
| 158 | |
| 159 // FIXME: This function is not HTML5 compliant. These belong in the MIME | |
| 160 // registry as "text/javascript<version>" entries. | |
| 161 return equalIgnoringASCIICase(language, "javascript") || | |
| 162 equalIgnoringASCIICase(language, "javascript1.0") || | |
| 163 equalIgnoringASCIICase(language, "javascript1.1") || | |
| 164 equalIgnoringASCIICase(language, "javascript1.2") || | |
| 165 equalIgnoringASCIICase(language, "javascript1.3") || | |
| 166 equalIgnoringASCIICase(language, "javascript1.4") || | |
| 167 equalIgnoringASCIICase(language, "javascript1.5") || | |
| 168 equalIgnoringASCIICase(language, "javascript1.6") || | |
| 169 equalIgnoringASCIICase(language, "javascript1.7") || | |
| 170 equalIgnoringASCIICase(language, "livescript") || | |
| 171 equalIgnoringASCIICase(language, "ecmascript") || | |
| 172 equalIgnoringASCIICase(language, "jscript"); | |
| 173 } | |
| 174 | |
| 175 void ScriptLoader::dispatchErrorEvent() { | 150 void ScriptLoader::dispatchErrorEvent() { |
| 176 m_element->dispatchErrorEvent(); | 151 m_element->dispatchErrorEvent(); |
| 177 } | 152 } |
| 178 | 153 |
| 179 void ScriptLoader::dispatchLoadEvent() { | 154 void ScriptLoader::dispatchLoadEvent() { |
| 180 m_element->dispatchLoadEvent(); | 155 m_element->dispatchLoadEvent(); |
| 181 setHaveFiredLoadEvent(true); | 156 setHaveFiredLoadEvent(true); |
| 182 } | 157 } |
| 183 | 158 |
| 184 bool ScriptLoader::isValidScriptTypeAndLanguage( | 159 bool ScriptLoader::isValidScriptTypeAndLanguage( |
| 185 const String& type, | 160 const String& type, |
| 186 const String& language, | 161 const String& language, |
| 187 LegacyTypeSupport supportLegacyTypes) { | 162 LegacyTypeSupport supportLegacyTypes) { |
| 188 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is used | 163 // FIXME: isLegacySupportedJavaScriptLanguage() is not valid HTML5. It is used |
| 189 // here to maintain backwards compatibility with existing layout tests. The | 164 // here to maintain backwards compatibility with existing layout tests. The |
| 190 // specific violations are: | 165 // specific violations are: |
| 191 // - Allowing type=javascript. type= should only support MIME types, such as | 166 // - Allowing type=javascript. type= should only support MIME types, such as |
| 192 // text/javascript. | 167 // text/javascript. |
| 193 // - Allowing a different set of languages for language= and type=. language= | 168 // - Allowing a different set of languages for language= and type=. language= |
| 194 // supports Javascript 1.1 and 1.4-1.6, but type= does not. | 169 // supports Javascript 1.1 and 1.4-1.6, but type= does not. |
| 195 if (type.isEmpty()) { | 170 if (type.isEmpty()) { |
| 196 return language.isEmpty() || // assume text/javascript. | 171 return language.isEmpty() || // assume text/javascript. |
| 197 MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + | 172 MIMETypeRegistry::isSupportedJavaScriptMIMEType("text/" + |
| 198 language) || | 173 language) || |
| 199 isLegacySupportedJavaScriptLanguage(language); | 174 MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(language); |
| 200 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && | 175 } else if (RuntimeEnabledFeatures::moduleScriptsEnabled() && |
| 201 type == "module") { | 176 type == "module") { |
| 202 return true; | 177 return true; |
| 203 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType( | 178 } else if (MIMETypeRegistry::isSupportedJavaScriptMIMEType( |
| 204 type.stripWhiteSpace()) || | 179 type.stripWhiteSpace()) || |
| 205 (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && | 180 (supportLegacyTypes == AllowLegacyTypeInTypeAttribute && |
| 206 isLegacySupportedJavaScriptLanguage(type))) { | 181 MIMETypeRegistry::isLegacySupportedJavaScriptLanguage(type))) { |
| 207 return true; | 182 return true; |
| 208 } | 183 } |
| 209 | 184 |
| 210 return false; | 185 return false; |
| 211 } | 186 } |
| 212 | 187 |
| 213 bool ScriptLoader::isScriptTypeSupported( | 188 bool ScriptLoader::isScriptTypeSupported( |
| 214 LegacyTypeSupport supportLegacyTypes) const { | 189 LegacyTypeSupport supportLegacyTypes) const { |
| 215 return isValidScriptTypeAndLanguage(m_element->typeAttributeValue(), | 190 return isValidScriptTypeAndLanguage(m_element->typeAttributeValue(), |
| 216 m_element->languageAttributeValue(), | 191 m_element->languageAttributeValue(), |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 // and the element doesn't have a src attribute. | 466 // and the element doesn't have a src attribute. |
| 492 | 467 |
| 493 // Reset line numbering for nested writes. | 468 // Reset line numbering for nested writes. |
| 494 TextPosition position = elementDocument.isInDocumentWrite() | 469 TextPosition position = elementDocument.isInDocumentWrite() |
| 495 ? TextPosition() | 470 ? TextPosition() |
| 496 : scriptStartPosition; | 471 : scriptStartPosition; |
| 497 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInserted) | 472 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInserted) |
| 498 ? elementDocument.url() | 473 ? elementDocument.url() |
| 499 : KURL(); | 474 : KURL(); |
| 500 | 475 |
| 501 if (!executeScript(ScriptSourceCode(scriptContent(), scriptURL, position))) { | 476 if (!executeScript(ClassicScript::create( |
| 477 ScriptSourceCode(scriptContent(), scriptURL, position)))) { |
| 502 dispatchErrorEvent(); | 478 dispatchErrorEvent(); |
| 503 return false; | 479 return false; |
| 504 } | 480 } |
| 505 | 481 |
| 506 return true; | 482 return true; |
| 507 } | 483 } |
| 508 | 484 |
| 509 // Steps 15--21 of https://html.spec.whatwg.org/#prepare-a-script | 485 // Steps 15--21 of https://html.spec.whatwg.org/#prepare-a-script |
| 510 bool ScriptLoader::fetchScript(const String& sourceUrl, | 486 bool ScriptLoader::fetchScript(const String& sourceUrl, |
| 511 const String& encoding, | 487 const String& encoding, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 if (m_createdDuringDocumentWrite && | 588 if (m_createdDuringDocumentWrite && |
| 613 m_resource->resourceRequest().getCachePolicy() == | 589 m_resource->resourceRequest().getCachePolicy() == |
| 614 WebCachePolicy::ReturnCacheDataDontLoad) { | 590 WebCachePolicy::ReturnCacheDataDontLoad) { |
| 615 m_documentWriteIntervention = | 591 m_documentWriteIntervention = |
| 616 DocumentWriteIntervention::DoNotFetchDocWrittenScript; | 592 DocumentWriteIntervention::DoNotFetchDocWrittenScript; |
| 617 } | 593 } |
| 618 | 594 |
| 619 return true; | 595 return true; |
| 620 } | 596 } |
| 621 | 597 |
| 622 void ScriptLoader::logScriptMIMEType(LocalFrame* frame, | 598 bool ScriptLoader::executeScript(const Script* script) { |
| 623 ScriptResource* resource, | |
| 624 const String& mimeType) { | |
| 625 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType)) | |
| 626 return; | |
| 627 bool isText = mimeType.startsWith("text/", TextCaseASCIIInsensitive); | |
| 628 if (isText && isLegacySupportedJavaScriptLanguage(mimeType.substring(5))) | |
| 629 return; | |
| 630 bool isSameOrigin = | |
| 631 m_element->document().getSecurityOrigin()->canRequest(resource->url()); | |
| 632 bool isApplication = | |
| 633 !isText && mimeType.startsWith("application/", TextCaseASCIIInsensitive); | |
| 634 | |
| 635 UseCounter::Feature feature = | |
| 636 isSameOrigin | |
| 637 ? (isText ? UseCounter::SameOriginTextScript | |
| 638 : isApplication ? UseCounter::SameOriginApplicationScript | |
| 639 : UseCounter::SameOriginOtherScript) | |
| 640 : (isText ? UseCounter::CrossOriginTextScript | |
| 641 : isApplication ? UseCounter::CrossOriginApplicationScript | |
| 642 : UseCounter::CrossOriginOtherScript); | |
| 643 | |
| 644 UseCounter::count(frame, feature); | |
| 645 } | |
| 646 | |
| 647 bool ScriptLoader::executeScript(const ScriptSourceCode& sourceCode) { | |
| 648 double scriptExecStartTime = monotonicallyIncreasingTime(); | 599 double scriptExecStartTime = monotonicallyIncreasingTime(); |
| 649 bool result = doExecuteScript(sourceCode); | 600 bool result = doExecuteScript(script); |
| 650 | 601 |
| 651 // NOTE: we do not check m_willBeParserExecuted here, since | 602 // NOTE: we do not check m_willBeParserExecuted here, since |
| 652 // m_willBeParserExecuted is false for inline scripts, and we want to | 603 // m_willBeParserExecuted is false for inline scripts, and we want to |
| 653 // include inline script execution time as part of parser blocked script | 604 // include inline script execution time as part of parser blocked script |
| 654 // execution time. | 605 // execution time. |
| 655 if (m_asyncExecType == ScriptRunner::None) | 606 if (m_asyncExecType == ScriptRunner::None) |
| 656 DocumentParserTiming::from(m_element->document()) | 607 DocumentParserTiming::from(m_element->document()) |
| 657 .recordParserBlockedOnScriptExecutionDuration( | 608 .recordParserBlockedOnScriptExecutionDuration( |
| 658 monotonicallyIncreasingTime() - scriptExecStartTime, | 609 monotonicallyIncreasingTime() - scriptExecStartTime, |
| 659 wasCreatedDuringDocumentWrite()); | 610 wasCreatedDuringDocumentWrite()); |
| 660 return result; | 611 return result; |
| 661 } | 612 } |
| 662 | 613 |
| 663 // https://html.spec.whatwg.org/#execute-the-script-block | 614 // https://html.spec.whatwg.org/#execute-the-script-block |
| 664 // with additional support for HTML imports. | 615 // with additional support for HTML imports. |
| 665 // Note that Steps 2 and 8 must be handled by the caller of doExecuteScript(), | 616 // Note that Steps 2 and 8 must be handled by the caller of doExecuteScript(), |
| 666 // i.e. load/error events are dispatched by the caller. | 617 // i.e. load/error events are dispatched by the caller. |
| 667 // Steps 3--7 are implemented here in doExecuteScript(). | 618 // Steps 3--7 are implemented here in doExecuteScript(). |
| 668 // TODO(hiroshige): Move event dispatching code to doExecuteScript(). | 619 // TODO(hiroshige): Move event dispatching code to doExecuteScript(). |
| 669 bool ScriptLoader::doExecuteScript(const ScriptSourceCode& sourceCode) { | 620 bool ScriptLoader::doExecuteScript(const Script* script) { |
| 670 DCHECK(m_alreadyStarted); | 621 DCHECK(m_alreadyStarted); |
| 671 | 622 |
| 672 if (sourceCode.isEmpty()) | 623 if (script->isEmpty()) |
| 673 return true; | 624 return true; |
| 674 | 625 |
| 675 Document* elementDocument = &(m_element->document()); | 626 Document* elementDocument = &(m_element->document()); |
| 676 Document* contextDocument = elementDocument->contextDocument(); | 627 Document* contextDocument = elementDocument->contextDocument(); |
| 677 if (!contextDocument) | 628 if (!contextDocument) |
| 678 return true; | 629 return true; |
| 679 | 630 |
| 680 LocalFrame* frame = contextDocument->frame(); | 631 LocalFrame* frame = contextDocument->frame(); |
| 681 if (!frame) | 632 if (!frame) |
| 682 return true; | 633 return true; |
| 683 | 634 |
| 684 const ContentSecurityPolicy* csp = elementDocument->contentSecurityPolicy(); | 635 if (!m_isExternalScript) { |
| 685 bool shouldBypassMainWorldCSP = | 636 const ContentSecurityPolicy* csp = elementDocument->contentSecurityPolicy(); |
| 686 (frame->script().shouldBypassMainWorldCSP()) || | 637 bool shouldBypassMainWorldCSP = |
| 687 csp->allowScriptWithHash(sourceCode.source(), | 638 frame->script().shouldBypassMainWorldCSP() || |
| 688 ContentSecurityPolicy::InlineType::Block); | 639 csp->allowScriptWithHash(script->inlineSourceTextForCSP(), |
| 640 ContentSecurityPolicy::InlineType::Block); |
| 689 | 641 |
| 690 AtomicString nonce = | 642 AtomicString nonce = |
| 691 m_element->isNonceableElement() ? m_element->nonce() : nullAtom; | 643 m_element->isNonceableElement() ? m_element->nonce() : nullAtom; |
| 692 if (!m_isExternalScript && !shouldBypassMainWorldCSP && | 644 |
| 693 !m_element->allowInlineScriptForCSP(nonce, m_startLineNumber, | 645 if (!shouldBypassMainWorldCSP && |
| 694 sourceCode.source())) { | 646 !m_element->allowInlineScriptForCSP(nonce, m_startLineNumber, |
| 695 return false; | 647 script->inlineSourceTextForCSP())) { |
| 648 return false; |
| 649 } |
| 696 } | 650 } |
| 697 | 651 |
| 698 if (m_isExternalScript) { | 652 if (m_isExternalScript) { |
| 699 ScriptResource* resource = sourceCode.resource(); | 653 if (!script->checkMIMETypeBeforeRunScript( |
| 700 CHECK_EQ(resource, m_resource); | 654 contextDocument, m_element->document().getSecurityOrigin())) |
| 701 CHECK(resource); | |
| 702 if (!ScriptResource::mimeTypeAllowedByNosniff(resource->response())) { | |
| 703 contextDocument->addConsoleMessage(ConsoleMessage::create( | |
| 704 SecurityMessageSource, ErrorMessageLevel, | |
| 705 "Refused to execute script from '" + resource->url().elidedString() + | |
| 706 "' because its MIME type ('" + resource->httpContentType() + | |
| 707 "') is not executable, and " | |
| 708 "strict MIME type checking is " | |
| 709 "enabled.")); | |
| 710 return false; | 655 return false; |
| 711 } | |
| 712 | |
| 713 String mimeType = resource->httpContentType(); | |
| 714 if (mimeType.startsWith("image/") || mimeType == "text/csv" || | |
| 715 mimeType.startsWith("audio/") || mimeType.startsWith("video/")) { | |
| 716 contextDocument->addConsoleMessage(ConsoleMessage::create( | |
| 717 SecurityMessageSource, ErrorMessageLevel, | |
| 718 "Refused to execute script from '" + resource->url().elidedString() + | |
| 719 "' because its MIME type ('" + mimeType + | |
| 720 "') is not executable.")); | |
| 721 if (mimeType.startsWith("image/")) | |
| 722 UseCounter::count(frame, UseCounter::BlockedSniffingImageToScript); | |
| 723 else if (mimeType.startsWith("audio/")) | |
| 724 UseCounter::count(frame, UseCounter::BlockedSniffingAudioToScript); | |
| 725 else if (mimeType.startsWith("video/")) | |
| 726 UseCounter::count(frame, UseCounter::BlockedSniffingVideoToScript); | |
| 727 else if (mimeType == "text/csv") | |
| 728 UseCounter::count(frame, UseCounter::BlockedSniffingCSVToScript); | |
| 729 return false; | |
| 730 } | |
| 731 | |
| 732 logScriptMIMEType(frame, resource, mimeType); | |
| 733 } | |
| 734 | |
| 735 AccessControlStatus accessControlStatus = NotSharableCrossOrigin; | |
| 736 if (!m_isExternalScript) { | |
| 737 accessControlStatus = SharableCrossOrigin; | |
| 738 } else { | |
| 739 CHECK(sourceCode.resource()); | |
| 740 accessControlStatus = sourceCode.resource()->calculateAccessControlStatus( | |
| 741 m_element->document().getSecurityOrigin()); | |
| 742 } | 656 } |
| 743 | 657 |
| 744 const bool isImportedScript = contextDocument != elementDocument; | 658 const bool isImportedScript = contextDocument != elementDocument; |
| 745 | 659 |
| 746 // 3. "If the script is from an external file, | 660 // 3. "If the script is from an external file, |
| 747 // or the script's type is module", | 661 // or the script's type is module", |
| 748 // then increment the ignore-destructive-writes counter of the | 662 // then increment the ignore-destructive-writes counter of the |
| 749 // script element's node document. Let neutralized doc be that Document." | 663 // script element's node document. Let neutralized doc be that Document." |
| 750 // TODO(hiroshige): Implement "module" case. | 664 // TODO(hiroshige): Implement "module" case. |
| 751 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer( | 665 IgnoreDestructiveWriteCountIncrementer ignoreDestructiveWriteCountIncrementer( |
| 752 m_isExternalScript || isImportedScript ? contextDocument : 0); | 666 m_isExternalScript || isImportedScript ? contextDocument : 0); |
| 753 | 667 |
| 754 // 4. "Let old script element be the value to which the script element's | 668 // 4. "Let old script element be the value to which the script element's |
| 755 // node document's currentScript object was most recently set." | 669 // node document's currentScript object was most recently set." |
| 756 // This is implemented as push/popCurrentScript(). | 670 // This is implemented as push/popCurrentScript(). |
| 757 | 671 |
| 758 // 5. "Switch on the script's type:" | 672 // 5. "Switch on the script's type:" |
| 759 // - "classic": | 673 // - "classic": |
| 760 // 1. "If the script element's root is not a shadow root, | 674 // 1. "If the script element's root is not a shadow root, |
| 761 // then set the script element's node document's currentScript | 675 // then set the script element's node document's currentScript |
| 762 // attribute to the script element. Otherwise, set it to null." | 676 // attribute to the script element. Otherwise, set it to null." |
| 763 contextDocument->pushCurrentScript(m_element.get()); | 677 contextDocument->pushCurrentScript(m_element.get()); |
| 764 | 678 |
| 765 // 2. "Run the classic script given by the script's script." | 679 // 2. "Run the classic script given by the script's script." |
| 766 // Note: This is where the script is compiled and actually executed. | 680 // Note: This is where the script is compiled and actually executed. |
| 767 frame->script().executeScriptInMainWorld(sourceCode, accessControlStatus); | 681 script->runScript(frame, m_element->document().getSecurityOrigin()); |
| 768 | 682 |
| 769 // - "module": | 683 // - "module": |
| 770 // TODO(hiroshige): Implement this. | 684 // TODO(hiroshige): Implement this. |
| 771 | 685 |
| 772 // 6. "Set the script element's node document's currentScript attribute | 686 // 6. "Set the script element's node document's currentScript attribute |
| 773 // to old script element." | 687 // to old script element." |
| 774 contextDocument->popCurrentScript(m_element.get()); | 688 contextDocument->popCurrentScript(m_element.get()); |
| 775 | 689 |
| 776 return true; | 690 return true; |
| 777 | 691 |
| 778 // 7. "Decrement the ignore-destructive-writes counter of neutralized doc, | 692 // 7. "Decrement the ignore-destructive-writes counter of neutralized doc, |
| 779 // if it was incremented in the earlier step." | 693 // if it was incremented in the earlier step." |
| 780 // Implemented as the scope out of IgnoreDestructiveWriteCountIncrementer. | 694 // Implemented as the scope out of IgnoreDestructiveWriteCountIncrementer. |
| 781 } | 695 } |
| 782 | 696 |
| 783 void ScriptLoader::execute() { | 697 void ScriptLoader::execute() { |
| 784 DCHECK(!m_willBeParserExecuted); | 698 DCHECK(!m_willBeParserExecuted); |
| 785 DCHECK(m_asyncExecType != ScriptRunner::None); | 699 DCHECK(m_asyncExecType != ScriptRunner::None); |
| 786 DCHECK(m_pendingScript->resource()); | 700 DCHECK(m_pendingScript->resource()); |
| 787 bool errorOccurred = false; | 701 bool errorOccurred = false; |
| 788 ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred); | 702 Script* script = m_pendingScript->getSource(KURL(), errorOccurred); |
| 789 detachPendingScript(); | 703 detachPendingScript(); |
| 790 if (errorOccurred) { | 704 if (errorOccurred) { |
| 791 dispatchErrorEvent(); | 705 dispatchErrorEvent(); |
| 792 } else if (!m_resource->wasCanceled()) { | 706 } else if (!m_resource->wasCanceled()) { |
| 793 if (executeScript(source)) | 707 if (executeScript(script)) |
| 794 dispatchLoadEvent(); | 708 dispatchLoadEvent(); |
| 795 else | 709 else |
| 796 dispatchErrorEvent(); | 710 dispatchErrorEvent(); |
| 797 } | 711 } |
| 798 m_resource = nullptr; | 712 m_resource = nullptr; |
| 799 } | 713 } |
| 800 | 714 |
| 801 void ScriptLoader::pendingScriptFinished(PendingScript* pendingScript) { | 715 void ScriptLoader::pendingScriptFinished(PendingScript* pendingScript) { |
| 802 DCHECK(!m_willBeParserExecuted); | 716 DCHECK(!m_willBeParserExecuted); |
| 803 DCHECK_EQ(m_pendingScript, pendingScript); | 717 DCHECK_EQ(m_pendingScript, pendingScript); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 // then abort these steps at this point. The script is not executed. | 778 // then abort these steps at this point. The script is not executed. |
| 865 return equalIgnoringCase(eventAttribute, "onload") || | 779 return equalIgnoringCase(eventAttribute, "onload") || |
| 866 equalIgnoringCase(eventAttribute, "onload()"); | 780 equalIgnoringCase(eventAttribute, "onload()"); |
| 867 } | 781 } |
| 868 | 782 |
| 869 String ScriptLoader::scriptContent() const { | 783 String ScriptLoader::scriptContent() const { |
| 870 return m_element->textFromChildren(); | 784 return m_element->textFromChildren(); |
| 871 } | 785 } |
| 872 | 786 |
| 873 } // namespace blink | 787 } // namespace blink |
| OLD | NEW |