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 11 matching lines...) Expand all Loading... |
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/PendingScript.h" |
32 #include "core/dom/ScriptElement.h" | 32 #include "core/dom/ScriptLoader.h" |
33 #include "core/loader/cache/CachedScript.h" | 33 #include "core/loader/cache/CachedScript.h" |
34 | 34 |
35 namespace WebCore { | 35 namespace WebCore { |
36 | 36 |
37 ScriptRunner::ScriptRunner(Document* document) | 37 ScriptRunner::ScriptRunner(Document* document) |
38 : m_document(document) | 38 : m_document(document) |
39 , m_timer(this, &ScriptRunner::timerFired) | 39 , m_timer(this, &ScriptRunner::timerFired) |
40 { | 40 { |
41 ASSERT(document); | 41 ASSERT(document); |
42 } | 42 } |
43 | 43 |
44 ScriptRunner::~ScriptRunner() | 44 ScriptRunner::~ScriptRunner() |
45 { | 45 { |
46 for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i) | 46 for (size_t i = 0; i < m_scriptsToExecuteSoon.size(); ++i) |
47 m_document->decrementLoadEventDelayCount(); | 47 m_document->decrementLoadEventDelayCount(); |
48 for (size_t i = 0; i < m_scriptsToExecuteInOrder.size(); ++i) | 48 for (size_t i = 0; i < m_scriptsToExecuteInOrder.size(); ++i) |
49 m_document->decrementLoadEventDelayCount(); | 49 m_document->decrementLoadEventDelayCount(); |
50 for (int i = 0; i < m_pendingAsyncScripts.size(); ++i) | 50 for (int i = 0; i < m_pendingAsyncScripts.size(); ++i) |
51 m_document->decrementLoadEventDelayCount(); | 51 m_document->decrementLoadEventDelayCount(); |
52 } | 52 } |
53 | 53 |
54 void ScriptRunner::queueScriptForExecution(ScriptElement* scriptElement, CachedR
esourceHandle<CachedScript> cachedScript, ExecutionType executionType) | 54 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, CachedRes
ourceHandle<CachedScript> cachedScript, ExecutionType executionType) |
55 { | 55 { |
56 ASSERT(scriptElement); | 56 ASSERT(scriptLoader); |
57 ASSERT(cachedScript.get()); | 57 ASSERT(cachedScript.get()); |
58 | 58 |
59 Element* element = scriptElement->element(); | 59 Element* element = scriptLoader->element(); |
60 ASSERT(element); | 60 ASSERT(element); |
61 ASSERT(element->inDocument()); | 61 ASSERT(element->inDocument()); |
62 | 62 |
63 m_document->incrementLoadEventDelayCount(); | 63 m_document->incrementLoadEventDelayCount(); |
64 | 64 |
65 switch (executionType) { | 65 switch (executionType) { |
66 case ASYNC_EXECUTION: | 66 case ASYNC_EXECUTION: |
67 m_pendingAsyncScripts.add(scriptElement, PendingScript(element, cachedSc
ript.get())); | 67 m_pendingAsyncScripts.add(scriptLoader, PendingScript(element, cachedScr
ipt.get())); |
68 break; | 68 break; |
69 | 69 |
70 case IN_ORDER_EXECUTION: | 70 case IN_ORDER_EXECUTION: |
71 m_scriptsToExecuteInOrder.append(PendingScript(element, cachedScript.get
())); | 71 m_scriptsToExecuteInOrder.append(PendingScript(element, cachedScript.get
())); |
72 break; | 72 break; |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void ScriptRunner::suspend() | 76 void ScriptRunner::suspend() |
77 { | 77 { |
78 m_timer.stop(); | 78 m_timer.stop(); |
79 } | 79 } |
80 | 80 |
81 void ScriptRunner::resume() | 81 void ScriptRunner::resume() |
82 { | 82 { |
83 if (hasPendingScripts()) | 83 if (hasPendingScripts()) |
84 m_timer.startOneShot(0); | 84 m_timer.startOneShot(0); |
85 } | 85 } |
86 | 86 |
87 void ScriptRunner::notifyScriptReady(ScriptElement* scriptElement, ExecutionType
executionType) | 87 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) |
88 { | 88 { |
89 switch (executionType) { | 89 switch (executionType) { |
90 case ASYNC_EXECUTION: | 90 case ASYNC_EXECUTION: |
91 ASSERT(m_pendingAsyncScripts.contains(scriptElement)); | 91 ASSERT(m_pendingAsyncScripts.contains(scriptLoader)); |
92 m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptElement))
; | 92 m_scriptsToExecuteSoon.append(m_pendingAsyncScripts.take(scriptLoader)); |
93 break; | 93 break; |
94 | 94 |
95 case IN_ORDER_EXECUTION: | 95 case IN_ORDER_EXECUTION: |
96 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); | 96 ASSERT(!m_scriptsToExecuteInOrder.isEmpty()); |
97 break; | 97 break; |
98 } | 98 } |
99 m_timer.startOneShot(0); | 99 m_timer.startOneShot(0); |
100 } | 100 } |
101 | 101 |
102 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) | 102 void ScriptRunner::timerFired(Timer<ScriptRunner>* timer) |
103 { | 103 { |
104 ASSERT_UNUSED(timer, timer == &m_timer); | 104 ASSERT_UNUSED(timer, timer == &m_timer); |
105 | 105 |
106 RefPtr<Document> protect(m_document); | 106 RefPtr<Document> protect(m_document); |
107 | 107 |
108 Vector<PendingScript> scripts; | 108 Vector<PendingScript> scripts; |
109 scripts.swap(m_scriptsToExecuteSoon); | 109 scripts.swap(m_scriptsToExecuteSoon); |
110 | 110 |
111 size_t numInOrderScriptsToExecute = 0; | 111 size_t numInOrderScriptsToExecute = 0; |
112 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc
riptsToExecuteInOrder[numInOrderScriptsToExecute].cachedScript()->isLoaded(); ++
numInOrderScriptsToExecute) | 112 for (; numInOrderScriptsToExecute < m_scriptsToExecuteInOrder.size() && m_sc
riptsToExecuteInOrder[numInOrderScriptsToExecute].cachedScript()->isLoaded(); ++
numInOrderScriptsToExecute) |
113 scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); | 113 scripts.append(m_scriptsToExecuteInOrder[numInOrderScriptsToExecute]); |
114 if (numInOrderScriptsToExecute) | 114 if (numInOrderScriptsToExecute) |
115 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); | 115 m_scriptsToExecuteInOrder.remove(0, numInOrderScriptsToExecute); |
116 | 116 |
117 size_t size = scripts.size(); | 117 size_t size = scripts.size(); |
118 for (size_t i = 0; i < size; ++i) { | 118 for (size_t i = 0; i < size; ++i) { |
119 CachedScript* cachedScript = scripts[i].cachedScript(); | 119 CachedScript* cachedScript = scripts[i].cachedScript(); |
120 RefPtr<Element> element = scripts[i].releaseElementAndClear(); | 120 RefPtr<Element> element = scripts[i].releaseElementAndClear(); |
121 toScriptElementIfPossible(element.get())->execute(cachedScript); | 121 toScriptLoaderIfPossible(element.get())->execute(cachedScript); |
122 m_document->decrementLoadEventDelayCount(); | 122 m_document->decrementLoadEventDelayCount(); |
123 } | 123 } |
124 } | 124 } |
125 | 125 |
126 } | 126 } |
OLD | NEW |