OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "core/dom/ClassicPendingScript.h" | 5 #include "core/dom/ClassicPendingScript.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptSourceCode.h" | 7 #include "bindings/core/v8/ScriptSourceCode.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "bindings/core/v8/ScriptStreamer.h" | 9 #include "bindings/core/v8/ScriptStreamer.h" |
10 #include "bindings/core/v8/V8BindingForCore.h" | 10 #include "bindings/core/v8/V8BindingForCore.h" |
11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
12 #include "core/dom/TaskRunnerHelper.h" | 12 #include "core/dom/TaskRunnerHelper.h" |
13 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
14 #include "core/frame/SubresourceIntegrity.h" | 14 #include "core/frame/SubresourceIntegrity.h" |
15 #include "platform/loader/fetch/MemoryCache.h" | 15 #include "platform/loader/fetch/MemoryCache.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 ClassicPendingScript* ClassicPendingScript::Create(ScriptElementBase* element, | 19 ClassicPendingScript* ClassicPendingScript::Create(ScriptElementBase* element, |
20 ScriptResource* resource) { | 20 ScriptResource* resource) { |
21 CHECK(resource); | |
21 return new ClassicPendingScript(element, resource, TextPosition()); | 22 return new ClassicPendingScript(element, resource, TextPosition()); |
22 } | 23 } |
23 | 24 |
24 ClassicPendingScript* ClassicPendingScript::Create( | 25 ClassicPendingScript* ClassicPendingScript::Create( |
25 ScriptElementBase* element, | 26 ScriptElementBase* element, |
26 const TextPosition& starting_position) { | 27 const TextPosition& starting_position) { |
27 return new ClassicPendingScript(element, nullptr, starting_position); | 28 return new ClassicPendingScript(element, nullptr, starting_position); |
28 } | 29 } |
29 | 30 |
30 ClassicPendingScript::ClassicPendingScript( | 31 ClassicPendingScript::ClassicPendingScript( |
31 ScriptElementBase* element, | 32 ScriptElementBase* element, |
32 ScriptResource* resource, | 33 ScriptResource* resource, |
33 const TextPosition& starting_position) | 34 const TextPosition& starting_position) |
34 : PendingScript(element, starting_position), integrity_failure_(false) { | 35 : PendingScript(element, starting_position), |
36 is_external_(resource), | |
37 integrity_failure_(false) { | |
38 CHECK(GetElement()); | |
39 SetResource(resource); | |
35 CheckState(); | 40 CheckState(); |
36 SetResource(resource); | |
37 MemoryCoordinator::Instance().RegisterClient(this); | 41 MemoryCoordinator::Instance().RegisterClient(this); |
38 } | 42 } |
39 | 43 |
40 ClassicPendingScript::~ClassicPendingScript() {} | 44 ClassicPendingScript::~ClassicPendingScript() {} |
41 | 45 |
42 NOINLINE void ClassicPendingScript::CheckState() const { | 46 NOINLINE void ClassicPendingScript::CheckState() const { |
43 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. | 47 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. |
44 CHECK(!prefinalizer_called_); | 48 CHECK(!prefinalizer_called_); |
45 CHECK(GetElement()); | 49 CHECK(GetElement()); |
50 CHECK_EQ(is_external_, !!GetResource()); | |
46 CHECK(GetResource() || !streamer_); | 51 CHECK(GetResource() || !streamer_); |
47 CHECK(!streamer_ || streamer_->GetResource() == GetResource()); | 52 CHECK(!streamer_ || streamer_->GetResource() == GetResource()); |
48 } | 53 } |
49 | 54 |
50 void ClassicPendingScript::Prefinalize() { | 55 void ClassicPendingScript::Prefinalize() { |
51 // TODO(hiroshige): Consider moving this to ScriptStreamer's prefinalizer. | 56 // TODO(hiroshige): Consider moving this to ScriptStreamer's prefinalizer. |
52 // https://crbug.com/715309 | 57 // https://crbug.com/715309 |
53 if (streamer_) | 58 if (streamer_) |
54 streamer_->Cancel(); | 59 streamer_->Cancel(); |
55 prefinalizer_called_ = true; | 60 prefinalizer_called_ = true; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 ResourceOwner<ScriptResource>::Trace(visitor); | 167 ResourceOwner<ScriptResource>::Trace(visitor); |
163 MemoryCoordinatorClient::Trace(visitor); | 168 MemoryCoordinatorClient::Trace(visitor); |
164 PendingScript::Trace(visitor); | 169 PendingScript::Trace(visitor); |
165 } | 170 } |
166 | 171 |
167 ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url, | 172 ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url, |
168 bool& error_occurred) const { | 173 bool& error_occurred) const { |
169 CheckState(); | 174 CheckState(); |
170 | 175 |
171 error_occurred = this->ErrorOccurred(); | 176 error_occurred = this->ErrorOccurred(); |
172 if (GetResource()) { | 177 if (is_external_) { |
sof
2017/04/29 15:01:10
Why is this (and all the other is_external_ checks
| |
173 DCHECK(GetResource()->IsLoaded()); | 178 DCHECK(GetResource()->IsLoaded()); |
174 if (streamer_ && !streamer_->StreamingSuppressed()) | 179 if (streamer_ && !streamer_->StreamingSuppressed()) |
175 return ClassicScript::Create(ScriptSourceCode(streamer_, GetResource())); | 180 return ClassicScript::Create(ScriptSourceCode(streamer_, GetResource())); |
176 return ClassicScript::Create(ScriptSourceCode(GetResource())); | 181 return ClassicScript::Create(ScriptSourceCode(GetResource())); |
177 } | 182 } |
178 | 183 |
179 return ClassicScript::Create(ScriptSourceCode( | 184 return ClassicScript::Create(ScriptSourceCode( |
180 GetElement()->TextContent(), document_url, StartingPosition())); | 185 GetElement()->TextContent(), document_url, StartingPosition())); |
181 } | 186 } |
182 | 187 |
183 void ClassicPendingScript::SetStreamer(ScriptStreamer* streamer) { | 188 void ClassicPendingScript::SetStreamer(ScriptStreamer* streamer) { |
184 DCHECK(!streamer_); | 189 DCHECK(!streamer_); |
185 DCHECK(!IsWatchingForLoad()); | 190 DCHECK(!IsWatchingForLoad()); |
186 streamer_ = streamer; | 191 streamer_ = streamer; |
187 CheckState(); | 192 CheckState(); |
188 } | 193 } |
189 | 194 |
190 bool ClassicPendingScript::IsReady() const { | 195 bool ClassicPendingScript::IsReady() const { |
191 CheckState(); | 196 CheckState(); |
192 if (GetResource()) { | 197 if (is_external_) { |
193 return GetResource()->IsLoaded() && (!streamer_ || streamer_->IsFinished()); | 198 return GetResource()->IsLoaded() && (!streamer_ || streamer_->IsFinished()); |
194 } | 199 } |
195 | 200 |
196 return true; | 201 return true; |
197 } | 202 } |
198 | 203 |
199 bool ClassicPendingScript::ErrorOccurred() const { | 204 bool ClassicPendingScript::ErrorOccurred() const { |
200 CheckState(); | 205 CheckState(); |
201 if (GetResource()) | 206 if (is_external_) |
202 return GetResource()->ErrorOccurred() || integrity_failure_; | 207 return GetResource()->ErrorOccurred() || integrity_failure_; |
203 | 208 |
204 return false; | 209 return false; |
205 } | 210 } |
206 | 211 |
207 void ClassicPendingScript::OnPurgeMemory() { | 212 void ClassicPendingScript::OnPurgeMemory() { |
208 CheckState(); | 213 CheckState(); |
209 if (!streamer_) | 214 if (!streamer_) |
210 return; | 215 return; |
211 streamer_->Cancel(); | 216 streamer_->Cancel(); |
(...skipping 21 matching lines...) Expand all Loading... | |
233 | 238 |
234 KURL ClassicPendingScript::UrlForClassicScript() const { | 239 KURL ClassicPendingScript::UrlForClassicScript() const { |
235 return GetResource()->Url(); | 240 return GetResource()->Url(); |
236 } | 241 } |
237 | 242 |
238 void ClassicPendingScript::RemoveFromMemoryCache() { | 243 void ClassicPendingScript::RemoveFromMemoryCache() { |
239 GetMemoryCache()->Remove(GetResource()); | 244 GetMemoryCache()->Remove(GetResource()); |
240 } | 245 } |
241 | 246 |
242 } // namespace blink | 247 } // namespace blink |
OLD | NEW |