OLD | NEW |
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 29 matching lines...) Expand all Loading... |
40 #include "core/frame/WebLocalFrameBase.h" | 40 #include "core/frame/WebLocalFrameBase.h" |
41 #include "core/inspector/ConsoleMessage.h" | 41 #include "core/inspector/ConsoleMessage.h" |
42 #include "core/loader/FrameLoadRequest.h" | 42 #include "core/loader/FrameLoadRequest.h" |
43 #include "core/loader/FrameLoader.h" | 43 #include "core/loader/FrameLoader.h" |
44 #include "core/loader/ThreadableLoadingContext.h" | 44 #include "core/loader/ThreadableLoadingContext.h" |
45 #include "core/loader/WorkerFetchContext.h" | 45 #include "core/loader/WorkerFetchContext.h" |
46 #include "core/probe/CoreProbes.h" | 46 #include "core/probe/CoreProbes.h" |
47 #include "core/workers/ParentFrameTaskRunners.h" | 47 #include "core/workers/ParentFrameTaskRunners.h" |
48 #include "core/workers/SharedWorkerGlobalScope.h" | 48 #include "core/workers/SharedWorkerGlobalScope.h" |
49 #include "core/workers/SharedWorkerThread.h" | 49 #include "core/workers/SharedWorkerThread.h" |
50 #include "core/workers/WorkerClients.h" | |
51 #include "core/workers/WorkerContentSettingsClient.h" | 50 #include "core/workers/WorkerContentSettingsClient.h" |
52 #include "core/workers/WorkerGlobalScope.h" | 51 #include "core/workers/WorkerGlobalScope.h" |
53 #include "core/workers/WorkerInspectorProxy.h" | 52 #include "core/workers/WorkerInspectorProxy.h" |
54 #include "core/workers/WorkerScriptLoader.h" | 53 #include "core/workers/WorkerScriptLoader.h" |
55 #include "core/workers/WorkerThreadStartupData.h" | 54 #include "core/workers/WorkerThreadStartupData.h" |
56 #include "platform/CrossThreadFunctional.h" | 55 #include "platform/CrossThreadFunctional.h" |
57 #include "platform/RuntimeEnabledFeatures.h" | 56 #include "platform/RuntimeEnabledFeatures.h" |
58 #include "platform/heap/Handle.h" | 57 #include "platform/heap/Handle.h" |
59 #include "platform/heap/Persistent.h" | 58 #include "platform/heap/Persistent.h" |
60 #include "platform/loader/fetch/ResourceResponse.h" | 59 #include "platform/loader/fetch/ResourceResponse.h" |
(...skipping 10 matching lines...) Expand all Loading... |
71 #include "public/platform/WebURLRequest.h" | 70 #include "public/platform/WebURLRequest.h" |
72 #include "public/platform/WebWorkerFetchContext.h" | 71 #include "public/platform/WebWorkerFetchContext.h" |
73 #include "public/platform/modules/serviceworker/WebServiceWorkerNetworkProvider.
h" | 72 #include "public/platform/modules/serviceworker/WebServiceWorkerNetworkProvider.
h" |
74 #include "public/web/WebDevToolsAgent.h" | 73 #include "public/web/WebDevToolsAgent.h" |
75 #include "public/web/WebFrame.h" | 74 #include "public/web/WebFrame.h" |
76 #include "public/web/WebSettings.h" | 75 #include "public/web/WebSettings.h" |
77 #include "public/web/WebView.h" | 76 #include "public/web/WebView.h" |
78 | 77 |
79 namespace blink { | 78 namespace blink { |
80 | 79 |
81 namespace { | |
82 | |
83 // Vector of callbacks for the OnScriptLoaderFinished method. | |
84 using WorkerClientsCreatedCallbackVector = | |
85 WTF::Vector<WebSharedWorkerImpl::WorkerClientsCreatedCallback>; | |
86 WorkerClientsCreatedCallbackVector& GetWorkerClientsCreatedCallbackVector() { | |
87 DEFINE_STATIC_LOCAL(WorkerClientsCreatedCallbackVector, callback_vector, ()); | |
88 return callback_vector; | |
89 } | |
90 | |
91 } // namespace | |
92 | |
93 // TODO(toyoshim): Share implementation with WebEmbeddedWorkerImpl as much as | 80 // TODO(toyoshim): Share implementation with WebEmbeddedWorkerImpl as much as |
94 // possible. | 81 // possible. |
95 | 82 |
| 83 template class CORE_TEMPLATE_EXPORT |
| 84 WorkerClientsInitializer<WebSharedWorkerImpl>; |
| 85 |
96 WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client) | 86 WebSharedWorkerImpl::WebSharedWorkerImpl(WebSharedWorkerClient* client) |
97 : web_view_(nullptr), | 87 : web_view_(nullptr), |
98 main_frame_(nullptr), | 88 main_frame_(nullptr), |
99 asked_to_terminate_(false), | 89 asked_to_terminate_(false), |
100 worker_inspector_proxy_(WorkerInspectorProxy::Create()), | 90 worker_inspector_proxy_(WorkerInspectorProxy::Create()), |
101 client_(client), | 91 client_(client), |
102 pause_worker_context_on_start_(false), | 92 pause_worker_context_on_start_(false), |
103 is_paused_on_start_(false), | 93 is_paused_on_start_(false), |
104 creation_address_space_(kWebAddressSpacePublic) { | 94 creation_address_space_(kWebAddressSpacePublic) { |
105 DCHECK(IsMainThread()); | 95 DCHECK(IsMainThread()); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 TerminateWorkerThread(); | 246 TerminateWorkerThread(); |
257 } | 247 } |
258 | 248 |
259 void WebSharedWorkerImpl::DidTerminateWorkerThread() { | 249 void WebSharedWorkerImpl::DidTerminateWorkerThread() { |
260 DCHECK(IsMainThread()); | 250 DCHECK(IsMainThread()); |
261 client_->WorkerContextDestroyed(); | 251 client_->WorkerContextDestroyed(); |
262 // The lifetime of this proxy is controlled by the worker context. | 252 // The lifetime of this proxy is controlled by the worker context. |
263 delete this; | 253 delete this; |
264 } | 254 } |
265 | 255 |
266 void WebSharedWorkerImpl::RegisterWorkerClientsCreatedCallback( | |
267 WorkerClientsCreatedCallback callback) { | |
268 GetWorkerClientsCreatedCallbackVector().push_back(callback); | |
269 } | |
270 | |
271 void WebSharedWorkerImpl::Connect( | 256 void WebSharedWorkerImpl::Connect( |
272 std::unique_ptr<WebMessagePortChannel> web_channel) { | 257 std::unique_ptr<WebMessagePortChannel> web_channel) { |
273 DCHECK(IsMainThread()); | 258 DCHECK(IsMainThread()); |
274 // The HTML spec requires to queue a connect event using the DOM manipulation | 259 // The HTML spec requires to queue a connect event using the DOM manipulation |
275 // task source. | 260 // task source. |
276 // https://html.spec.whatwg.org/multipage/workers.html#shared-workers-and-the-
sharedworker-interface | 261 // https://html.spec.whatwg.org/multipage/workers.html#shared-workers-and-the-
sharedworker-interface |
277 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) | 262 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) |
278 ->PostTask( | 263 ->PostTask( |
279 BLINK_FROM_HERE, | 264 BLINK_FROM_HERE, |
280 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, | 265 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 delete this; | 316 delete this; |
332 return; | 317 return; |
333 } | 318 } |
334 | 319 |
335 // FIXME: this document's origin is pristine and without any extra privileges | 320 // FIXME: this document's origin is pristine and without any extra privileges |
336 // (e.g. GrantUniversalAccess) that can be overriden in regular documents | 321 // (e.g. GrantUniversalAccess) that can be overriden in regular documents |
337 // via WebPreference by embedders. (crbug.com/254993) | 322 // via WebPreference by embedders. (crbug.com/254993) |
338 SecurityOrigin* starter_origin = loading_document_->GetSecurityOrigin(); | 323 SecurityOrigin* starter_origin = loading_document_->GetSecurityOrigin(); |
339 | 324 |
340 WorkerClients* worker_clients = WorkerClients::Create(); | 325 WorkerClients* worker_clients = WorkerClients::Create(); |
341 DCHECK(!GetWorkerClientsCreatedCallbackVector().IsEmpty()); | 326 WorkerClientsInitializer<WebSharedWorkerImpl>::Run(worker_clients); |
342 for (auto& callback : GetWorkerClientsCreatedCallbackVector()) { | |
343 callback(worker_clients); | |
344 } | |
345 | 327 |
346 WebSecurityOrigin web_security_origin(loading_document_->GetSecurityOrigin()); | 328 WebSecurityOrigin web_security_origin(loading_document_->GetSecurityOrigin()); |
347 ProvideContentSettingsClientToWorker( | 329 ProvideContentSettingsClientToWorker( |
348 worker_clients, | 330 worker_clients, |
349 client_->CreateWorkerContentSettingsClient(web_security_origin)); | 331 client_->CreateWorkerContentSettingsClient(web_security_origin)); |
350 | 332 |
351 if (RuntimeEnabledFeatures::OffMainThreadFetchEnabled()) { | 333 if (RuntimeEnabledFeatures::OffMainThreadFetchEnabled()) { |
352 std::unique_ptr<WebWorkerFetchContext> web_worker_fetch_context = | 334 std::unique_ptr<WebWorkerFetchContext> web_worker_fetch_context = |
353 client_->CreateWorkerFetchContext( | 335 client_->CreateWorkerFetchContext( |
354 WebLocalFrameBase::FromFrame(main_frame_->GetFrame()) | 336 WebLocalFrameBase::FromFrame(main_frame_->GetFrame()) |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, | 431 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, |
450 message); | 432 message); |
451 } | 433 } |
452 } | 434 } |
453 | 435 |
454 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { | 436 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { |
455 return new WebSharedWorkerImpl(client); | 437 return new WebSharedWorkerImpl(client); |
456 } | 438 } |
457 | 439 |
458 } // namespace blink | 440 } // namespace blink |
OLD | NEW |