| 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 |
| 71 WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, W
orkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigin, Pas
sOwnPtrWillBeRawPtr<WorkerClients> workerClients) | 88 WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, W
orkerThread* thread, double timeOrigin, const SecurityOrigin* starterOrigin, Pas
sOwnPtrWillBeRawPtr<WorkerClients> workerClients) |
| 72 : m_url(url) | 89 : m_url(url) |
| 73 , m_userAgent(userAgent) | 90 , m_userAgent(userAgent) |
| 74 , m_v8CacheOptions(V8CacheOptionsDefault) | 91 , m_v8CacheOptions(V8CacheOptionsDefault) |
| 75 , m_script(adoptPtr(new WorkerScriptController(*this, thread->isolate()))) | 92 , m_script(adoptPtr(new WorkerScriptController(*this, thread->isolate()))) |
| 76 , m_thread(thread) | 93 , m_thread(thread) |
| 77 , m_workerInspectorController(adoptRefWillBeNoop(new WorkerInspectorControll
er(this))) | 94 , m_workerInspectorController(adoptRefWillBeNoop(new WorkerInspectorControll
er(this))) |
| 78 , m_closing(false) | 95 , m_closing(false) |
| 79 , m_eventQueue(WorkerEventQueue::create(this)) | 96 , m_eventQueue(WorkerEventQueue::create(this)) |
| 80 , m_workerClients(workerClients) | 97 , m_workerClients(workerClients) |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 169 |
| 153 WorkerLocation* WorkerGlobalScope::location() const | 170 WorkerLocation* WorkerGlobalScope::location() const |
| 154 { | 171 { |
| 155 if (!m_location) | 172 if (!m_location) |
| 156 m_location = WorkerLocation::create(m_url); | 173 m_location = WorkerLocation::create(m_url); |
| 157 return m_location.get(); | 174 return m_location.get(); |
| 158 } | 175 } |
| 159 | 176 |
| 160 void WorkerGlobalScope::close() | 177 void WorkerGlobalScope::close() |
| 161 { | 178 { |
| 162 // Let current script run to completion, but tell the worker micro task runn
er to tear down the thread after this task. | 179 if (m_closing) |
| 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. |
| 163 m_closing = true; | 185 m_closing = true; |
| 186 postTask(FROM_HERE, CloseWorkerGlobalScopeTask::create()); |
| 164 } | 187 } |
| 165 | 188 |
| 166 WorkerConsole* WorkerGlobalScope::console() | 189 WorkerConsole* WorkerGlobalScope::console() |
| 167 { | 190 { |
| 168 if (!m_console) | 191 if (!m_console) |
| 169 m_console = WorkerConsole::create(this); | 192 m_console = WorkerConsole::create(this); |
| 170 return m_console.get(); | 193 return m_console.get(); |
| 171 } | 194 } |
| 172 | 195 |
| 173 WorkerNavigator* WorkerGlobalScope::navigator() const | 196 WorkerNavigator* WorkerGlobalScope::navigator() const |
| (...skipping 12 matching lines...) Expand all Loading... |
| 186 { | 209 { |
| 187 ASSERT(m_workerInspectorController); | 210 ASSERT(m_workerInspectorController); |
| 188 thread()->setWorkerInspectorController(nullptr); | 211 thread()->setWorkerInspectorController(nullptr); |
| 189 m_workerInspectorController->dispose(); | 212 m_workerInspectorController->dispose(); |
| 190 m_workerInspectorController.clear(); | 213 m_workerInspectorController.clear(); |
| 191 } | 214 } |
| 192 | 215 |
| 193 void WorkerGlobalScope::dispose() | 216 void WorkerGlobalScope::dispose() |
| 194 { | 217 { |
| 195 ASSERT(thread()->isCurrentThread()); | 218 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(); | |
| 201 | 219 |
| 202 clearScript(); | 220 clearScript(); |
| 203 clearInspector(); | 221 clearInspector(); |
| 204 m_eventQueue->close(); | 222 m_eventQueue->close(); |
| 205 | 223 |
| 206 // We do not clear the thread field of the | 224 // We do not clear the thread field of the |
| 207 // WorkerGlobalScope. Other objects keep the worker global scope | 225 // WorkerGlobalScope. Other objects keep the worker global scope |
| 208 // alive because they need its thread field to check that work is | 226 // alive because they need its thread field to check that work is |
| 209 // being carried out on the right thread. We therefore cannot clear | 227 // being carried out on the right thread. We therefore cannot clear |
| 210 // the thread field before all references to the worker global | 228 // the thread field before all references to the worker global |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 visitor->trace(m_timers); | 410 visitor->trace(m_timers); |
| 393 visitor->trace(m_messageStorage); | 411 visitor->trace(m_messageStorage); |
| 394 visitor->trace(m_pendingMessages); | 412 visitor->trace(m_pendingMessages); |
| 395 HeapSupplementable<WorkerGlobalScope>::trace(visitor); | 413 HeapSupplementable<WorkerGlobalScope>::trace(visitor); |
| 396 #endif | 414 #endif |
| 397 ExecutionContext::trace(visitor); | 415 ExecutionContext::trace(visitor); |
| 398 EventTargetWithInlineData::trace(visitor); | 416 EventTargetWithInlineData::trace(visitor); |
| 399 } | 417 } |
| 400 | 418 |
| 401 } // namespace blink | 419 } // namespace blink |
| OLD | NEW |