| 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 13 matching lines...) Expand all Loading... |
| 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/PendingScript.h" |
| 32 #include "core/dom/ScriptLoader.h" | 32 #include "core/dom/ScriptLoader.h" |
| 33 #include "core/fetch/ScriptResource.h" | 33 #include "core/fetch/ScriptResource.h" |
| 34 #include "platform/heap/Handle.h" |
| 34 | 35 |
| 35 namespace WebCore { | 36 namespace WebCore { |
| 36 | 37 |
| 37 ScriptRunner::ScriptRunner(Document* document) | 38 ScriptRunner::ScriptRunner(Document* document) |
| 38 : m_document(document) | 39 : m_document(document) |
| 39 , m_timer(this, &ScriptRunner::timerFired) | 40 , m_timer(this, &ScriptRunner::timerFired) |
| 40 { | 41 { |
| 41 ASSERT(document); | 42 ASSERT(document); |
| 42 } | 43 } |
| 43 | 44 |
| 44 ScriptRunner::~ScriptRunner() | 45 ScriptRunner::~ScriptRunner() |
| 45 { | 46 { |
| 46 for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i) | |
| 47 m_document->decrementLoadEventDelayCount(); | |
| 48 for (size_t i = 0; i < m_scriptsToExecuteInOrder.size(); ++i) | |
| 49 m_document->decrementLoadEventDelayCount(); | |
| 50 for (size_t i = 0; i < m_pendingAsyncScripts.size(); ++i) | |
| 51 m_document->decrementLoadEventDelayCount(); | |
| 52 } | 47 } |
| 53 | 48 |
| 54 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ResourceP
tr<ScriptResource> resource, ExecutionType executionType) | 49 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, ResourceP
tr<ScriptResource> resource, ExecutionType executionType) |
| 55 { | 50 { |
| 56 ASSERT(scriptLoader); | 51 ASSERT(scriptLoader); |
| 57 ASSERT(resource.get()); | 52 ASSERT(resource.get()); |
| 58 | 53 |
| 59 Element* element = scriptLoader->element(); | 54 Element* element = scriptLoader->element(); |
| 60 ASSERT(element); | 55 ASSERT(element); |
| 61 ASSERT(element->inDocument()); | 56 ASSERT(element->inDocument()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 case IN_ORDER_EXECUTION: | 106 case IN_ORDER_EXECUTION: |
| 112 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); | 107 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); |
| 113 break; | 108 break; |
| 114 } | 109 } |
| 115 } | 110 } |
| 116 | 111 |
| 117 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) | 112 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) |
| 118 { | 113 { |
| 119 ASSERT_UNUSED(timer, timer == &m_timer); | 114 ASSERT_UNUSED(timer, timer == &m_timer); |
| 120 | 115 |
| 121 RefPtr<Document> protect(m_document); | 116 RefPtrWillBeRawPtr<Document> protect(m_document.get()); |
| 122 | 117 |
| 123 Vector<PendingScript> scripts; | 118 Vector<PendingScript> scripts; |
| 124 scripts.swap(m_scriptsToExecuteSoon); | 119 scripts.swap(m_scriptsToExecuteSoon); |
| 125 | 120 |
| 126 size_t numInOrderScriptsToExecute = 0; | 121 size_t numInOrderScriptsToExecute = 0; |
| 127 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc
riptsToExecuteInOrder[numInOrderScriptsToExecute].resource()->isLoaded(); ++numI
nOrderScriptsToExecute) | 122 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc
riptsToExecuteInOrder[numInOrderScriptsToExecute].resource()->isLoaded(); ++numI
nOrderScriptsToExecute) |
| 128 scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); | 123 scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); |
| 129 if (numInOrderScriptsToExecute) | 124 if (numInOrderScriptsToExecute) |
| 130 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); | 125 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); |
| 131 | 126 |
| 132 size_t size = scripts.size(); | 127 size_t size = scripts.size(); |
| 133 for (size_t i = 0; i < size; ++i) { | 128 for (size_t i = 0; i < size; ++i) { |
| 134 ScriptResource* resource = scripts[i].resource(); | 129 ScriptResource* resource = scripts[i].resource(); |
| 135 RefPtr<Element> element = scripts[i].releaseElementAndClear(); | 130 RefPtrWillBeRawPtr<Element> element = scripts[i].releaseElementAndClear(
); |
| 136 toScriptLoaderIfPossible(element.get())->execute(resource); | 131 toScriptLoaderIfPossible(element.get())->execute(resource); |
| 137 m_document->decrementLoadEventDelayCount(); | 132 m_document->decrementLoadEventDelayCount(); |
| 138 } | 133 } |
| 139 } | 134 } |
| 140 | 135 |
| 136 void ScriptRunner::trace(Visitor* visitor) |
| 137 { |
| 138 visitor->trace(m_document); |
| 139 visitor->trace(m_scriptsToExecuteInOrder); |
| 140 visitor->trace(m_scriptsToExecuteSoon); |
| 141 visitor->trace(m_pendingAsyncScripts); |
| 141 } | 142 } |
| 143 |
| 144 } |
| OLD | NEW |