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

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

Issue 2827163003: Remove ClassicPendingScript::CreateForTesting() (Closed)
Patch Set: Rebase 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
« no previous file with comments | « third_party/WebKit/Source/core/dom/ClassicPendingScript.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 return new ClassicPendingScript(element, resource, TextPosition()); 21 return new ClassicPendingScript(element, resource, TextPosition());
22 } 22 }
23 23
24 ClassicPendingScript* ClassicPendingScript::Create( 24 ClassicPendingScript* ClassicPendingScript::Create(
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::CreateForTesting(
31 ScriptResource* resource) {
32 return new ClassicPendingScript(nullptr, resource, TextPosition(), true);
33 }
34
35 ClassicPendingScript::ClassicPendingScript( 30 ClassicPendingScript::ClassicPendingScript(
36 ScriptElementBase* element, 31 ScriptElementBase* element,
37 ScriptResource* resource, 32 ScriptResource* resource,
38 const TextPosition& starting_position, 33 const TextPosition& starting_position)
39 bool is_for_testing) 34 : PendingScript(element, starting_position), integrity_failure_(false) {
40 : PendingScript(element, starting_position),
41 integrity_failure_(false),
42 is_for_testing_(is_for_testing) {
43 CheckState(); 35 CheckState();
44 SetResource(resource); 36 SetResource(resource);
45 MemoryCoordinator::Instance().RegisterClient(this); 37 MemoryCoordinator::Instance().RegisterClient(this);
46 } 38 }
47 39
48 ClassicPendingScript::~ClassicPendingScript() {} 40 ClassicPendingScript::~ClassicPendingScript() {}
49 41
50 NOINLINE void ClassicPendingScript::CheckState() const { 42 NOINLINE void ClassicPendingScript::CheckState() const {
51 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta. 43 // TODO(hiroshige): Turn these CHECK()s into DCHECK() before going to beta.
52 CHECK(is_for_testing_ || GetElement()); 44 CHECK(GetElement());
53 CHECK(GetResource() || !streamer_); 45 CHECK(GetResource() || !streamer_);
54 CHECK(!streamer_ || streamer_->GetResource() == GetResource()); 46 CHECK(!streamer_ || streamer_->GetResource() == GetResource());
55 } 47 }
56 48
57 NOINLINE void ClassicPendingScript::Dispose() { 49 NOINLINE void ClassicPendingScript::Dispose() {
58 PendingScript::Dispose(); 50 PendingScript::Dispose();
59 } 51 }
60 52
61 void ClassicPendingScript::DisposeInternal() { 53 void ClassicPendingScript::DisposeInternal() {
62 MemoryCoordinator::Instance().UnregisterClient(this); 54 MemoryCoordinator::Instance().UnregisterClient(this);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // In order to simulate the correct behavior, Blink explicitly does the SRI 128 // In order to simulate the correct behavior, Blink explicitly does the SRI
137 // checks here, when a PendingScript tied to a particular request is 129 // checks here, when a PendingScript tied to a particular request is
138 // finished (and in the case of a StyleSheet, at the point of execution), 130 // finished (and in the case of a StyleSheet, at the point of execution),
139 // while having proper Fetch checks in the fetch module for use in the 131 // while having proper Fetch checks in the fetch module for use in the
140 // fetch JavaScript API. In a future world where the ResourceFetcher uses 132 // fetch JavaScript API. In a future world where the ResourceFetcher uses
141 // the Fetch algorithm, this should be fixed by having separate Response 133 // the Fetch algorithm, this should be fixed by having separate Response
142 // objects (perhaps attached to identical Resource objects) per request. 134 // objects (perhaps attached to identical Resource objects) per request.
143 // 135 //
144 // See https://crbug.com/500701 for more information. 136 // See https://crbug.com/500701 for more information.
145 CheckState(); 137 CheckState();
146 if (!is_for_testing_ && GetElement()) { 138 if (GetElement()) {
147 integrity_failure_ = !CheckScriptResourceIntegrity(resource, GetElement()); 139 integrity_failure_ = !CheckScriptResourceIntegrity(resource, GetElement());
148 } 140 }
149 141
150 // If script streaming is in use, the client will be notified in 142 // If script streaming is in use, the client will be notified in
151 // streamingFinished. 143 // streamingFinished.
152 if (streamer_) 144 if (streamer_)
153 streamer_->NotifyFinished(resource); 145 streamer_->NotifyFinished(resource);
154 else if (Client()) 146 else if (Client())
155 Client()->PendingScriptFinished(this); 147 Client()->PendingScriptFinished(this);
156 } 148 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 228
237 KURL ClassicPendingScript::Url() const { 229 KURL ClassicPendingScript::Url() const {
238 return GetResource()->Url(); 230 return GetResource()->Url();
239 } 231 }
240 232
241 void ClassicPendingScript::RemoveFromMemoryCache() { 233 void ClassicPendingScript::RemoveFromMemoryCache() {
242 GetMemoryCache()->Remove(GetResource()); 234 GetMemoryCache()->Remove(GetResource());
243 } 235 }
244 236
245 } // namespace blink 237 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/ClassicPendingScript.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698