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

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

Issue 288673002: Make ScriptLoader into a ResourceOwner (Closed) Base URL: svn://svn.chromium.org/blink/trunk
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(Element* element) 247 void HTMLScriptRunner::requestParsingBlockingScript(const ResourcePtr<ScriptReso urce>& resource, Element* element)
248 { 248 {
249 if (!requestPendingScript(m_parserBlockingScript, element)) 249 if (!requestPendingScript(resource, 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(Element* element) 261 void HTMLScriptRunner::requestDeferredScript(const ResourcePtr<ScriptResource>& resource, Element* element)
262 { 262 {
263 PendingScript pendingScript; 263 PendingScript pendingScript;
264 if (!requestPendingScript(pendingScript, element)) 264 if (!requestPendingScript(resource, 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(PendingScript& pendingScript, Elemen t* script) const 271 bool HTMLScriptRunner::requestPendingScript(const ResourcePtr<ScriptResource>& r esource, PendingScript& pendingScript, Element* 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( );
277 if (!resource) { 276 if (!resource) {
278 notImplemented(); // Dispatch error event. 277 notImplemented(); // Dispatch error event.
279 return false; 278 return false;
280 } 279 }
281 pendingScript.setScriptResource(resource); 280 pendingScript.setScriptResource(resource.get());
282 return true; 281 return true;
283 } 282 }
284 283
285 // Implements the initial steps for 'An end tag whose tag name is "script"' 284 // Implements the initial steps for 'An end tag whose tag name is "script"'
286 // http://whatwg.org/html#scriptEndTag 285 // http://whatwg.org/html#scriptEndTag
287 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar tPosition) 286 void HTMLScriptRunner::runScript(Element* script, const TextPosition& scriptStar tPosition)
288 { 287 {
289 ASSERT(m_document); 288 ASSERT(m_document);
290 ASSERT(!hasParserBlockingScript()); 289 ASSERT(!hasParserBlockingScript());
291 { 290 {
292 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script); 291 ScriptLoader* scriptLoader = toScriptLoaderIfPossible(script);
293 292
294 // This contains both and ASSERTION and a null check since we should not 293 // This contains both and ASSERTION and a null check since we should not
295 // be getting into the case of a null script element, but seem to be fro m 294 // be getting into the case of a null script element, but seem to be fro m
296 // time to time. The assertion is left in to help find those cases and 295 // time to time. The assertion is left in to help find those cases and
297 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>. 296 // is being tracked by <https://bugs.webkit.org/show_bug.cgi?id=60559>.
298 ASSERT(scriptLoader); 297 ASSERT(scriptLoader);
299 if (!scriptLoader) 298 if (!scriptLoader)
300 return; 299 return;
301 300
302 ASSERT(scriptLoader->isParserInserted()); 301 ASSERT(scriptLoader->isParserInserted());
303 302
304 if (!isExecutingScript()) 303 if (!isExecutingScript())
305 Microtask::performCheckpoint(); 304 Microtask::performCheckpoint();
306 305
307 InsertionPointRecord insertionPointRecord(m_host->inputStream()); 306 InsertionPointRecord insertionPointRecord(m_host->inputStream());
308 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel); 307 NestingLevelIncrementer nestingLevelIncrementer(m_scriptNestingLevel);
309 308
310 scriptLoader->prepareScript(scriptStartPosition); 309 ScriptPrep prep = scriptLoader->prepareScript(scriptStartPosition);
311 310
312 if (!scriptLoader->willBeParserExecuted()) 311 if (!scriptLoader->willBeParserExecuted())
313 return; 312 return;
314 313
315 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) { 314 if (scriptLoader->willExecuteWhenDocumentFinishedParsing()) {
316 requestDeferredScript(script); 315 requestDeferredScript(prep.resource(), script);
317 } else if (scriptLoader->readyToBeParserExecuted()) { 316 } else if (scriptLoader->readyToBeParserExecuted()) {
318 if (m_scriptNestingLevel == 1) { 317 if (m_scriptNestingLevel == 1) {
319 m_parserBlockingScript.setElement(script); 318 m_parserBlockingScript.setElement(script);
320 m_parserBlockingScript.setStartingPosition(scriptStartPosition); 319 m_parserBlockingScript.setStartingPosition(scriptStartPosition);
321 } else { 320 } else {
322 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition); 321 ScriptSourceCode sourceCode(script->textContent(), documentURLFo rScriptExecution(m_document), scriptStartPosition);
323 scriptLoader->executeScript(sourceCode); 322 scriptLoader->executeScript(sourceCode);
324 } 323 }
325 } else { 324 } else {
326 requestParsingBlockingScript(script); 325 requestParsingBlockingScript(prep.resource(), script);
327 } 326 }
328 } 327 }
329 } 328 }
330 329
331 } 330 }
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLScriptRunner.h ('k') | Source/core/xml/parser/XMLDocumentParser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698