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/ScriptStreamer.h" | 8 #include "bindings/core/v8/ScriptStreamer.h" |
9 #include "bindings/core/v8/V8BindingForCore.h" | 9 #include "bindings/core/v8/V8BindingForCore.h" |
10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
11 #include "core/dom/TaskRunnerHelper.h" | 11 #include "core/dom/TaskRunnerHelper.h" |
12 #include "core/frame/LocalFrame.h" | 12 #include "core/frame/LocalFrame.h" |
13 #include "core/loader/SubresourceIntegrityHelper.h" | 13 #include "core/loader/SubresourceIntegrityHelper.h" |
14 #include "platform/bindings/ScriptState.h" | 14 #include "platform/bindings/ScriptState.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), | 35 : PendingScript(element, starting_position), |
| 36 is_external_(resource), |
35 ready_state_(resource ? kWaitingForResource : kReady), | 37 ready_state_(resource ? kWaitingForResource : kReady), |
36 integrity_failure_(false) { | 38 integrity_failure_(false) { |
| 39 CHECK(GetElement()); |
| 40 SetResource(resource); |
37 CheckState(); | 41 CheckState(); |
38 SetResource(resource); | |
39 MemoryCoordinator::Instance().RegisterClient(this); | 42 MemoryCoordinator::Instance().RegisterClient(this); |
40 } | 43 } |
41 | 44 |
42 ClassicPendingScript::~ClassicPendingScript() {} | 45 ClassicPendingScript::~ClassicPendingScript() {} |
43 | 46 |
44 NOINLINE void ClassicPendingScript::CheckState() const { | 47 NOINLINE void ClassicPendingScript::CheckState() const { |
45 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. | 48 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. |
46 CHECK(!prefinalizer_called_); | 49 CHECK(!prefinalizer_called_); |
47 CHECK(GetElement()); | 50 CHECK(GetElement()); |
| 51 CHECK_EQ(is_external_, !!GetResource()); |
48 CHECK(GetResource() || !streamer_); | 52 CHECK(GetResource() || !streamer_); |
49 CHECK(!streamer_ || streamer_->GetResource() == GetResource()); | 53 CHECK(!streamer_ || streamer_->GetResource() == GetResource()); |
50 } | 54 } |
51 | 55 |
52 void ClassicPendingScript::Prefinalize() { | 56 void ClassicPendingScript::Prefinalize() { |
53 // TODO(hiroshige): Consider moving this to ScriptStreamer's prefinalizer. | 57 // TODO(hiroshige): Consider moving this to ScriptStreamer's prefinalizer. |
54 // https://crbug.com/715309 | 58 // https://crbug.com/715309 |
55 if (streamer_) | 59 if (streamer_) |
56 streamer_->Cancel(); | 60 streamer_->Cancel(); |
57 prefinalizer_called_ = true; | 61 prefinalizer_called_ = true; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 MemoryCoordinatorClient::Trace(visitor); | 163 MemoryCoordinatorClient::Trace(visitor); |
160 PendingScript::Trace(visitor); | 164 PendingScript::Trace(visitor); |
161 } | 165 } |
162 | 166 |
163 ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url, | 167 ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url, |
164 bool& error_occurred) const { | 168 bool& error_occurred) const { |
165 CheckState(); | 169 CheckState(); |
166 DCHECK(IsReady()); | 170 DCHECK(IsReady()); |
167 | 171 |
168 error_occurred = ErrorOccurred(); | 172 error_occurred = ErrorOccurred(); |
169 if (!GetResource()) { | 173 if (!is_external_) { |
170 return ClassicScript::Create(ScriptSourceCode( | 174 return ClassicScript::Create(ScriptSourceCode( |
171 GetElement()->TextFromChildren(), document_url, StartingPosition())); | 175 GetElement()->TextFromChildren(), document_url, StartingPosition())); |
172 } | 176 } |
173 | 177 |
174 DCHECK(GetResource()->IsLoaded()); | 178 DCHECK(GetResource()->IsLoaded()); |
175 bool streamer_ready = (ready_state_ == kReady) && streamer_ && | 179 bool streamer_ready = (ready_state_ == kReady) && streamer_ && |
176 !streamer_->StreamingSuppressed(); | 180 !streamer_->StreamingSuppressed(); |
177 return ClassicScript::Create( | 181 return ClassicScript::Create( |
178 ScriptSourceCode(streamer_ready ? streamer_ : nullptr, GetResource())); | 182 ScriptSourceCode(streamer_ready ? streamer_ : nullptr, GetResource())); |
179 } | 183 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 311 |
308 bool ClassicPendingScript::IsCurrentlyStreaming() const { | 312 bool ClassicPendingScript::IsCurrentlyStreaming() const { |
309 // We could either check our local state, or ask the streamer. Let's | 313 // We could either check our local state, or ask the streamer. Let's |
310 // double-check these are consistent. | 314 // double-check these are consistent. |
311 DCHECK_EQ(streamer_ && !streamer_->IsStreamingFinished(), | 315 DCHECK_EQ(streamer_ && !streamer_->IsStreamingFinished(), |
312 ready_state_ == kReadyStreaming || (streamer_ && !IsReady())); | 316 ready_state_ == kReadyStreaming || (streamer_ && !IsReady())); |
313 return ready_state_ == kReadyStreaming || (streamer_ && !IsReady()); | 317 return ready_state_ == kReadyStreaming || (streamer_ && !IsReady()); |
314 } | 318 } |
315 | 319 |
316 bool ClassicPendingScript::WasCanceled() const { | 320 bool ClassicPendingScript::WasCanceled() const { |
317 if (!GetResource()) | 321 if (!is_external_) |
318 return false; | 322 return false; |
319 return GetResource()->WasCanceled(); | 323 return GetResource()->WasCanceled(); |
320 } | 324 } |
321 | 325 |
322 KURL ClassicPendingScript::UrlForClassicScript() const { | 326 KURL ClassicPendingScript::UrlForClassicScript() const { |
323 return GetResource()->Url(); | 327 return GetResource()->Url(); |
324 } | 328 } |
325 | 329 |
326 void ClassicPendingScript::RemoveFromMemoryCache() { | 330 void ClassicPendingScript::RemoveFromMemoryCache() { |
327 GetMemoryCache()->Remove(GetResource()); | 331 GetMemoryCache()->Remove(GetResource()); |
328 } | 332 } |
329 | 333 |
330 } // namespace blink | 334 } // namespace blink |
OLD | NEW |