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

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

Issue 1854423002: ASSERT -> {DCHECK|DCHECK_XX}, ENABLE(ASSERT) -> DCHECK_IS_ON() in dom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mark svg/as-image/svg-nested.html crash on win Created 4 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google, Inc. All Rights Reserved. 2 * Copyright (C) 2010 Google, Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 m_element = other.m_element; 73 m_element = other.m_element;
74 m_startingPosition = other.m_startingPosition; 74 m_startingPosition = other.m_startingPosition;
75 m_integrityFailure = other.m_integrityFailure; 75 m_integrityFailure = other.m_integrityFailure;
76 m_streamer = other.m_streamer; 76 m_streamer = other.m_streamer;
77 this->ResourceOwner<ScriptResource, ScriptResourceClient>::operator=(other); 77 this->ResourceOwner<ScriptResource, ScriptResourceClient>::operator=(other);
78 return *this; 78 return *this;
79 } 79 }
80 80
81 void PendingScript::watchForLoad(ScriptResourceClient* client) 81 void PendingScript::watchForLoad(ScriptResourceClient* client)
82 { 82 {
83 ASSERT(!m_watchingForLoad); 83 DCHECK(!m_watchingForLoad);
84 // addClient() will call streamingFinished() if the load is complete. Caller s 84 // addClient() will call streamingFinished() if the load is complete. Caller s
85 // who do not expect to be re-entered from this call should not call 85 // who do not expect to be re-entered from this call should not call
86 // watchForLoad for a PendingScript which isReady. We also need to set 86 // watchForLoad for a PendingScript which isReady. We also need to set
87 // m_watchingForLoad early, since addClient() can result in calling 87 // m_watchingForLoad early, since addClient() can result in calling
88 // notifyFinished and further stopWatchingForLoad(). 88 // notifyFinished and further stopWatchingForLoad().
89 m_watchingForLoad = true; 89 m_watchingForLoad = true;
90 m_client = client; 90 m_client = client;
91 if (!m_streamer) 91 if (!m_streamer)
92 resource()->addClient(client); 92 resource()->addClient(client);
93 } 93 }
94 94
95 void PendingScript::stopWatchingForLoad() 95 void PendingScript::stopWatchingForLoad()
96 { 96 {
97 if (!m_watchingForLoad) 97 if (!m_watchingForLoad)
98 return; 98 return;
99 ASSERT(resource()); 99 DCHECK(resource());
100 if (!m_streamer) 100 if (!m_streamer)
101 resource()->removeClient(m_client); 101 resource()->removeClient(m_client);
102 m_client = nullptr; 102 m_client = nullptr;
103 m_watchingForLoad = false; 103 m_watchingForLoad = false;
104 } 104 }
105 105
106 void PendingScript::streamingFinished() 106 void PendingScript::streamingFinished()
107 { 107 {
108 ASSERT(resource()); 108 DCHECK(resource());
109 if (m_client) 109 if (m_client)
110 m_client->notifyFinished(resource()); 110 m_client->notifyFinished(resource());
111 } 111 }
112 112
113 void PendingScript::setElement(Element* element) 113 void PendingScript::setElement(Element* element)
114 { 114 {
115 m_element = element; 115 m_element = element;
116 } 116 }
117 117
118 RawPtr<Element> PendingScript::releaseElementAndClear() 118 RawPtr<Element> PendingScript::releaseElementAndClear()
119 { 119 {
120 setScriptResource(0); 120 setScriptResource(0);
121 m_watchingForLoad = false; 121 m_watchingForLoad = false;
122 m_startingPosition = TextPosition::belowRangePosition(); 122 m_startingPosition = TextPosition::belowRangePosition();
123 m_integrityFailure = false; 123 m_integrityFailure = false;
124 m_parserBlockingLoadStartTime = 0; 124 m_parserBlockingLoadStartTime = 0;
125 if (m_streamer) 125 if (m_streamer)
126 m_streamer->cancel(); 126 m_streamer->cancel();
127 m_streamer.release(); 127 m_streamer.release();
128 return m_element.release(); 128 return m_element.release();
129 } 129 }
130 130
131 void PendingScript::setScriptResource(ScriptResource* resource) 131 void PendingScript::setScriptResource(ScriptResource* resource)
132 { 132 {
133 setResource(resource); 133 setResource(resource);
134 } 134 }
135 135
136 void PendingScript::markParserBlockingLoadStartTime() 136 void PendingScript::markParserBlockingLoadStartTime()
137 { 137 {
138 ASSERT(m_parserBlockingLoadStartTime == 0.0); 138 DCHECK_EQ(m_parserBlockingLoadStartTime, 0.0);
139 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime(); 139 m_parserBlockingLoadStartTime = monotonicallyIncreasingTime();
140 } 140 }
141 141
142 void PendingScript::notifyFinished(Resource* resource) 142 void PendingScript::notifyFinished(Resource* resource)
143 { 143 {
144 // The following SRI checks need to be here because, unfortunately, fetches 144 // The following SRI checks need to be here because, unfortunately, fetches
145 // are not done purely according to the Fetch spec. In particular, 145 // are not done purely according to the Fetch spec. In particular,
146 // different requests for the same resource do not have different 146 // different requests for the same resource do not have different
147 // responses; the memory cache can (and will) return the exact same 147 // responses; the memory cache can (and will) return the exact same
148 // Resource object. 148 // Resource object.
149 // 149 //
150 // For different requests, the same Resource object will be returned and 150 // For different requests, the same Resource object will be returned and
151 // will not be associated with the particular request. Therefore, when the 151 // will not be associated with the particular request. Therefore, when the
152 // body of the response comes in, there's no way to validate the integrity 152 // body of the response comes in, there's no way to validate the integrity
153 // of the Resource object against a particular request (since there may be 153 // of the Resource object against a particular request (since there may be
154 // several pending requests all tied to the identical object, and the 154 // several pending requests all tied to the identical object, and the
155 // actual requests are not stored). 155 // actual requests are not stored).
156 // 156 //
157 // In order to simulate the correct behavior, Blink explicitly does the SRI 157 // In order to simulate the correct behavior, Blink explicitly does the SRI
158 // checks here, when a PendingScript tied to a particular request is 158 // checks here, when a PendingScript tied to a particular request is
159 // finished (and in the case of a StyleSheet, at the point of execution), 159 // finished (and in the case of a StyleSheet, at the point of execution),
160 // while having proper Fetch checks in the fetch module for use in the 160 // while having proper Fetch checks in the fetch module for use in the
161 // fetch JavaScript API. In a future world where the ResourceFetcher uses 161 // fetch JavaScript API. In a future world where the ResourceFetcher uses
162 // the Fetch algorithm, this should be fixed by having separate Response 162 // the Fetch algorithm, this should be fixed by having separate Response
163 // objects (perhaps attached to identical Resource objects) per request. 163 // objects (perhaps attached to identical Resource objects) per request.
164 // 164 //
165 // See https://crbug.com/500701 for more information. 165 // See https://crbug.com/500701 for more information.
166 if (m_element) { 166 if (m_element) {
167 ASSERT(resource->getType() == Resource::Script); 167 DCHECK_EQ(resource->getType(), Resource::Script);
168 ScriptResource* scriptResource = toScriptResource(resource); 168 ScriptResource* scriptResource = toScriptResource(resource);
169 String integrityAttr = m_element->fastGetAttribute(HTMLNames::integrityA ttr); 169 String integrityAttr = m_element->fastGetAttribute(HTMLNames::integrityA ttr);
170 170
171 // It is possible to get back a script resource with integrity metadata 171 // It is possible to get back a script resource with integrity metadata
172 // for a request with an empty integrity attribute. In that case, the 172 // for a request with an empty integrity attribute. In that case, the
173 // integrity check should be skipped, so this check ensures that the 173 // integrity check should be skipped, so this check ensures that the
174 // integrity attribute isn't empty in addition to checking if the 174 // integrity attribute isn't empty in addition to checking if the
175 // resource has empty integrity metadata. 175 // resource has empty integrity metadata.
176 if (!integrityAttr.isEmpty() && !scriptResource->integrityMetadata().isE mpty()) { 176 if (!integrityAttr.isEmpty() && !scriptResource->integrityMetadata().isE mpty()) {
177 ScriptIntegrityDisposition disposition = scriptResource->integrityDi sposition(); 177 ScriptIntegrityDisposition disposition = scriptResource->integrityDi sposition();
(...skipping 23 matching lines...) Expand all
201 { 201 {
202 visitor->trace(m_element); 202 visitor->trace(m_element);
203 visitor->trace(m_streamer); 203 visitor->trace(m_streamer);
204 ResourceOwner<ScriptResource>::trace(visitor); 204 ResourceOwner<ScriptResource>::trace(visitor);
205 } 205 }
206 206
207 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const 207 ScriptSourceCode PendingScript::getSource(const KURL& documentURL, bool& errorOc curred) const
208 { 208 {
209 if (resource()) { 209 if (resource()) {
210 errorOccurred = resource()->errorOccurred() || m_integrityFailure; 210 errorOccurred = resource()->errorOccurred() || m_integrityFailure;
211 ASSERT(resource()->isLoaded()); 211 DCHECK(resource()->isLoaded());
212 if (m_streamer && !m_streamer->streamingSuppressed()) 212 if (m_streamer && !m_streamer->streamingSuppressed())
213 return ScriptSourceCode(m_streamer, resource()); 213 return ScriptSourceCode(m_streamer, resource());
214 return ScriptSourceCode(resource()); 214 return ScriptSourceCode(resource());
215 } 215 }
216 errorOccurred = false; 216 errorOccurred = false;
217 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion()); 217 return ScriptSourceCode(m_element->textContent(), documentURL, startingPosit ion());
218 } 218 }
219 219
220 void PendingScript::setStreamer(RawPtr<ScriptStreamer> streamer) 220 void PendingScript::setStreamer(RawPtr<ScriptStreamer> streamer)
221 { 221 {
222 ASSERT(!m_streamer); 222 DCHECK(!m_streamer);
223 ASSERT(!m_watchingForLoad); 223 DCHECK(!m_watchingForLoad);
224 m_streamer = streamer; 224 m_streamer = streamer;
225 } 225 }
226 226
227 bool PendingScript::isReady() const 227 bool PendingScript::isReady() const
228 { 228 {
229 if (resource() && !resource()->isLoaded()) 229 if (resource() && !resource()->isLoaded())
230 return false; 230 return false;
231 if (m_streamer && !m_streamer->isFinished()) 231 if (m_streamer && !m_streamer->isFinished())
232 return false; 232 return false;
233 return true; 233 return true;
234 } 234 }
235 235
236 bool PendingScript::errorOccurred() const 236 bool PendingScript::errorOccurred() const
237 { 237 {
238 if (resource()) 238 if (resource())
239 return resource()->errorOccurred(); 239 return resource()->errorOccurred();
240 if (m_streamer && m_streamer->resource()) 240 if (m_streamer && m_streamer->resource())
241 return m_streamer->resource()->errorOccurred(); 241 return m_streamer->resource()->errorOccurred();
242 return false; 242 return false;
243 } 243 }
244 244
245 } // namespace blink 245 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698