| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/dom/ScriptRunner.h" | 27 #include "core/dom/ScriptRunner.h" |
| 28 | 28 |
| 29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
| 30 #include "core/dom/Element.h" | 30 #include "core/dom/Element.h" |
| 31 #include "core/dom/PendingScript.h" |
| 31 #include "core/dom/ScriptLoader.h" | 32 #include "core/dom/ScriptLoader.h" |
| 33 #include "core/fetch/ScriptResource.h" |
| 32 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
| 33 | 35 |
| 34 namespace blink { | 36 namespace blink { |
| 35 | 37 |
| 36 ScriptRunner::ScriptRunner(Document* document) | 38 ScriptRunner::ScriptRunner(Document* document) |
| 37 : m_document(document) | 39 : m_document(document) |
| 38 , m_timer(this, &ScriptRunner::timerFired) | 40 , m_timer(this, &ScriptRunner::timerFired) |
| 39 { | 41 { |
| 40 ASSERT(document); | 42 ASSERT(document); |
| 41 } | 43 } |
| 42 | 44 |
| 43 ScriptRunner::~ScriptRunner() | 45 ScriptRunner::~ScriptRunner() |
| 44 { | 46 { |
| 45 } | 47 } |
| 46 | 48 |
| 47 void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader) | 49 void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader, const Pendi
ngScript& pendingScript) |
| 48 { | 50 { |
| 49 m_document->incrementLoadEventDelayCount(); | 51 m_document->incrementLoadEventDelayCount(); |
| 50 m_pendingAsyncScripts.add(scriptLoader); | 52 m_pendingAsyncScripts.add(scriptLoader, pendingScript); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution
Type executionType) | 55 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ResourceP
tr<ScriptResource> resource, ExecutionType executionType) |
| 54 { | 56 { |
| 55 ASSERT(scriptLoader); | 57 ASSERT(scriptLoader); |
| 58 ASSERT(resource.get()); |
| 59 |
| 60 Element* element = scriptLoader->element(); |
| 61 ASSERT(element); |
| 62 ASSERT(element->inDocument()); |
| 56 | 63 |
| 57 switch (executionType) { | 64 switch (executionType) { |
| 58 case ASYNC_EXECUTION: | 65 case ASYNC_EXECUTION: |
| 59 addPendingAsyncScript(scriptLoader); | 66 addPendingAsyncScript(scriptLoader, PendingScript(element, resource.get(
))); |
| 60 break; | 67 break; |
| 61 | 68 |
| 62 case IN_ORDER_EXECUTION: | 69 case IN_ORDER_EXECUTION: |
| 63 m_document->incrementLoadEventDelayCount(); | 70 m_document->incrementLoadEventDelayCount(); |
| 64 m_scriptsToExecuteInOrder.append(scriptLoader); | 71 m_scriptsToExecuteInOrder.append(PendingScript(element, resource.get()))
; |
| 65 break; | 72 break; |
| 66 } | 73 } |
| 67 } | 74 } |
| 68 | 75 |
| 69 void ScriptRunner::suspend() | 76 void ScriptRunner::suspend() |
| 70 { | 77 { |
| 71 m_timer.stop(); | 78 m_timer.stop(); |
| 72 } | 79 } |
| 73 | 80 |
| 74 void ScriptRunner::resume() | 81 void ScriptRunner::resume() |
| 75 { | 82 { |
| 76 if (hasPendingScripts()) | 83 if (hasPendingScripts()) |
| 77 m_timer.startOneShot(0, FROM_HERE); | 84 m_timer.startOneShot(0, FROM_HERE); |
| 78 } | 85 } |
| 79 | 86 |
| 80 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) | 87 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) |
| 81 { | 88 { |
| 82 switch (executionType) { | 89 switch (executionType) { |
| 83 case ASYNC_EXECUTION: | 90 case ASYNC_EXECUTION: |
| 84 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); | 91 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); |
| 85 m_scriptsToExecuteSoon.append(scriptLoader); | 92 m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptLoader)); |
| 86 m_pendingAsyncScripts.remove(scriptLoader); | |
| 87 break; | 93 break; |
| 88 | 94 |
| 89 case IN_ORDER_EXECUTION: | 95 case IN_ORDER_EXECUTION: |
| 90 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); | 96 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); |
| 91 break; | 97 break; |
| 92 } | 98 } |
| 93 m_timer.startOneShot(0, FROM_HERE); | 99 m_timer.startOneShot(0, FROM_HERE); |
| 94 } | 100 } |
| 95 | 101 |
| 96 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy
pe executionType) | 102 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy
pe executionType) |
| 97 { | 103 { |
| 98 switch (executionType) { | 104 switch (executionType) { |
| 99 case ASYNC_EXECUTION: | 105 case ASYNC_EXECUTION: |
| 100 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); | 106 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); |
| 101 m_pendingAsyncScripts.remove(scriptLoader); | 107 m_pendingAsyncScripts.remove(scriptLoader); |
| 102 m_document->decrementLoadEventDelayCount(); | 108 m_document->decrementLoadEventDelayCount(); |
| 103 break; | 109 break; |
| 104 | 110 |
| 105 case IN_ORDER_EXECUTION: | 111 case IN_ORDER_EXECUTION: |
| 106 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); | 112 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); |
| 107 break; | 113 break; |
| 108 } | 114 } |
| 109 } | 115 } |
| 110 | 116 |
| 111 void ScriptRunner::movePendingAsyncScript(ScriptRunner* newRunner, ScriptLoader*
scriptLoader) | 117 void ScriptRunner::movePendingAsyncScript(ScriptRunner* newRunner, ScriptLoader*
scriptLoader) |
| 112 { | 118 { |
| 113 if (m_pendingAsyncScripts.contains(scriptLoader)) { | 119 if (m_pendingAsyncScripts.contains(scriptLoader)) { |
| 114 newRunner->addPendingAsyncScript(scriptLoader); | 120 newRunner->addPendingAsyncScript(scriptLoader, m_pendingAsyncScripts.tak
e(scriptLoader)); |
| 115 m_pendingAsyncScripts.remove(scriptLoader); | |
| 116 m_document->decrementLoadEventDelayCount(); | 121 m_document->decrementLoadEventDelayCount(); |
| 117 } | 122 } |
| 118 } | 123 } |
| 119 | 124 |
| 120 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) | 125 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) |
| 121 { | 126 { |
| 122 ASSERT_UNUSED(timer, timer == &m_timer); | 127 ASSERT_UNUSED(timer, timer == &m_timer); |
| 123 | 128 |
| 124 RefPtrWillBeRawPtr<Document> protect(m_document.get()); | 129 RefPtrWillBeRawPtr<Document> protect(m_document.get()); |
| 125 | 130 |
| 126 Vector<ScriptLoader*> scriptLoaders; | 131 Vector<PendingScript> scripts; |
| 127 scriptLoaders.swap(m_scriptsToExecuteSoon); | 132 scripts.swap(m_scriptsToExecuteSoon); |
| 128 | 133 |
| 129 size_t numInOrderScriptsToExecute = 0; | 134 size_t numInOrderScriptsToExecute = 0; |
| 130 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc
riptsToExecuteInOrder[numInOrderScriptsToExecute]->isReady(); ++numInOrderScript
sToExecute) | 135 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc
riptsToExecuteInOrder[numInOrderScriptsToExecute].resource()->isLoaded(); ++numI
nOrderScriptsToExecute) |
| 131 scriptLoaders.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecut
e]); | 136 scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); |
| 132 if (numInOrderScriptsToExecute) | 137 if (numInOrderScriptsToExecute) |
| 133 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); | 138 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); |
| 134 | 139 |
| 135 size_t size = scriptLoaders.size(); | 140 size_t size = scripts.size(); |
| 136 for (size_t i = 0; i < size; ++i) { | 141 for (size_t i = 0; i < size; ++i) { |
| 137 scriptLoaders[i]->execute(); | 142 ScriptResource* resource = scripts[i].resource(); |
| 143 RefPtrWillBeRawPtr<Element> element = scripts[i].releaseElementAndClear(
); |
| 144 toScriptLoaderIfPossible(element.get())->execute(resource); |
| 138 m_document->decrementLoadEventDelayCount(); | 145 m_document->decrementLoadEventDelayCount(); |
| 139 } | 146 } |
| 140 } | 147 } |
| 141 | 148 |
| 142 void ScriptRunner::trace(Visitor* visitor) | 149 void ScriptRunner::trace(Visitor* visitor) |
| 143 { | 150 { |
| 144 #if ENABLE(OILPAN) | 151 #if ENABLE(OILPAN) |
| 145 visitor->trace(m_document); | 152 visitor->trace(m_document); |
| 146 visitor->trace(m_scriptsToExecuteInOrder); | 153 visitor->trace(m_scriptsToExecuteInOrder); |
| 147 visitor->trace(m_scriptsToExecuteSoon); | 154 visitor->trace(m_scriptsToExecuteSoon); |
| 148 visitor->trace(m_pendingAsyncScripts); | 155 visitor->trace(m_pendingAsyncScripts); |
| 149 #endif | 156 #endif |
| 150 } | 157 } |
| 151 | 158 |
| 152 } | 159 } |
| OLD | NEW |