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

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

Issue 2653923008: Reland of Split PendingScript into PendingScript and ClassicPendingScript (Closed)
Patch Set: Rebase Created 3 years, 7 months 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
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/V8BindingForCore.h"
30 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
31 #include "core/SVGNames.h" 30 #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/imports/HTMLImport.h" 45 #include "core/html/imports/HTMLImport.h"
46 #include "core/html/parser/HTMLParserIdioms.h" 46 #include "core/html/parser/HTMLParserIdioms.h"
47 #include "core/loader/resource/ScriptResource.h" 47 #include "core/loader/resource/ScriptResource.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"
52 #include "platform/loader/fetch/ResourceFetcher.h" 51 #include "platform/loader/fetch/ResourceFetcher.h"
53 #include "platform/network/mime/MIMETypeRegistry.h" 52 #include "platform/network/mime/MIMETypeRegistry.h"
54 #include "platform/weborigin/SecurityOrigin.h" 53 #include "platform/weborigin/SecurityOrigin.h"
55 #include "platform/wtf/StdLibExtras.h" 54 #include "platform/wtf/StdLibExtras.h"
56 #include "platform/wtf/text/StringBuilder.h" 55 #include "platform/wtf/text/StringBuilder.h"
57 #include "platform/wtf/text/StringHash.h" 56 #include "platform/wtf/text/StringHash.h"
58 #include "public/platform/WebCachePolicy.h" 57 #include "public/platform/WebCachePolicy.h"
59 58
60 namespace blink { 59 namespace blink {
61 60
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 WebCachePolicy::kReturnCacheDataDontLoad) { 662 WebCachePolicy::kReturnCacheDataDontLoad) {
664 document_write_intervention_ = 663 document_write_intervention_ =
665 DocumentWriteIntervention::kDoNotFetchDocWrittenScript; 664 DocumentWriteIntervention::kDoNotFetchDocWrittenScript;
666 } 665 }
667 666
668 return true; 667 return true;
669 } 668 }
670 669
671 PendingScript* ScriptLoader::CreatePendingScript() { 670 PendingScript* ScriptLoader::CreatePendingScript() {
672 CHECK(resource_); 671 CHECK(resource_);
673 return PendingScript::Create(element_, resource_); 672 return ClassicPendingScript::Create(element_, resource_);
674 } 673 }
675 674
676 bool ScriptLoader::ExecuteScript(const Script* script) { 675 bool ScriptLoader::ExecuteScript(const Script* script) {
677 double script_exec_start_time = MonotonicallyIncreasingTime(); 676 double script_exec_start_time = MonotonicallyIncreasingTime();
678 bool result = DoExecuteScript(script); 677 bool result = DoExecuteScript(script);
679 678
680 // NOTE: we do not check m_willBeParserExecuted here, since 679 // NOTE: we do not check m_willBeParserExecuted here, since
681 // m_willBeParserExecuted is false for inline scripts, and we want to 680 // m_willBeParserExecuted is false for inline scripts, and we want to
682 // include inline script execution time as part of parser blocked script 681 // include inline script execution time as part of parser blocked script
683 // execution time. 682 // execution time.
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 return true; 768 return true;
770 769
771 // 7. "Decrement the ignore-destructive-writes counter of neutralized doc, 770 // 7. "Decrement the ignore-destructive-writes counter of neutralized doc,
772 // if it was incremented in the earlier step." 771 // if it was incremented in the earlier step."
773 // Implemented as the scope out of IgnoreDestructiveWriteCountIncrementer. 772 // Implemented as the scope out of IgnoreDestructiveWriteCountIncrementer.
774 } 773 }
775 774
776 void ScriptLoader::Execute() { 775 void ScriptLoader::Execute() {
777 DCHECK(!will_be_parser_executed_); 776 DCHECK(!will_be_parser_executed_);
778 DCHECK(async_exec_type_ != ScriptRunner::kNone); 777 DCHECK(async_exec_type_ != ScriptRunner::kNone);
779 DCHECK(pending_script_->GetResource()); 778 DCHECK(pending_script_->IsExternal());
780 bool error_occurred = false; 779 bool error_occurred = false;
781 Script* script = pending_script_->GetSource(KURL(), error_occurred); 780 Script* script = pending_script_->GetSource(KURL(), error_occurred);
781 const bool wasCanceled = pending_script_->WasCanceled();
782 DetachPendingScript(); 782 DetachPendingScript();
783 if (error_occurred) { 783 if (error_occurred) {
784 DispatchErrorEvent(); 784 DispatchErrorEvent();
785 } else if (!resource_->WasCanceled()) { 785 } else if (!wasCanceled) {
786 if (ExecuteScript(script)) 786 if (ExecuteScript(script))
787 DispatchLoadEvent(); 787 DispatchLoadEvent();
788 else 788 else
789 DispatchErrorEvent(); 789 DispatchErrorEvent();
790 } 790 }
791 resource_ = nullptr; 791 resource_ = nullptr;
792 } 792 }
793 793
794 void ScriptLoader::PendingScriptFinished(PendingScript* pending_script) { 794 void ScriptLoader::PendingScriptFinished(PendingScript* pending_script) {
795 DCHECK(!will_be_parser_executed_); 795 DCHECK(!will_be_parser_executed_);
796 DCHECK_EQ(pending_script_, pending_script); 796 DCHECK_EQ(pending_script_, pending_script);
797 DCHECK_EQ(pending_script->GetResource(), resource_);
798 797
799 // We do not need this script in the memory cache. The primary goals of 798 // We do not need this script in the memory cache. The primary goals of
800 // sending this fetch request are to let the third party server know 799 // sending this fetch request are to let the third party server know
801 // about the document.write scripts intervention and populate the http 800 // about the document.write scripts intervention and populate the http
802 // cache for subsequent uses. 801 // cache for subsequent uses.
803 if (document_write_intervention_ == 802 if (document_write_intervention_ ==
804 DocumentWriteIntervention::kFetchDocWrittenScriptDeferIdle) { 803 DocumentWriteIntervention::kFetchDocWrittenScriptDeferIdle) {
805 GetMemoryCache()->Remove(pending_script_->GetResource()); 804 DCHECK_EQ(pending_script_->GetScriptType(), ScriptType::kClassic);
805 pending_script_->RemoveFromMemoryCache();
806 pending_script_->StopWatchingForLoad(); 806 pending_script_->StopWatchingForLoad();
807 return; 807 return;
808 } 808 }
809 809
810 DCHECK(async_exec_type_ != ScriptRunner::kNone); 810 DCHECK(async_exec_type_ != ScriptRunner::kNone);
811 811
812 Document* context_document = element_->GetDocument().ContextDocument(); 812 Document* context_document = element_->GetDocument().ContextDocument();
813 if (!context_document) { 813 if (!context_document) {
814 DetachPendingScript(); 814 DetachPendingScript();
815 return; 815 return;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 // then abort these steps at this point. The script is not executed. 858 // then abort these steps at this point. The script is not executed.
859 return DeprecatedEqualIgnoringCase(event_attribute, "onload") || 859 return DeprecatedEqualIgnoringCase(event_attribute, "onload") ||
860 DeprecatedEqualIgnoringCase(event_attribute, "onload()"); 860 DeprecatedEqualIgnoringCase(event_attribute, "onload()");
861 } 861 }
862 862
863 String ScriptLoader::ScriptContent() const { 863 String ScriptLoader::ScriptContent() const {
864 return element_->TextFromChildren(); 864 return element_->TextFromChildren();
865 } 865 }
866 866
867 } // namespace blink 867 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698