| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 ScriptElementBase* element, | 25 ScriptElementBase* element, |
| 26 const TextPosition& starting_position) { | 26 const TextPosition& starting_position) { |
| 27 return new ClassicPendingScript(element, nullptr, starting_position); | 27 return new ClassicPendingScript(element, nullptr, starting_position); |
| 28 } | 28 } |
| 29 | 29 |
| 30 ClassicPendingScript::ClassicPendingScript( | 30 ClassicPendingScript::ClassicPendingScript( |
| 31 ScriptElementBase* element, | 31 ScriptElementBase* element, |
| 32 ScriptResource* resource, | 32 ScriptResource* resource, |
| 33 const TextPosition& starting_position) | 33 const TextPosition& starting_position) |
| 34 : PendingScript(element, starting_position), | 34 : PendingScript(element, starting_position), |
| 35 ready_state_(resource ? kWaitingForResource : kReady), | 35 ready_state_(kInConstructor), |
| 36 integrity_failure_(false) { | 36 integrity_failure_(false) { |
| 37 CheckState(); | 37 CheckState(); |
| 38 SetResource(resource); | 38 SetResource(resource); |
| 39 MemoryCoordinator::Instance().RegisterClient(this); | 39 MemoryCoordinator::Instance().RegisterClient(this); |
| 40 AdvanceReadyState(resource ? kWaitingForResource : kReady); |
| 40 } | 41 } |
| 41 | 42 |
| 42 ClassicPendingScript::~ClassicPendingScript() {} | 43 ClassicPendingScript::~ClassicPendingScript() {} |
| 43 | 44 |
| 44 NOINLINE void ClassicPendingScript::CheckState() const { | 45 NOINLINE void ClassicPendingScript::CheckState() const { |
| 45 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. | 46 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. |
| 46 CHECK(!prefinalizer_called_); | 47 CHECK(!prefinalizer_called_); |
| 47 CHECK(GetElement()); | 48 CHECK(GetElement()); |
| 48 CHECK(GetResource() || !streamer_); | 49 CHECK(GetResource() || !streamer_); |
| 49 CHECK(!streamer_ || streamer_->GetResource() == GetResource()); | 50 CHECK(!streamer_ || streamer_->GetResource() == GetResource()); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 : ResourceIntegrityDisposition::kFailed); | 115 : ResourceIntegrityDisposition::kFailed); |
| 115 return passed; | 116 return passed; |
| 116 } | 117 } |
| 117 } | 118 } |
| 118 | 119 |
| 119 NOTREACHED(); | 120 NOTREACHED(); |
| 120 return true; | 121 return true; |
| 121 } | 122 } |
| 122 | 123 |
| 123 void ClassicPendingScript::NotifyFinished(Resource* resource) { | 124 void ClassicPendingScript::NotifyFinished(Resource* resource) { |
| 125 // If we're notified that the resource is synchronously ready, defer the |
| 126 // notification until later anyway. |
| 127 if (ready_state_ == kInConstructor) { |
| 128 TaskRunnerHelper::Get(TaskType::kNetworking, &GetElement()->GetDocument()) |
| 129 ->PostTask(BLINK_FROM_HERE, |
| 130 WTF::Bind(&ClassicPendingScript::NotifyFinished, |
| 131 WrapPersistent(this), WrapPersistent(resource))); |
| 132 return; |
| 133 } |
| 134 |
| 124 // The following SRI checks need to be here because, unfortunately, fetches | 135 // The following SRI checks need to be here because, unfortunately, fetches |
| 125 // are not done purely according to the Fetch spec. In particular, | 136 // are not done purely according to the Fetch spec. In particular, |
| 126 // different requests for the same resource do not have different | 137 // different requests for the same resource do not have different |
| 127 // responses; the memory cache can (and will) return the exact same | 138 // responses; the memory cache can (and will) return the exact same |
| 128 // Resource object. | 139 // Resource object. |
| 129 // | 140 // |
| 130 // For different requests, the same Resource object will be returned and | 141 // For different requests, the same Resource object will be returned and |
| 131 // will not be associated with the particular request. Therefore, when the | 142 // will not be associated with the particular request. Therefore, when the |
| 132 // body of the response comes in, there's no way to validate the integrity | 143 // body of the response comes in, there's no way to validate the integrity |
| 133 // of the Resource object against a particular request (since there may be | 144 // of the Resource object against a particular request (since there may be |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 260 |
| 250 KURL ClassicPendingScript::UrlForClassicScript() const { | 261 KURL ClassicPendingScript::UrlForClassicScript() const { |
| 251 return GetResource()->Url(); | 262 return GetResource()->Url(); |
| 252 } | 263 } |
| 253 | 264 |
| 254 void ClassicPendingScript::RemoveFromMemoryCache() { | 265 void ClassicPendingScript::RemoveFromMemoryCache() { |
| 255 GetMemoryCache()->Remove(GetResource()); | 266 GetMemoryCache()->Remove(GetResource()); |
| 256 } | 267 } |
| 257 | 268 |
| 258 } // namespace blink | 269 } // namespace blink |
| OLD | NEW |