| OLD | NEW |
| 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 Loading... |
| 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 stopLoadRequest(); | 78 m_pendingScript.stopWatchingForLoad(this); |
| 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 Loading... |
| 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 contextDocument->scriptRunner()->queueScriptForExecution(this, m_resourc
e, ScriptRunner::IN_ORDER_EXECUTION); | 238 m_pendingScript = PendingScript(m_element, m_resource.get()); |
| 239 m_resource->addClient(this); | 239 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun
ner::IN_ORDER_EXECUTION); |
| 240 // Note that watchForLoad can immediately call notifyFinished. |
| 241 m_pendingScript.watchForLoad(this); |
| 240 } else if (client->hasSourceAttribute()) { | 242 } else if (client->hasSourceAttribute()) { |
| 241 contextDocument->scriptRunner()->queueScriptForExecution(this, m_resourc
e, ScriptRunner::ASYNC_EXECUTION); | 243 m_pendingScript = PendingScript(m_element, m_resource.get()); |
| 242 m_resource->addClient(this); | 244 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun
ner::ASYNC_EXECUTION); |
| 245 // Note that watchForLoad can immediately call notifyFinished. |
| 246 m_pendingScript.watchForLoad(this); |
| 243 } else { | 247 } else { |
| 244 // Reset line numbering for nested writes. | 248 // Reset line numbering for nested writes. |
| 245 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi
on() : scriptStartPosition; | 249 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi
on() : scriptStartPosition; |
| 246 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert
ed) ? elementDocument.url() : KURL(); | 250 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert
ed) ? elementDocument.url() : KURL(); |
| 247 executeScript(ScriptSourceCode(scriptContent(), scriptURL, position)); | 251 executeScript(ScriptSourceCode(scriptContent(), scriptURL, position)); |
| 248 } | 252 } |
| 249 | 253 |
| 250 return true; | 254 return true; |
| 251 } | 255 } |
| 252 | 256 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // block's source and the script block's type. | 353 // block's source and the script block's type. |
| 350 // Note: This is where the script is compiled and actually executed. | 354 // Note: This is where the script is compiled and actually executed. |
| 351 frame->script().executeScriptInMainWorld(sourceCode, corsCheck, compilationF
inishTime); | 355 frame->script().executeScriptInMainWorld(sourceCode, corsCheck, compilationF
inishTime); |
| 352 | 356 |
| 353 if (isHTMLScriptLoader(m_element)) { | 357 if (isHTMLScriptLoader(m_element)) { |
| 354 ASSERT(contextDocument->currentScript() == m_element); | 358 ASSERT(contextDocument->currentScript() == m_element); |
| 355 contextDocument->popCurrentScript(); | 359 contextDocument->popCurrentScript(); |
| 356 } | 360 } |
| 357 } | 361 } |
| 358 | 362 |
| 359 void ScriptLoader::stopLoadRequest() | 363 void ScriptLoader::execute() |
| 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) | |
| 369 { | 364 { |
| 370 ASSERT(!m_willBeParserExecuted); | 365 ASSERT(!m_willBeParserExecuted); |
| 371 ASSERT(resource); | 366 ASSERT(m_pendingScript.resource()); |
| 372 if (resource->errorOccurred()) { | 367 bool errorOccurred = false; |
| 368 ScriptSourceCode source = m_pendingScript.getSource(KURL(), errorOccurred); |
| 369 RefPtr<Element> element = m_pendingScript.releaseElementAndClear(); |
| 370 if (errorOccurred) { |
| 373 dispatchErrorEvent(); | 371 dispatchErrorEvent(); |
| 374 } else if (!resource->wasCanceled()) { | 372 } else if (!m_resource->wasCanceled()) { |
| 375 executeScript(ScriptSourceCode(resource)); | 373 executeScript(source); |
| 376 dispatchLoadEvent(); | 374 dispatchLoadEvent(); |
| 377 } | 375 } |
| 378 resource->removeClient(this); | 376 m_resource = 0; |
| 379 } | 377 } |
| 380 | 378 |
| 381 void ScriptLoader::notifyFinished(Resource* resource) | 379 void ScriptLoader::notifyFinished(Resource* resource) |
| 382 { | 380 { |
| 383 ASSERT(!m_willBeParserExecuted); | 381 ASSERT(!m_willBeParserExecuted); |
| 384 | 382 |
| 385 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document()); | 383 RefPtrWillBeRawPtr<Document> elementDocument(m_element->document()); |
| 386 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum
ent().get(); | 384 RefPtrWillBeRawPtr<Document> contextDocument = elementDocument->contextDocum
ent().get(); |
| 387 if (!contextDocument) | 385 if (!contextDocument) |
| 388 return; | 386 return; |
| 389 | 387 |
| 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. | |
| 394 ASSERT_UNUSED(resource, resource == m_resource); | 388 ASSERT_UNUSED(resource, resource == m_resource); |
| 395 if (!m_resource) | 389 |
| 396 return; | |
| 397 if (m_resource->errorOccurred()) { | 390 if (m_resource->errorOccurred()) { |
| 398 dispatchErrorEvent(); | 391 dispatchErrorEvent(); |
| 399 contextDocument->scriptRunner()->notifyScriptLoadError(this, m_willExecu
teInOrder ? ScriptRunner::IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION); | 392 contextDocument->scriptRunner()->notifyScriptLoadError(this, m_willExecu
teInOrder ? ScriptRunner::IN_ORDER_EXECUTION : ScriptRunner::ASYNC_EXECUTION); |
| 400 return; | 393 return; |
| 401 } | 394 } |
| 402 if (m_willExecuteInOrder) | 395 if (m_willExecuteInOrder) |
| 403 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::I
N_ORDER_EXECUTION); | 396 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::I
N_ORDER_EXECUTION); |
| 404 else | 397 else |
| 405 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::A
SYNC_EXECUTION); | 398 contextDocument->scriptRunner()->notifyScriptReady(this, ScriptRunner::A
SYNC_EXECUTION); |
| 406 | 399 |
| 407 m_resource = 0; | 400 m_pendingScript.stopWatchingForLoad(this); |
| 408 } | 401 } |
| 409 | 402 |
| 410 bool ScriptLoader::ignoresLoadRequest() const | 403 bool ScriptLoader::ignoresLoadRequest() const |
| 411 { | 404 { |
| 412 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen
t() || !element()->inDocument(); | 405 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen
t() || !element()->inDocument(); |
| 413 } | 406 } |
| 414 | 407 |
| 415 bool ScriptLoader::isScriptForEventSupported() const | 408 bool ScriptLoader::isScriptForEventSupported() const |
| 416 { | 409 { |
| 417 String eventAttribute = client()->eventAttributeValue(); | 410 String eventAttribute = client()->eventAttributeValue(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 if (isHTMLScriptLoader(element)) | 443 if (isHTMLScriptLoader(element)) |
| 451 return toHTMLScriptElement(element)->loader(); | 444 return toHTMLScriptElement(element)->loader(); |
| 452 | 445 |
| 453 if (isSVGScriptLoader(element)) | 446 if (isSVGScriptLoader(element)) |
| 454 return toSVGScriptElement(element)->loader(); | 447 return toSVGScriptElement(element)->loader(); |
| 455 | 448 |
| 456 return 0; | 449 return 0; |
| 457 } | 450 } |
| 458 | 451 |
| 459 } | 452 } |
| OLD | NEW |