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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "core/inspector/WorkerInspectorController.h" | 52 #include "core/inspector/WorkerInspectorController.h" |
53 #include "core/loader/WorkerThreadableLoader.h" | 53 #include "core/loader/WorkerThreadableLoader.h" |
54 #include "core/frame/LocalDOMWindow.h" | 54 #include "core/frame/LocalDOMWindow.h" |
55 #include "core/workers/WorkerNavigator.h" | 55 #include "core/workers/WorkerNavigator.h" |
56 #include "core/workers/WorkerClients.h" | 56 #include "core/workers/WorkerClients.h" |
57 #include "core/workers/WorkerConsole.h" | 57 #include "core/workers/WorkerConsole.h" |
58 #include "core/workers/WorkerLoaderProxy.h" | 58 #include "core/workers/WorkerLoaderProxy.h" |
59 #include "core/workers/WorkerLocation.h" | 59 #include "core/workers/WorkerLocation.h" |
60 #include "core/workers/WorkerNavigator.h" | 60 #include "core/workers/WorkerNavigator.h" |
61 #include "core/workers/WorkerReportingProxy.h" | 61 #include "core/workers/WorkerReportingProxy.h" |
| 62 #include "core/workers/WorkerScript.h" |
62 #include "core/workers/WorkerScriptLoader.h" | 63 #include "core/workers/WorkerScriptLoader.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 { | 71 class CloseWorkerGlobalScopeTask : public ExecutionContextTask { |
72 public: | 72 public: |
73 static PassOwnPtr<CloseWorkerGlobalScopeTask> create() | 73 static PassOwnPtr<CloseWorkerGlobalScopeTask> create() |
74 { | 74 { |
75 return adoptPtr(new CloseWorkerGlobalScopeTask); | 75 return adoptPtr(new CloseWorkerGlobalScopeTask); |
76 } | 76 } |
77 | 77 |
78 virtual void performTask(ExecutionContext *context) | 78 virtual void performTask(ExecutionContext *context) |
79 { | 79 { |
80 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); | 80 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); |
81 // Notify parent that this context is closed. Parent is responsible for
calling WorkerThread::stop(). | 81 // Notify parent that this context is closed. Parent is responsible for
calling WorkerScript::stop(). |
82 workerGlobalScope->thread()->workerReportingProxy().workerGlobalScopeClo
sed(); | 82 workerGlobalScope->script()->workerReportingProxy().workerGlobalScopeClo
sed(); |
83 } | 83 } |
84 | 84 |
85 virtual bool isCleanupTask() const { return true; } | 85 virtual bool isCleanupTask() const { return true; } |
86 }; | 86 }; |
87 | 87 |
88 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
orkerScript* script, double timeOrigin, const SecurityOrigin* starterOrigin, Pas
sOwnPtrWillBeRawPtr<WorkerClients> workerClients) |
89 : m_url(url) | 89 : m_url(url) |
90 , m_userAgent(userAgent) | 90 , m_userAgent(userAgent) |
91 , m_v8CacheOptions(V8CacheOptionsDefault) | 91 , m_v8CacheOptions(V8CacheOptionsDefault) |
92 , m_script(adoptPtr(new WorkerScriptController(*this, thread->isolate()))) | 92 , m_scriptController(adoptPtr(new WorkerScriptController(*this, script->isol
ate()))) |
93 , m_thread(thread) | 93 , m_script(script) |
94 , m_workerInspectorController(adoptRefWillBeNoop(new WorkerInspectorControll
er(this))) | 94 , m_workerInspectorController(adoptRefWillBeNoop(new WorkerInspectorControll
er(this))) |
95 , m_closing(false) | 95 , m_closing(false) |
96 , m_eventQueue(WorkerEventQueue::create(this)) | 96 , m_eventQueue(WorkerEventQueue::create(this)) |
97 , m_workerClients(workerClients) | 97 , m_workerClients(workerClients) |
98 , m_timeOrigin(timeOrigin) | 98 , m_timeOrigin(timeOrigin) |
99 , m_messageStorage(ConsoleMessageStorage::create()) | 99 , m_messageStorage(ConsoleMessageStorage::create()) |
100 , m_workerExceptionUniqueIdentifier(0) | 100 , m_workerExceptionUniqueIdentifier(0) |
101 { | 101 { |
102 setSecurityOrigin(SecurityOrigin::create(url)); | 102 setSecurityOrigin(SecurityOrigin::create(url)); |
103 if (starterOrigin) | 103 if (starterOrigin) |
104 securityOrigin()->transferPrivilegesFrom(*starterOrigin); | 104 securityOrigin()->transferPrivilegesFrom(*starterOrigin); |
105 | 105 |
106 m_workerClients->reattachThread(); | 106 m_workerClients->reattachThread(); |
107 m_thread->setWorkerInspectorController(m_workerInspectorController.get()); | 107 m_script->setWorkerInspectorController(m_workerInspectorController.get()); |
108 } | 108 } |
109 | 109 |
110 WorkerGlobalScope::~WorkerGlobalScope() | 110 WorkerGlobalScope::~WorkerGlobalScope() |
111 { | 111 { |
112 ASSERT(!m_script); | 112 ASSERT(!m_scriptController); |
113 ASSERT(!m_workerInspectorController); | 113 ASSERT(!m_workerInspectorController); |
114 } | 114 } |
115 | 115 |
116 void WorkerGlobalScope::applyContentSecurityPolicyFromString(const String& polic
y, ContentSecurityPolicyHeaderType contentSecurityPolicyType) | 116 void WorkerGlobalScope::applyContentSecurityPolicyFromString(const String& polic
y, ContentSecurityPolicyHeaderType contentSecurityPolicyType) |
117 { | 117 { |
118 // FIXME: This doesn't match the CSP2 spec's Worker behavior (see https://w3
c.github.io/webappsec/specs/content-security-policy/#processing-model-workers) | 118 // FIXME: This doesn't match the CSP2 spec's Worker behavior (see https://w3
c.github.io/webappsec/specs/content-security-policy/#processing-model-workers) |
119 RefPtr<ContentSecurityPolicy> csp = ContentSecurityPolicy::create(); | 119 RefPtr<ContentSecurityPolicy> csp = ContentSecurityPolicy::create(); |
120 csp->didReceiveHeader(policy, contentSecurityPolicyType, ContentSecurityPoli
cyHeaderSourceHTTP); | 120 csp->didReceiveHeader(policy, contentSecurityPolicyType, ContentSecurityPoli
cyHeaderSourceHTTP); |
121 csp->bindToExecutionContext(executionContext()); | 121 csp->bindToExecutionContext(executionContext()); |
122 setContentSecurityPolicy(csp); | 122 setContentSecurityPolicy(csp); |
(...skipping 24 matching lines...) Expand all Loading... |
147 return KURL(m_url, url); | 147 return KURL(m_url, url); |
148 } | 148 } |
149 | 149 |
150 String WorkerGlobalScope::userAgent(const KURL&) const | 150 String WorkerGlobalScope::userAgent(const KURL&) const |
151 { | 151 { |
152 return m_userAgent; | 152 return m_userAgent; |
153 } | 153 } |
154 | 154 |
155 void WorkerGlobalScope::disableEval(const String& errorMessage) | 155 void WorkerGlobalScope::disableEval(const String& errorMessage) |
156 { | 156 { |
157 m_script->disableEval(errorMessage); | 157 m_scriptController->disableEval(errorMessage); |
158 } | 158 } |
159 | 159 |
160 double WorkerGlobalScope::timerAlignmentInterval() const | 160 double WorkerGlobalScope::timerAlignmentInterval() const |
161 { | 161 { |
162 return DOMTimer::visiblePageAlignmentInterval(); | 162 return DOMTimer::visiblePageAlignmentInterval(); |
163 } | 163 } |
164 | 164 |
165 DOMTimerCoordinator* WorkerGlobalScope::timers() | 165 DOMTimerCoordinator* WorkerGlobalScope::timers() |
166 { | 166 { |
167 return &m_timers; | 167 return &m_timers; |
(...skipping 27 matching lines...) Expand all Loading... |
195 | 195 |
196 WorkerNavigator* WorkerGlobalScope::navigator() const | 196 WorkerNavigator* WorkerGlobalScope::navigator() const |
197 { | 197 { |
198 if (!m_navigator) | 198 if (!m_navigator) |
199 m_navigator = WorkerNavigator::create(m_userAgent); | 199 m_navigator = WorkerNavigator::create(m_userAgent); |
200 return m_navigator.get(); | 200 return m_navigator.get(); |
201 } | 201 } |
202 | 202 |
203 void WorkerGlobalScope::postTask(const WebTraceLocation& location, PassOwnPtr<Ex
ecutionContextTask> task) | 203 void WorkerGlobalScope::postTask(const WebTraceLocation& location, PassOwnPtr<Ex
ecutionContextTask> task) |
204 { | 204 { |
205 thread()->postTask(location, task); | 205 script()->postTask(location, task); |
206 } | 206 } |
207 | 207 |
208 void WorkerGlobalScope::clearInspector() | 208 void WorkerGlobalScope::clearInspector() |
209 { | 209 { |
210 ASSERT(m_workerInspectorController); | 210 ASSERT(m_workerInspectorController); |
211 thread()->setWorkerInspectorController(nullptr); | 211 script()->setWorkerInspectorController(nullptr); |
212 m_workerInspectorController->dispose(); | 212 m_workerInspectorController->dispose(); |
213 m_workerInspectorController.clear(); | 213 m_workerInspectorController.clear(); |
214 } | 214 } |
215 | 215 |
216 void WorkerGlobalScope::dispose() | 216 void WorkerGlobalScope::dispose() |
217 { | 217 { |
218 ASSERT(thread()->isCurrentThread()); | 218 ASSERT(script()->isCurrentThread()); |
219 | 219 |
220 clearScript(); | 220 m_scriptController.clear(); |
221 clearInspector(); | 221 clearInspector(); |
222 m_eventQueue->close(); | 222 m_eventQueue->close(); |
223 | 223 |
224 // We do not clear the thread field of the | 224 // We do not clear the script field of the |
225 // WorkerGlobalScope. Other objects keep the worker global scope | 225 // WorkerGlobalScope. Other objects keep the worker global scope |
226 // alive because they need its thread field to check that work is | 226 // alive because they need its script field to check that work is |
227 // being carried out on the right thread. We therefore cannot clear | 227 // being carried out on the right thread. We therefore cannot clear |
228 // the thread field before all references to the worker global | 228 // the script field before all references to the worker global |
229 // scope are gone. | 229 // scope are gone. |
230 } | 230 } |
231 | 231 |
232 void WorkerGlobalScope::didEvaluateWorkerScript() | 232 void WorkerGlobalScope::didEvaluateWorkerScript() |
233 { | 233 { |
234 } | 234 } |
235 | 235 |
236 void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState
& exceptionState) | 236 void WorkerGlobalScope::importScripts(const Vector<String>& urls, ExceptionState
& exceptionState) |
237 { | 237 { |
238 ASSERT(contentSecurityPolicy()); | 238 ASSERT(contentSecurityPolicy()); |
(...skipping 25 matching lines...) Expand all Loading... |
264 exceptionState.throwDOMException(NetworkError, "The script at '" + c
ompleteURL.elidedString() + "' failed to load."); | 264 exceptionState.throwDOMException(NetworkError, "The script at '" + c
ompleteURL.elidedString() + "' failed to load."); |
265 return; | 265 return; |
266 } | 266 } |
267 | 267 |
268 InspectorInstrumentation::scriptImported(&executionContext, scriptLoader
->identifier(), scriptLoader->script()); | 268 InspectorInstrumentation::scriptImported(&executionContext, scriptLoader
->identifier(), scriptLoader->script()); |
269 scriptLoaded(scriptLoader->script().length(), scriptLoader->cachedMetada
ta() ? scriptLoader->cachedMetadata()->size() : 0); | 269 scriptLoaded(scriptLoader->script().length(), scriptLoader->cachedMetada
ta() ? scriptLoader->cachedMetadata()->size() : 0); |
270 | 270 |
271 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = nullptr; | 271 RefPtrWillBeRawPtr<ErrorEvent> errorEvent = nullptr; |
272 OwnPtr<Vector<char>> cachedMetaData(scriptLoader->releaseCachedMetadata(
)); | 272 OwnPtr<Vector<char>> cachedMetaData(scriptLoader->releaseCachedMetadata(
)); |
273 OwnPtr<CachedMetadataHandler> handler(createWorkerScriptCachedMetadataHa
ndler(completeURL, cachedMetaData.get())); | 273 OwnPtr<CachedMetadataHandler> handler(createWorkerScriptCachedMetadataHa
ndler(completeURL, cachedMetaData.get())); |
274 m_script->evaluate(ScriptSourceCode(scriptLoader->script(), scriptLoader
->responseURL()), &errorEvent, handler.get(), m_v8CacheOptions); | 274 m_scriptController->evaluate(ScriptSourceCode(scriptLoader->script(), sc
riptLoader->responseURL()), &errorEvent, handler.get(), m_v8CacheOptions); |
275 if (errorEvent) { | 275 if (errorEvent) { |
276 m_script->rethrowExceptionFromImportedScript(errorEvent.release(), e
xceptionState); | 276 m_scriptController->rethrowExceptionFromImportedScript(errorEvent.re
lease(), exceptionState); |
277 return; | 277 return; |
278 } | 278 } |
279 } | 279 } |
280 } | 280 } |
281 | 281 |
282 EventTarget* WorkerGlobalScope::errorEventTarget() | 282 EventTarget* WorkerGlobalScope::errorEventTarget() |
283 { | 283 { |
284 return this; | 284 return this; |
285 } | 285 } |
286 | 286 |
287 void WorkerGlobalScope::logExceptionToConsole(const String& errorMessage, int, c
onst String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr
<ScriptCallStack> callStack) | 287 void WorkerGlobalScope::logExceptionToConsole(const String& errorMessage, int, c
onst String& sourceURL, int lineNumber, int columnNumber, PassRefPtrWillBeRawPtr
<ScriptCallStack> callStack) |
288 { | 288 { |
289 unsigned long exceptionId = ++m_workerExceptionUniqueIdentifier; | 289 unsigned long exceptionId = ++m_workerExceptionUniqueIdentifier; |
290 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J
SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber); | 290 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(J
SMessageSource, ErrorMessageLevel, errorMessage, sourceURL, lineNumber); |
291 consoleMessage->setCallStack(callStack); | 291 consoleMessage->setCallStack(callStack); |
292 m_pendingMessages.set(exceptionId, consoleMessage); | 292 m_pendingMessages.set(exceptionId, consoleMessage); |
293 | 293 |
294 thread()->workerReportingProxy().reportException(errorMessage, lineNumber, c
olumnNumber, sourceURL, exceptionId); | 294 script()->workerReportingProxy().reportException(errorMessage, lineNumber, c
olumnNumber, sourceURL, exceptionId); |
295 } | 295 } |
296 | 296 |
297 void WorkerGlobalScope::reportBlockedScriptExecutionToInspector(const String& di
rectiveText) | 297 void WorkerGlobalScope::reportBlockedScriptExecutionToInspector(const String& di
rectiveText) |
298 { | 298 { |
299 InspectorInstrumentation::scriptExecutionBlockedByCSP(this, directiveText); | 299 InspectorInstrumentation::scriptExecutionBlockedByCSP(this, directiveText); |
300 } | 300 } |
301 | 301 |
302 void WorkerGlobalScope::addConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>
prpConsoleMessage) | 302 void WorkerGlobalScope::addConsoleMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>
prpConsoleMessage) |
303 { | 303 { |
304 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = prpConsoleMessage; | 304 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = prpConsoleMessage; |
305 if (!isContextThread()) { | 305 if (!isContextThread()) { |
306 postTask(FROM_HERE, AddConsoleMessageTask::create(consoleMessage->source
(), consoleMessage->level(), consoleMessage->message())); | 306 postTask(FROM_HERE, AddConsoleMessageTask::create(consoleMessage->source
(), consoleMessage->level(), consoleMessage->message())); |
307 return; | 307 return; |
308 } | 308 } |
309 thread()->workerReportingProxy().reportConsoleMessage(consoleMessage); | 309 script()->workerReportingProxy().reportConsoleMessage(consoleMessage); |
310 addMessageToWorkerConsole(consoleMessage.release()); | 310 addMessageToWorkerConsole(consoleMessage.release()); |
311 } | 311 } |
312 | 312 |
313 void WorkerGlobalScope::addMessageToWorkerConsole(PassRefPtrWillBeRawPtr<Console
Message> consoleMessage) | 313 void WorkerGlobalScope::addMessageToWorkerConsole(PassRefPtrWillBeRawPtr<Console
Message> consoleMessage) |
314 { | 314 { |
315 ASSERT(isContextThread()); | 315 ASSERT(isContextThread()); |
316 m_messageStorage->reportMessage(this, consoleMessage); | 316 m_messageStorage->reportMessage(this, consoleMessage); |
317 } | 317 } |
318 | 318 |
319 bool WorkerGlobalScope::isContextThread() const | 319 bool WorkerGlobalScope::isContextThread() const |
320 { | 320 { |
321 return thread()->isCurrentThread(); | 321 return script()->isCurrentThread(); |
322 } | 322 } |
323 | 323 |
324 bool WorkerGlobalScope::isJSExecutionForbidden() const | 324 bool WorkerGlobalScope::isJSExecutionForbidden() const |
325 { | 325 { |
326 return m_script->isExecutionForbidden(); | 326 return m_scriptController->isExecutionForbidden(); |
327 } | 327 } |
328 | 328 |
329 WorkerEventQueue* WorkerGlobalScope::eventQueue() const | 329 WorkerEventQueue* WorkerGlobalScope::eventQueue() const |
330 { | 330 { |
331 return m_eventQueue.get(); | 331 return m_eventQueue.get(); |
332 } | 332 } |
333 | 333 |
334 void WorkerGlobalScope::countFeature(UseCounter::Feature) const | 334 void WorkerGlobalScope::countFeature(UseCounter::Feature) const |
335 { | 335 { |
336 // FIXME: How should we count features for shared/service workers? | 336 // FIXME: How should we count features for shared/service workers? |
(...skipping 26 matching lines...) Expand all Loading... |
363 addConsoleMessage(consoleMessage.release()); | 363 addConsoleMessage(consoleMessage.release()); |
364 } | 364 } |
365 | 365 |
366 bool WorkerGlobalScope::isPrivilegedContext(String& errorMessage, const Privileg
eContextCheck privilegeContextCheck) | 366 bool WorkerGlobalScope::isPrivilegedContext(String& errorMessage, const Privileg
eContextCheck privilegeContextCheck) |
367 { | 367 { |
368 // Until there are APIs that are available in workers and that | 368 // Until there are APIs that are available in workers and that |
369 // require a privileged context test that checks ancestors, just do | 369 // require a privileged context test that checks ancestors, just do |
370 // a simple check here. Once we have a need for a real | 370 // a simple check here. Once we have a need for a real |
371 // |isPrivilegedContext| check here, we can check the responsible | 371 // |isPrivilegedContext| check here, we can check the responsible |
372 // document for a privileged context at worker creation time, pass | 372 // document for a privileged context at worker creation time, pass |
373 // it in via WorkerThreadStartupData, and check it here. | 373 // it in via WorkerScriptStartupData, and check it here. |
374 return securityOrigin()->isPotentiallyTrustworthy(errorMessage); | 374 return securityOrigin()->isPotentiallyTrustworthy(errorMessage); |
375 } | 375 } |
376 | 376 |
377 void WorkerGlobalScope::removeURLFromMemoryCache(const KURL& url) | 377 void WorkerGlobalScope::removeURLFromMemoryCache(const KURL& url) |
378 { | 378 { |
379 m_thread->workerLoaderProxy()->postTaskToLoader(createCrossThreadTask(&Worke
rGlobalScope::removeURLFromMemoryCacheInternal, url)); | 379 m_script->workerLoaderProxy()->postTaskToLoader(createCrossThreadTask(&Worke
rGlobalScope::removeURLFromMemoryCacheInternal, url)); |
380 } | 380 } |
381 | 381 |
382 void WorkerGlobalScope::removeURLFromMemoryCacheInternal(const KURL& url) | 382 void WorkerGlobalScope::removeURLFromMemoryCacheInternal(const KURL& url) |
383 { | 383 { |
384 memoryCache()->removeURLFromCache(url); | 384 memoryCache()->removeURLFromCache(url); |
385 } | 385 } |
386 | 386 |
387 v8::Local<v8::Object> WorkerGlobalScope::wrap(v8::Local<v8::Object> creationCont
ext, v8::Isolate*) | 387 v8::Local<v8::Object> WorkerGlobalScope::wrap(v8::Local<v8::Object> creationCont
ext, v8::Isolate*) |
388 { | 388 { |
389 // WorkerGlobalScope must never be wrapped with wrap method. The global | 389 // WorkerGlobalScope must never be wrapped with wrap method. The global |
(...skipping 20 matching lines...) Expand all Loading... |
410 visitor->trace(m_timers); | 410 visitor->trace(m_timers); |
411 visitor->trace(m_messageStorage); | 411 visitor->trace(m_messageStorage); |
412 visitor->trace(m_pendingMessages); | 412 visitor->trace(m_pendingMessages); |
413 HeapSupplementable<WorkerGlobalScope>::trace(visitor); | 413 HeapSupplementable<WorkerGlobalScope>::trace(visitor); |
414 #endif | 414 #endif |
415 ExecutionContext::trace(visitor); | 415 ExecutionContext::trace(visitor); |
416 EventTargetWithInlineData::trace(visitor); | 416 EventTargetWithInlineData::trace(visitor); |
417 } | 417 } |
418 | 418 |
419 } // namespace blink | 419 } // namespace blink |
OLD | NEW |