| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 { | 56 { |
| 57 #if !ENABLE(OILPAN) | 57 #if !ENABLE(OILPAN) |
| 58 dispose(); | 58 dispose(); |
| 59 #endif | 59 #endif |
| 60 } | 60 } |
| 61 | 61 |
| 62 class ScriptRunner::Task : public WebTaskRunner::Task { | 62 class ScriptRunner::Task : public WebTaskRunner::Task { |
| 63 WTF_MAKE_NONCOPYABLE(Task); | 63 WTF_MAKE_NONCOPYABLE(Task); |
| 64 | 64 |
| 65 public: | 65 public: |
| 66 explicit Task(WeakPtrWillBeRawPtr<ScriptRunner> scriptRunner) | 66 explicit Task(RawPtr<ScriptRunner> scriptRunner) |
| 67 : m_scriptRunner(scriptRunner) | 67 : m_scriptRunner(scriptRunner) |
| 68 { | 68 { |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual ~Task() { }; | 71 virtual ~Task() { }; |
| 72 | 72 |
| 73 void run() override | 73 void run() override |
| 74 { | 74 { |
| 75 if (!m_scriptRunner) | 75 if (!m_scriptRunner) |
| 76 return; | 76 return; |
| 77 m_scriptRunner->executeTask(); | 77 m_scriptRunner->executeTask(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 private: | 80 private: |
| 81 WeakPtrWillBeWeakPersistent<ScriptRunner> m_scriptRunner; | 81 WeakPersistent<ScriptRunner> m_scriptRunner; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 #if !ENABLE(OILPAN) | 84 #if !ENABLE(OILPAN) |
| 85 void ScriptRunner::dispose() | 85 void ScriptRunner::dispose() |
| 86 { | 86 { |
| 87 // Make sure that ScriptLoaders don't keep their PendingScripts alive. | 87 // Make sure that ScriptLoaders don't keep their PendingScripts alive. |
| 88 for (ScriptLoader* scriptLoader : m_pendingInOrderScripts) | 88 for (ScriptLoader* scriptLoader : m_pendingInOrderScripts) |
| 89 scriptLoader->detach(); | 89 scriptLoader->detach(); |
| 90 for (ScriptLoader* scriptLoader : m_pendingAsyncScripts) | 90 for (ScriptLoader* scriptLoader : m_pendingAsyncScripts) |
| 91 scriptLoader->detach(); | 91 scriptLoader->detach(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 115 case IN_ORDER_EXECUTION: | 115 case IN_ORDER_EXECUTION: |
| 116 m_pendingInOrderScripts.append(scriptLoader); | 116 m_pendingInOrderScripts.append(scriptLoader); |
| 117 m_numberOfInOrderScriptsWithPendingNotification++; | 117 m_numberOfInOrderScriptsWithPendingNotification++; |
| 118 break; | 118 break; |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 void ScriptRunner::postTask(const WebTraceLocation& webTraceLocation) | 122 void ScriptRunner::postTask(const WebTraceLocation& webTraceLocation) |
| 123 { | 123 { |
| 124 // TODO(altimin): Replace all this with `new Task(this)` when Oilpan is here
. | 124 // TODO(altimin): Replace all this with `new Task(this)` when Oilpan is here
. |
| 125 WeakPtrWillBeRawPtr<ScriptRunner> scriptRunnerForTask; | 125 RawPtr<ScriptRunner> scriptRunnerForTask; |
| 126 #if !ENABLE(OILPAN) | 126 #if !ENABLE(OILPAN) |
| 127 scriptRunnerForTask = m_weakPointerFactoryForTasks.createWeakPtr(); | 127 scriptRunnerForTask = m_weakPointerFactoryForTasks.createWeakPtr(); |
| 128 #else | 128 #else |
| 129 scriptRunnerForTask = this; | 129 scriptRunnerForTask = this; |
| 130 #endif | 130 #endif |
| 131 m_taskRunner->postTask(webTraceLocation, new Task(scriptRunnerForTask)); | 131 m_taskRunner->postTask(webTraceLocation, new Task(scriptRunnerForTask)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ScriptRunner::suspend() | 134 void ScriptRunner::suspend() |
| 135 { | 135 { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 #endif | 222 #endif |
| 223 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundLoader); | 223 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(foundLoader); |
| 224 break; | 224 break; |
| 225 } | 225 } |
| 226 scriptLoader->detach(); | 226 scriptLoader->detach(); |
| 227 m_document->decrementLoadEventDelayCount(); | 227 m_document->decrementLoadEventDelayCount(); |
| 228 } | 228 } |
| 229 | 229 |
| 230 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) | 230 void ScriptRunner::movePendingScript(Document& oldDocument, Document& newDocumen
t, ScriptLoader* scriptLoader) |
| 231 { | 231 { |
| 232 RefPtrWillBeRawPtr<Document> newContextDocument = newDocument.contextDocumen
t().get(); | 232 RawPtr<Document> newContextDocument = newDocument.contextDocument().get(); |
| 233 if (!newContextDocument) { | 233 if (!newContextDocument) { |
| 234 // Document's contextDocument() method will return no Document if the | 234 // Document's contextDocument() method will return no Document if the |
| 235 // following conditions both hold: | 235 // following conditions both hold: |
| 236 // | 236 // |
| 237 // - The Document wasn't created with an explicit context document | 237 // - The Document wasn't created with an explicit context document |
| 238 // and that document is otherwise kept alive. | 238 // and that document is otherwise kept alive. |
| 239 // - The Document itself is detached from its frame. | 239 // - The Document itself is detached from its frame. |
| 240 // | 240 // |
| 241 // The script element's loader is in that case moved to document() and | 241 // The script element's loader is in that case moved to document() and |
| 242 // its script runner, which is the non-null Document that contextDocumen
t() | 242 // its script runner, which is the non-null Document that contextDocumen
t() |
| 243 // would return if not detached. | 243 // would return if not detached. |
| 244 ASSERT(!newDocument.frame()); | 244 ASSERT(!newDocument.frame()); |
| 245 newContextDocument = &newDocument; | 245 newContextDocument = &newDocument; |
| 246 } | 246 } |
| 247 RefPtrWillBeRawPtr<Document> oldContextDocument = oldDocument.contextDocumen
t().get(); | 247 RawPtr<Document> oldContextDocument = oldDocument.contextDocument().get(); |
| 248 if (!oldContextDocument) { | 248 if (!oldContextDocument) { |
| 249 ASSERT(!oldDocument.frame()); | 249 ASSERT(!oldDocument.frame()); |
| 250 oldContextDocument = &oldDocument; | 250 oldContextDocument = &oldDocument; |
| 251 } | 251 } |
| 252 if (oldContextDocument != newContextDocument) | 252 if (oldContextDocument != newContextDocument) |
| 253 oldContextDocument->scriptRunner()->movePendingScript(newContextDocument
->scriptRunner(), scriptLoader); | 253 oldContextDocument->scriptRunner()->movePendingScript(newContextDocument
->scriptRunner(), scriptLoader); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void ScriptRunner::movePendingScript(ScriptRunner* newRunner, ScriptLoader* scri
ptLoader) | 256 void ScriptRunner::movePendingScript(ScriptRunner* newRunner, ScriptLoader* scri
ptLoader) |
| 257 { | 257 { |
| 258 if (m_pendingAsyncScripts.contains(scriptLoader)) { | 258 if (m_pendingAsyncScripts.contains(scriptLoader)) { |
| 259 newRunner->queueScriptForExecution(scriptLoader, ASYNC_EXECUTION); | 259 newRunner->queueScriptForExecution(scriptLoader, ASYNC_EXECUTION); |
| 260 m_pendingAsyncScripts.remove(scriptLoader); | 260 m_pendingAsyncScripts.remove(scriptLoader); |
| 261 m_document->decrementLoadEventDelayCount(); | 261 m_document->decrementLoadEventDelayCount(); |
| 262 return; | 262 return; |
| 263 } | 263 } |
| 264 if (removePendingInOrderScript(scriptLoader)) { | 264 if (removePendingInOrderScript(scriptLoader)) { |
| 265 newRunner->queueScriptForExecution(scriptLoader, IN_ORDER_EXECUTION); | 265 newRunner->queueScriptForExecution(scriptLoader, IN_ORDER_EXECUTION); |
| 266 m_document->decrementLoadEventDelayCount(); | 266 m_document->decrementLoadEventDelayCount(); |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 // Returns true if task was run, and false otherwise. | 270 // Returns true if task was run, and false otherwise. |
| 271 bool ScriptRunner::executeTaskFromQueue(WillBeHeapDeque<RawPtrWillBeMember<Scrip
tLoader>>* taskQueue) | 271 bool ScriptRunner::executeTaskFromQueue(HeapDeque<Member<ScriptLoader>>* taskQue
ue) |
| 272 { | 272 { |
| 273 if (taskQueue->isEmpty()) | 273 if (taskQueue->isEmpty()) |
| 274 return false; | 274 return false; |
| 275 taskQueue->takeFirst()->execute(); | 275 taskQueue->takeFirst()->execute(); |
| 276 | 276 |
| 277 m_document->decrementLoadEventDelayCount(); | 277 m_document->decrementLoadEventDelayCount(); |
| 278 return true; | 278 return true; |
| 279 } | 279 } |
| 280 | 280 |
| 281 void ScriptRunner::executeTask() | 281 void ScriptRunner::executeTask() |
| (...skipping 18 matching lines...) Expand all Loading... |
| 300 #if ENABLE(OILPAN) | 300 #if ENABLE(OILPAN) |
| 301 visitor->trace(m_document); | 301 visitor->trace(m_document); |
| 302 visitor->trace(m_pendingInOrderScripts); | 302 visitor->trace(m_pendingInOrderScripts); |
| 303 visitor->trace(m_pendingAsyncScripts); | 303 visitor->trace(m_pendingAsyncScripts); |
| 304 visitor->trace(m_asyncScriptsToExecuteSoon); | 304 visitor->trace(m_asyncScriptsToExecuteSoon); |
| 305 visitor->trace(m_inOrderScriptsToExecuteSoon); | 305 visitor->trace(m_inOrderScriptsToExecuteSoon); |
| 306 #endif | 306 #endif |
| 307 } | 307 } |
| 308 | 308 |
| 309 } // namespace blink | 309 } // namespace blink |
| OLD | NEW |