| 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 28 matching lines...) Expand all Loading... |
| 39 #include "core/loader/FrameLoader.h" | 39 #include "core/loader/FrameLoader.h" |
| 40 #include "core/loader/ThreadableLoadingContext.h" | 40 #include "core/loader/ThreadableLoadingContext.h" |
| 41 #include "core/probe/CoreProbes.h" | 41 #include "core/probe/CoreProbes.h" |
| 42 #include "core/workers/ParentFrameTaskRunners.h" | 42 #include "core/workers/ParentFrameTaskRunners.h" |
| 43 #include "core/workers/SharedWorkerGlobalScope.h" | 43 #include "core/workers/SharedWorkerGlobalScope.h" |
| 44 #include "core/workers/SharedWorkerThread.h" | 44 #include "core/workers/SharedWorkerThread.h" |
| 45 #include "core/workers/WorkerClients.h" | 45 #include "core/workers/WorkerClients.h" |
| 46 #include "core/workers/WorkerContentSettingsClient.h" | 46 #include "core/workers/WorkerContentSettingsClient.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" | |
| 50 #include "core/workers/WorkerScriptLoader.h" | 49 #include "core/workers/WorkerScriptLoader.h" |
| 51 #include "core/workers/WorkerThreadStartupData.h" | 50 #include "core/workers/WorkerThreadStartupData.h" |
| 52 #include "platform/CrossThreadFunctional.h" | 51 #include "platform/CrossThreadFunctional.h" |
| 53 #include "platform/heap/Handle.h" | 52 #include "platform/heap/Handle.h" |
| 54 #include "platform/heap/Persistent.h" | 53 #include "platform/heap/Persistent.h" |
| 55 #include "platform/loader/fetch/ResourceResponse.h" | 54 #include "platform/loader/fetch/ResourceResponse.h" |
| 56 #include "platform/network/ContentSecurityPolicyParsers.h" | 55 #include "platform/network/ContentSecurityPolicyParsers.h" |
| 57 #include "platform/weborigin/KURL.h" | 56 #include "platform/weborigin/KURL.h" |
| 58 #include "platform/weborigin/SecurityOrigin.h" | 57 #include "platform/weborigin/SecurityOrigin.h" |
| 59 #include "platform/wtf/Functional.h" | 58 #include "platform/wtf/Functional.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 91 } |
| 93 | 92 |
| 94 WebSharedWorkerImpl::~WebSharedWorkerImpl() { | 93 WebSharedWorkerImpl::~WebSharedWorkerImpl() { |
| 95 DCHECK(IsMainThread()); | 94 DCHECK(IsMainThread()); |
| 96 DCHECK(web_view_); | 95 DCHECK(web_view_); |
| 97 // 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. |
| 98 main_frame_->SetClient(0); | 97 main_frame_->SetClient(0); |
| 99 | 98 |
| 100 web_view_->Close(); | 99 web_view_->Close(); |
| 101 main_frame_->Close(); | 100 main_frame_->Close(); |
| 102 if (loader_proxy_) | |
| 103 loader_proxy_->DetachProvider(this); | |
| 104 } | 101 } |
| 105 | 102 |
| 106 void WebSharedWorkerImpl::TerminateWorkerThread() { | 103 void WebSharedWorkerImpl::TerminateWorkerThread() { |
| 107 DCHECK(IsMainThread()); | 104 DCHECK(IsMainThread()); |
| 108 if (asked_to_terminate_) | 105 if (asked_to_terminate_) |
| 109 return; | 106 return; |
| 110 asked_to_terminate_ = true; | 107 asked_to_terminate_ = true; |
| 111 if (main_script_loader_) { | 108 if (main_script_loader_) { |
| 112 main_script_loader_->Cancel(); | 109 main_script_loader_->Cancel(); |
| 113 main_script_loader_.Clear(); | 110 main_script_loader_.Clear(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 TerminateWorkerThread(); | 231 TerminateWorkerThread(); |
| 235 } | 232 } |
| 236 | 233 |
| 237 void WebSharedWorkerImpl::DidTerminateWorkerThread() { | 234 void WebSharedWorkerImpl::DidTerminateWorkerThread() { |
| 238 DCHECK(IsMainThread()); | 235 DCHECK(IsMainThread()); |
| 239 client_->WorkerContextDestroyed(); | 236 client_->WorkerContextDestroyed(); |
| 240 // The lifetime of this proxy is controlled by the worker context. | 237 // The lifetime of this proxy is controlled by the worker context. |
| 241 delete this; | 238 delete this; |
| 242 } | 239 } |
| 243 | 240 |
| 244 ThreadableLoadingContext* WebSharedWorkerImpl::GetThreadableLoadingContext() { | |
| 245 if (!loading_context_) { | |
| 246 loading_context_ = | |
| 247 ThreadableLoadingContext::Create(*ToDocument(loading_document_.Get())); | |
| 248 } | |
| 249 return loading_context_; | |
| 250 } | |
| 251 | |
| 252 void WebSharedWorkerImpl::Connect( | 241 void WebSharedWorkerImpl::Connect( |
| 253 std::unique_ptr<WebMessagePortChannel> web_channel) { | 242 std::unique_ptr<WebMessagePortChannel> web_channel) { |
| 254 DCHECK(IsMainThread()); | 243 DCHECK(IsMainThread()); |
| 255 // The HTML spec requires to queue a connect event using the DOM manipulation | 244 // The HTML spec requires to queue a connect event using the DOM manipulation |
| 256 // task source. | 245 // task source. |
| 257 // https://html.spec.whatwg.org/multipage/workers.html#shared-workers-and-the-
sharedworker-interface | 246 // https://html.spec.whatwg.org/multipage/workers.html#shared-workers-and-the-
sharedworker-interface |
| 258 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) | 247 TaskRunnerHelper::Get(TaskType::kDOMManipulation, GetWorkerThread()) |
| 259 ->PostTask( | 248 ->PostTask( |
| 260 BLINK_FROM_HERE, | 249 BLINK_FROM_HERE, |
| 261 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, | 250 CrossThreadBind(&WebSharedWorkerImpl::ConnectTaskOnWorkerThread, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 | 335 |
| 347 // SharedWorker can sometimes run tasks that are initiated by/associated with | 336 // SharedWorker can sometimes run tasks that are initiated by/associated with |
| 348 // a document's frame but these documents can be from a different process. So | 337 // a document's frame but these documents can be from a different process. So |
| 349 // we intentionally populate the task runners with null document in order to | 338 // we intentionally populate the task runners with null document in order to |
| 350 // use the thread's default task runner. Note that |m_document| should not be | 339 // use the thread's default task runner. Note that |m_document| should not be |
| 351 // used as it's a dummy document for loading that doesn't represent the frame | 340 // used as it's a dummy document for loading that doesn't represent the frame |
| 352 // of any associated document. | 341 // of any associated document. |
| 353 ParentFrameTaskRunners* task_runners = | 342 ParentFrameTaskRunners* task_runners = |
| 354 ParentFrameTaskRunners::Create(nullptr); | 343 ParentFrameTaskRunners::Create(nullptr); |
| 355 | 344 |
| 356 loader_proxy_ = WorkerLoaderProxy::Create(this); | |
| 357 reporting_proxy_ = new WebSharedWorkerReportingProxyImpl(this, task_runners); | 345 reporting_proxy_ = new WebSharedWorkerReportingProxyImpl(this, task_runners); |
| 358 worker_thread_ = | 346 worker_thread_ = SharedWorkerThread::Create( |
| 359 SharedWorkerThread::Create(name_, loader_proxy_, *reporting_proxy_); | 347 name_, |
| 348 ThreadableLoadingContext::Create(*ToDocument(loading_document_.Get())), |
| 349 *reporting_proxy_); |
| 360 probe::scriptImported(loading_document_, main_script_loader_->Identifier(), | 350 probe::scriptImported(loading_document_, main_script_loader_->Identifier(), |
| 361 main_script_loader_->SourceText()); | 351 main_script_loader_->SourceText()); |
| 362 main_script_loader_.Clear(); | 352 main_script_loader_.Clear(); |
| 363 | 353 |
| 364 GetWorkerThread()->Start(std::move(startup_data), task_runners); | 354 GetWorkerThread()->Start(std::move(startup_data), task_runners); |
| 365 worker_inspector_proxy_->WorkerThreadCreated(ToDocument(loading_document_), | 355 worker_inspector_proxy_->WorkerThreadCreated(ToDocument(loading_document_), |
| 366 GetWorkerThread(), url_); | 356 GetWorkerThread(), url_); |
| 367 client_->WorkerScriptLoaded(); | 357 client_->WorkerScriptLoaded(); |
| 368 } | 358 } |
| 369 | 359 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 if (devtools_agent) | 398 if (devtools_agent) |
| 409 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, | 399 devtools_agent->DispatchOnInspectorBackend(session_id, call_id, method, |
| 410 message); | 400 message); |
| 411 } | 401 } |
| 412 | 402 |
| 413 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { | 403 WebSharedWorker* WebSharedWorker::Create(WebSharedWorkerClient* client) { |
| 414 return new WebSharedWorkerImpl(client); | 404 return new WebSharedWorkerImpl(client); |
| 415 } | 405 } |
| 416 | 406 |
| 417 } // namespace blink | 407 } // namespace blink |
| OLD | NEW |