Chromium Code Reviews| 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" | |
| 32 #include "core/dom/ScriptLoader.h" | 31 #include "core/dom/ScriptLoader.h" |
| 33 #include "core/fetch/ScriptResource.h" | |
| 34 #include "platform/heap/Handle.h" | 32 #include "platform/heap/Handle.h" |
| 35 | 33 |
| 36 namespace blink { | 34 namespace blink { |
| 37 | 35 |
| 38 ScriptRunner::ScriptRunner(Document* document) | 36 ScriptRunner::ScriptRunner(Document* document) |
| 39 : m_document(document) | 37 : m_document(document) |
| 40 , m_timer(this, &ScriptRunner::timerFired) | 38 , m_timer(this, &ScriptRunner::timerFired) |
| 41 { | 39 { |
| 42 ASSERT(document); | 40 ASSERT(document); |
| 43 } | 41 } |
| 44 | 42 |
| 45 ScriptRunner::~ScriptRunner() | 43 ScriptRunner::~ScriptRunner() |
| 46 { | 44 { |
| 47 } | 45 } |
| 48 | 46 |
| 49 void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader, const Pendi ngScript& pendingScript) | 47 void ScriptRunner::addPendingAsyncScript(ScriptLoader* scriptLoader) |
| 50 { | 48 { |
| 51 m_document->incrementLoadEventDelayCount(); | 49 m_document->incrementLoadEventDelayCount(); |
| 52 m_pendingAsyncScripts.add(scriptLoader, pendingScript); | 50 m_pendingAsyncScripts.add(scriptLoader); |
| 53 } | 51 } |
| 54 | 52 |
| 55 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ResourceP tr<ScriptResource> resource, ExecutionType executionType) | 53 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution Type executionType) |
| 56 { | 54 { |
| 57 ASSERT(scriptLoader); | 55 ASSERT(scriptLoader); |
| 58 ASSERT(resource.get()); | |
| 59 | |
| 60 Element* element = scriptLoader->element(); | |
| 61 ASSERT(element); | |
| 62 ASSERT(element->inDocument()); | |
|
haraken
2014/10/15 15:09:41
Why did you remove these ASSERTs?
marja
2014/10/16 15:19:03
Because we no longer need to access the Element he
| |
| 63 | 56 |
| 64 switch (executionType) { | 57 switch (executionType) { |
| 65 case ASYNC_EXECUTION: | 58 case ASYNC_EXECUTION: |
| 66 addPendingAsyncScript(scriptLoader, PendingScript(element, resource.get( ))); | 59 addPendingAsyncScript(scriptLoader); |
| 67 break; | 60 break; |
| 68 | 61 |
| 69 case IN_ORDER_EXECUTION: | 62 case IN_ORDER_EXECUTION: |
| 70 m_document->incrementLoadEventDelayCount(); | 63 m_document->incrementLoadEventDelayCount(); |
| 71 m_scriptsToExecuteInOrder.append(PendingScript(element, resource.get())) ; | 64 m_scriptsToExecuteInOrder.append(scriptLoader); |
| 72 break; | 65 break; |
| 73 } | 66 } |
| 74 } | 67 } |
| 75 | 68 |
| 76 void ScriptRunner::suspend() | 69 void ScriptRunner::suspend() |
| 77 { | 70 { |
| 78 m_timer.stop(); | 71 m_timer.stop(); |
| 79 } | 72 } |
| 80 | 73 |
| 81 void ScriptRunner::resume() | 74 void ScriptRunner::resume() |
| 82 { | 75 { |
| 83 if (hasPendingScripts()) | 76 if (hasPendingScripts()) |
| 84 m_timer.startOneShot(0, FROM_HERE); | 77 m_timer.startOneShot(0, FROM_HERE); |
| 85 } | 78 } |
| 86 | 79 |
| 87 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e xecutionType) | 80 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e xecutionType) |
| 88 { | 81 { |
| 89 switch (executionType) { | 82 switch (executionType) { |
| 90 case ASYNC_EXECUTION: | 83 case ASYNC_EXECUTION: |
| 91 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); | 84 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); |
| 92 m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptLoader)); | 85 m_scriptsToExecuteSoon.append(scriptLoader); |
| 86 m_pendingAsyncScripts.remove(scriptLoader); | |
| 93 break; | 87 break; |
| 94 | 88 |
| 95 case IN_ORDER_EXECUTION: | 89 case IN_ORDER_EXECUTION: |
| 96 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); | 90 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); |
| 97 break; | 91 break; |
| 98 } | 92 } |
| 99 m_timer.startOneShot(0, FROM_HERE); | 93 m_timer.startOneShot(0, FROM_HERE); |
| 100 } | 94 } |
| 101 | 95 |
| 102 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy pe executionType) | 96 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy pe executionType) |
| 103 { | 97 { |
| 104 switch (executionType) { | 98 switch (executionType) { |
| 105 case ASYNC_EXECUTION: | 99 case ASYNC_EXECUTION: |
| 106 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); | 100 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); |
| 107 m_pendingAsyncScripts.remove(scriptLoader); | 101 m_pendingAsyncScripts.remove(scriptLoader); |
| 108 m_document->decrementLoadEventDelayCount(); | 102 m_document->decrementLoadEventDelayCount(); |
| 109 break; | 103 break; |
| 110 | 104 |
| 111 case IN_ORDER_EXECUTION: | 105 case IN_ORDER_EXECUTION: |
| 112 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); | 106 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); |
| 113 break; | 107 break; |
| 114 } | 108 } |
| 115 } | 109 } |
| 116 | 110 |
| 117 void ScriptRunner::movePendingAsyncScript(ScriptRunner* newRunner, ScriptLoader* scriptLoader) | 111 void ScriptRunner::movePendingAsyncScript(ScriptRunner* newRunner, ScriptLoader* scriptLoader) |
| 118 { | 112 { |
| 119 if (m_pendingAsyncScripts.contains(scriptLoader)) { | 113 if (m_pendingAsyncScripts.contains(scriptLoader)) { |
| 120 newRunner->addPendingAsyncScript(scriptLoader, m_pendingAsyncScripts.tak e(scriptLoader)); | 114 newRunner->addPendingAsyncScript(scriptLoader); |
| 115 m_pendingAsyncScripts.remove(scriptLoader); | |
| 121 m_document->decrementLoadEventDelayCount(); | 116 m_document->decrementLoadEventDelayCount(); |
| 122 } | 117 } |
| 123 } | 118 } |
| 124 | 119 |
| 125 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) | 120 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) |
| 126 { | 121 { |
| 127 ASSERT_UNUSED(timer, timer == &m_timer); | 122 ASSERT_UNUSED(timer, timer == &m_timer); |
| 128 | 123 |
| 129 RefPtrWillBeRawPtr<Document> protect(m_document.get()); | 124 RefPtrWillBeRawPtr<Document> protect(m_document.get()); |
| 130 | 125 |
| 131 Vector<PendingScript> scripts; | 126 Vector<ScriptLoader*> scriptLoaders; |
| 132 scripts.swap(m_scriptsToExecuteSoon); | 127 scriptLoaders.swap(m_scriptsToExecuteSoon); |
| 133 | 128 |
| 134 size_t numInOrderScriptsToExecute = 0; | 129 size_t numInOrderScriptsToExecute = 0; |
| 135 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc riptsToExecuteInOrder[numInOrderScriptsToExecute].resource()->isLoaded(); ++numI nOrderScriptsToExecute) | 130 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc riptsToExecuteInOrder[numInOrderScriptsToExecute]->isReady(); ++numInOrderScript sToExecute) |
| 136 scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); | 131 scriptLoaders.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecut e]); |
| 137 if (numInOrderScriptsToExecute) | 132 if (numInOrderScriptsToExecute) |
| 138 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); | 133 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); |
| 139 | 134 |
| 140 size_t size = scripts.size(); | 135 size_t size = scriptLoaders.size(); |
| 141 for (size_t i = 0; i < size; ++i) { | 136 for (size_t i = 0; i < size; ++i) { |
| 142 ScriptResource* resource = scripts[i].resource(); | 137 scriptLoaders[i]->execute(); |
| 143 RefPtrWillBeRawPtr<Element> element = scripts[i].releaseElementAndClear( ); | |
| 144 toScriptLoaderIfPossible(element.get())->execute(resource); | |
| 145 m_document->decrementLoadEventDelayCount(); | 138 m_document->decrementLoadEventDelayCount(); |
| 146 } | 139 } |
| 147 } | 140 } |
| 148 | 141 |
| 149 void ScriptRunner::trace(Visitor* visitor) | 142 void ScriptRunner::trace(Visitor* visitor) |
| 150 { | 143 { |
| 151 #if ENABLE(OILPAN) | 144 #if ENABLE(OILPAN) |
| 152 visitor->trace(m_document); | 145 visitor->trace(m_document); |
| 153 visitor->trace(m_scriptsToExecuteInOrder); | 146 visitor->trace(m_scriptsToExecuteInOrder); |
| 154 visitor->trace(m_scriptsToExecuteSoon); | 147 visitor->trace(m_scriptsToExecuteSoon); |
| 155 visitor->trace(m_pendingAsyncScripts); | 148 visitor->trace(m_pendingAsyncScripts); |
| 156 #endif | 149 #endif |
| 157 } | 150 } |
| 158 | 151 |
| 159 } | 152 } |
| OLD | NEW |