Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: third_party/WebKit/Source/web/WebEmbeddedWorkerImpl.cpp

Issue 1728803002: Rename WorkerThread to WorkerScript Base URL: https://chromium.googlesource.com/chromium/src.git@workerscript-controller
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
36 #include "core/frame/csp/ContentSecurityPolicy.h" 36 #include "core/frame/csp/ContentSecurityPolicy.h"
37 #include "core/inspector/InspectorInstrumentation.h" 37 #include "core/inspector/InspectorInstrumentation.h"
38 #include "core/inspector/WorkerDebuggerAgent.h" 38 #include "core/inspector/WorkerDebuggerAgent.h"
39 #include "core/inspector/WorkerInspectorController.h" 39 #include "core/inspector/WorkerInspectorController.h"
40 #include "core/loader/FrameLoadRequest.h" 40 #include "core/loader/FrameLoadRequest.h"
41 #include "core/workers/WorkerClients.h" 41 #include "core/workers/WorkerClients.h"
42 #include "core/workers/WorkerGlobalScope.h" 42 #include "core/workers/WorkerGlobalScope.h"
43 #include "core/workers/WorkerInspectorProxy.h" 43 #include "core/workers/WorkerInspectorProxy.h"
44 #include "core/workers/WorkerLoaderProxy.h" 44 #include "core/workers/WorkerLoaderProxy.h"
45 #include "core/workers/WorkerScriptLoader.h" 45 #include "core/workers/WorkerScriptLoader.h"
46 #include "core/workers/WorkerThreadStartupData.h" 46 #include "core/workers/WorkerScriptStartupData.h"
47 #include "modules/serviceworkers/ServiceWorkerContainerClient.h" 47 #include "modules/serviceworkers/ServiceWorkerContainerClient.h"
48 #include "modules/serviceworkers/ServiceWorkerThread.h" 48 #include "modules/serviceworkers/ServiceWorkerScript.h"
49 #include "platform/Histogram.h" 49 #include "platform/Histogram.h"
50 #include "platform/SharedBuffer.h" 50 #include "platform/SharedBuffer.h"
51 #include "platform/heap/Handle.h" 51 #include "platform/heap/Handle.h"
52 #include "platform/network/ContentSecurityPolicyParsers.h" 52 #include "platform/network/ContentSecurityPolicyParsers.h"
53 #include "platform/network/ContentSecurityPolicyResponseHeaders.h" 53 #include "platform/network/ContentSecurityPolicyResponseHeaders.h"
54 #include "public/platform/Platform.h" 54 #include "public/platform/Platform.h"
55 #include "public/platform/WebURLRequest.h" 55 #include "public/platform/WebURLRequest.h"
56 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h" 56 #include "public/platform/modules/serviceworker/WebServiceWorkerProvider.h"
57 #include "public/web/WebDevToolsAgent.h" 57 #include "public/web/WebDevToolsAgent.h"
58 #include "public/web/WebSettings.h" 58 #include "public/web/WebSettings.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 , m_waitingForDebuggerState(NotWaitingForDebugger) 92 , m_waitingForDebuggerState(NotWaitingForDebugger)
93 { 93 {
94 runningWorkerInstances().add(this); 94 runningWorkerInstances().add(this);
95 } 95 }
96 96
97 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl() 97 WebEmbeddedWorkerImpl::~WebEmbeddedWorkerImpl()
98 { 98 {
99 // Prevent onScriptLoaderFinished from deleting 'this'. 99 // Prevent onScriptLoaderFinished from deleting 'this'.
100 m_askedToTerminate = true; 100 m_askedToTerminate = true;
101 101
102 if (m_workerThread) 102 if (m_workerScript)
103 m_workerThread->terminateAndWait(); 103 m_workerScript->terminateAndWait();
104 104
105 ASSERT(runningWorkerInstances().contains(this)); 105 ASSERT(runningWorkerInstances().contains(this));
106 runningWorkerInstances().remove(this); 106 runningWorkerInstances().remove(this);
107 ASSERT(m_webView); 107 ASSERT(m_webView);
108 108
109 // Detach the client before closing the view to avoid getting called back. 109 // Detach the client before closing the view to avoid getting called back.
110 m_mainFrame->setClient(0); 110 m_mainFrame->setClient(0);
111 111
112 if (m_workerGlobalScopeProxy) { 112 if (m_workerGlobalScopeProxy) {
113 m_workerGlobalScopeProxy->detach(); 113 m_workerGlobalScopeProxy->detach();
(...skipping 28 matching lines...) Expand all
142 m_workerContextClient->workerContextFailedToStart(); 142 m_workerContextClient->workerContextFailedToStart();
143 return; 143 return;
144 } 144 }
145 if (m_mainScriptLoader) { 145 if (m_mainScriptLoader) {
146 m_mainScriptLoader->cancel(); 146 m_mainScriptLoader->cancel();
147 m_mainScriptLoader.clear(); 147 m_mainScriptLoader.clear();
148 // This deletes 'this'. 148 // This deletes 'this'.
149 m_workerContextClient->workerContextFailedToStart(); 149 m_workerContextClient->workerContextFailedToStart();
150 return; 150 return;
151 } 151 }
152 if (!m_workerThread) { 152 if (!m_workerScript) {
153 // The worker thread has not been created yet if the worker is asked to 153 // The worker thread has not been created yet if the worker is asked to
154 // terminate during waiting for debugger or paused after download. 154 // terminate during waiting for debugger or paused after download.
155 ASSERT(m_workerStartData.waitForDebuggerMode == WebEmbeddedWorkerStartDa ta::WaitForDebugger || m_pauseAfterDownloadState == IsPausedAfterDownload); 155 ASSERT(m_workerStartData.waitForDebuggerMode == WebEmbeddedWorkerStartDa ta::WaitForDebugger || m_pauseAfterDownloadState == IsPausedAfterDownload);
156 // This deletes 'this'. 156 // This deletes 'this'.
157 m_workerContextClient->workerContextFailedToStart(); 157 m_workerContextClient->workerContextFailedToStart();
158 return; 158 return;
159 } 159 }
160 m_workerThread->terminate(); 160 m_workerScript->terminate();
161 m_workerInspectorProxy->workerThreadTerminated(); 161 m_workerInspectorProxy->workerScriptTerminated();
162 } 162 }
163 163
164 void WebEmbeddedWorkerImpl::resumeAfterDownload() 164 void WebEmbeddedWorkerImpl::resumeAfterDownload()
165 { 165 {
166 ASSERT(!m_askedToTerminate); 166 ASSERT(!m_askedToTerminate);
167 ASSERT(m_pauseAfterDownloadState == IsPausedAfterDownload); 167 ASSERT(m_pauseAfterDownloadState == IsPausedAfterDownload);
168 168
169 m_pauseAfterDownloadState = DontPauseAfterDownload; 169 m_pauseAfterDownloadState = DontPauseAfterDownload;
170 startWorkerThread(); 170 startWorkerScript();
171 } 171 }
172 172
173 void WebEmbeddedWorkerImpl::attachDevTools(const WebString& hostId, int sessionI d) 173 void WebEmbeddedWorkerImpl::attachDevTools(const WebString& hostId, int sessionI d)
174 { 174 {
175 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); 175 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent();
176 if (devtoolsAgent) 176 if (devtoolsAgent)
177 devtoolsAgent->attach(hostId, sessionId); 177 devtoolsAgent->attach(hostId, sessionId);
178 } 178 }
179 179
180 void WebEmbeddedWorkerImpl::reattachDevTools(const WebString& hostId, int sessio nId, const WebString& savedState) 180 void WebEmbeddedWorkerImpl::reattachDevTools(const WebString& hostId, int sessio nId, const WebString& savedState)
(...skipping 28 matching lines...) Expand all
209 pageInspector->dispatchMessageFromWorker(message); 209 pageInspector->dispatchMessageFromWorker(message);
210 } 210 }
211 211
212 void WebEmbeddedWorkerImpl::postTaskToLoader(PassOwnPtr<ExecutionContextTask> ta sk) 212 void WebEmbeddedWorkerImpl::postTaskToLoader(PassOwnPtr<ExecutionContextTask> ta sk)
213 { 213 {
214 m_mainFrame->frame()->document()->postTask(BLINK_FROM_HERE, task); 214 m_mainFrame->frame()->document()->postTask(BLINK_FROM_HERE, task);
215 } 215 }
216 216
217 bool WebEmbeddedWorkerImpl::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionCont extTask> task) 217 bool WebEmbeddedWorkerImpl::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionCont extTask> task)
218 { 218 {
219 if (m_askedToTerminate || !m_workerThread) 219 if (m_askedToTerminate || !m_workerScript)
220 return false; 220 return false;
221 221
222 m_workerThread->postTask(BLINK_FROM_HERE, task); 222 m_workerScript->postTask(BLINK_FROM_HERE, task);
223 return !m_workerThread->terminated(); 223 return !m_workerScript->terminated();
224 } 224 }
225 225
226 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader() 226 void WebEmbeddedWorkerImpl::prepareShadowPageForLoader()
227 { 227 {
228 // Create 'shadow page', which is never displayed and is used mainly to 228 // Create 'shadow page', which is never displayed and is used mainly to
229 // provide a context for loading on the main thread. 229 // provide a context for loading on the main thread.
230 // 230 //
231 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader. 231 // FIXME: This does mostly same as WebSharedWorkerImpl::initializeLoader.
232 // This code, and probably most of the code in this class should be shared 232 // This code, and probably most of the code in this class should be shared
233 // with SharedWorker. 233 // with SharedWorker.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 scriptSizeHistogram.count(m_mainScriptLoader->script().length()); 328 scriptSizeHistogram.count(m_mainScriptLoader->script().length());
329 if (m_mainScriptLoader->cachedMetadata()) { 329 if (m_mainScriptLoader->cachedMetadata()) {
330 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptCachedMetadataSizeHistog ram, ("ServiceWorker.ScriptCachedMetadataSize", 1000, 50000000, 50)); 330 DEFINE_STATIC_LOCAL(CustomCountHistogram, scriptCachedMetadataSizeHistog ram, ("ServiceWorker.ScriptCachedMetadataSize", 1000, 50000000, 50));
331 scriptCachedMetadataSizeHistogram.count(m_mainScriptLoader->cachedMetada ta()->size()); 331 scriptCachedMetadataSizeHistogram.count(m_mainScriptLoader->cachedMetada ta()->size());
332 } 332 }
333 333
334 if (m_pauseAfterDownloadState == DoPauseAfterDownload) { 334 if (m_pauseAfterDownloadState == DoPauseAfterDownload) {
335 m_pauseAfterDownloadState = IsPausedAfterDownload; 335 m_pauseAfterDownloadState = IsPausedAfterDownload;
336 return; 336 return;
337 } 337 }
338 startWorkerThread(); 338 startWorkerScript();
339 } 339 }
340 340
341 void WebEmbeddedWorkerImpl::startWorkerThread() 341 void WebEmbeddedWorkerImpl::startWorkerScript()
342 { 342 {
343 ASSERT(m_pauseAfterDownloadState == DontPauseAfterDownload); 343 ASSERT(m_pauseAfterDownloadState == DontPauseAfterDownload);
344 ASSERT(!m_askedToTerminate); 344 ASSERT(!m_askedToTerminate);
345 345
346 Document* document = m_mainFrame->frame()->document(); 346 Document* document = m_mainFrame->frame()->document();
347 347
348 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; 348 WorkerScriptStartMode startMode = DontPauseWorkerGlobalScopeOnStart;
349 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document)) 349 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document))
350 startMode = PauseWorkerGlobalScopeOnStart; 350 startMode = PauseWorkerGlobalScopeOnStart;
351 351
352 // FIXME: this document's origin is pristine and without any extra privilege s. (crbug.com/254993) 352 // FIXME: this document's origin is pristine and without any extra privilege s. (crbug.com/254993)
353 SecurityOrigin* starterOrigin = document->securityOrigin(); 353 SecurityOrigin* starterOrigin = document->securityOrigin();
354 354
355 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); 355 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create();
356 provideContentSettingsClientToWorker(workerClients.get(), m_contentSettingsC lient.release()); 356 provideContentSettingsClientToWorker(workerClients.get(), m_contentSettingsC lient.release());
357 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo rkerGlobalScopeClientImpl::create(*m_workerContextClient)); 357 provideServiceWorkerGlobalScopeClientToWorker(workerClients.get(), ServiceWo rkerGlobalScopeClientImpl::create(*m_workerContextClient));
358 provideServiceWorkerContainerClientToWorker(workerClients.get(), adoptPtr(m_ workerContextClient->createServiceWorkerProvider())); 358 provideServiceWorkerContainerClientToWorker(workerClients.get(), adoptPtr(m_ workerContextClient->createServiceWorkerProvider()));
359 359
360 // We need to set the CSP to both the shadow page's document and the Service WorkerGlobalScope. 360 // We need to set the CSP to both the shadow page's document and the Service WorkerGlobalScope.
361 document->initContentSecurityPolicy(m_mainScriptLoader->releaseContentSecuri tyPolicy()); 361 document->initContentSecurityPolicy(m_mainScriptLoader->releaseContentSecuri tyPolicy());
362 362
363 KURL scriptURL = m_mainScriptLoader->url(); 363 KURL scriptURL = m_mainScriptLoader->url();
364 OwnPtr<WorkerThreadStartupData> startupData = WorkerThreadStartupData::creat e( 364 OwnPtr<WorkerScriptStartupData> startupData = WorkerScriptStartupData::creat e(
365 scriptURL, 365 scriptURL,
366 m_workerStartData.userAgent, 366 m_workerStartData.userAgent,
367 m_mainScriptLoader->script(), 367 m_mainScriptLoader->script(),
368 m_mainScriptLoader->releaseCachedMetadata(), 368 m_mainScriptLoader->releaseCachedMetadata(),
369 startMode, 369 startMode,
370 document->contentSecurityPolicy()->headers(), 370 document->contentSecurityPolicy()->headers(),
371 starterOrigin, 371 starterOrigin,
372 workerClients.release(), 372 workerClients.release(),
373 static_cast<V8CacheOptions>(m_workerStartData.v8CacheOptions)); 373 static_cast<V8CacheOptions>(m_workerStartData.v8CacheOptions));
374 374
375 m_mainScriptLoader.clear(); 375 m_mainScriptLoader.clear();
376 376
377 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc ument, *m_workerContextClient); 377 m_workerGlobalScopeProxy = ServiceWorkerGlobalScopeProxy::create(*this, *doc ument, *m_workerContextClient);
378 m_loaderProxy = WorkerLoaderProxy::create(this); 378 m_loaderProxy = WorkerLoaderProxy::create(this);
379 m_workerThread = ServiceWorkerThread::create(m_loaderProxy, *m_workerGlobalS copeProxy); 379 m_workerScript = ServiceWorkerScript::create(m_loaderProxy, *m_workerGlobalS copeProxy);
380 m_workerThread->start(startupData.release()); 380 m_workerScript->start(startupData.release());
381 m_workerInspectorProxy->workerThreadCreated(document, m_workerThread.get(), scriptURL); 381 m_workerInspectorProxy->workerScriptCreated(document, m_workerScript.get(), scriptURL);
382 } 382 }
383 383
384 } // namespace blink 384 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698