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
|
2020-06-01 20:34:34 +00:00
|
|
|
index 4cc9d55795035e6857f6e4ceb839d056d48c96cd..9d321040de33acac09e83cc582f685740f425009 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
|
2020-06-01 20:34:34 +00:00
|
|
|
@@ -395,6 +395,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
|
2020-06-22 17:35:10 +00:00
|
|
|
index 138a0aafcafa7512ba13026c26b433b3517867f4..e5c439f283a14d58235ce08ac62ce4c82bdbd0f7 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
|
2020-06-22 17:35:10 +00:00
|
|
|
@@ -860,6 +860,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
|
2020-06-22 17:35:10 +00:00
|
|
|
index 12044eb34510d190981e5e82b4939adc159f9aa5..54d3dd4245aa880ff7503264edbf47cf46f8796a 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
|
2020-06-22 17:35:10 +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;
|
2019-06-04 03:44:12 +00:00
|
|
|
bool IsExcludedHeaderForServiceWorkerFetchEvent(
|
|
|
|
const blink::WebString& header_name) override;
|
2019-03-21 22:45:52 +00:00
|
|
|
|
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
|
2020-06-22 17:35:10 +00:00
|
|
|
index 977d2c47345264bb3c4c6662fe97adf8f9faccd0..5d1187cb10f828e4774f871ead1c23833ce63948 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
|
2020-06-22 17:35:10 +00:00
|
|
|
@@ -623,6 +623,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
|
2020-06-01 20:34:34 +00:00
|
|
|
index f655c4ecc13e8445e35c6a79625946c9c7fb671b..32bac98ed79471178c36590b7db99fc1a95363b0 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
|
2020-06-01 20:34:34 +00:00
|
|
|
@@ -686,6 +686,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
|
|
|
|