| 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 23 matching lines...) Expand all Loading... |
| 34 #include "public/platform/WebScheduler.h" | 34 #include "public/platform/WebScheduler.h" |
| 35 #include "public/platform/WebThread.h" | 35 #include "public/platform/WebThread.h" |
| 36 | 36 |
| 37 namespace blink { | 37 namespace blink { |
| 38 | 38 |
| 39 ScriptRunner::ScriptRunner(Document* document) | 39 ScriptRunner::ScriptRunner(Document* document) |
| 40 : m_document(document) | 40 : m_document(document) |
| 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 #if !ENABLE(OILPAN) | |
| 45 , m_isDisposed(false) | |
| 46 , m_weakPointerFactoryForTasks(this) | |
| 47 #endif | |
| 48 { | 44 { |
| 49 DCHECK(document); | 45 DCHECK(document); |
| 50 #ifndef NDEBUG | 46 #ifndef NDEBUG |
| 51 m_hasEverBeenSuspended = false; | 47 m_hasEverBeenSuspended = false; |
| 52 #endif | 48 #endif |
| 53 } | 49 } |
| 54 | 50 |
| 55 ScriptRunner::~ScriptRunner() | 51 ScriptRunner::~ScriptRunner() |
| 56 { | 52 { |
| 57 #if !ENABLE(OILPAN) | |
| 58 dispose(); | |
| 59 #endif | |
| 60 } | 53 } |
| 61 | 54 |
| 62 #if !ENABLE(OILPAN) | |
| 63 void ScriptRunner::dispose() | |
| 64 { | |
| 65 // Make sure that ScriptLoaders don't keep their PendingScripts alive. | |
| 66 for (ScriptLoader* scriptLoader : m_pendingInOrderScripts) | |
| 67 scriptLoader->detach(); | |
| 68 for (ScriptLoader* scriptLoader : m_pendingAsyncScripts) | |
| 69 scriptLoader->detach(); | |
| 70 for (ScriptLoader* scriptLoader : m_inOrderScriptsToExecuteSoon) | |
| 71 scriptLoader->detach(); | |
| 72 for (ScriptLoader* scriptLoader : m_asyncScriptsToExecuteSoon) | |
| 73 scriptLoader->detach(); | |
| 74 | |
| 75 m_pendingInOrderScripts.clear(); | |
| 76 m_pendingAsyncScripts.clear(); | |
| 77 m_inOrderScriptsToExecuteSoon.clear(); | |
| 78 m_asyncScriptsToExecuteSoon.clear(); | |
| 79 m_isDisposed = true; | |
| 80 m_numberOfInOrderScriptsWithPendingNotification = 0; | |
| 81 } | |
| 82 #endif | |
| 83 | |
| 84 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution
Type executionType) | 55 void ScriptRunner::queueScriptForExecution(ScriptLoader* scriptLoader, Execution
Type executionType) |
| 85 { | 56 { |
| 86 DCHECK(scriptLoader); | 57 DCHECK(scriptLoader); |
| 87 m_document->incrementLoadEventDelayCount(); | 58 m_document->incrementLoadEventDelayCount(); |
| 88 switch (executionType) { | 59 switch (executionType) { |
| 89 case ASYNC_EXECUTION: | 60 case ASYNC_EXECUTION: |
| 90 m_pendingAsyncScripts.add(scriptLoader); | 61 m_pendingAsyncScripts.add(scriptLoader); |
| 91 break; | 62 break; |
| 92 | 63 |
| 93 case IN_ORDER_EXECUTION: | 64 case IN_ORDER_EXECUTION: |
| 94 m_pendingInOrderScripts.append(scriptLoader); | 65 m_pendingInOrderScripts.append(scriptLoader); |
| 95 m_numberOfInOrderScriptsWithPendingNotification++; | 66 m_numberOfInOrderScriptsWithPendingNotification++; |
| 96 break; | 67 break; |
| 97 } | 68 } |
| 98 } | 69 } |
| 99 | 70 |
| 100 void ScriptRunner::postTask(const WebTraceLocation& webTraceLocation) | 71 void ScriptRunner::postTask(const WebTraceLocation& webTraceLocation) |
| 101 { | 72 { |
| 102 #if !ENABLE(OILPAN) | |
| 103 m_taskRunner->postTask(webTraceLocation, bind(&ScriptRunner::executeTask, m_
weakPointerFactoryForTasks.createWeakPtr())); | |
| 104 #else | |
| 105 m_taskRunner->postTask(webTraceLocation, bind(&ScriptRunner::executeTask, We
akPersistentThisPointer<ScriptRunner>(this))); | 73 m_taskRunner->postTask(webTraceLocation, bind(&ScriptRunner::executeTask, We
akPersistentThisPointer<ScriptRunner>(this))); |
| 106 #endif | |
| 107 } | 74 } |
| 108 | 75 |
| 109 void ScriptRunner::suspend() | 76 void ScriptRunner::suspend() |
| 110 { | 77 { |
| 111 #ifndef NDEBUG | 78 #ifndef NDEBUG |
| 112 m_hasEverBeenSuspended = true; | 79 m_hasEverBeenSuspended = true; |
| 113 #endif | 80 #endif |
| 114 | 81 |
| 115 m_isSuspended = true; | 82 m_isSuspended = true; |
| 116 } | 83 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 } | 150 } |
| 184 | 151 |
| 185 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy
pe executionType) | 152 void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader, ExecutionTy
pe executionType) |
| 186 { | 153 { |
| 187 switch (executionType) { | 154 switch (executionType) { |
| 188 case ASYNC_EXECUTION: { | 155 case ASYNC_EXECUTION: { |
| 189 // RELEASE_ASSERT makes us crash in a controlled way in error cases | 156 // RELEASE_ASSERT makes us crash in a controlled way in error cases |
| 190 // where the ScriptLoader is associated with the wrong ScriptRunner | 157 // where the ScriptLoader is associated with the wrong ScriptRunner |
| 191 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries | 158 // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries |
| 192 // to detach). | 159 // to detach). |
| 193 bool foundLoader = m_pendingAsyncScripts.contains(scriptLoader); | 160 SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader)); |
| 194 #if !ENABLE(OILPAN) | |
| 195 // If the ScriptRunner has been disposed of, no pending scripts remain. | |
| 196 foundLoader = foundLoader || m_isDisposed; | |
| 197 #endif | |
| 198 SECURITY_CHECK(foundLoader); | |
| 199 m_pendingAsyncScripts.remove(scriptLoader); | 161 m_pendingAsyncScripts.remove(scriptLoader); |
| 200 break; | 162 break; |
| 201 } | 163 } |
| 202 case IN_ORDER_EXECUTION: | 164 case IN_ORDER_EXECUTION: |
| 203 bool foundLoader = removePendingInOrderScript(scriptLoader); | 165 SECURITY_CHECK(removePendingInOrderScript(scriptLoader)); |
| 204 #if !ENABLE(OILPAN) | |
| 205 foundLoader = foundLoader || m_isDisposed; | |
| 206 #endif | |
| 207 SECURITY_CHECK(foundLoader); | |
| 208 scheduleReadyInOrderScripts(); | 166 scheduleReadyInOrderScripts(); |
| 209 break; | 167 break; |
| 210 } | 168 } |
| 211 m_document->decrementLoadEventDelayCount(); | 169 m_document->decrementLoadEventDelayCount(); |
| 212 } | 170 } |
| 213 | 171 |
| 214 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) | 172 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) |
| 215 { | 173 { |
| 216 Document* newContextDocument = newDocument.contextDocument(); | 174 Document* newContextDocument = newDocument.contextDocument(); |
| 217 if (!newContextDocument) { | 175 if (!newContextDocument) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 DEFINE_TRACE(ScriptRunner) | 240 DEFINE_TRACE(ScriptRunner) |
| 283 { | 241 { |
| 284 visitor->trace(m_document); | 242 visitor->trace(m_document); |
| 285 visitor->trace(m_pendingInOrderScripts); | 243 visitor->trace(m_pendingInOrderScripts); |
| 286 visitor->trace(m_pendingAsyncScripts); | 244 visitor->trace(m_pendingAsyncScripts); |
| 287 visitor->trace(m_asyncScriptsToExecuteSoon); | 245 visitor->trace(m_asyncScriptsToExecuteSoon); |
| 288 visitor->trace(m_inOrderScriptsToExecuteSoon); | 246 visitor->trace(m_inOrderScriptsToExecuteSoon); |
| 289 } | 247 } |
| 290 | 248 |
| 291 } // namespace blink | 249 } // namespace blink |
| OLD | NEW |