2018-10-24 18:24:11 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2018-09-21 00:30:26 +00: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 17:18:45 +00: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-21 00:30:26 +00:00
|
|
|
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h
|
2022-10-03 20:21:00 +00:00
|
|
|
index 69e9da01fd70890a3df6c3c3959f87feb9ea316e..ce8cbdd6ce54bb2e0f1e6371679fc0d1438ae69c 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/public/renderer/content_renderer_client.h
|
|
|
|
+++ b/content/public/renderer/content_renderer_client.h
|
2022-10-03 20:21:00 +00:00
|
|
|
@@ -369,6 +369,11 @@ class CONTENT_EXPORT ContentRendererClient {
|
2018-09-14 05:02:16 +00: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
|
2022-10-17 14:22:24 +00:00
|
|
|
index 9a29b47834bd99129c73397e8873cedc8cf7f014..c3adc4563f0c5d8e50dc1f5acdd61f314b21493d 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/renderer/renderer_blink_platform_impl.cc
|
|
|
|
+++ b/content/renderer/renderer_blink_platform_impl.cc
|
2022-10-17 14:22:24 +00:00
|
|
|
@@ -867,6 +867,12 @@ void RendererBlinkPlatformImpl::WillStopWorkerThread() {
|
2018-09-14 05:02:16 +00: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
|
2022-10-17 14:22:24 +00:00
|
|
|
index bb3be5a46b3dfd9f279c780d501a264cf4fc5be7..799cec3e793b1acf33864bea4d49b3544634781b 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/content/renderer/renderer_blink_platform_impl.h
|
|
|
|
+++ b/content/renderer/renderer_blink_platform_impl.h
|
2022-10-17 14:22:24 +00:00
|
|
|
@@ -181,6 +181,7 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
|
2018-09-14 05:02:16 +00: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-14 01:13:34 +00:00
|
|
|
bool AllowScriptExtensionForServiceWorker(
|
|
|
|
const blink::WebSecurityOrigin& script_origin) override;
|
2020-11-14 00:16:56 +00:00
|
|
|
blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel()
|
2018-09-14 18:03:43 +00:00
|
|
|
diff --git a/third_party/blink/public/platform/platform.h b/third_party/blink/public/platform/platform.h
|
2022-10-17 14:22:24 +00:00
|
|
|
index 4bbd5c412ff46a865de52c07c0f91b2bd05ce476..9b4559f6dd51cec07a4fdc7da35ce645906f1a74 100644
|
2018-09-14 18:03:43 +00:00
|
|
|
--- a/third_party/blink/public/platform/platform.h
|
|
|
|
+++ b/third_party/blink/public/platform/platform.h
|
2022-10-17 14:22:24 +00:00
|
|
|
@@ -633,6 +633,7 @@ class BLINK_PLATFORM_EXPORT Platform {
|
2018-09-14 18:03:43 +00: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 16:34:15 +00:00
|
|
|
virtual bool AllowScriptExtensionForServiceWorker(
|
|
|
|
const WebSecurityOrigin& script_origin) {
|
2018-09-14 18:03:43 +00:00
|
|
|
return false;
|
2018-09-14 05:02:16 +00:00
|
|
|
diff --git a/third_party/blink/renderer/core/workers/worker_thread.cc b/third_party/blink/renderer/core/workers/worker_thread.cc
|
2022-10-17 14:22:24 +00:00
|
|
|
index 8bb4af88c478ba374682ee7fd56616336c1176b6..b5ab51bf0e8277794303046748ca43ed8cbcf9ba 100644
|
2018-09-14 05:02:16 +00:00
|
|
|
--- a/third_party/blink/renderer/core/workers/worker_thread.cc
|
|
|
|
+++ b/third_party/blink/renderer/core/workers/worker_thread.cc
|
2022-10-17 14:22:24 +00:00
|
|
|
@@ -745,6 +745,12 @@ void WorkerThread::PrepareForShutdownOnWorkerThread() {
|
2019-05-13 18:49:01 +00:00
|
|
|
nested_runner_->QuitNow();
|
2018-09-14 05:02:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+ {
|
|
|
|
+ v8::HandleScope handle_scope(GetIsolate());
|
|
|
|
+ Platform::Current()->WorkerContextWillDestroy(
|
|
|
|
+ GlobalScope()->ScriptController()->GetContext());
|
|
|
|
+ }
|
|
|
|
+
|
2019-01-12 01:00:43 +00:00
|
|
|
if (WorkerThreadDebugger* debugger = WorkerThreadDebugger::From(GetIsolate()))
|
|
|
|
debugger->WorkerThreadDestroyed(this);
|
2018-09-21 00:30:26 +00:00
|
|
|
|