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

Side by Side Diff: trunk/Source/core/html/parser/HTMLScriptRunner.cpp

Issue 283333002: Revert 174019 "Make ScriptLoader into a ResourceOwner" (Closed) Base URL: svn://svn.chromium.org/blink/
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 PendingScript first = m_scriptsToExecuteAfterParsing.takeFirst(); 238 PendingScript first = m_scriptsToExecuteAfterParsing.takeFirst();
239 executePendingScriptAndDispatchEvent(first, PendingScriptDeferred); 239 executePendingScriptAndDispatchEvent(first, PendingScriptDeferred);
240 // FIXME: What is this m_document check for? 240 // FIXME: What is this m_document check for?
241 if (!m_document) 241 if (!m_document)
242 return false; 242 return false;
243 } 243 }
244 return true; 244 return true;
245 } 245 }
246 246
247 void HTMLScriptRunner::requestParsingBlockingScript(const ResourcePtr<ScriptReso urce>& resource, Element* element) 247 void HTMLScriptRunner::requestParsingBlockingScript(Element* element)
248 { 248 {
249 if (!requestPendingScript(resource, m_parserBlockingScript, element)) 249 if (!requestPendingScript(m_parserBlockingScript, element))
250 return; 250 return;
251 251
252 ASSERT(m_parserBlockingScript.resource()); 252 ASSERT(m_parserBlockingScript.resource());
253 253
254 // We only care about a load callback if resource is not already 254 // We only care about a load callback if resource is not already
255 // in the cache. Callers will attempt to run the m_parserBlockingScript 255 // in the cache. Callers will attempt to run the m_parserBlockingScript
256 // if possible before returning control to the parser. 256 // if possible before returning control to the parser.
257 if (!m_parserBlockingScript.resource()->isLoaded()) 257 if (!m_parserBlockingScript.resource()->isLoaded())
258 watchForLoad(m_parserBlockingScript); 258 watchForLoad(m_parserBlockingScript);
259 } 259 }
260 260
261 void HTMLScriptRunner::requestDeferredScript(const ResourcePtr<ScriptResource>& resource, Element* element) 261 void HTMLScriptRunner::requestDeferredScript(Element* element)
262 { 262 {
263 PendingScript pendingScript; 263 PendingScript pendingScript;
264 if (!requestPendingScript(resource, pendingScript, element)) 264 if (!requestPendingScript(pendingScript, element))
265 return; 265 return;
266 266
267 ASSERT(pendingScript.resource()); 267 ASSERT(pendingScript.resource());
268 m_scriptsToExecuteAfterParsing.append(pendingScript); 268 m_scriptsToExecuteAfterParsing.append(pendingScript);
269 } 269 }
270 270
271 bool HTMLScriptRunner::requestPendingScript(const ResourcePtr<ScriptResource>& r esource, PendingScript& pendingScript, Element* script) const 271 bool HTMLScriptRunner::requestPendingScript(PendingScript& pendingScript, Elemen t* script) const
272 { 272 {
273 ASSERT(!pendingScript.element()); 273 ASSERT(!pendingScript.element());
274 pendingScript.setElement(script); 274 pendingScript.setElement(script);
275 // This should correctly return 0 for empty or invalid srcValues. 275 // This should correctly return 0 for empty or invalid srcValues.
276 ScriptResource* resource = toScriptLoaderIfPossible(script)->resource().get( );
276 if (!resource) { 277 if (!resource) {
277 notImplemented(); // Dispatch error event. 278 notImplemented(); // Dispatch error event.
278 return false; 279 return false;
279 } 280 }
280 pendingScript.setScriptResource(resource.get()); 281 pendingScript.setScriptResource(resource);
281 return true; 282 return true;
282 } 283 }
283 284
284 // Implements the initial steps for 'An end tag whose tag name is "script"' 285 // Implements the initial steps for 'An end tag whose tag name is "script"'
285 // http://whatwg.org/html#scriptEndTag 286 // http://whatwg.org/html#scriptEndTag
286 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar tPosition) 287 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar tPosition)
287 { 288 {
288 ASSERT(m_document); 289 ASSERT(m_document);
289 ASSERT(!hasParserBlockingScript()); 290 ASSERT(!hasParserBlockingScript());
290 { 291 {
291 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script); 292 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script);
292 293
293 // This contains both and ASSERTION and a null check since we should not 294 // This contains both and ASSERTION and a null check since we should not
294 // be getting into the case of a null script element, but seem to be fro m 295 // be getting into the case of a null script element, but seem to be fro m
295 // time to time. The assertion is left in to help find those cases and 296 // time to time. The assertion is left in to help find those cases and
296 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. 297 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>.
297 ASSERT(scriptLoader); 298 ASSERT(scriptLoader);
298 if (!scriptLoader) 299 if (!scriptLoader)
299 return; 300 return;
300 301
301 ASSERT(scriptLoader->isParserInserted()); 302 ASSERT(scriptLoader->isParserInserted());
302 303
303 if (!isExecutingScript()) 304 if (!isExecutingScript())
304 Microtask::performCheckpoint(); 305 Microtask::performCheckpoint();
305 306
306 InsertionPointRecord insertionPointRecord(m_host->inputStream()); 307 InsertionPointRecord insertionPointRecord(m_host->inputStream());
307 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 308 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
308 309
309 ScriptPrep prep = scriptLoader->prepareScript(scriptStartPosition); 310 scriptLoader->prepareScript(scriptStartPosition);
310 311
311 if (!scriptLoader->willBeParserExecuted()) 312 if (!scriptLoader->willBeParserExecuted())
312 return; 313 return;
313 314
314 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { 315 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) {
315 requestDeferredScript(prep.resource(), script); 316 requestDeferredScript(script);
316 } else if (scriptLoader->readyToBeParserExecuted()) { 317 } else if (scriptLoader->readyToBeParserExecuted()) {
317 if (m_scriptNestingLevel == 1) { 318 if (m_scriptNestingLevel == 1) {
318 m_parserBlockingScript.setElement(script); 319 m_parserBlockingScript.setElement(script);
319 m_parserBlockingScript.setStartingPosition(scriptStartPosition); 320 m_parserBlockingScript.setStartingPosition(scriptStartPosition);
320 } else { 321 } else {
321 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); 322 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition);
322 scriptLoader->executeScript(sourceCode); 323 scriptLoader->executeScript(sourceCode);
323 } 324 }
324 } else { 325 } else {
325 requestParsingBlockingScript(prep.resource(), script); 326 requestParsingBlockingScript(script);
326 } 327 }
327 } 328 }
328 } 329 }
329 330
330 } 331 }
OLDNEW
« no previous file with comments | « trunk/Source/core/html/parser/HTMLScriptRunner.h ('k') | trunk/Source/core/xml/parser/XMLDocumentParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698