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" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // while having proper Fetch checks in the fetch module for use in the | 141 // while having proper Fetch checks in the fetch module for use in the |
142 // fetch JavaScript API. In a future world where the ResourceFetcher uses | 142 // fetch JavaScript API. In a future world where the ResourceFetcher uses |
143 // the Fetch algorithm, this should be fixed by having separate Response | 143 // the Fetch algorithm, this should be fixed by having separate Response |
144 // objects (perhaps attached to identical Resource objects) per request. | 144 // objects (perhaps attached to identical Resource objects) per request. |
145 // | 145 // |
146 // See https://crbug.com/500701 for more information. | 146 // See https://crbug.com/500701 for more information. |
147 CheckState(); | 147 CheckState(); |
148 if (GetElement()) { | 148 if (GetElement()) { |
149 integrity_failure_ = !CheckScriptResourceIntegrity(resource, GetElement()); | 149 integrity_failure_ = !CheckScriptResourceIntegrity(resource, GetElement()); |
150 } | 150 } |
| 151 DCHECK(!resource_data_); |
| 152 resource_data_ = GetResource()->ResourceData(); |
| 153 DCHECK(resource_data_); |
151 | 154 |
152 // If script streaming is in use, the client will be notified in | 155 // If script streaming is in use, the client will be notified in |
153 // streamingFinished. | 156 // streamingFinished. |
154 if (streamer_) | 157 if (streamer_) |
155 streamer_->NotifyFinished(resource); | 158 streamer_->NotifyFinished(resource); |
156 else if (Client()) | 159 else if (Client()) |
157 Client()->PendingScriptFinished(this); | 160 Client()->PendingScriptFinished(this); |
158 } | 161 } |
159 | 162 |
160 void ClassicPendingScript::NotifyAppendData(ScriptResource* resource) { | 163 void ClassicPendingScript::NotifyAppendData(ScriptResource* resource) { |
161 if (streamer_) | 164 if (streamer_) |
162 streamer_->NotifyAppendData(resource); | 165 streamer_->NotifyAppendData(resource); |
163 } | 166 } |
164 | 167 |
165 DEFINE_TRACE(ClassicPendingScript) { | 168 DEFINE_TRACE(ClassicPendingScript) { |
166 visitor->Trace(streamer_); | 169 visitor->Trace(streamer_); |
| 170 visitor->Trace(resource_data_); |
167 ResourceOwner<ScriptResource>::Trace(visitor); | 171 ResourceOwner<ScriptResource>::Trace(visitor); |
168 MemoryCoordinatorClient::Trace(visitor); | 172 MemoryCoordinatorClient::Trace(visitor); |
169 PendingScript::Trace(visitor); | 173 PendingScript::Trace(visitor); |
170 } | 174 } |
171 | 175 |
172 ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url, | 176 ClassicScript* ClassicPendingScript::GetSource(const KURL& document_url, |
173 bool& error_occurred) const { | 177 bool& error_occurred) const { |
174 CheckState(); | 178 CheckState(); |
175 | 179 |
176 error_occurred = this->ErrorOccurred(); | 180 error_occurred = this->ErrorOccurred(); |
177 if (is_external_) { | 181 if (is_external_) { |
178 DCHECK(GetResource()->IsLoaded()); | 182 CHECK(ResourceData()); |
179 if (streamer_ && !streamer_->StreamingSuppressed()) | 183 if (streamer_ && !streamer_->StreamingSuppressed()) |
180 return ClassicScript::Create(ScriptSourceCode(streamer_, GetResource())); | 184 return ClassicScript::Create(ScriptSourceCode(streamer_, ResourceData())); |
181 return ClassicScript::Create(ScriptSourceCode(GetResource())); | 185 return ClassicScript::Create(ScriptSourceCode(ResourceData())); |
182 } | 186 } |
183 | 187 |
184 return ClassicScript::Create(ScriptSourceCode( | 188 return ClassicScript::Create(ScriptSourceCode( |
185 GetElement()->TextContent(), document_url, StartingPosition())); | 189 GetElement()->TextContent(), document_url, StartingPosition())); |
186 } | 190 } |
187 | 191 |
188 void ClassicPendingScript::SetStreamer(ScriptStreamer* streamer) { | 192 void ClassicPendingScript::SetStreamer(ScriptStreamer* streamer) { |
189 DCHECK(!streamer_); | 193 DCHECK(!streamer_); |
190 DCHECK(!IsWatchingForLoad()); | 194 DCHECK(!IsWatchingForLoad()); |
191 streamer_ = streamer; | 195 streamer_ = streamer; |
192 CheckState(); | 196 CheckState(); |
193 } | 197 } |
194 | 198 |
195 bool ClassicPendingScript::IsReady() const { | 199 bool ClassicPendingScript::IsReady() const { |
196 CheckState(); | 200 CheckState(); |
197 if (is_external_) { | 201 if (is_external_) { |
198 return GetResource()->IsLoaded() && (!streamer_ || streamer_->IsFinished()); | 202 return ResourceData() && (!streamer_ || streamer_->IsFinished()); |
199 } | 203 } |
200 | 204 |
201 return true; | 205 return true; |
202 } | 206 } |
203 | 207 |
204 bool ClassicPendingScript::ErrorOccurred() const { | 208 bool ClassicPendingScript::ErrorOccurred() const { |
205 CheckState(); | 209 CheckState(); |
206 if (is_external_) | 210 if (is_external_) { |
207 return GetResource()->ErrorOccurred() || integrity_failure_; | 211 CHECK(ResourceData()); |
| 212 return ResourceData()->ErrorOccurred() || integrity_failure_; |
| 213 } |
208 | 214 |
209 return false; | 215 return false; |
210 } | 216 } |
211 | 217 |
212 void ClassicPendingScript::OnPurgeMemory() { | 218 void ClassicPendingScript::OnPurgeMemory() { |
213 CheckState(); | 219 CheckState(); |
214 if (!streamer_) | 220 if (!streamer_) |
215 return; | 221 return; |
216 streamer_->Cancel(); | 222 streamer_->Cancel(); |
217 streamer_ = nullptr; | 223 streamer_ = nullptr; |
(...skipping 12 matching lines...) Expand all Loading... |
230 ScriptStreamer::StartStreaming( | 236 ScriptStreamer::StartStreaming( |
231 this, streamer_type, document->GetFrame()->GetSettings(), script_state, | 237 this, streamer_type, document->GetFrame()->GetSettings(), script_state, |
232 TaskRunnerHelper::Get(TaskType::kNetworking, document)); | 238 TaskRunnerHelper::Get(TaskType::kNetworking, document)); |
233 } | 239 } |
234 | 240 |
235 bool ClassicPendingScript::WasCanceled() const { | 241 bool ClassicPendingScript::WasCanceled() const { |
236 return GetResource()->WasCanceled(); | 242 return GetResource()->WasCanceled(); |
237 } | 243 } |
238 | 244 |
239 KURL ClassicPendingScript::UrlForClassicScript() const { | 245 KURL ClassicPendingScript::UrlForClassicScript() const { |
| 246 if (ResourceData()) |
| 247 return ResourceData()->Url(); |
| 248 CHECK(GetResource()); |
240 return GetResource()->Url(); | 249 return GetResource()->Url(); |
241 } | 250 } |
242 | 251 |
243 void ClassicPendingScript::RemoveFromMemoryCache() { | 252 void ClassicPendingScript::RemoveFromMemoryCache() { |
244 GetMemoryCache()->Remove(GetResource()); | 253 GetMemoryCache()->Remove(GetResource()); |
245 } | 254 } |
246 | 255 |
247 } // namespace blink | 256 } // namespace blink |
OLD | NEW |