| 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 30 matching lines...) Expand all Loading... |
| 41 , m_taskRunner(Platform::current()->currentThread()->scheduler()->loadingTas
kRunner()) | 41 , m_taskRunner(Platform::current()->currentThread()->scheduler()->loadingTas
kRunner()) |
| 42 , m_numberOfInOrderScriptsWithPendingNotification(0) | 42 , m_numberOfInOrderScriptsWithPendingNotification(0) |
| 43 , m_isSuspended(false) | 43 , m_isSuspended(false) |
| 44 { | 44 { |
| 45 DCHECK(document); | 45 DCHECK(document); |
| 46 #ifndef NDEBUG | 46 #ifndef NDEBUG |
| 47 m_hasEverBeenSuspended = false; | 47 m_hasEverBeenSuspended = false; |
| 48 #endif | 48 #endif |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution
Type executionType) | 51 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, AsyncExec
utionType executionType) |
| 52 { | 52 { |
| 53 DCHECK(scriptLoader); | 53 DCHECK(scriptLoader); |
| 54 m_document->incrementLoadEventDelayCount(); | 54 m_document->incrementLoadEventDelayCount(); |
| 55 switch (executionType) { | 55 switch (executionType) { |
| 56 case ASYNC_EXECUTION: | 56 case Async: |
| 57 m_pendingAsyncScripts.add(scriptLoader); | 57 m_pendingAsyncScripts.add(scriptLoader); |
| 58 break; | 58 break; |
| 59 | 59 |
| 60 case IN_ORDER_EXECUTION: | 60 case InOrder: |
| 61 m_pendingInOrderScripts.append(scriptLoader); | 61 m_pendingInOrderScripts.append(scriptLoader); |
| 62 m_numberOfInOrderScriptsWithPendingNotification++; | 62 m_numberOfInOrderScriptsWithPendingNotification++; |
| 63 break; | 63 break; |
| 64 case None: |
| 65 NOTREACHED(); |
| 66 break; |
| 64 } | 67 } |
| 65 } | 68 } |
| 66 | 69 |
| 67 void ScriptRunner::postTask(const WebTraceLocation& webTraceLocation) | 70 void ScriptRunner::postTask(const WebTraceLocation& webTraceLocation) |
| 68 { | 71 { |
| 69 m_taskRunner->postTask(webTraceLocation, WTF::bind(&ScriptRunner::executeTas
k, wrapWeakPersistent(this))); | 72 m_taskRunner->postTask(webTraceLocation, WTF::bind(&ScriptRunner::executeTas
k, wrapWeakPersistent(this))); |
| 70 } | 73 } |
| 71 | 74 |
| 72 void ScriptRunner::suspend() | 75 void ScriptRunner::suspend() |
| 73 { | 76 { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 97 while (!m_pendingInOrderScripts.isEmpty() && m_pendingInOrderScripts.first()
->isReady()) { | 100 while (!m_pendingInOrderScripts.isEmpty() && m_pendingInOrderScripts.first()
->isReady()) { |
| 98 // A ScriptLoader that failed is responsible for cancelling itself | 101 // A ScriptLoader that failed is responsible for cancelling itself |
| 99 // notifyScriptLoadError(); it continues this draining of ready scripts. | 102 // notifyScriptLoadError(); it continues this draining of ready scripts. |
| 100 if (m_pendingInOrderScripts.first()->errorOccurred()) | 103 if (m_pendingInOrderScripts.first()->errorOccurred()) |
| 101 break; | 104 break; |
| 102 m_inOrderScriptsToExecuteSoon.append(m_pendingInOrderScripts.takeFirst()
); | 105 m_inOrderScriptsToExecuteSoon.append(m_pendingInOrderScripts.takeFirst()
); |
| 103 postTask(BLINK_FROM_HERE); | 106 postTask(BLINK_FROM_HERE); |
| 104 } | 107 } |
| 105 } | 108 } |
| 106 | 109 |
| 107 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, ExecutionType e
xecutionType) | 110 void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader, AsyncExecutionT
ype executionType) |
| 108 { | 111 { |
| 109 SECURITY_CHECK(scriptLoader); | 112 SECURITY_CHECK(scriptLoader); |
| 110 switch (executionType) { | 113 switch (executionType) { |
| 111 case ASYNC_EXECUTION: | 114 case Async: |
| 112 // RELEASE_ASSERT makes us crash in a controlled way in error cases | 115 // RELEASE_ASSERT makes us crash in a controlled way in error cases |
| 113 // where the ScriptLoader is associated with the wrong ScriptRunner | 116 // where the ScriptLoader is associated with the wrong ScriptRunner |
| 114 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries | 117 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries |
| 115 // to detach). | 118 // to detach). |
| 116 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); | 119 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); |
| 117 | 120 |
| 118 m_pendingAsyncScripts.remove(scriptLoader); | 121 m_pendingAsyncScripts.remove(scriptLoader); |
| 119 m_asyncScriptsToExecuteSoon.append(scriptLoader); | 122 m_asyncScriptsToExecuteSoon.append(scriptLoader); |
| 120 | 123 |
| 121 postTask(BLINK_FROM_HERE); | 124 postTask(BLINK_FROM_HERE); |
| 122 | 125 |
| 123 break; | 126 break; |
| 124 | 127 |
| 125 case IN_ORDER_EXECUTION: | 128 case InOrder: |
| 126 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); | 129 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); |
| 127 m_numberOfInOrderScriptsWithPendingNotification--; | 130 m_numberOfInOrderScriptsWithPendingNotification--; |
| 128 | 131 |
| 129 scheduleReadyInOrderScripts(); | 132 scheduleReadyInOrderScripts(); |
| 130 | 133 |
| 131 break; | 134 break; |
| 135 case None: |
| 136 NOTREACHED(); |
| 137 break; |
| 132 } | 138 } |
| 133 } | 139 } |
| 134 | 140 |
| 135 bool ScriptRunner::removePendingInOrderScript(ScriptLoader* scriptLoader) | 141 bool ScriptRunner::removePendingInOrderScript(ScriptLoader* scriptLoader) |
| 136 { | 142 { |
| 137 for (auto it = m_pendingInOrderScripts.begin(); it != m_pendingInOrderScript
s.end(); ++it) { | 143 for (auto it = m_pendingInOrderScripts.begin(); it != m_pendingInOrderScript
s.end(); ++it) { |
| 138 if (*it == scriptLoader) { | 144 if (*it == scriptLoader) { |
| 139 m_pendingInOrderScripts.remove(it); | 145 m_pendingInOrderScripts.remove(it); |
| 140 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); | 146 SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0); |
| 141 m_numberOfInOrderScriptsWithPendingNotification--; | 147 m_numberOfInOrderScriptsWithPendingNotification--; |
| 142 return true; | 148 return true; |
| 143 } | 149 } |
| 144 } | 150 } |
| 145 return false; | 151 return false; |
| 146 } | 152 } |
| 147 | 153 |
| 148 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy
pe executionType) | 154 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, AsyncExecut
ionType executionType) |
| 149 { | 155 { |
| 150 switch (executionType) { | 156 switch (executionType) { |
| 151 case ASYNC_EXECUTION: { | 157 case Async: { |
| 152 // SECURITY_CHECK makes us crash in a controlled way in error cases | 158 // SECURITY_CHECK makes us crash in a controlled way in error cases |
| 153 // where the ScriptLoader is associated with the wrong ScriptRunner | 159 // where the ScriptLoader is associated with the wrong ScriptRunner |
| 154 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries | 160 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries |
| 155 // to detach). | 161 // to detach). |
| 156 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); | 162 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); |
| 157 m_pendingAsyncScripts.remove(scriptLoader); | 163 m_pendingAsyncScripts.remove(scriptLoader); |
| 158 break; | 164 break; |
| 159 } | 165 } |
| 160 case IN_ORDER_EXECUTION: | 166 case InOrder: |
| 161 SECURITY_CHECK(removePendingInOrderScript(scriptLoader)); | 167 SECURITY_CHECK(removePendingInOrderScript(scriptLoader)); |
| 162 scheduleReadyInOrderScripts(); | 168 scheduleReadyInOrderScripts(); |
| 163 break; | 169 break; |
| 170 case None: |
| 171 NOTREACHED(); |
| 172 break; |
| 164 } | 173 } |
| 165 m_document->decrementLoadEventDelayCount(); | 174 m_document->decrementLoadEventDelayCount(); |
| 166 } | 175 } |
| 167 | 176 |
| 168 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) | 177 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) |
| 169 { | 178 { |
| 170 Document* newContextDocument = newDocument.contextDocument(); | 179 Document* newContextDocument = newDocument.contextDocument(); |
| 171 if (!newContextDocument) { | 180 if (!newContextDocument) { |
| 172 // Document's contextDocument() method will return no Document if the | 181 // Document's contextDocument() method will return no Document if the |
| 173 // following conditions both hold: | 182 // following conditions both hold: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 187 DCHECK(!oldDocument.frame()); | 196 DCHECK(!oldDocument.frame()); |
| 188 oldContextDocument = &oldDocument; | 197 oldContextDocument = &oldDocument; |
| 189 } | 198 } |
| 190 if (oldContextDocument != newContextDocument) | 199 if (oldContextDocument != newContextDocument) |
| 191 oldContextDocument->scriptRunner()->movePendingScript(newContextDocument
->scriptRunner(), scriptLoader); | 200 oldContextDocument->scriptRunner()->movePendingScript(newContextDocument
->scriptRunner(), scriptLoader); |
| 192 } | 201 } |
| 193 | 202 |
| 194 void ScriptRunner::movePendingScript(ScriptRunner* newRunner, ScriptLoader* scri
ptLoader) | 203 void ScriptRunner::movePendingScript(ScriptRunner* newRunner, ScriptLoader* scri
ptLoader) |
| 195 { | 204 { |
| 196 if (m_pendingAsyncScripts.contains(scriptLoader)) { | 205 if (m_pendingAsyncScripts.contains(scriptLoader)) { |
| 197 newRunner->queueScriptForExecution(scriptLoader, ASYNC_EXECUTION); | 206 newRunner->queueScriptForExecution(scriptLoader, Async); |
| 198 m_pendingAsyncScripts.remove(scriptLoader); | 207 m_pendingAsyncScripts.remove(scriptLoader); |
| 199 m_document->decrementLoadEventDelayCount(); | 208 m_document->decrementLoadEventDelayCount(); |
| 200 return; | 209 return; |
| 201 } | 210 } |
| 202 if (removePendingInOrderScript(scriptLoader)) { | 211 if (removePendingInOrderScript(scriptLoader)) { |
| 203 newRunner->queueScriptForExecution(scriptLoader, IN_ORDER_EXECUTION); | 212 newRunner->queueScriptForExecution(scriptLoader, InOrder); |
| 204 m_document->decrementLoadEventDelayCount(); | 213 m_document->decrementLoadEventDelayCount(); |
| 205 } | 214 } |
| 206 } | 215 } |
| 207 | 216 |
| 208 // Returns true if task was run, and false otherwise. | 217 // Returns true if task was run, and false otherwise. |
| 209 bool ScriptRunner::executeTaskFromQueue(HeapDeque<Member<ScriptLoader>>* taskQue
ue) | 218 bool ScriptRunner::executeTaskFromQueue(HeapDeque<Member<ScriptLoader>>* taskQue
ue) |
| 210 { | 219 { |
| 211 if (taskQueue->isEmpty()) | 220 if (taskQueue->isEmpty()) |
| 212 return false; | 221 return false; |
| 213 taskQueue->takeFirst()->execute(); | 222 taskQueue->takeFirst()->execute(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 236 DEFINE_TRACE(ScriptRunner) | 245 DEFINE_TRACE(ScriptRunner) |
| 237 { | 246 { |
| 238 visitor->trace(m_document); | 247 visitor->trace(m_document); |
| 239 visitor->trace(m_pendingInOrderScripts); | 248 visitor->trace(m_pendingInOrderScripts); |
| 240 visitor->trace(m_pendingAsyncScripts); | 249 visitor->trace(m_pendingAsyncScripts); |
| 241 visitor->trace(m_asyncScriptsToExecuteSoon); | 250 visitor->trace(m_asyncScriptsToExecuteSoon); |
| 242 visitor->trace(m_inOrderScriptsToExecuteSoon); | 251 visitor->trace(m_inOrderScriptsToExecuteSoon); |
| 243 } | 252 } |
| 244 | 253 |
| 245 } // namespace blink | 254 } // namespace blink |
| OLD | NEW |