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

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

Issue 2815453006: Introduce ModulePendingScript (Closed)
Patch Set: Created 3 years, 8 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/dom/ModulePendingScript.h"
6
7 #include "core/dom/ScriptLoader.h"
8 #include "core/frame/LocalFrame.h"
9
10 namespace blink {
11
12 ModulePendingScriptTreeClient::ModulePendingScriptTreeClient()
13 : module_script_(this, nullptr), pending_script_(this, nullptr) {}
14
15 void ModulePendingScriptTreeClient::SetPendingScript(
16 ModulePendingScript* pending_script) {
17 DCHECK(!pending_script_);
18 pending_script_ = pending_script;
19
20 if (finished_) {
21 pending_script_->NotifyModuleTreeLoadFinished();
22 }
23 }
24
25 void ModulePendingScriptTreeClient::NotifyModuleTreeLoadFinished(
26 ModuleScript* module_script) {
27 printf("notifyFinishedModuleTree!!! moduleScript: %p\n", module_script);
28 DCHECK(!(module_script && module_script->InstantiationState() ==
29 ModuleInstantiationState::kUninstantiated));
30 DCHECK(!finished_);
31 finished_ = true;
32 module_script_ = module_script;
33
34 if (pending_script_)
35 pending_script_->NotifyModuleTreeLoadFinished();
36 }
37
38 DEFINE_TRACE(ModulePendingScriptTreeClient) {
39 visitor->Trace(module_script_);
40 visitor->Trace(pending_script_);
41 ModuleTreeClient::Trace(visitor);
42 }
43
44 DEFINE_TRACE_WRAPPERS(ModulePendingScriptTreeClient) {
45 visitor->TraceWrappers(module_script_);
46 }
47
48 ModulePendingScript::ModulePendingScript(ScriptElementBase* element,
49 ModulePendingScriptTreeClient* client)
50 : PendingScript(element, TextPosition()),
51 module_tree_client_(this, client) {
52 CHECK(this->GetElement());
53 DCHECK(module_tree_client_);
54 client->SetPendingScript(this);
55 }
56
57 ModulePendingScript::~ModulePendingScript() {}
58
59 void ModulePendingScript::DisposeInternal() {
60 module_tree_client_ = nullptr;
61 }
62
63 DEFINE_TRACE(ModulePendingScript) {
64 visitor->Trace(module_tree_client_);
65 PendingScript::Trace(visitor);
66 }
67
68 DEFINE_TRACE_WRAPPERS(ModulePendingScript) {
69 visitor->TraceWrappers(module_tree_client_);
70 PendingScript::TraceWrappers(visitor);
71 }
72
73 void ModulePendingScript::NotifyModuleTreeLoadFinished() {
74 CHECK(!IsReady());
75 finished_ = true;
76
77 if (Client())
78 Client()->PendingScriptFinished(this);
79 }
80
81 Script* ModulePendingScript::GetSource(const KURL& document_url,
82 bool& error_occurred) const {
83 CHECK(IsReady());
84 error_occurred = ErrorOccurred();
85 return GetModuleScript();
86 }
87
88 bool ModulePendingScript::IsReady() const {
89 return finished_;
90 }
91
92 bool ModulePendingScript::ErrorOccurred() const {
93 CHECK(IsReady());
94 return !GetModuleScript();
95 }
96 bool ModulePendingScript::WasCanceled() const {
97 return false;
98 }
99
100 KURL ModulePendingScript::Url() const {
101 return KURL();
102 }
103
104 void ModulePendingScript::StartStreamingIfPossible(Document*,
105 ScriptStreamer::Type) {
106 return;
107 }
108
109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698