| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 #include "core/workers/WorkerReportingProxy.h" | 61 #include "core/workers/WorkerReportingProxy.h" |
| 62 #include "core/workers/WorkerScriptLoader.h" | 62 #include "core/workers/WorkerScriptLoader.h" |
| 63 #include "core/workers/WorkerThread.h" | 63 #include "core/workers/WorkerThread.h" |
| 64 #include "platform/network/ContentSecurityPolicyParsers.h" | 64 #include "platform/network/ContentSecurityPolicyParsers.h" |
| 65 #include "platform/weborigin/KURL.h" | 65 #include "platform/weborigin/KURL.h" |
| 66 #include "platform/weborigin/SecurityOrigin.h" | 66 #include "platform/weborigin/SecurityOrigin.h" |
| 67 #include "public/platform/WebURLRequest.h" | 67 #include "public/platform/WebURLRequest.h" |
| 68 | 68 |
| 69 namespace blink { | 69 namespace blink { |
| 70 | 70 |
| 71 class CloseWorkerGlobalScopeTask : public ExecutionContextTask { | |
| 72 public: | |
| 73 static PassOwnPtr<CloseWorkerGlobalScopeTask> create() | |
| 74 { | |
| 75 return adoptPtr(new CloseWorkerGlobalScopeTask); | |
| 76 } | |
| 77 | |
| 78 virtual void performTask(ExecutionContext *context) | |
| 79 { | |
| 80 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); | |
| 81 // Notify parent that this context is closed. Parent is responsible for
calling WorkerThread::stop(). | |
| 82 workerGlobalScope->thread()->workerReportingProxy().workerGlobalScopeClo
sed(); | |
| 83 } | |
| 84 | |
| 85 virtual bool isCleanupTask() const { return true; } | |
| 86 }; | |
| 87 | |
| 88 WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, W
orkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigin, Pas
sOwnPtrWillBeRawPtr<WorkerClients> workerClients) | 71 WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, W
orkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigin, Pas
sOwnPtrWillBeRawPtr<WorkerClients> workerClients) |
| 89 : m_url(url) | 72 : m_url(url) |
| 90 , m_userAgent(userAgent) | 73 , m_userAgent(userAgent) |
| 91 , m_v8CacheOptions(V8CacheOptionsDefault) | 74 , m_v8CacheOptions(V8CacheOptionsDefault) |
| 92 , m_script(adoptPtr(new WorkerScriptController(*this, thread->isolate()))) | 75 , m_script(adoptPtr(new WorkerScriptController(*this, thread->isolate()))) |
| 93 , m_thread(thread) | 76 , m_thread(thread) |
| 94 , m_workerInspectorController(adoptRefWillBeNoop(new WorkerInspectorControll
er(this))) | 77 , m_workerInspectorController(adoptRefWillBeNoop(new WorkerInspectorControll
er(this))) |
| 95 , m_closing(false) | 78 , m_closing(false) |
| 96 , m_eventQueue(WorkerEventQueue::create(this)) | 79 , m_eventQueue(WorkerEventQueue::create(this)) |
| 97 , m_workerClients(workerClients) | 80 , m_workerClients(workerClients) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 | 152 |
| 170 WorkerLocation* WorkerGlobalScope::location() const | 153 WorkerLocation* WorkerGlobalScope::location() const |
| 171 { | 154 { |
| 172 if (!m_location) | 155 if (!m_location) |
| 173 m_location = WorkerLocation::create(m_url); | 156 m_location = WorkerLocation::create(m_url); |
| 174 return m_location.get(); | 157 return m_location.get(); |
| 175 } | 158 } |
| 176 | 159 |
| 177 void WorkerGlobalScope::close() | 160 void WorkerGlobalScope::close() |
| 178 { | 161 { |
| 179 if (m_closing) | 162 // Let current script run to completion, but tell the worker micro task runn
er to tear down the thread after this task. |
| 180 return; | |
| 181 | |
| 182 // Let current script run to completion but prevent future script evaluation
s. | |
| 183 // After m_closing is set, all the tasks in the queue continue to be fetched
but only | |
| 184 // tasks with isCleanupTask()==true will be executed. | |
| 185 m_closing = true; | 163 m_closing = true; |
| 186 postTask(FROM_HERE, CloseWorkerGlobalScopeTask::create()); | |
| 187 } | 164 } |
| 188 | 165 |
| 189 WorkerConsole* WorkerGlobalScope::console() | 166 WorkerConsole* WorkerGlobalScope::console() |
| 190 { | 167 { |
| 191 if (!m_console) | 168 if (!m_console) |
| 192 m_console = WorkerConsole::create(this); | 169 m_console = WorkerConsole::create(this); |
| 193 return m_console.get(); | 170 return m_console.get(); |
| 194 } | 171 } |
| 195 | 172 |
| 196 WorkerNavigator* WorkerGlobalScope::navigator() const | 173 WorkerNavigator* WorkerGlobalScope::navigator() const |
| (...skipping 12 matching lines...) Expand all Loading... |
| 209 { | 186 { |
| 210 ASSERT(m_workerInspectorController); | 187 ASSERT(m_workerInspectorController); |
| 211 thread()->setWorkerInspectorController(nullptr); | 188 thread()->setWorkerInspectorController(nullptr); |
| 212 m_workerInspectorController->dispose(); | 189 m_workerInspectorController->dispose(); |
| 213 m_workerInspectorController.clear(); | 190 m_workerInspectorController.clear(); |
| 214 } | 191 } |
| 215 | 192 |
| 216 void WorkerGlobalScope::dispose() | 193 void WorkerGlobalScope::dispose() |
| 217 { | 194 { |
| 218 ASSERT(thread()->isCurrentThread()); | 195 ASSERT(thread()->isCurrentThread()); |
| 196 stopActiveDOMObjects(); |
| 197 |
| 198 // Event listeners would keep DOMWrapperWorld objects alive for too long. Al
so, they have references to JS objects, |
| 199 // which become dangling once Heap is destroyed. |
| 200 removeAllEventListeners(); |
| 219 | 201 |
| 220 clearScript(); | 202 clearScript(); |
| 221 clearInspector(); | 203 clearInspector(); |
| 222 m_eventQueue->close(); | 204 m_eventQueue->close(); |
| 223 | 205 |
| 224 // We do not clear the thread field of the | 206 // We do not clear the thread field of the |
| 225 // WorkerGlobalScope. Other objects keep the worker global scope | 207 // WorkerGlobalScope. Other objects keep the worker global scope |
| 226 // alive because they need its thread field to check that work is | 208 // alive because they need its thread field to check that work is |
| 227 // being carried out on the right thread. We therefore cannot clear | 209 // being carried out on the right thread. We therefore cannot clear |
| 228 // the thread field before all references to the worker global | 210 // the thread field before all references to the worker global |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 visitor->trace(m_timers); | 392 visitor->trace(m_timers); |
| 411 visitor->trace(m_messageStorage); | 393 visitor->trace(m_messageStorage); |
| 412 visitor->trace(m_pendingMessages); | 394 visitor->trace(m_pendingMessages); |
| 413 HeapSupplementable<WorkerGlobalScope>::trace(visitor); | 395 HeapSupplementable<WorkerGlobalScope>::trace(visitor); |
| 414 #endif | 396 #endif |
| 415 ExecutionContext::trace(visitor); | 397 ExecutionContext::trace(visitor); |
| 416 EventTargetWithInlineData::trace(visitor); | 398 EventTargetWithInlineData::trace(visitor); |
| 417 } | 399 } |
| 418 | 400 |
| 419 } // namespace blink | 401 } // namespace blink |
| OLD | NEW |