electron/patches/common/chromium/worker_context_will_destroy.patch
2019-03-08 15:06:16 -08:00

80 lines
4.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Cheng Zhao <zcbenz@gmail.com>
Date: Thu, 20 Sep 2018 17:47:12 -0700
Subject: worker_context_will_destroy.patch
diff --git a/content/public/renderer/content_renderer_client.h b/content/public/renderer/content_renderer_client.h
index fd33e51221676c6315aec8db4aa469d4805dab8a..af15512b6d26bf79413e34a590d664a56d78828d 100644
--- a/content/public/renderer/content_renderer_client.h
+++ b/content/public/renderer/content_renderer_client.h
@@ -379,6 +379,11 @@ class CONTENT_EXPORT ContentRendererClient {
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
index de849f696e15004cda5648f565972f4529503d50..2c007dbd46f39a85406e2ffe23cd44d4f7d02574 100644
--- a/content/renderer/renderer_blink_platform_impl.cc
+++ b/content/renderer/renderer_blink_platform_impl.cc
@@ -1064,6 +1064,12 @@ void RendererBlinkPlatformImpl::WillStopWorkerThread() {
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
index 38ff3be9084334641d5537dda5b5fe5e8f9f8417..93c4dc904fd4f539faf48adc3c8770d052855050 100644
--- a/content/renderer/renderer_blink_platform_impl.h
+++ b/content/renderer/renderer_blink_platform_impl.h
@@ -210,6 +210,7 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
void DidStartWorkerThread() override;
void WillStopWorkerThread() override;
void WorkerContextCreated(const v8::Local<v8::Context>& worker) override;
+ void WorkerContextWillDestroy(const v8::Local<v8::Context>& worker) override;
// Disables the WebSandboxSupport implementation for testing.
// Tests that do not set up a full sandbox environment should call
diff --git a/third_party/blink/public/platform/platform.h b/third_party/blink/public/platform/platform.h
index d7ac7d96ad5c3e20075948c329a6d5ede0ae7a38..66881ba9b2511ef39e58c983907ec1894c046c2a 100644
--- a/third_party/blink/public/platform/platform.h
+++ b/third_party/blink/public/platform/platform.h
@@ -687,6 +687,7 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual void DidStartWorkerThread() {}
virtual void WillStopWorkerThread() {}
virtual void WorkerContextCreated(const v8::Local<v8::Context>& worker) {}
+ virtual void WorkerContextWillDestroy(const v8::Local<v8::Context>& worker) {}
virtual bool AllowScriptExtensionForServiceWorker(
const WebSecurityOrigin& script_origin) {
return false;
diff --git a/third_party/blink/renderer/core/workers/worker_thread.cc b/third_party/blink/renderer/core/workers/worker_thread.cc
index e55b99843fa42056197875b883a944f6de4ad79d..eb1508065eee7235816e2d6047220291007324e4 100644
--- a/third_party/blink/renderer/core/workers/worker_thread.cc
+++ b/third_party/blink/renderer/core/workers/worker_thread.cc
@@ -559,6 +559,12 @@ void WorkerThread::PrepareForShutdownOnWorkerThread() {
SetExitCode(ExitCode::kGracefullyTerminated);
}
+ {
+ v8::HandleScope handle_scope(GetIsolate());
+ Platform::Current()->WorkerContextWillDestroy(
+ GlobalScope()->ScriptController()->GetContext());
+ }
+
if (WorkerThreadDebugger* debugger = WorkerThreadDebugger::From(GetIsolate()))
debugger->WorkerThreadDestroyed(this);