| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 , m_haveFiredLoad(false) | 67 , m_haveFiredLoad(false) |
| 68 , m_willBeParserExecuted(false) | 68 , m_willBeParserExecuted(false) |
| 69 , m_readyToBeParserExecuted(false) | 69 , m_readyToBeParserExecuted(false) |
| 70 , m_willExecuteWhenDocumentFinishedParsing(false) | 70 , m_willExecuteWhenDocumentFinishedParsing(false) |
| 71 , m_forceAsync(!parserInserted) | 71 , m_forceAsync(!parserInserted) |
| 72 , m_willExecuteInOrder(false) | 72 , m_willExecuteInOrder(false) |
| 73 { | 73 { |
| 74 ASSERT(m_element); | 74 ASSERT(m_element); |
| 75 if (parserInserted && element->document().scriptableDocumentParser() && !ele
ment->document().isInDocumentWrite()) | 75 if (parserInserted && element->document().scriptableDocumentParser() && !ele
ment->document().isInDocumentWrite()) |
| 76 m_startLineNumber = element->document().scriptableDocumentParser()->line
Number(); | 76 m_startLineNumber = element->document().scriptableDocumentParser()->line
Number(); |
| 77 #if ENABLE(OILPAN) |
| 78 ThreadState::current()->registerPreFinalizer(this); |
| 79 #endif |
| 77 } | 80 } |
| 78 | 81 |
| 79 ScriptLoader::~ScriptLoader() | 82 ScriptLoader::~ScriptLoader() |
| 80 { | 83 { |
| 81 m_pendingScript.stopWatchingForLoad(this); | 84 #if !ENABLE(OILPAN) |
| 85 detach(); |
| 86 #endif |
| 82 } | 87 } |
| 83 | 88 |
| 84 DEFINE_TRACE(ScriptLoader) | 89 DEFINE_TRACE(ScriptLoader) |
| 85 { | 90 { |
| 86 visitor->trace(m_element); | 91 visitor->trace(m_element); |
| 87 visitor->trace(m_pendingScript); | 92 visitor->trace(m_pendingScript); |
| 88 } | 93 } |
| 89 | 94 |
| 90 void ScriptLoader::didNotifySubtreeInsertionsToDocument() | 95 void ScriptLoader::didNotifySubtreeInsertionsToDocument() |
| 91 { | 96 { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 107 prepareScript(); // FIXME: Provide a real starting line number here. | 112 prepareScript(); // FIXME: Provide a real starting line number here. |
| 108 } | 113 } |
| 109 | 114 |
| 110 void ScriptLoader::handleAsyncAttribute() | 115 void ScriptLoader::handleAsyncAttribute() |
| 111 { | 116 { |
| 112 m_forceAsync = false; | 117 m_forceAsync = false; |
| 113 } | 118 } |
| 114 | 119 |
| 115 void ScriptLoader::detach() | 120 void ScriptLoader::detach() |
| 116 { | 121 { |
| 117 m_pendingScript.stopWatchingForLoad(this); | 122 if (!m_pendingScript) |
| 118 m_pendingScript.releaseElementAndClear(); | 123 return; |
| 124 m_pendingScript->stopWatchingForLoad(this); |
| 125 m_pendingScript->releaseElementAndClear(); |
| 126 m_pendingScript = nullptr; |
| 119 } | 127 } |
| 120 | 128 |
| 121 // Helper function | 129 // Helper function |
| 122 static bool isLegacySupportedJavaScriptLanguage(const String& language) | 130 static bool isLegacySupportedJavaScriptLanguage(const String& language) |
| 123 { | 131 { |
| 124 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on
ly javascript1.1 - javascript1.3. | 132 // Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts on
ly javascript1.1 - javascript1.3. |
| 125 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. | 133 // Mozilla 1.8 and WinIE 7 both accept javascript and livescript. |
| 126 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. | 134 // WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't. |
| 127 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. | 135 // Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace. |
| 128 // We want to accept all the values that either of these browsers accept, bu
t not other values. | 136 // We want to accept all the values that either of these browsers accept, bu
t not other values. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse
rInserted && !client->asyncAttributeValue()) { | 251 if (client->hasSourceAttribute() && client->deferAttributeValue() && m_parse
rInserted && !client->asyncAttributeValue()) { |
| 244 m_willExecuteWhenDocumentFinishedParsing = true; | 252 m_willExecuteWhenDocumentFinishedParsing = true; |
| 245 m_willBeParserExecuted = true; | 253 m_willBeParserExecuted = true; |
| 246 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn
cAttributeValue()) { | 254 } else if (client->hasSourceAttribute() && m_parserInserted && !client->asyn
cAttributeValue()) { |
| 247 m_willBeParserExecuted = true; | 255 m_willBeParserExecuted = true; |
| 248 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu
ment.isRenderingReady()) { | 256 } else if (!client->hasSourceAttribute() && m_parserInserted && !elementDocu
ment.isRenderingReady()) { |
| 249 m_willBeParserExecuted = true; | 257 m_willBeParserExecuted = true; |
| 250 m_readyToBeParserExecuted = true; | 258 m_readyToBeParserExecuted = true; |
| 251 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() &&
!m_forceAsync) { | 259 } else if (client->hasSourceAttribute() && !client->asyncAttributeValue() &&
!m_forceAsync) { |
| 252 m_willExecuteInOrder = true; | 260 m_willExecuteInOrder = true; |
| 253 m_pendingScript = PendingScript(m_element, m_resource.get()); | 261 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
| 254 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun
ner::IN_ORDER_EXECUTION); | 262 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun
ner::IN_ORDER_EXECUTION); |
| 255 // Note that watchForLoad can immediately call notifyFinished. | 263 // Note that watchForLoad can immediately call notifyFinished. |
| 256 m_pendingScript.watchForLoad(this); | 264 m_pendingScript->watchForLoad(this); |
| 257 } else if (client->hasSourceAttribute()) { | 265 } else if (client->hasSourceAttribute()) { |
| 258 m_pendingScript = PendingScript(m_element, m_resource.get()); | 266 m_pendingScript = PendingScript::create(m_element, m_resource.get()); |
| 259 LocalFrame* frame = m_element->document().frame(); | 267 LocalFrame* frame = m_element->document().frame(); |
| 260 if (frame) { | 268 if (frame) { |
| 261 ScriptState* scriptState = ScriptState::forMainWorld(frame); | 269 ScriptState* scriptState = ScriptState::forMainWorld(frame); |
| 262 if (scriptState) | 270 if (scriptState) |
| 263 ScriptStreamer::startStreaming(m_pendingScript, PendingScript::A
sync, frame->settings(), scriptState, frame->frameScheduler()->loadingTaskRunner
()); | 271 ScriptStreamer::startStreaming(m_pendingScript.get(), ScriptStre
amer::Async, frame->settings(), scriptState, frame->frameScheduler()->loadingTas
kRunner()); |
| 264 } | 272 } |
| 265 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun
ner::ASYNC_EXECUTION); | 273 contextDocument->scriptRunner()->queueScriptForExecution(this, ScriptRun
ner::ASYNC_EXECUTION); |
| 266 // Note that watchForLoad can immediately call notifyFinished. | 274 // Note that watchForLoad can immediately call notifyFinished. |
| 267 m_pendingScript.watchForLoad(this); | 275 m_pendingScript->watchForLoad(this); |
| 268 } else { | 276 } else { |
| 269 // Reset line numbering for nested writes. | 277 // Reset line numbering for nested writes. |
| 270 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi
on() : scriptStartPosition; | 278 TextPosition position = elementDocument.isInDocumentWrite() ? TextPositi
on() : scriptStartPosition; |
| 271 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert
ed) ? elementDocument.url() : KURL(); | 279 KURL scriptURL = (!elementDocument.isInDocumentWrite() && m_parserInsert
ed) ? elementDocument.url() : KURL(); |
| 272 if (!executeScript(ScriptSourceCode(scriptContent(), scriptURL, position
))) { | 280 if (!executeScript(ScriptSourceCode(scriptContent(), scriptURL, position
))) { |
| 273 dispatchErrorEvent(); | 281 dispatchErrorEvent(); |
| 274 return false; | 282 return false; |
| 275 } | 283 } |
| 276 } | 284 } |
| 277 | 285 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 ASSERT(contextDocument->currentScript() == m_element); | 430 ASSERT(contextDocument->currentScript() == m_element); |
| 423 contextDocument->popCurrentScript(); | 431 contextDocument->popCurrentScript(); |
| 424 } | 432 } |
| 425 | 433 |
| 426 return true; | 434 return true; |
| 427 } | 435 } |
| 428 | 436 |
| 429 void ScriptLoader::execute() | 437 void ScriptLoader::execute() |
| 430 { | 438 { |
| 431 ASSERT(!m_willBeParserExecuted); | 439 ASSERT(!m_willBeParserExecuted); |
| 432 ASSERT(m_pendingScript.resource()); | 440 ASSERT(m_pendingScript->resource()); |
| 433 bool errorOccurred = false; | 441 bool errorOccurred = false; |
| 434 ScriptSourceCode source = m_pendingScript.getSource(KURL(), errorOccurred); | 442 ScriptSourceCode source = m_pendingScript->getSource(KURL(), errorOccurred); |
| 435 RefPtrWillBeRawPtr<Element> element = m_pendingScript.releaseElementAndClear
(); | 443 RefPtrWillBeRawPtr<Element> element = m_pendingScript->releaseElementAndClea
r(); |
| 436 ALLOW_UNUSED_LOCAL(element); | 444 ALLOW_UNUSED_LOCAL(element); |
| 437 if (errorOccurred) { | 445 if (errorOccurred) { |
| 438 dispatchErrorEvent(); | 446 dispatchErrorEvent(); |
| 439 } else if (!m_resource->wasCanceled()) { | 447 } else if (!m_resource->wasCanceled()) { |
| 440 if (executeScript(source)) | 448 if (executeScript(source)) |
| 441 dispatchLoadEvent(); | 449 dispatchLoadEvent(); |
| 442 else | 450 else |
| 443 dispatchErrorEvent(); | 451 dispatchErrorEvent(); |
| 444 } | 452 } |
| 445 m_resource = 0; | 453 m_resource = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 462 // dispatchErrorEvent might move the HTMLScriptElement to a new | 470 // dispatchErrorEvent might move the HTMLScriptElement to a new |
| 463 // document. In that case, we must notify the ScriptRunner of the new | 471 // document. In that case, we must notify the ScriptRunner of the new |
| 464 // document, not the ScriptRunner of the old docuemnt. | 472 // document, not the ScriptRunner of the old docuemnt. |
| 465 contextDocument = m_element->document().contextDocument().get(); | 473 contextDocument = m_element->document().contextDocument().get(); |
| 466 if (!contextDocument) | 474 if (!contextDocument) |
| 467 return; | 475 return; |
| 468 contextDocument->scriptRunner()->notifyScriptLoadError(this, runOrder); | 476 contextDocument->scriptRunner()->notifyScriptLoadError(this, runOrder); |
| 469 return; | 477 return; |
| 470 } | 478 } |
| 471 contextDocument->scriptRunner()->notifyScriptReady(this, runOrder); | 479 contextDocument->scriptRunner()->notifyScriptReady(this, runOrder); |
| 472 m_pendingScript.stopWatchingForLoad(this); | 480 m_pendingScript->stopWatchingForLoad(this); |
| 473 } | 481 } |
| 474 | 482 |
| 475 bool ScriptLoader::ignoresLoadRequest() const | 483 bool ScriptLoader::ignoresLoadRequest() const |
| 476 { | 484 { |
| 477 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen
t() || !element()->inDocument(); | 485 return m_alreadyStarted || m_isExternalScript || m_parserInserted || !elemen
t() || !element()->inDocument(); |
| 478 } | 486 } |
| 479 | 487 |
| 480 bool ScriptLoader::isScriptForEventSupported() const | 488 bool ScriptLoader::isScriptForEventSupported() const |
| 481 { | 489 { |
| 482 String eventAttribute = client()->eventAttributeValue(); | 490 String eventAttribute = client()->eventAttributeValue(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 513 if (isHTMLScriptLoader(element)) | 521 if (isHTMLScriptLoader(element)) |
| 514 return toHTMLScriptElement(element)->loader(); | 522 return toHTMLScriptElement(element)->loader(); |
| 515 | 523 |
| 516 if (isSVGScriptLoader(element)) | 524 if (isSVGScriptLoader(element)) |
| 517 return toSVGScriptElement(element)->loader(); | 525 return toSVGScriptElement(element)->loader(); |
| 518 | 526 |
| 519 return 0; | 527 return 0; |
| 520 } | 528 } |
| 521 | 529 |
| 522 } // namespace blink | 530 } // namespace blink |
| OLD | NEW |