OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "core/inspector/InspectorInstrumentation.h" | 38 #include "core/inspector/InspectorInstrumentation.h" |
39 #include "core/inspector/WorkerDebuggerAgent.h" | 39 #include "core/inspector/WorkerDebuggerAgent.h" |
40 #include "core/inspector/WorkerInspectorController.h" | 40 #include "core/inspector/WorkerInspectorController.h" |
41 #include "core/loader/FrameLoadRequest.h" | 41 #include "core/loader/FrameLoadRequest.h" |
42 #include "core/workers/WorkerClients.h" | 42 #include "core/workers/WorkerClients.h" |
43 #include "core/workers/WorkerGlobalScope.h" | 43 #include "core/workers/WorkerGlobalScope.h" |
44 #include "core/workers/WorkerInspectorProxy.h" | 44 #include "core/workers/WorkerInspectorProxy.h" |
45 #include "core/workers/WorkerLoaderProxy.h" | 45 #include "core/workers/WorkerLoaderProxy.h" |
46 #include "core/workers/WorkerScriptLoader.h" | 46 #include "core/workers/WorkerScriptLoader.h" |
47 #include "core/workers/WorkerScriptLoaderClient.h" | 47 #include "core/workers/WorkerScriptLoaderClient.h" |
48 #include "core/workers/WorkerThreadStartupData.h" | 48 #include "core/workers/WorkerScriptStartupData.h" |
49 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" | 49 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" |
50 #include "modules/serviceworkers/ServiceWorkerThread.h" | 50 #include "modules/serviceworkers/ServiceWorkerThread.h" |
51 #include "platform/SharedBuffer.h" | 51 #include "platform/SharedBuffer.h" |
52 #include "platform/heap/Handle.h" | 52 #include "platform/heap/Handle.h" |
53 #include "platform/network/ContentSecurityPolicyParsers.h" | 53 #include "platform/network/ContentSecurityPolicyParsers.h" |
54 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" | 54 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" |
55 #include "public/platform/Platform.h" | 55 #include "public/platform/Platform.h" |
56 #include "public/platform/WebServiceWorkerProvider.h" | 56 #include "public/platform/WebServiceWorkerProvider.h" |
57 #include "public/platform/WebURLRequest.h" | 57 #include "public/platform/WebURLRequest.h" |
58 #include "public/web/WebDevToolsAgent.h" | 58 #include "public/web/WebDevToolsAgent.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 , m_waitingForDebuggerState(NotWaitingForDebugger) | 148 , m_waitingForDebuggerState(NotWaitingForDebugger) |
149 { | 149 { |
150 runningWorkerInstances().add(this); | 150 runningWorkerInstances().add(this); |
151 } | 151 } |
152 | 152 |
153 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() | 153 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() |
154 { | 154 { |
155 // Prevent onScriptLoaderFinished from deleting 'this'. | 155 // Prevent onScriptLoaderFinished from deleting 'this'. |
156 m_askedToTerminate = true; | 156 m_askedToTerminate = true; |
157 | 157 |
158 if (m_workerThread) | 158 if (m_workerScript) |
159 m_workerThread->terminateAndWait(); | 159 m_workerScript->terminateAndWait(); |
160 | 160 |
161 ASSERT(runningWorkerInstances().contains(this)); | 161 ASSERT(runningWorkerInstances().contains(this)); |
162 runningWorkerInstances().remove(this); | 162 runningWorkerInstances().remove(this); |
163 ASSERT(m_webView); | 163 ASSERT(m_webView); |
164 | 164 |
165 // Detach the client before closing the view to avoid getting called back. | 165 // Detach the client before closing the view to avoid getting called back. |
166 m_mainFrame->setClient(0); | 166 m_mainFrame->setClient(0); |
167 | 167 |
168 m_webView->close(); | 168 m_webView->close(); |
169 m_mainFrame->close(); | 169 m_mainFrame->close(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 m_mainScriptLoader.clear(); | 201 m_mainScriptLoader.clear(); |
202 // This may delete 'this'. | 202 // This may delete 'this'. |
203 m_workerContextClient->workerContextFailedToStart(); | 203 m_workerContextClient->workerContextFailedToStart(); |
204 return; | 204 return; |
205 } | 205 } |
206 if (m_pauseAfterDownloadState == IsPausedAfterDownload) { | 206 if (m_pauseAfterDownloadState == IsPausedAfterDownload) { |
207 // This may delete 'this'. | 207 // This may delete 'this'. |
208 m_workerContextClient->workerContextFailedToStart(); | 208 m_workerContextClient->workerContextFailedToStart(); |
209 return; | 209 return; |
210 } | 210 } |
211 if (m_workerThread) | 211 if (m_workerScript) |
212 m_workerThread->stop(); | 212 m_workerScript->stop(); |
213 m_workerInspectorProxy->workerThreadTerminated(); | 213 m_workerInspectorProxy->workerScriptTerminated(); |
214 } | 214 } |
215 | 215 |
216 void WebEmbeddedWorkerImpl::resumeAfterDownload() | 216 void WebEmbeddedWorkerImpl::resumeAfterDownload() |
217 { | 217 { |
218 ASSERT(!m_askedToTerminate); | 218 ASSERT(!m_askedToTerminate); |
219 bool wasPaused = (m_pauseAfterDownloadState == IsPausedAfterDownload); | 219 bool wasPaused = (m_pauseAfterDownloadState == IsPausedAfterDownload); |
220 m_pauseAfterDownloadState = DontPauseAfterDownload; | 220 m_pauseAfterDownloadState = DontPauseAfterDownload; |
221 | 221 |
222 // If we were asked to wait for debugger while updating service worker versi
on then it is good time now. | 222 // If we were asked to wait for debugger while updating service worker versi
on then it is good time now. |
223 m_workerContextClient->workerReadyForInspection(); | 223 m_workerContextClient->workerReadyForInspection(); |
224 if (m_workerStartData.waitForDebuggerMode == WebEmbeddedWorkerStartData::Wai
tForDebugger) | 224 if (m_workerStartData.waitForDebuggerMode == WebEmbeddedWorkerStartData::Wai
tForDebugger) |
225 m_waitingForDebuggerState = WaitingForDebuggerAfterScriptLoaded; | 225 m_waitingForDebuggerState = WaitingForDebuggerAfterScriptLoaded; |
226 else if (wasPaused) | 226 else if (wasPaused) |
227 startWorkerThread(); | 227 startWorkerScript(); |
228 } | 228 } |
229 | 229 |
230 void WebEmbeddedWorkerImpl::attachDevTools(const WebString& hostId) | 230 void WebEmbeddedWorkerImpl::attachDevTools(const WebString& hostId) |
231 { | 231 { |
232 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); | 232 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); |
233 if (devtoolsAgent) | 233 if (devtoolsAgent) |
234 devtoolsAgent->attach(hostId); | 234 devtoolsAgent->attach(hostId); |
235 } | 235 } |
236 | 236 |
237 void WebEmbeddedWorkerImpl::reattachDevTools(const WebString& hostId, const WebS
tring& savedState) | 237 void WebEmbeddedWorkerImpl::reattachDevTools(const WebString& hostId, const WebS
tring& savedState) |
(...skipping 28 matching lines...) Expand all Loading... |
266 pageInspector->dispatchMessageFromWorker(message); | 266 pageInspector->dispatchMessageFromWorker(message); |
267 } | 267 } |
268 | 268 |
269 void WebEmbeddedWorkerImpl::postTaskToLoader(PassOwnPtr<ExecutionContextTask> ta
sk) | 269 void WebEmbeddedWorkerImpl::postTaskToLoader(PassOwnPtr<ExecutionContextTask> ta
sk) |
270 { | 270 { |
271 m_mainFrame->frame()->document()->postTask(FROM_HERE, task); | 271 m_mainFrame->frame()->document()->postTask(FROM_HERE, task); |
272 } | 272 } |
273 | 273 |
274 bool WebEmbeddedWorkerImpl::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionCont
extTask> task) | 274 bool WebEmbeddedWorkerImpl::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionCont
extTask> task) |
275 { | 275 { |
276 if (m_askedToTerminate || !m_workerThread) | 276 if (m_askedToTerminate || !m_workerScript) |
277 return false; | 277 return false; |
278 | 278 |
279 m_workerThread->postTask(FROM_HERE, task); | 279 m_workerScript->postTask(FROM_HERE, task); |
280 return !m_workerThread->terminated(); | 280 return !m_workerScript->terminated(); |
281 } | 281 } |
282 | 282 |
283 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() | 283 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() |
284 { | 284 { |
285 // Create 'shadow page', which is never displayed and is used mainly to | 285 // Create 'shadow page', which is never displayed and is used mainly to |
286 // provide a context for loading on the main thread. | 286 // provide a context for loading on the main thread. |
287 // | 287 // |
288 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. | 288 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. |
289 // This code, and probably most of the code in this class should be shared | 289 // This code, and probably most of the code in this class should be shared |
290 // with SharedWorker. | 290 // with SharedWorker. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 m_workerContextClient->sendDevToolsMessage(callId, message, state); | 356 m_workerContextClient->sendDevToolsMessage(callId, message, state); |
357 } | 357 } |
358 | 358 |
359 void WebEmbeddedWorkerImpl::resumeStartup() | 359 void WebEmbeddedWorkerImpl::resumeStartup() |
360 { | 360 { |
361 WaitingForDebuggerState waitingForDebuggerState = m_waitingForDebuggerState; | 361 WaitingForDebuggerState waitingForDebuggerState = m_waitingForDebuggerState; |
362 m_waitingForDebuggerState = NotWaitingForDebugger; | 362 m_waitingForDebuggerState = NotWaitingForDebugger; |
363 if (waitingForDebuggerState == WaitingForDebuggerBeforeLoadingScript) | 363 if (waitingForDebuggerState == WaitingForDebuggerBeforeLoadingScript) |
364 loadShadowPage(); | 364 loadShadowPage(); |
365 else if (waitingForDebuggerState == WaitingForDebuggerAfterScriptLoaded) | 365 else if (waitingForDebuggerState == WaitingForDebuggerAfterScriptLoaded) |
366 startWorkerThread(); | 366 startWorkerScript(); |
367 } | 367 } |
368 | 368 |
369 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() | 369 void WebEmbeddedWorkerImpl::onScriptLoaderFinished() |
370 { | 370 { |
371 ASSERT(m_mainScriptLoader); | 371 ASSERT(m_mainScriptLoader); |
372 | 372 |
373 if (m_askedToTerminate) | 373 if (m_askedToTerminate) |
374 return; | 374 return; |
375 | 375 |
376 if (m_mainScriptLoader->failed()) { | 376 if (m_mainScriptLoader->failed()) { |
377 m_mainScriptLoader.clear(); | 377 m_mainScriptLoader.clear(); |
378 // This may delete 'this'. | 378 // This may delete 'this'. |
379 m_workerContextClient->workerContextFailedToStart(); | 379 m_workerContextClient->workerContextFailedToStart(); |
380 return; | 380 return; |
381 } | 381 } |
382 | 382 |
383 Platform::current()->histogramCustomCounts("ServiceWorker.ScriptSize", m_mai
nScriptLoader->script().length(), 1000, 5000000, 50); | 383 Platform::current()->histogramCustomCounts("ServiceWorker.ScriptSize", m_mai
nScriptLoader->script().length(), 1000, 5000000, 50); |
384 if (m_mainScriptLoader->cachedMetadata()) | 384 if (m_mainScriptLoader->cachedMetadata()) |
385 Platform::current()->histogramCustomCounts("ServiceWorker.ScriptCachedMe
tadataSize", m_mainScriptLoader->cachedMetadata()->size(), 1000, 50000000, 50); | 385 Platform::current()->histogramCustomCounts("ServiceWorker.ScriptCachedMe
tadataSize", m_mainScriptLoader->cachedMetadata()->size(), 1000, 50000000, 50); |
386 | 386 |
387 if (m_pauseAfterDownloadState == DoPauseAfterDownload) { | 387 if (m_pauseAfterDownloadState == DoPauseAfterDownload) { |
388 m_pauseAfterDownloadState = IsPausedAfterDownload; | 388 m_pauseAfterDownloadState = IsPausedAfterDownload; |
389 m_workerContextClient->didPauseAfterDownload(); | 389 m_workerContextClient->didPauseAfterDownload(); |
390 return; | 390 return; |
391 } | 391 } |
392 startWorkerThread(); | 392 startWorkerScript(); |
393 } | 393 } |
394 | 394 |
395 void WebEmbeddedWorkerImpl::startWorkerThread() | 395 void WebEmbeddedWorkerImpl::startWorkerScript() |
396 { | 396 { |
397 ASSERT(m_pauseAfterDownloadState == DontPauseAfterDownload); | 397 ASSERT(m_pauseAfterDownloadState == DontPauseAfterDownload); |
398 ASSERT(!m_askedToTerminate); | 398 ASSERT(!m_askedToTerminate); |
399 | 399 |
400 Document* document = m_mainFrame->frame()->document(); | 400 Document* document = m_mainFrame->frame()->document(); |
401 | 401 |
402 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; | 402 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; |
403 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document)) | 403 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document)) |
404 startMode = PauseWorkerGlobalScopeOnStart; | 404 startMode = PauseWorkerGlobalScopeOnStart; |
405 | 405 |
406 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) | 406 // FIXME: this document's origin is pristine and without any extra privilege
s. (crbug.com/254993) |
407 SecurityOrigin* starterOrigin = document->securityOrigin(); | 407 SecurityOrigin* starterOrigin = document->securityOrigin(); |
408 | 408 |
409 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); | 409 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); |
410 provideContentSettingsClientToWorker(workerClients.get(), m_contentSettingsC
lient.release()); | 410 provideContentSettingsClientToWorker(workerClients.get(), m_contentSettingsC
lient.release()); |
411 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo
rkerGlobalScopeClientImpl::create(*m_workerContextClient)); | 411 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo
rkerGlobalScopeClientImpl::create(*m_workerContextClient)); |
412 provideServiceWorkerContainerClientToWorker(workerClients.get(), adoptPtr(m_
workerContextClient->createServiceWorkerProvider())); | 412 provideServiceWorkerContainerClientToWorker(workerClients.get(), adoptPtr(m_
workerContextClient->createServiceWorkerProvider())); |
413 | 413 |
414 // We need to set the CSP to both the shadow page's document and the Service
WorkerGlobalScope. | 414 // We need to set the CSP to both the shadow page's document and the Service
WorkerGlobalScope. |
415 document->initContentSecurityPolicy(m_mainScriptLoader->releaseContentSecuri
tyPolicy()); | 415 document->initContentSecurityPolicy(m_mainScriptLoader->releaseContentSecuri
tyPolicy()); |
416 | 416 |
417 KURL scriptURL = m_mainScriptLoader->url(); | 417 KURL scriptURL = m_mainScriptLoader->url(); |
418 OwnPtr<WorkerThreadStartupData> startupData = | 418 OwnPtr<WorkerScriptStartupData> startupData = |
419 WorkerThreadStartupData::create( | 419 WorkerScriptStartupData::create( |
420 scriptURL, | 420 scriptURL, |
421 m_workerStartData.userAgent, | 421 m_workerStartData.userAgent, |
422 m_mainScriptLoader->script(), | 422 m_mainScriptLoader->script(), |
423 m_mainScriptLoader->releaseCachedMetadata(), | 423 m_mainScriptLoader->releaseCachedMetadata(), |
424 startMode, | 424 startMode, |
425 document->contentSecurityPolicy()->deprecatedHeader(), | 425 document->contentSecurityPolicy()->deprecatedHeader(), |
426 document->contentSecurityPolicy()->deprecatedHeaderType(), | 426 document->contentSecurityPolicy()->deprecatedHeaderType(), |
427 starterOrigin, | 427 starterOrigin, |
428 workerClients.release(), | 428 workerClients.release(), |
429 static_cast<V8CacheOptions>(m_workerStartData.v8CacheOptions)); | 429 static_cast<V8CacheOptions>(m_workerStartData.v8CacheOptions)); |
430 | 430 |
431 m_mainScriptLoader.clear(); | 431 m_mainScriptLoader.clear(); |
432 | 432 |
433 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); | 433 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc
ument, *m_workerContextClient); |
434 m_loaderProxy = WorkerLoaderProxy::create(this); | 434 m_loaderProxy = WorkerLoaderProxy::create(this); |
435 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy, startupData.release()); | 435 m_workerScript = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS
copeProxy, startupData.release()); |
436 m_workerThread->start(); | 436 m_workerScript->start(); |
437 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(),
scriptURL); | 437 m_workerInspectorProxy->workerScriptCreated(document, m_workerScript.get(),
scriptURL); |
438 } | 438 } |
439 | 439 |
440 } // namespace blink | 440 } // namespace blink |
OLD | NEW |