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 |
11 * License as published by the Free Software Foundation; either | 11 * License as published by the Free Software Foundation; either |
12 * version 2 of the License, or (at your option) any later version. | 12 * version 2 of the License, or (at your option) any later version. |
13 * | 13 * |
14 * This library is distributed in the hope that it will be useful, | 14 * This library is distributed in the hope that it will be useful, |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 * Library General Public License for more details. | 17 * Library General Public License for more details. |
18 * | 18 * |
19 * You should have received a copy of the GNU Library General Public License | 19 * You should have received a copy of the GNU Library General Public License |
20 * along with this library; see the file COPYING.LIB. If not, write to | 20 * along with this library; see the file COPYING.LIB. If not, write to |
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
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 "core/HTMLNames.h" | 30 #include "core/HTMLNames.h" |
30 #include "core/SVGNames.h" | 31 #include "core/SVGNames.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/ScriptElementBase.h" | 37 #include "core/dom/ScriptElementBase.h" |
38 #include "core/dom/ScriptRunner.h" | 38 #include "core/dom/ScriptRunner.h" |
39 #include "core/dom/ScriptableDocumentParser.h" | 39 #include "core/dom/ScriptableDocumentParser.h" |
40 #include "core/dom/Text.h" | 40 #include "core/dom/Text.h" |
41 #include "core/events/Event.h" | 41 #include "core/events/Event.h" |
42 #include "core/frame/LocalFrame.h" | 42 #include "core/frame/LocalFrame.h" |
43 #include "core/frame/SubresourceIntegrity.h" | 43 #include "core/frame/SubresourceIntegrity.h" |
44 #include "core/frame/csp/ContentSecurityPolicy.h" | 44 #include "core/frame/csp/ContentSecurityPolicy.h" |
45 #include "core/html/CrossOriginAttribute.h" | 45 #include "core/html/CrossOriginAttribute.h" |
46 #include "core/html/imports/HTMLImport.h" | 46 #include "core/html/imports/HTMLImport.h" |
47 #include "core/html/parser/HTMLParserIdioms.h" | 47 #include "core/html/parser/HTMLParserIdioms.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/FetchParameters.h" | 50 #include "platform/loader/fetch/FetchParameters.h" |
| 51 #include "platform/loader/fetch/MemoryCache.h" |
51 #include "platform/loader/fetch/ResourceFetcher.h" | 52 #include "platform/loader/fetch/ResourceFetcher.h" |
52 #include "platform/network/mime/MIMETypeRegistry.h" | 53 #include "platform/network/mime/MIMETypeRegistry.h" |
53 #include "platform/weborigin/SecurityOrigin.h" | 54 #include "platform/weborigin/SecurityOrigin.h" |
54 #include "platform/wtf/StdLibExtras.h" | 55 #include "platform/wtf/StdLibExtras.h" |
55 #include "platform/wtf/text/StringBuilder.h" | 56 #include "platform/wtf/text/StringBuilder.h" |
56 #include "platform/wtf/text/StringHash.h" | 57 #include "platform/wtf/text/StringHash.h" |
57 #include "public/platform/WebCachePolicy.h" | 58 #include "public/platform/WebCachePolicy.h" |
58 | 59 |
59 namespace blink { | 60 namespace blink { |
60 | 61 |
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 WebCachePolicy::kReturnCacheDataDontLoad) { | 586 WebCachePolicy::kReturnCacheDataDontLoad) { |
586 document_write_intervention_ = | 587 document_write_intervention_ = |
587 DocumentWriteIntervention::kDoNotFetchDocWrittenScript; | 588 DocumentWriteIntervention::kDoNotFetchDocWrittenScript; |
588 } | 589 } |
589 | 590 |
590 return true; | 591 return true; |
591 } | 592 } |
592 | 593 |
593 PendingScript* ScriptLoader::CreatePendingScript() { | 594 PendingScript* ScriptLoader::CreatePendingScript() { |
594 CHECK(resource_); | 595 CHECK(resource_); |
595 return ClassicPendingScript::Create(element_, resource_); | 596 return PendingScript::Create(element_, resource_); |
596 } | 597 } |
597 | 598 |
598 bool ScriptLoader::ExecuteScript(const Script* script) { | 599 bool ScriptLoader::ExecuteScript(const Script* script) { |
599 double script_exec_start_time = MonotonicallyIncreasingTime(); | 600 double script_exec_start_time = MonotonicallyIncreasingTime(); |
600 bool result = DoExecuteScript(script); | 601 bool result = DoExecuteScript(script); |
601 | 602 |
602 // NOTE: we do not check m_willBeParserExecuted here, since | 603 // NOTE: we do not check m_willBeParserExecuted here, since |
603 // m_willBeParserExecuted is false for inline scripts, and we want to | 604 // m_willBeParserExecuted is false for inline scripts, and we want to |
604 // include inline script execution time as part of parser blocked script | 605 // include inline script execution time as part of parser blocked script |
605 // execution time. | 606 // execution time. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 return true; | 692 return true; |
692 | 693 |
693 // 7. "Decrement the ignore-destructive-writes counter of neutralized doc, | 694 // 7. "Decrement the ignore-destructive-writes counter of neutralized doc, |
694 // if it was incremented in the earlier step." | 695 // if it was incremented in the earlier step." |
695 // Implemented as the scope out of IgnoreDestructiveWriteCountIncrementer. | 696 // Implemented as the scope out of IgnoreDestructiveWriteCountIncrementer. |
696 } | 697 } |
697 | 698 |
698 void ScriptLoader::Execute() { | 699 void ScriptLoader::Execute() { |
699 DCHECK(!will_be_parser_executed_); | 700 DCHECK(!will_be_parser_executed_); |
700 DCHECK(async_exec_type_ != ScriptRunner::kNone); | 701 DCHECK(async_exec_type_ != ScriptRunner::kNone); |
701 DCHECK(pending_script_->IsExternal()); | 702 DCHECK(pending_script_->GetResource()); |
702 bool error_occurred = false; | 703 bool error_occurred = false; |
703 Script* script = pending_script_->GetSource(KURL(), error_occurred); | 704 Script* script = pending_script_->GetSource(KURL(), error_occurred); |
704 const bool wasCanceled = pending_script_->WasCanceled(); | |
705 DetachPendingScript(); | 705 DetachPendingScript(); |
706 if (error_occurred) { | 706 if (error_occurred) { |
707 DispatchErrorEvent(); | 707 DispatchErrorEvent(); |
708 } else if (!wasCanceled) { | 708 } else if (!resource_->WasCanceled()) { |
709 if (ExecuteScript(script)) | 709 if (ExecuteScript(script)) |
710 DispatchLoadEvent(); | 710 DispatchLoadEvent(); |
711 else | 711 else |
712 DispatchErrorEvent(); | 712 DispatchErrorEvent(); |
713 } | 713 } |
714 resource_ = nullptr; | 714 resource_ = nullptr; |
715 } | 715 } |
716 | 716 |
717 void ScriptLoader::PendingScriptFinished(PendingScript* pending_script) { | 717 void ScriptLoader::PendingScriptFinished(PendingScript* pending_script) { |
718 DCHECK(!will_be_parser_executed_); | 718 DCHECK(!will_be_parser_executed_); |
719 DCHECK_EQ(pending_script_, pending_script); | 719 DCHECK_EQ(pending_script_, pending_script); |
| 720 DCHECK_EQ(pending_script->GetResource(), resource_); |
720 | 721 |
721 // We do not need this script in the memory cache. The primary goals of | 722 // We do not need this script in the memory cache. The primary goals of |
722 // sending this fetch request are to let the third party server know | 723 // sending this fetch request are to let the third party server know |
723 // about the document.write scripts intervention and populate the http | 724 // about the document.write scripts intervention and populate the http |
724 // cache for subsequent uses. | 725 // cache for subsequent uses. |
725 if (document_write_intervention_ == | 726 if (document_write_intervention_ == |
726 DocumentWriteIntervention::kFetchDocWrittenScriptDeferIdle) { | 727 DocumentWriteIntervention::kFetchDocWrittenScriptDeferIdle) { |
727 DCHECK_EQ(pending_script_->GetScriptType(), ScriptType::kClassic); | 728 GetMemoryCache()->Remove(pending_script_->GetResource()); |
728 pending_script_->RemoveFromMemoryCache(); | |
729 pending_script_->StopWatchingForLoad(); | 729 pending_script_->StopWatchingForLoad(); |
730 return; | 730 return; |
731 } | 731 } |
732 | 732 |
733 DCHECK(async_exec_type_ != ScriptRunner::kNone); | 733 DCHECK(async_exec_type_ != ScriptRunner::kNone); |
734 | 734 |
735 Document* context_document = element_->GetDocument().ContextDocument(); | 735 Document* context_document = element_->GetDocument().ContextDocument(); |
736 if (!context_document) { | 736 if (!context_document) { |
737 DetachPendingScript(); | 737 DetachPendingScript(); |
738 return; | 738 return; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 // then abort these steps at this point. The script is not executed. | 781 // then abort these steps at this point. The script is not executed. |
782 return DeprecatedEqualIgnoringCase(event_attribute, "onload") || | 782 return DeprecatedEqualIgnoringCase(event_attribute, "onload") || |
783 DeprecatedEqualIgnoringCase(event_attribute, "onload()"); | 783 DeprecatedEqualIgnoringCase(event_attribute, "onload()"); |
784 } | 784 } |
785 | 785 |
786 String ScriptLoader::ScriptContent() const { | 786 String ScriptLoader::ScriptContent() const { |
787 return element_->TextFromChildren(); | 787 return element_->TextFromChildren(); |
788 } | 788 } |
789 | 789 |
790 } // namespace blink | 790 } // namespace blink |
OLD | NEW |