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/WebSharedWorkerImpl.cpp

Issue 1728803002: Rename WorkerThread to WorkerScript Base URL: https://chromium.googlesource.com/chromium/src.git@workerscript-controller
Patch Set: Created 4 years, 10 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 24 matching lines...) Expand all
35 #include "core/events/MessageEvent.h" 35 #include "core/events/MessageEvent.h"
36 #include "core/html/HTMLFormElement.h" 36 #include "core/html/HTMLFormElement.h"
37 #include "core/inspector/ConsoleMessage.h" 37 #include "core/inspector/ConsoleMessage.h"
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/loader/FrameLoader.h" 42 #include "core/loader/FrameLoader.h"
43 #include "core/page/Page.h" 43 #include "core/page/Page.h"
44 #include "core/workers/SharedWorkerGlobalScope.h" 44 #include "core/workers/SharedWorkerGlobalScope.h"
45 #include "core/workers/SharedWorkerThread.h" 45 #include "core/workers/SharedWorkerScript.h"
46 #include "core/workers/WorkerClients.h" 46 #include "core/workers/WorkerClients.h"
47 #include "core/workers/WorkerGlobalScope.h" 47 #include "core/workers/WorkerGlobalScope.h"
48 #include "core/workers/WorkerInspectorProxy.h" 48 #include "core/workers/WorkerInspectorProxy.h"
49 #include "core/workers/WorkerLoaderProxy.h" 49 #include "core/workers/WorkerLoaderProxy.h"
50 #include "core/workers/WorkerScriptLoader.h" 50 #include "core/workers/WorkerScriptLoader.h"
51 #include "core/workers/WorkerThreadStartupData.h" 51 #include "core/workers/WorkerScriptStartupData.h"
52 #include "platform/RuntimeEnabledFeatures.h" 52 #include "platform/RuntimeEnabledFeatures.h"
53 #include "platform/ThreadSafeFunctional.h" 53 #include "platform/ThreadSafeFunctional.h"
54 #include "platform/heap/Handle.h" 54 #include "platform/heap/Handle.h"
55 #include "platform/network/ContentSecurityPolicyParsers.h" 55 #include "platform/network/ContentSecurityPolicyParsers.h"
56 #include "platform/network/ResourceResponse.h" 56 #include "platform/network/ResourceResponse.h"
57 #include "platform/weborigin/KURL.h" 57 #include "platform/weborigin/KURL.h"
58 #include "platform/weborigin/SecurityOrigin.h" 58 #include "platform/weborigin/SecurityOrigin.h"
59 #include "public/platform/WebFileError.h" 59 #include "public/platform/WebFileError.h"
60 #include "public/platform/WebMessagePortChannel.h" 60 #include "public/platform/WebMessagePortChannel.h"
61 #include "public/platform/WebString.h" 61 #include "public/platform/WebString.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 ASSERT(m_webView); 95 ASSERT(m_webView);
96 // Detach the client before closing the view to avoid getting called back. 96 // Detach the client before closing the view to avoid getting called back.
97 m_mainFrame->setClient(0); 97 m_mainFrame->setClient(0);
98 98
99 m_webView->close(); 99 m_webView->close();
100 m_mainFrame->close(); 100 m_mainFrame->close();
101 if (m_loaderProxy) 101 if (m_loaderProxy)
102 m_loaderProxy->detachProvider(this); 102 m_loaderProxy->detachProvider(this);
103 } 103 }
104 104
105 void WebSharedWorkerImpl::terminateWorkerThread() 105 void WebSharedWorkerImpl::terminateWorkerScript()
106 { 106 {
107 if (m_askedToTerminate) 107 if (m_askedToTerminate)
108 return; 108 return;
109 m_askedToTerminate = true; 109 m_askedToTerminate = true;
110 if (m_mainScriptLoader) { 110 if (m_mainScriptLoader) {
111 m_mainScriptLoader->cancel(); 111 m_mainScriptLoader->cancel();
112 m_mainScriptLoader.clear(); 112 m_mainScriptLoader.clear();
113 m_client->workerScriptLoadFailed(); 113 m_client->workerScriptLoadFailed();
114 delete this; 114 delete this;
115 return; 115 return;
116 } 116 }
117 if (m_workerThread) 117 if (m_workerScript)
118 m_workerThread->terminate(); 118 m_workerScript->terminate();
119 m_workerInspectorProxy->workerThreadTerminated(); 119 m_workerInspectorProxy->workerScriptTerminated();
120 } 120 }
121 121
122 void WebSharedWorkerImpl::initializeLoader() 122 void WebSharedWorkerImpl::initializeLoader()
123 { 123 {
124 // Create 'shadow page'. This page is never displayed, it is used to proxy t he 124 // Create 'shadow page'. This page is never displayed, it is used to proxy t he
125 // loading requests from the worker context to the rest of WebKit and Chromi um 125 // loading requests from the worker context to the rest of WebKit and Chromi um
126 // infrastructure. 126 // infrastructure.
127 ASSERT(!m_webView); 127 ASSERT(!m_webView);
128 m_webView = WebView::create(0); 128 m_webView = WebView::create(0);
129 // FIXME: http://crbug.com/363843. This needs to find a better way to 129 // FIXME: http://crbug.com/363843. This needs to find a better way to
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 void WebSharedWorkerImpl::workerGlobalScopeClosed() 238 void WebSharedWorkerImpl::workerGlobalScopeClosed()
239 { 239 {
240 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&WebSharedWorkerImpl::workerGlobalScopeClosedOnMainThread, AllowCr ossThreadAccess(this))); 240 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&WebSharedWorkerImpl::workerGlobalScopeClosedOnMainThread, AllowCr ossThreadAccess(this)));
241 } 241 }
242 242
243 void WebSharedWorkerImpl::workerGlobalScopeClosedOnMainThread() 243 void WebSharedWorkerImpl::workerGlobalScopeClosedOnMainThread()
244 { 244 {
245 m_client->workerContextClosed(); 245 m_client->workerContextClosed();
246 246
247 terminateWorkerThread(); 247 terminateWorkerScript();
248 } 248 }
249 249
250 void WebSharedWorkerImpl::workerGlobalScopeStarted(WorkerGlobalScope*) 250 void WebSharedWorkerImpl::workerGlobalScopeStarted(WorkerGlobalScope*)
251 { 251 {
252 } 252 }
253 253
254 void WebSharedWorkerImpl::workerThreadTerminated() 254 void WebSharedWorkerImpl::workerScriptTerminated()
255 { 255 {
256 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&WebSharedWorkerImpl::workerThreadTerminatedOnMainThread, AllowCro ssThreadAccess(this))); 256 Platform::current()->mainThread()->taskRunner()->postTask(BLINK_FROM_HERE, t hreadSafeBind(&WebSharedWorkerImpl::workerScriptTerminatedOnMainThread, AllowCro ssThreadAccess(this)));
257 } 257 }
258 258
259 void WebSharedWorkerImpl::workerThreadTerminatedOnMainThread() 259 void WebSharedWorkerImpl::workerScriptTerminatedOnMainThread()
260 { 260 {
261 m_client->workerContextDestroyed(); 261 m_client->workerContextDestroyed();
262 // The lifetime of this proxy is controlled by the worker context. 262 // The lifetime of this proxy is controlled by the worker context.
263 delete this; 263 delete this;
264 } 264 }
265 265
266 // WorkerLoaderProxyProvider --------------------------------------------------- -------- 266 // WorkerLoaderProxyProvider --------------------------------------------------- --------
267 267
268 void WebSharedWorkerImpl::postTaskToLoader(PassOwnPtr<ExecutionContextTask> task ) 268 void WebSharedWorkerImpl::postTaskToLoader(PassOwnPtr<ExecutionContextTask> task )
269 { 269 {
270 m_mainFrame->frame()->document()->postTask(BLINK_FROM_HERE, task); 270 m_mainFrame->frame()->document()->postTask(BLINK_FROM_HERE, task);
271 } 271 }
272 272
273 bool WebSharedWorkerImpl::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContex tTask> task) 273 bool WebSharedWorkerImpl::postTaskToWorkerGlobalScope(PassOwnPtr<ExecutionContex tTask> task)
274 { 274 {
275 m_workerThread->postTask(BLINK_FROM_HERE, task); 275 m_workerScript->postTask(BLINK_FROM_HERE, task);
276 return true; 276 return true;
277 } 277 }
278 278
279 void WebSharedWorkerImpl::connect(WebMessagePortChannel* webChannel) 279 void WebSharedWorkerImpl::connect(WebMessagePortChannel* webChannel)
280 { 280 {
281 workerThread()->postTask( 281 workerScript()->postTask(
282 BLINK_FROM_HERE, createCrossThreadTask(&connectTask, adoptPtr(webChannel ))); 282 BLINK_FROM_HERE, createCrossThreadTask(&connectTask, adoptPtr(webChannel )));
283 } 283 }
284 284
285 void WebSharedWorkerImpl::connectTask(PassOwnPtr<WebMessagePortChannel> channel, ExecutionContext* context) 285 void WebSharedWorkerImpl::connectTask(PassOwnPtr<WebMessagePortChannel> channel, ExecutionContext* context)
286 { 286 {
287 // Wrap the passed-in channel in a MessagePort, and send it off via a connec t event. 287 // Wrap the passed-in channel in a MessagePort, and send it off via a connec t event.
288 MessagePort* port = MessagePort::create(*context); 288 MessagePort* port = MessagePort::create(*context);
289 port->entangle(channel); 289 port->entangle(channel);
290 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context); 290 WorkerGlobalScope* workerGlobalScope = toWorkerGlobalScope(context);
291 ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope->isSharedWorkerGlobalScop e()); 291 ASSERT_WITH_SECURITY_IMPLICATION(workerGlobalScope->isSharedWorkerGlobalScop e());
(...skipping 23 matching lines...) Expand all
315 m_mainScriptLoader->cancel(); 315 m_mainScriptLoader->cancel();
316 m_client->workerScriptLoadFailed(); 316 m_client->workerScriptLoadFailed();
317 317
318 // The SharedWorker was unable to load the initial script, so 318 // The SharedWorker was unable to load the initial script, so
319 // shut it down right here. 319 // shut it down right here.
320 delete this; 320 delete this;
321 return; 321 return;
322 } 322 }
323 323
324 Document* document = m_mainFrame->frame()->document(); 324 Document* document = m_mainFrame->frame()->document();
325 WorkerThreadStartMode startMode = DontPauseWorkerGlobalScopeOnStart; 325 WorkerScriptStartMode startMode = DontPauseWorkerGlobalScopeOnStart;
326 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document)) 326 if (InspectorInstrumentation::shouldPauseDedicatedWorkerOnStart(document))
327 startMode = PauseWorkerGlobalScopeOnStart; 327 startMode = PauseWorkerGlobalScopeOnStart;
328 328
329 // FIXME: this document's origin is pristine and without any extra privilege s. (crbug.com/254993) 329 // FIXME: this document's origin is pristine and without any extra privilege s. (crbug.com/254993)
330 SecurityOrigin* starterOrigin = document->securityOrigin(); 330 SecurityOrigin* starterOrigin = document->securityOrigin();
331 331
332 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create(); 332 OwnPtrWillBeRawPtr<WorkerClients> workerClients = WorkerClients::create();
333 provideLocalFileSystemToWorker(workerClients.get(), LocalFileSystemClient::c reate()); 333 provideLocalFileSystemToWorker(workerClients.get(), LocalFileSystemClient::c reate());
334 WebSecurityOrigin webSecurityOrigin(m_loadingDocument->securityOrigin()); 334 WebSecurityOrigin webSecurityOrigin(m_loadingDocument->securityOrigin());
335 provideContentSettingsClientToWorker(workerClients.get(), adoptPtr(m_client- >createWorkerContentSettingsClientProxy(webSecurityOrigin))); 335 provideContentSettingsClientToWorker(workerClients.get(), adoptPtr(m_client- >createWorkerContentSettingsClientProxy(webSecurityOrigin)));
336 RefPtrWillBeRawPtr<ContentSecurityPolicy> contentSecurityPolicy = m_mainScri ptLoader->releaseContentSecurityPolicy(); 336 RefPtrWillBeRawPtr<ContentSecurityPolicy> contentSecurityPolicy = m_mainScri ptLoader->releaseContentSecurityPolicy();
337 OwnPtr<WorkerThreadStartupData> startupData = WorkerThreadStartupData::creat e( 337 OwnPtr<WorkerScriptStartupData> startupData = WorkerScriptStartupData::creat e(
338 m_url, 338 m_url,
339 m_loadingDocument->userAgent(), 339 m_loadingDocument->userAgent(),
340 m_mainScriptLoader->script(), 340 m_mainScriptLoader->script(),
341 nullptr, 341 nullptr,
342 startMode, 342 startMode,
343 contentSecurityPolicy ? contentSecurityPolicy->headers() : nullptr, 343 contentSecurityPolicy ? contentSecurityPolicy->headers() : nullptr,
344 starterOrigin, 344 starterOrigin,
345 workerClients.release()); 345 workerClients.release());
346 m_loaderProxy = WorkerLoaderProxy::create(this); 346 m_loaderProxy = WorkerLoaderProxy::create(this);
347 setWorkerThread(SharedWorkerThread::create(m_name, m_loaderProxy, *this)); 347 setWorkerScript(SharedWorkerScript::create(m_name, m_loaderProxy, *this));
348 InspectorInstrumentation::scriptImported(m_loadingDocument.get(), m_mainScri ptLoader->identifier(), m_mainScriptLoader->script()); 348 InspectorInstrumentation::scriptImported(m_loadingDocument.get(), m_mainScri ptLoader->identifier(), m_mainScriptLoader->script());
349 m_mainScriptLoader.clear(); 349 m_mainScriptLoader.clear();
350 350
351 workerThread()->start(startupData.release()); 351 workerScript()->start(startupData.release());
352 m_workerInspectorProxy->workerThreadCreated(m_loadingDocument.get(), workerT hread(), m_url); 352 m_workerInspectorProxy->workerScriptCreated(m_loadingDocument.get(), workerS cript(), m_url);
353 m_client->workerScriptLoaded(); 353 m_client->workerScriptLoaded();
354 } 354 }
355 355
356 void WebSharedWorkerImpl::terminateWorkerContext() 356 void WebSharedWorkerImpl::terminateWorkerContext()
357 { 357 {
358 terminateWorkerThread(); 358 terminateWorkerScript();
359 } 359 }
360 360
361 void WebSharedWorkerImpl::pauseWorkerContextOnStart() 361 void WebSharedWorkerImpl::pauseWorkerContextOnStart()
362 { 362 {
363 m_pauseWorkerContextOnStart = true; 363 m_pauseWorkerContextOnStart = true;
364 } 364 }
365 365
366 void WebSharedWorkerImpl::attachDevTools(const WebString& hostId, int sessionId) 366 void WebSharedWorkerImpl::attachDevTools(const WebString& hostId, int sessionId)
367 { 367 {
368 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent(); 368 WebDevToolsAgent* devtoolsAgent = m_mainFrame->devToolsAgent();
(...skipping 24 matching lines...) Expand all
393 if (devtoolsAgent) 393 if (devtoolsAgent)
394 devtoolsAgent->dispatchOnInspectorBackend(sessionId, message); 394 devtoolsAgent->dispatchOnInspectorBackend(sessionId, message);
395 } 395 }
396 396
397 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client) 397 WebSharedWorker* WebSharedWorker::create(WebSharedWorkerClient* client)
398 { 398 {
399 return new WebSharedWorkerImpl(client); 399 return new WebSharedWorkerImpl(client);
400 } 400 }
401 401
402 } // namespace blink 402 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698