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 |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 * | 25 * |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 | 29 |
30 #include "core/workers/WorkerContext.h" | 30 #include "core/workers/WorkerGlobalScope.h" |
31 | 31 |
32 #include <wtf/RefPtr.h> | |
33 #include <wtf/UnusedParam.h> | |
34 #include "bindings/v8/ScheduledAction.h" | 32 #include "bindings/v8/ScheduledAction.h" |
35 #include "bindings/v8/ScriptSourceCode.h" | 33 #include "bindings/v8/ScriptSourceCode.h" |
36 #include "bindings/v8/ScriptValue.h" | 34 #include "bindings/v8/ScriptValue.h" |
37 #include "core/dom/ActiveDOMObject.h" | 35 #include "core/dom/ActiveDOMObject.h" |
38 #include "core/dom/ContextLifecycleNotifier.h" | 36 #include "core/dom/ContextLifecycleNotifier.h" |
39 #include "core/dom/ErrorEvent.h" | 37 #include "core/dom/ErrorEvent.h" |
40 #include "core/dom/Event.h" | 38 #include "core/dom/Event.h" |
41 #include "core/dom/MessagePort.h" | 39 #include "core/dom/MessagePort.h" |
42 #include "core/html/DOMURL.h" | 40 #include "core/html/DOMURL.h" |
43 #include "core/inspector/InspectorConsoleInstrumentation.h" | 41 #include "core/inspector/InspectorConsoleInstrumentation.h" |
44 #include "core/inspector/ScriptCallStack.h" | 42 #include "core/inspector/ScriptCallStack.h" |
45 #include "core/inspector/WorkerInspectorController.h" | 43 #include "core/inspector/WorkerInspectorController.h" |
46 #include "core/loader/WorkerThreadableLoader.h" | 44 #include "core/loader/WorkerThreadableLoader.h" |
47 #include "core/page/ContentSecurityPolicy.h" | 45 #include "core/page/ContentSecurityPolicy.h" |
48 #include "core/page/DOMTimer.h" | 46 #include "core/page/DOMTimer.h" |
49 #include "core/page/DOMWindow.h" | 47 #include "core/page/DOMWindow.h" |
50 #include "core/page/WorkerNavigator.h" | 48 #include "core/page/WorkerNavigator.h" |
51 #include "core/platform/NotImplemented.h" | 49 #include "core/platform/NotImplemented.h" |
52 #include "core/workers/WorkerLocation.h" | 50 #include "core/workers/WorkerLocation.h" |
53 #include "core/workers/WorkerObjectProxy.h" | 51 #include "core/workers/WorkerObjectProxy.h" |
54 #include "core/workers/WorkerScriptLoader.h" | 52 #include "core/workers/WorkerScriptLoader.h" |
55 #include "core/workers/WorkerThread.h" | 53 #include "core/workers/WorkerThread.h" |
56 #include "weborigin/KURL.h" | 54 #include "weborigin/KURL.h" |
57 #include "weborigin/SecurityOrigin.h" | 55 #include "weborigin/SecurityOrigin.h" |
| 56 #include "wtf/RefPtr.h" |
| 57 #include "wtf/UnusedParam.h" |
58 | 58 |
59 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) | 59 #if ENABLE(NOTIFICATIONS) || ENABLE(LEGACY_NOTIFICATIONS) |
60 #include "modules/notifications/NotificationCenter.h" | 60 #include "modules/notifications/NotificationCenter.h" |
61 #endif | 61 #endif |
62 | 62 |
63 #include "core/dom/ExceptionCode.h" | 63 #include "core/dom/ExceptionCode.h" |
64 | 64 |
65 namespace WebCore { | 65 namespace WebCore { |
66 | 66 |
67 class CloseWorkerContextTask : public ScriptExecutionContext::Task { | 67 class CloseWorkerGlobalScopeTask : public ScriptExecutionContext::Task { |
68 public: | 68 public: |
69 static PassOwnPtr<CloseWorkerContextTask> create() | 69 static PassOwnPtr<CloseWorkerGlobalScopeTask> create() |
70 { | 70 { |
71 return adoptPtr(new CloseWorkerContextTask); | 71 return adoptPtr(new CloseWorkerGlobalScopeTask); |
72 } | 72 } |
73 | 73 |
74 virtual void performTask(ScriptExecutionContext *context) | 74 virtual void performTask(ScriptExecutionContext *context) |
75 { | 75 { |
76 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerContext()); | 76 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerGlobalScope()); |
77 WorkerContext* workerContext = static_cast<WorkerContext*>(context); | 77 WorkerGlobalScope* workerGlobalScope = static_cast<WorkerGlobalScope*>(c
ontext); |
78 // Notify parent that this context is closed. Parent is responsible for
calling WorkerThread::stop(). | 78 // Notify parent that this context is closed. Parent is responsible for
calling WorkerThread::stop(). |
79 workerContext->thread()->workerReportingProxy().workerContextClosed(); | 79 workerGlobalScope->thread()->workerReportingProxy().workerGlobalScopeClo
sed(); |
80 } | 80 } |
81 | 81 |
82 virtual bool isCleanupTask() const { return true; } | 82 virtual bool isCleanupTask() const { return true; } |
83 }; | 83 }; |
84 | 84 |
85 WorkerContext::WorkerContext(const KURL& url, const String& userAgent, WorkerThr
ead* thread, PassRefPtr<SecurityOrigin> topOrigin, double timeOrigin) | 85 WorkerGlobalScope::WorkerGlobalScope(const KURL& url, const String& userAgent, W
orkerThread* thread, PassRefPtr<SecurityOrigin> topOrigin, double timeOrigin) |
86 : m_url(url) | 86 : m_url(url) |
87 , m_userAgent(userAgent) | 87 , m_userAgent(userAgent) |
88 , m_script(adoptPtr(new WorkerScriptController(this))) | 88 , m_script(adoptPtr(new WorkerScriptController(this))) |
89 , m_thread(thread) | 89 , m_thread(thread) |
90 , m_workerInspectorController(adoptPtr(new WorkerInspectorController(this))) | 90 , m_workerInspectorController(adoptPtr(new WorkerInspectorController(this))) |
91 , m_closing(false) | 91 , m_closing(false) |
92 , m_eventQueue(WorkerEventQueue::create(this)) | 92 , m_eventQueue(WorkerEventQueue::create(this)) |
93 , m_topOrigin(topOrigin) | 93 , m_topOrigin(topOrigin) |
94 , m_timeOrigin(timeOrigin) | 94 , m_timeOrigin(timeOrigin) |
95 { | 95 { |
96 ScriptWrappable::init(this); | 96 ScriptWrappable::init(this); |
97 setSecurityOrigin(SecurityOrigin::create(url)); | 97 setSecurityOrigin(SecurityOrigin::create(url)); |
98 } | 98 } |
99 | 99 |
100 WorkerContext::~WorkerContext() | 100 WorkerGlobalScope::~WorkerGlobalScope() |
101 { | 101 { |
102 ASSERT(thread()->isCurrentThread()); | 102 ASSERT(thread()->isCurrentThread()); |
103 | 103 |
104 // Make sure we have no observers. | 104 // Make sure we have no observers. |
105 notifyObserversOfStop(); | 105 notifyObserversOfStop(); |
106 | 106 |
107 // Notify proxy that we are going away. This can free the WorkerThread objec
t, so do not access it after this. | 107 // Notify proxy that we are going away. This can free the WorkerThread objec
t, so do not access it after this. |
108 thread()->workerReportingProxy().workerContextDestroyed(); | 108 thread()->workerReportingProxy().workerGlobalScopeDestroyed(); |
109 } | 109 } |
110 | 110 |
111 void WorkerContext::applyContentSecurityPolicyFromString(const String& policy, C
ontentSecurityPolicy::HeaderType contentSecurityPolicyType) | 111 void WorkerGlobalScope::applyContentSecurityPolicyFromString(const String& polic
y, ContentSecurityPolicy::HeaderType contentSecurityPolicyType) |
112 { | 112 { |
113 setContentSecurityPolicy(ContentSecurityPolicy::create(this)); | 113 setContentSecurityPolicy(ContentSecurityPolicy::create(this)); |
114 contentSecurityPolicy()->didReceiveHeader(policy, contentSecurityPolicyType)
; | 114 contentSecurityPolicy()->didReceiveHeader(policy, contentSecurityPolicyType)
; |
115 } | 115 } |
116 | 116 |
117 ScriptExecutionContext* WorkerContext::scriptExecutionContext() const | 117 ScriptExecutionContext* WorkerGlobalScope::scriptExecutionContext() const |
118 { | 118 { |
119 return const_cast<WorkerContext*>(this); | 119 return const_cast<WorkerGlobalScope*>(this); |
120 } | 120 } |
121 | 121 |
122 const KURL& WorkerContext::virtualURL() const | 122 const KURL& WorkerGlobalScope::virtualURL() const |
123 { | 123 { |
124 return m_url; | 124 return m_url; |
125 } | 125 } |
126 | 126 |
127 KURL WorkerContext::virtualCompleteURL(const String& url) const | 127 KURL WorkerGlobalScope::virtualCompleteURL(const String& url) const |
128 { | 128 { |
129 return completeURL(url); | 129 return completeURL(url); |
130 } | 130 } |
131 | 131 |
132 KURL WorkerContext::completeURL(const String& url) const | 132 KURL WorkerGlobalScope::completeURL(const String& url) const |
133 { | 133 { |
134 // Always return a null URL when passed a null string. | 134 // Always return a null URL when passed a null string. |
135 // FIXME: Should we change the KURL constructor to have this behavior? | 135 // FIXME: Should we change the KURL constructor to have this behavior? |
136 if (url.isNull()) | 136 if (url.isNull()) |
137 return KURL(); | 137 return KURL(); |
138 // Always use UTF-8 in Workers. | 138 // Always use UTF-8 in Workers. |
139 return KURL(m_url, url); | 139 return KURL(m_url, url); |
140 } | 140 } |
141 | 141 |
142 String WorkerContext::userAgent(const KURL&) const | 142 String WorkerGlobalScope::userAgent(const KURL&) const |
143 { | 143 { |
144 return m_userAgent; | 144 return m_userAgent; |
145 } | 145 } |
146 | 146 |
147 void WorkerContext::disableEval(const String& errorMessage) | 147 void WorkerGlobalScope::disableEval(const String& errorMessage) |
148 { | 148 { |
149 m_script->disableEval(errorMessage); | 149 m_script->disableEval(errorMessage); |
150 } | 150 } |
151 | 151 |
152 WorkerLocation* WorkerContext::location() const | 152 WorkerLocation* WorkerGlobalScope::location() const |
153 { | 153 { |
154 if (!m_location) | 154 if (!m_location) |
155 m_location = WorkerLocation::create(m_url); | 155 m_location = WorkerLocation::create(m_url); |
156 return m_location.get(); | 156 return m_location.get(); |
157 } | 157 } |
158 | 158 |
159 void WorkerContext::close() | 159 void WorkerGlobalScope::close() |
160 { | 160 { |
161 if (m_closing) | 161 if (m_closing) |
162 return; | 162 return; |
163 | 163 |
164 // Let current script run to completion but prevent future script evaluation
s. | 164 // Let current script run to completion but prevent future script evaluation
s. |
165 // After m_closing is set, all the tasks in the queue continue to be fetched
but only | 165 // After m_closing is set, all the tasks in the queue continue to be fetched
but only |
166 // tasks with isCleanupTask()==true will be executed. | 166 // tasks with isCleanupTask()==true will be executed. |
167 m_closing = true; | 167 m_closing = true; |
168 postTask(CloseWorkerContextTask::create()); | 168 postTask(CloseWorkerGlobalScopeTask::create()); |
169 } | 169 } |
170 | 170 |
171 WorkerNavigator* WorkerContext::navigator() const | 171 WorkerNavigator* WorkerGlobalScope::navigator() const |
172 { | 172 { |
173 if (!m_navigator) | 173 if (!m_navigator) |
174 m_navigator = WorkerNavigator::create(m_userAgent); | 174 m_navigator = WorkerNavigator::create(m_userAgent); |
175 return m_navigator.get(); | 175 return m_navigator.get(); |
176 } | 176 } |
177 | 177 |
178 void WorkerContext::postTask(PassOwnPtr<Task> task) | 178 void WorkerGlobalScope::postTask(PassOwnPtr<Task> task) |
179 { | 179 { |
180 thread()->runLoop().postTask(task); | 180 thread()->runLoop().postTask(task); |
181 } | 181 } |
182 | 182 |
183 int WorkerContext::setTimeout(PassOwnPtr<ScheduledAction> action, int timeout) | 183 int WorkerGlobalScope::setTimeout(PassOwnPtr<ScheduledAction> action, int timeou
t) |
184 { | 184 { |
185 return DOMTimer::install(scriptExecutionContext(), action, timeout, true); | 185 return DOMTimer::install(scriptExecutionContext(), action, timeout, true); |
186 } | 186 } |
187 | 187 |
188 void WorkerContext::clearTimeout(int timeoutId) | 188 void WorkerGlobalScope::clearTimeout(int timeoutId) |
189 { | 189 { |
190 DOMTimer::removeById(scriptExecutionContext(), timeoutId); | 190 DOMTimer::removeById(scriptExecutionContext(), timeoutId); |
191 } | 191 } |
192 | 192 |
193 void WorkerContext::clearInspector() | 193 void WorkerGlobalScope::clearInspector() |
194 { | 194 { |
195 m_workerInspectorController.clear(); | 195 m_workerInspectorController.clear(); |
196 } | 196 } |
197 | 197 |
198 int WorkerContext::setInterval(PassOwnPtr<ScheduledAction> action, int timeout) | 198 int WorkerGlobalScope::setInterval(PassOwnPtr<ScheduledAction> action, int timeo
ut) |
199 { | 199 { |
200 return DOMTimer::install(scriptExecutionContext(), action, timeout, false); | 200 return DOMTimer::install(scriptExecutionContext(), action, timeout, false); |
201 } | 201 } |
202 | 202 |
203 void WorkerContext::clearInterval(int timeoutId) | 203 void WorkerGlobalScope::clearInterval(int timeoutId) |
204 { | 204 { |
205 DOMTimer::removeById(scriptExecutionContext(), timeoutId); | 205 DOMTimer::removeById(scriptExecutionContext(), timeoutId); |
206 } | 206 } |
207 | 207 |
208 void WorkerContext::importScripts(const Vector<String>& urls, ExceptionCode& ec) | 208 void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionCode&
ec) |
209 { | 209 { |
210 ASSERT(contentSecurityPolicy()); | 210 ASSERT(contentSecurityPolicy()); |
211 ec = 0; | 211 ec = 0; |
212 Vector<String>::const_iterator urlsEnd = urls.end(); | 212 Vector<String>::const_iterator urlsEnd = urls.end(); |
213 Vector<KURL> completedURLs; | 213 Vector<KURL> completedURLs; |
214 for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it)
{ | 214 for (Vector<String>::const_iterator it = urls.begin(); it != urlsEnd; ++it)
{ |
215 const KURL& url = scriptExecutionContext()->completeURL(*it); | 215 const KURL& url = scriptExecutionContext()->completeURL(*it); |
216 if (!url.isValid()) { | 216 if (!url.isValid()) { |
217 ec = SYNTAX_ERR; | 217 ec = SYNTAX_ERR; |
218 return; | 218 return; |
(...skipping 17 matching lines...) Expand all Loading... |
236 | 236 |
237 ScriptValue exception; | 237 ScriptValue exception; |
238 m_script->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader
->responseURL()), &exception); | 238 m_script->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader
->responseURL()), &exception); |
239 if (!exception.hasNoValue()) { | 239 if (!exception.hasNoValue()) { |
240 m_script->setException(exception); | 240 m_script->setException(exception); |
241 return; | 241 return; |
242 } | 242 } |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 EventTarget* WorkerContext::errorEventTarget() | 246 EventTarget* WorkerGlobalScope::errorEventTarget() |
247 { | 247 { |
248 return this; | 248 return this; |
249 } | 249 } |
250 | 250 |
251 void WorkerContext::logExceptionToConsole(const String& errorMessage, const Stri
ng& sourceURL, int lineNumber, PassRefPtr<ScriptCallStack>) | 251 void WorkerGlobalScope::logExceptionToConsole(const String& errorMessage, const
String& sourceURL, int lineNumber, PassRefPtr<ScriptCallStack>) |
252 { | 252 { |
253 thread()->workerReportingProxy().postExceptionToWorkerObject(errorMessage, l
ineNumber, sourceURL); | 253 thread()->workerReportingProxy().postExceptionToWorkerObject(errorMessage, l
ineNumber, sourceURL); |
254 } | 254 } |
255 | 255 |
256 void WorkerContext::addConsoleMessage(MessageSource source, MessageLevel level,
const String& message, unsigned long requestIdentifier) | 256 void WorkerGlobalScope::addConsoleMessage(MessageSource source, MessageLevel lev
el, const String& message, unsigned long requestIdentifier) |
257 { | 257 { |
258 if (!isContextThread()) { | 258 if (!isContextThread()) { |
259 postTask(AddConsoleMessageTask::create(source, level, message)); | 259 postTask(AddConsoleMessageTask::create(source, level, message)); |
260 return; | 260 return; |
261 } | 261 } |
262 thread()->workerReportingProxy().postConsoleMessageToWorkerObject(source, le
vel, message, 0, String()); | 262 thread()->workerReportingProxy().postConsoleMessageToWorkerObject(source, le
vel, message, 0, String()); |
263 | 263 |
264 addMessageToWorkerConsole(source, level, message, String(), 0, 0, 0, request
Identifier); | 264 addMessageToWorkerConsole(source, level, message, String(), 0, 0, 0, request
Identifier); |
265 } | 265 } |
266 | 266 |
267 void WorkerContext::addMessage(MessageSource source, MessageLevel level, const S
tring& message, const String& sourceURL, unsigned lineNumber, PassRefPtr<ScriptC
allStack> callStack, ScriptState* state, unsigned long requestIdentifier) | 267 void WorkerGlobalScope::addMessage(MessageSource source, MessageLevel level, con
st String& message, const String& sourceURL, unsigned lineNumber, PassRefPtr<Scr
iptCallStack> callStack, ScriptState* state, unsigned long requestIdentifier) |
268 { | 268 { |
269 if (!isContextThread()) { | 269 if (!isContextThread()) { |
270 postTask(AddConsoleMessageTask::create(source, level, message)); | 270 postTask(AddConsoleMessageTask::create(source, level, message)); |
271 return; | 271 return; |
272 } | 272 } |
273 thread()->workerReportingProxy().postConsoleMessageToWorkerObject(source, le
vel, message, lineNumber, sourceURL); | 273 thread()->workerReportingProxy().postConsoleMessageToWorkerObject(source, le
vel, message, lineNumber, sourceURL); |
274 addMessageToWorkerConsole(source, level, message, sourceURL, lineNumber, cal
lStack, state, requestIdentifier); | 274 addMessageToWorkerConsole(source, level, message, sourceURL, lineNumber, cal
lStack, state, requestIdentifier); |
275 } | 275 } |
276 | 276 |
277 void WorkerContext::addMessageToWorkerConsole(MessageSource source, MessageLevel
level, const String& message, const String& sourceURL, unsigned lineNumber, Pas
sRefPtr<ScriptCallStack> callStack, ScriptState* state, unsigned long requestIde
ntifier) | 277 void WorkerGlobalScope::addMessageToWorkerConsole(MessageSource source, MessageL
evel level, const String& message, const String& sourceURL, unsigned lineNumber,
PassRefPtr<ScriptCallStack> callStack, ScriptState* state, unsigned long reques
tIdentifier) |
278 { | 278 { |
279 ASSERT(isContextThread()); | 279 ASSERT(isContextThread()); |
280 if (callStack) | 280 if (callStack) |
281 InspectorInstrumentation::addMessageToConsole(this, source, LogMessageTy
pe, level, message, callStack, requestIdentifier); | 281 InspectorInstrumentation::addMessageToConsole(this, source, LogMessageTy
pe, level, message, callStack, requestIdentifier); |
282 else | 282 else |
283 InspectorInstrumentation::addMessageToConsole(this, source, LogMessageTy
pe, level, message, sourceURL, lineNumber, state, requestIdentifier); | 283 InspectorInstrumentation::addMessageToConsole(this, source, LogMessageTy
pe, level, message, sourceURL, lineNumber, state, requestIdentifier); |
284 } | 284 } |
285 | 285 |
286 bool WorkerContext::isContextThread() const | 286 bool WorkerGlobalScope::isContextThread() const |
287 { | 287 { |
288 return thread()->isCurrentThread(); | 288 return thread()->isCurrentThread(); |
289 } | 289 } |
290 | 290 |
291 bool WorkerContext::isJSExecutionForbidden() const | 291 bool WorkerGlobalScope::isJSExecutionForbidden() const |
292 { | 292 { |
293 return m_script->isExecutionForbidden(); | 293 return m_script->isExecutionForbidden(); |
294 } | 294 } |
295 | 295 |
296 EventTargetData* WorkerContext::eventTargetData() | 296 EventTargetData* WorkerGlobalScope::eventTargetData() |
297 { | 297 { |
298 return &m_eventTargetData; | 298 return &m_eventTargetData; |
299 } | 299 } |
300 | 300 |
301 EventTargetData* WorkerContext::ensureEventTargetData() | 301 EventTargetData* WorkerGlobalScope::ensureEventTargetData() |
302 { | 302 { |
303 return &m_eventTargetData; | 303 return &m_eventTargetData; |
304 } | 304 } |
305 | 305 |
306 WorkerContext::Observer::Observer(WorkerContext* context) | 306 WorkerGlobalScope::Observer::Observer(WorkerGlobalScope* context) |
307 : m_context(context) | 307 : m_context(context) |
308 { | 308 { |
309 ASSERT(m_context && m_context->isContextThread()); | 309 ASSERT(m_context && m_context->isContextThread()); |
310 m_context->registerObserver(this); | 310 m_context->registerObserver(this); |
311 } | 311 } |
312 | 312 |
313 WorkerContext::Observer::~Observer() | 313 WorkerGlobalScope::Observer::~Observer() |
314 { | 314 { |
315 if (!m_context) | 315 if (!m_context) |
316 return; | 316 return; |
317 ASSERT(m_context->isContextThread()); | 317 ASSERT(m_context->isContextThread()); |
318 m_context->unregisterObserver(this); | 318 m_context->unregisterObserver(this); |
319 } | 319 } |
320 | 320 |
321 void WorkerContext::Observer::stopObserving() | 321 void WorkerGlobalScope::Observer::stopObserving() |
322 { | 322 { |
323 if (!m_context) | 323 if (!m_context) |
324 return; | 324 return; |
325 ASSERT(m_context->isContextThread()); | 325 ASSERT(m_context->isContextThread()); |
326 m_context->unregisterObserver(this); | 326 m_context->unregisterObserver(this); |
327 m_context = 0; | 327 m_context = 0; |
328 } | 328 } |
329 | 329 |
330 void WorkerContext::registerObserver(Observer* observer) | 330 void WorkerGlobalScope::registerObserver(Observer* observer) |
331 { | 331 { |
332 ASSERT(observer); | 332 ASSERT(observer); |
333 m_workerObservers.add(observer); | 333 m_workerObservers.add(observer); |
334 } | 334 } |
335 | 335 |
336 void WorkerContext::unregisterObserver(Observer* observer) | 336 void WorkerGlobalScope::unregisterObserver(Observer* observer) |
337 { | 337 { |
338 ASSERT(observer); | 338 ASSERT(observer); |
339 m_workerObservers.remove(observer); | 339 m_workerObservers.remove(observer); |
340 } | 340 } |
341 | 341 |
342 void WorkerContext::notifyObserversOfStop() | 342 void WorkerGlobalScope::notifyObserversOfStop() |
343 { | 343 { |
344 HashSet<Observer*>::iterator iter = m_workerObservers.begin(); | 344 HashSet<Observer*>::iterator iter = m_workerObservers.begin(); |
345 while (iter != m_workerObservers.end()) { | 345 while (iter != m_workerObservers.end()) { |
346 WorkerContext::Observer* observer = *iter; | 346 WorkerGlobalScope::Observer* observer = *iter; |
347 observer->stopObserving(); | 347 observer->stopObserving(); |
348 observer->notifyStop(); | 348 observer->notifyStop(); |
349 iter = m_workerObservers.begin(); | 349 iter = m_workerObservers.begin(); |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 WorkerEventQueue* WorkerContext::eventQueue() const | 353 WorkerEventQueue* WorkerGlobalScope::eventQueue() const |
354 { | 354 { |
355 return m_eventQueue.get(); | 355 return m_eventQueue.get(); |
356 } | 356 } |
357 | 357 |
358 } // namespace WebCore | 358 } // namespace WebCore |
OLD | NEW |