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

Side by Side Diff: Source/core/dom/ScriptLoader.cpp

Issue 669503003: Revert of Refactor Script(Loader|Runner): don't access Resources all over the place... (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 2 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 | « Source/core/dom/ScriptLoader.h ('k') | Source/core/dom/ScriptRunner.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserv ed.
6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org> 6 * Copyright (C) 2008 Nikolas Zimmermann <zimmermann@kde.org>
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 , m_forceAsync(!parserInserted) 68 , m_forceAsync(!parserInserted)
69 , m_willExecuteInOrder(false) 69 , m_willExecuteInOrder(false)
70 { 70 {
71 ASSERT(m_element); 71 ASSERT(m_element);
72 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite()) 72 if (parserInserted && element->document().scriptableDocumentParser() && !ele ment->document().isInDocumentWrite())
73 m_startLineNumber = element->document().scriptableDocumentParser()->line Number(); 73 m_startLineNumber = element->document().scriptableDocumentParser()->line Number();
74 } 74 }
75 75
76 ScriptLoader::~ScriptLoader() 76 ScriptLoader::~ScriptLoader()
77 { 77 {
78 m_pendingScript.stopWatchingForLoad(this); 78 stopLoadRequest();
79 } 79 }
80 80
81 void ScriptLoader::didNotifySubtreeInsertionsToDocument() 81 void ScriptLoader::didNotifySubtreeInsertionsToDocument()
82 { 82 {
83 if (!m_parserInserted) 83 if (!m_parserInserted)
84 prepareScript(); // FIXME: Provide a real starting line number here. 84 prepareScript(); // FIXME: Provide a real starting line number here.
85 } 85 }
86 86
87 void ScriptLoader::childrenChanged() 87 void ScriptLoader::childrenChanged()
88 { 88 {
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse rInserted && !client->asyncAttributeValue()) { 228 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse rInserted && !client->asyncAttributeValue()) {
229 m_willExecuteWhenDocumentFinishedParsing = true; 229 m_willExecuteWhenDocumentFinishedParsing = true;
230 m_willBeParserExecuted = true; 230 m_willBeParserExecuted = true;
231 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn cAttributeValue()) { 231 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn cAttributeValue()) {
232 m_willBeParserExecuted = true; 232 m_willBeParserExecuted = true;
233 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu ment.isRenderingReady()) { 233 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu ment.isRenderingReady()) {
234 m_willBeParserExecuted = true; 234 m_willBeParserExecuted = true;
235 m_readyToBeParserExecuted = true; 235 m_readyToBeParserExecuted = true;
236 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) { 236 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() && !m_forceAsync) {
237 m_willExecuteInOrder = true; 237 m_willExecuteInOrder = true;
238 m_pendingScript = PendingScript(m_element, m_resource.get()); 238 contextDocument->scriptRunner()->queueScriptForExecution(this, m_resourc e, ScriptRunner::IN_ORDER_EXECUTION);
239 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun ner::IN_ORDER_EXECUTION); 239 m_resource->addClient(this);
240 // Note that watchForLoad can immediately call notifyFinished.
241 m_pendingScript.watchForLoad(this);
242 } else if (client->hasSourceAttribute()) { 240 } else if (client->hasSourceAttribute()) {
243 m_pendingScript = PendingScript(m_element, m_resource.get()); 241 contextDocument->scriptRunner()->queueScriptForExecution(this, m_resourc e, ScriptRunner::ASYNC_EXECUTION);
244 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun ner::ASYNC_EXECUTION); 242 m_resource->addClient(this);
245 // Note that watchForLoad can immediately call notifyFinished.
246 m_pendingScript.watchForLoad(this);
247 } else { 243 } else {
248 // Reset line numbering for nested writes. 244 // Reset line numbering for nested writes.
249 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi on() : scriptStartPosition; 245 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi on() : scriptStartPosition;
250 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert ed) ? elementDocument.url() : KURL(); 246 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert ed) ? elementDocument.url() : KURL();
251 executeScript(ScriptSourceCode(scriptContent(), scriptURL, position)); 247 executeScript(ScriptSourceCode(scriptContent(), scriptURL, position));
252 } 248 }
253 249
254 return true; 250 return true;
255 } 251 }
256 252
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 // block's source and the script block's type. 349 // block's source and the script block's type.
354 // Note: This is where the script is compiled and actually executed. 350 // Note: This is where the script is compiled and actually executed.
355 frame->script().executeScriptInMainWorld(sourceCode, corsCheck, compilationF inishTime); 351 frame->script().executeScriptInMainWorld(sourceCode, corsCheck, compilationF inishTime);
356 352
357 if (isHTMLScriptLoader(m_element)) { 353 if (isHTMLScriptLoader(m_element)) {
358 ASSERT(contextDocument->currentScript() == m_element); 354 ASSERT(contextDocument->currentScript() == m_element);
359 contextDocument->popCurrentScript(); 355 contextDocument->popCurrentScript();
360 } 356 }
361 } 357 }
362 358
363 void ScriptLoader::execute() 359 void ScriptLoader::stopLoadRequest()
360 {
361 if (m_resource) {
362 if (!m_willBeParserExecuted)
363 m_resource->removeClient(this);
364 m_resource = 0;
365 }
366 }
367
368 void ScriptLoader::execute(ScriptResource* resource)
364 { 369 {
365 ASSERT(!m_willBeParserExecuted); 370 ASSERT(!m_willBeParserExecuted);
366 ASSERT(m_pendingScript.resource()); 371 ASSERT(resource);
367 bool errorOccurred = false; 372 if (resource->errorOccurred()) {
368 ScriptSourceCode source = m_pendingScript.getSource(KURL(), errorOccurred);
369 RefPtr<Element> element = m_pendingScript.releaseElementAndClear();
370 if (errorOccurred) {
371 dispatchErrorEvent(); 373 dispatchErrorEvent();
372 } else if (!m_resource->wasCanceled()) { 374 } else if (!resource->wasCanceled()) {
373 executeScript(source); 375 executeScript(ScriptSourceCode(resource));
374 dispatchLoadEvent(); 376 dispatchLoadEvent();
375 } 377 }
376 m_resource = 0; 378 resource->removeClient(this);
377 } 379 }
378 380
379 void ScriptLoader::notifyFinished(Resource* resource) 381 void ScriptLoader::notifyFinished(Resource* resource)
380 { 382 {
381 ASSERT(!m_willBeParserExecuted); 383 ASSERT(!m_willBeParserExecuted);
382 384
383 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document()); 385 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document());
384 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum ent().get(); 386 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum ent().get();
385 if (!contextDocument) 387 if (!contextDocument)
386 return; 388 return;
387 389
390 // Resource possibly invokes this notifyFinished() more than
391 // once because ScriptLoader doesn't unsubscribe itself from
392 // Resource here and does it in execute() instead.
393 // We use m_resource to check if this function is already called.
388 ASSERT_UNUSED(resource, resource == m_resource); 394 ASSERT_UNUSED(resource, resource == m_resource);
389 395 if (!m_resource)
396 return;
390 if (m_resource->errorOccurred()) { 397 if (m_resource->errorOccurred()) {
391 dispatchErrorEvent(); 398 dispatchErrorEvent();
392 contextDocument->scriptRunner()->notifyScriptLoadError(this, m_willExecu teInOrder ? ScriptRunner::IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION); 399 contextDocument->scriptRunner()->notifyScriptLoadError(this, m_willExecu teInOrder ? ScriptRunner::IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION);
393 return; 400 return;
394 } 401 }
395 if (m_willExecuteInOrder) 402 if (m_willExecuteInOrder)
396 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::I N_ORDER_EXECUTION); 403 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::I N_ORDER_EXECUTION);
397 else 404 else
398 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::A SYNC_EXECUTION); 405 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::A SYNC_EXECUTION);
399 406
400 m_pendingScript.stopWatchingForLoad(this); 407 m_resource = 0;
401 } 408 }
402 409
403 bool ScriptLoader::ignoresLoadRequest() const 410 bool ScriptLoader::ignoresLoadRequest() const
404 { 411 {
405 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen t() || !element()->inDocument(); 412 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen t() || !element()->inDocument();
406 } 413 }
407 414
408 bool ScriptLoader::isScriptForEventSupported() const 415 bool ScriptLoader::isScriptForEventSupported() const
409 { 416 {
410 String eventAttribute = client()->eventAttributeValue(); 417 String eventAttribute = client()->eventAttributeValue();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 if (isHTMLScriptLoader(element)) 450 if (isHTMLScriptLoader(element))
444 return toHTMLScriptElement(element)->loader(); 451 return toHTMLScriptElement(element)->loader();
445 452
446 if (isSVGScriptLoader(element)) 453 if (isSVGScriptLoader(element))
447 return toSVGScriptElement(element)->loader(); 454 return toSVGScriptElement(element)->loader();
448 455
449 return 0; 456 return 0;
450 } 457 }
451 458
452 } 459 }
OLDNEW
« no previous file with comments | « Source/core/dom/ScriptLoader.h ('k') | Source/core/dom/ScriptRunner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698