| 
									
										
										
										
											2018-10-24 11:24:11 -07:00
										 |  |  | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | 
					
						
							| 
									
										
										
										
											2018-09-20 17:30:26 -07:00
										 |  |  | From: Cheng Zhao <zcbenz@gmail.com> | 
					
						
							|  |  |  | Date: Thu, 20 Sep 2018 17:47:12 -0700 | 
					
						
							|  |  |  | Subject: worker_context_will_destroy.patch | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-13 09:18:45 -08:00
										 |  |  | This adds a hook for worker context destruction, which we use in Electron to | 
					
						
							|  |  |  | shutdown node integration in the worker if relevant. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | An attempt to upstream this was made, but rejected: | 
					
						
							|  |  |  | https://chromium-review.googlesource.com/c/chromium/src/+/1954347 | 
					
						
							| 
									
										
										
										
											2018-09-20 17:30:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h
 | 
					
						
							| 
									
										
										
										
											2023-05-23 14:58:58 -05:00
										 |  |  | index 834a07bb92d77eceb37d0378e9fe2bf13a74a64d..13815369562c1f78c2411cde8e14d9e8795eff38 100644
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | --- a/content/public/renderer/content_renderer_client.h
 | 
					
						
							|  |  |  | +++ b/content/public/renderer/content_renderer_client.h
 | 
					
						
							| 
									
										
										
										
											2023-05-23 14:58:58 -05:00
										 |  |  | @@ -371,6 +371,11 @@ class CONTENT_EXPORT ContentRendererClient {
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |    virtual void DidInitializeWorkerContextOnWorkerThread( | 
					
						
							|  |  |  |        v8::Local<v8::Context> context) {} | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | +  // Notifies that a worker context will be destroyed. This function is called
 | 
					
						
							|  |  |  | +  // from the worker thread.
 | 
					
						
							|  |  |  | +  virtual void WillDestroyWorkerContextOnWorkerThread(
 | 
					
						
							|  |  |  | +      v8::Local<v8::Context> context) {}
 | 
					
						
							|  |  |  | +
 | 
					
						
							|  |  |  |    // Overwrites the given URL to use an HTML5 embed if possible. | 
					
						
							|  |  |  |    // An empty URL is returned if the URL is not overriden. | 
					
						
							|  |  |  |    virtual GURL OverrideFlashEmbedWithHTML(const GURL& url); | 
					
						
							|  |  |  | diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc
 | 
					
						
							| 
									
										
										
										
											2023-06-09 16:08:36 -07:00
										 |  |  | index a790f204157bb76c90fefac15110f940ed7f1194..696ad0eac2b187517ad737ec733a4bae2a0993f0 100644
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | --- a/content/renderer/renderer_blink_platform_impl.cc
 | 
					
						
							|  |  |  | +++ b/content/renderer/renderer_blink_platform_impl.cc
 | 
					
						
							| 
									
										
										
										
											2023-05-23 14:58:58 -05:00
										 |  |  | @@ -813,6 +813,12 @@ void RendererBlinkPlatformImpl::WillStopWorkerThread() {
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |    WorkerThreadRegistry::Instance()->WillStopCurrentWorkerThread(); | 
					
						
							|  |  |  |  } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  | +void RendererBlinkPlatformImpl::WorkerContextWillDestroy(
 | 
					
						
							|  |  |  | +    const v8::Local<v8::Context>& worker) {
 | 
					
						
							|  |  |  | +  GetContentClient()->renderer()->WillDestroyWorkerContextOnWorkerThread(
 | 
					
						
							|  |  |  | +      worker);
 | 
					
						
							|  |  |  | +}
 | 
					
						
							|  |  |  | +
 | 
					
						
							|  |  |  |  void RendererBlinkPlatformImpl::WorkerContextCreated( | 
					
						
							|  |  |  |      const v8::Local<v8::Context>& worker) { | 
					
						
							|  |  |  |    GetContentClient()->renderer()->DidInitializeWorkerContextOnWorkerThread( | 
					
						
							|  |  |  | diff --git a/content/renderer/renderer_blink_platform_impl.h b/content/renderer/renderer_blink_platform_impl.h
 | 
					
						
							| 
									
										
										
										
											2023-06-09 16:08:36 -07:00
										 |  |  | index 278defce6db13bdfca7faad1edd8b9ed97fa6ba0..1ba3b8a4b85a274e3f53968f4f68766796440555 100644
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | --- a/content/renderer/renderer_blink_platform_impl.h
 | 
					
						
							|  |  |  | +++ b/content/renderer/renderer_blink_platform_impl.h
 | 
					
						
							| 
									
										
										
										
											2023-05-23 14:58:58 -05:00
										 |  |  | @@ -175,6 +175,7 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |    void DidStartWorkerThread() override; | 
					
						
							|  |  |  |    void WillStopWorkerThread() override; | 
					
						
							|  |  |  |    void WorkerContextCreated(const v8::Local<v8::Context>& worker) override; | 
					
						
							|  |  |  | +  void WorkerContextWillDestroy(const v8::Local<v8::Context>& worker) override;
 | 
					
						
							| 
									
										
										
										
											2020-07-13 18:13:34 -07:00
										 |  |  |    bool AllowScriptExtensionForServiceWorker( | 
					
						
							|  |  |  |        const blink::WebSecurityOrigin& script_origin) override; | 
					
						
							| 
									
										
										
										
											2020-11-13 16:16:56 -08:00
										 |  |  |    blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel() | 
					
						
							| 
									
										
										
										
											2018-09-14 11:03:43 -07:00
										 |  |  | diff --git a/third_party/blink/public/platform/platform.h b/third_party/blink/public/platform/platform.h
 | 
					
						
							| 
									
										
										
										
											2023-06-09 16:08:36 -07:00
										 |  |  | index f44407557557343d9ecbf3b3e1115f57fe77e1bb..77c31b107cb0786248510e64f019cdb92b4fb4af 100644
 | 
					
						
							| 
									
										
										
										
											2018-09-14 11:03:43 -07:00
										 |  |  | --- a/third_party/blink/public/platform/platform.h
 | 
					
						
							|  |  |  | +++ b/third_party/blink/public/platform/platform.h
 | 
					
						
							| 
									
										
										
										
											2023-06-09 16:08:36 -07:00
										 |  |  | @@ -621,6 +621,7 @@ class BLINK_PLATFORM_EXPORT Platform {
 | 
					
						
							| 
									
										
										
										
											2018-09-14 11:03:43 -07:00
										 |  |  |    virtual void DidStartWorkerThread() {} | 
					
						
							|  |  |  |    virtual void WillStopWorkerThread() {} | 
					
						
							|  |  |  |    virtual void WorkerContextCreated(const v8::Local<v8::Context>& worker) {} | 
					
						
							|  |  |  | +  virtual void WorkerContextWillDestroy(const v8::Local<v8::Context>& worker) {}
 | 
					
						
							| 
									
										
										
										
											2019-02-14 22:04:15 +05:30
										 |  |  |    virtual bool AllowScriptExtensionForServiceWorker( | 
					
						
							|  |  |  |        const WebSecurityOrigin& script_origin) { | 
					
						
							| 
									
										
										
										
											2018-09-14 11:03:43 -07:00
										 |  |  |      return false; | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | diff --git a/third_party/blink/renderer/core/workers/worker_thread.cc b/third_party/blink/renderer/core/workers/worker_thread.cc
 | 
					
						
							| 
									
										
										
										
											2023-03-20 21:37:21 -04:00
										 |  |  | index b52cbc1f1393551e95f885b415ae12a1c2d58ab0..3fbdd5054881fef201158a8b71279fadf1f87fe9 100644
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  | --- a/third_party/blink/renderer/core/workers/worker_thread.cc
 | 
					
						
							|  |  |  | +++ b/third_party/blink/renderer/core/workers/worker_thread.cc
 | 
					
						
							| 
									
										
										
										
											2023-03-20 21:37:21 -04:00
										 |  |  | @@ -767,6 +767,12 @@ void WorkerThread::PrepareForShutdownOnWorkerThread() {
 | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |    } | 
					
						
							| 
									
										
										
										
											2022-10-27 12:37:04 -04:00
										 |  |  |    pause_handle_.reset(); | 
					
						
							| 
									
										
										
										
											2018-09-13 22:02:16 -07:00
										 |  |  |   | 
					
						
							|  |  |  | +  {
 | 
					
						
							|  |  |  | +    v8::HandleScope handle_scope(GetIsolate());
 | 
					
						
							|  |  |  | +    Platform::Current()->WorkerContextWillDestroy(
 | 
					
						
							|  |  |  | +        GlobalScope()->ScriptController()->GetContext());
 | 
					
						
							|  |  |  | +  }
 | 
					
						
							|  |  |  | +
 | 
					
						
							| 
									
										
										
										
											2019-01-12 06:30:43 +05:30
										 |  |  |    if (WorkerThreadDebugger* debugger = WorkerThreadDebugger::From(GetIsolate())) | 
					
						
							|  |  |  |      debugger->WorkerThreadDestroyed(this); | 
					
						
							| 
									
										
										
										
											2018-09-20 17:30:26 -07:00
										 |  |  |   |