| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 m_isSuspended = false; | 122 m_isSuspended = false; |
| 123 | 123 |
| 124 for (size_t i = 0; i < m_asyncScriptsToExecuteSoon.size(); ++i) { | 124 for (size_t i = 0; i < m_asyncScriptsToExecuteSoon.size(); ++i) { |
| 125 postTask(BLINK_FROM_HERE); | 125 postTask(BLINK_FROM_HERE); |
| 126 } | 126 } |
| 127 for (size_t i = 0; i < m_inOrderScriptsToExecuteSoon.size(); ++i) { | 127 for (size_t i = 0; i < m_inOrderScriptsToExecuteSoon.size(); ++i) { |
| 128 postTask(BLINK_FROM_HERE); | 128 postTask(BLINK_FROM_HERE); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 void ScriptRunner::scheduleReadyInOrderScripts() |
| 133 { |
| 134 while (!m_pendingInOrderScripts.isEmpty() && m_pendingInOrderScripts.first()
->isReady()) { |
| 135 // A ScriptLoader that failed is responsible for cancelling itself |
| 136 // notifyScriptLoadError(); it continues this draining of ready scripts. |
| 137 if (m_pendingInOrderScripts.first()->errorOccurred()) |
| 138 break; |
| 139 m_inOrderScriptsToExecuteSoon.append(m_pendingInOrderScripts.takeFirst()
); |
| 140 postTask(BLINK_FROM_HERE); |
| 141 } |
| 142 } |
| 143 |
| 132 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) | 144 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) |
| 133 { | 145 { |
| 134 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptLoader); | 146 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptLoader); |
| 135 switch (executionType) { | 147 switch (executionType) { |
| 136 case ASYNC_EXECUTION: | 148 case ASYNC_EXECUTION: |
| 137 // RELEASE_ASSERT makes us crash in a controlled way in error cases | 149 // RELEASE_ASSERT makes us crash in a controlled way in error cases |
| 138 // where the ScriptLoader is associated with the wrong ScriptRunner | 150 // where the ScriptLoader is associated with the wrong ScriptRunner |
| 139 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries | 151 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries |
| 140 // to detach). | 152 // to detach). |
| 141 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_pendingAsyncScripts.contains(
scriptLoader)); | 153 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_pendingAsyncScripts.contains(
scriptLoader)); |
| 142 | 154 |
| 143 m_pendingAsyncScripts.remove(scriptLoader); | 155 m_pendingAsyncScripts.remove(scriptLoader); |
| 144 m_asyncScriptsToExecuteSoon.append(scriptLoader); | 156 m_asyncScriptsToExecuteSoon.append(scriptLoader); |
| 145 | 157 |
| 146 postTask(BLINK_FROM_HERE); | 158 postTask(BLINK_FROM_HERE); |
| 147 | 159 |
| 148 break; | 160 break; |
| 149 | 161 |
| 150 case IN_ORDER_EXECUTION: | 162 case IN_ORDER_EXECUTION: |
| 151 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_numberOfInOrderScriptsWithPen
dingNotification > 0); | 163 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(m_numberOfInOrderScriptsWithPen
dingNotification > 0); |
| 152 m_numberOfInOrderScriptsWithPendingNotification--; | 164 m_numberOfInOrderScriptsWithPendingNotification--; |
| 153 | 165 |
| 154 while (!m_pendingInOrderScripts.isEmpty() && m_pendingInOrderScripts.fir
st()->isReady()) { | 166 scheduleReadyInOrderScripts(); |
| 155 m_inOrderScriptsToExecuteSoon.append(m_pendingInOrderScripts.takeFir
st()); | |
| 156 postTask(BLINK_FROM_HERE); | |
| 157 } | |
| 158 | 167 |
| 159 break; | 168 break; |
| 160 } | 169 } |
| 161 } | 170 } |
| 162 | 171 |
| 163 bool ScriptRunner::removePendingInOrderScript(ScriptLoader* scriptLoader) | 172 bool ScriptRunner::removePendingInOrderScript(ScriptLoader* scriptLoader) |
| 164 { | 173 { |
| 165 for (auto it = m_pendingInOrderScripts.begin(); it != m_pendingInOrderScript
s.end(); ++it) { | 174 for (auto it = m_pendingInOrderScripts.begin(); it != m_pendingInOrderScript
s.end(); ++it) { |
| 166 if (*it == scriptLoader) { | 175 if (*it == scriptLoader) { |
| 167 m_pendingInOrderScripts.remove(it); | 176 m_pendingInOrderScripts.remove(it); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 189 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundLoader); | 198 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundLoader); |
| 190 m_pendingAsyncScripts.remove(scriptLoader); | 199 m_pendingAsyncScripts.remove(scriptLoader); |
| 191 break; | 200 break; |
| 192 } | 201 } |
| 193 case IN_ORDER_EXECUTION: | 202 case IN_ORDER_EXECUTION: |
| 194 bool foundLoader = removePendingInOrderScript(scriptLoader); | 203 bool foundLoader = removePendingInOrderScript(scriptLoader); |
| 195 #if !ENABLE(OILPAN) | 204 #if !ENABLE(OILPAN) |
| 196 foundLoader = foundLoader || m_isDisposed; | 205 foundLoader = foundLoader || m_isDisposed; |
| 197 #endif | 206 #endif |
| 198 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundLoader); | 207 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundLoader); |
| 208 scheduleReadyInOrderScripts(); |
| 199 break; | 209 break; |
| 200 } | 210 } |
| 201 m_document->decrementLoadEventDelayCount(); | 211 m_document->decrementLoadEventDelayCount(); |
| 202 } | 212 } |
| 203 | 213 |
| 204 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) | 214 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) |
| 205 { | 215 { |
| 206 RefPtrWillBeRawPtr<Document> newContextDocument = newDocument.contextDocumen
t().get(); | 216 RefPtrWillBeRawPtr<Document> newContextDocument = newDocument.contextDocumen
t().get(); |
| 207 if (!newContextDocument) { | 217 if (!newContextDocument) { |
| 208 // Document's contextDocument() method will return no Document if the | 218 // Document's contextDocument() method will return no Document if the |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 #if ENABLE(OILPAN) | 284 #if ENABLE(OILPAN) |
| 275 visitor->trace(m_document); | 285 visitor->trace(m_document); |
| 276 visitor->trace(m_pendingInOrderScripts); | 286 visitor->trace(m_pendingInOrderScripts); |
| 277 visitor->trace(m_pendingAsyncScripts); | 287 visitor->trace(m_pendingAsyncScripts); |
| 278 visitor->trace(m_asyncScriptsToExecuteSoon); | 288 visitor->trace(m_asyncScriptsToExecuteSoon); |
| 279 visitor->trace(m_inOrderScriptsToExecuteSoon); | 289 visitor->trace(m_inOrderScriptsToExecuteSoon); |
| 280 #endif | 290 #endif |
| 281 } | 291 } |
| 282 | 292 |
| 283 } // namespace blink | 293 } // namespace blink |
| OLD | NEW |