From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Cheng Zhao 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 fad5f104f0113813133c69fe8a4392d73f153ba5..01c826ef12b4e04033377d4e5e50fcb871ca1e1d 100644 --- a/content/public/renderer/content_renderer_client.h +++ b/content/public/renderer/content_renderer_client.h @@ -383,6 +383,11 @@ class CONTENT_EXPORT ContentRendererClient { virtual void DidInitializeWorkerContextOnWorkerThread( v8::Local context) {} + // Notifies that a worker context will be destroyed. This function is called + // from the worker thread. + virtual void WillDestroyWorkerContextOnWorkerThread( + v8::Local 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 30273211857b6aa7b9f98dfaa46e3f539c4e7931..f98cb1d4e72c2fd0fffbe177d3e19ef8dc6afe1e 100644 --- a/content/renderer/renderer_blink_platform_impl.cc +++ b/content/renderer/renderer_blink_platform_impl.cc @@ -1095,6 +1095,12 @@ void RendererBlinkPlatformImpl::WillStopWorkerThread() { WorkerThreadRegistry::Instance()->WillStopCurrentWorkerThread(); } +void RendererBlinkPlatformImpl::WorkerContextWillDestroy( + const v8::Local& worker) { + GetContentClient()->renderer()->WillDestroyWorkerContextOnWorkerThread( + worker); +} + void RendererBlinkPlatformImpl::WorkerContextCreated( const v8::Local& worker) { GetContentClient()->renderer()->DidInitializeWorkerContextOnWorkerThread( diff --git a/content/renderer/renderer_blink_platform_impl.h b/content/renderer/renderer_blink_platform_impl.h index 629362d2f99059f941220dbc50645f7f7f838e99..cc0654a4555cea5281353756e80bb9e5b7a398c7 100644 --- a/content/renderer/renderer_blink_platform_impl.h +++ b/content/renderer/renderer_blink_platform_impl.h @@ -214,6 +214,7 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { void DidStartWorkerThread() override; void WillStopWorkerThread() override; void WorkerContextCreated(const v8::Local& worker) override; + void WorkerContextWillDestroy(const v8::Local& worker) override; void RecordMetricsForBackgroundedRendererPurge() override; diff --git a/third_party/blink/public/platform/platform.h b/third_party/blink/public/platform/platform.h index 198d6649ef4164800b8c8ba86e522e643d7a420f..9841217dcdb9fc2c0e6506206103b9192d9d15d9 100644 --- a/third_party/blink/public/platform/platform.h +++ b/third_party/blink/public/platform/platform.h @@ -682,6 +682,7 @@ class BLINK_PLATFORM_EXPORT Platform { virtual void DidStartWorkerThread() {} virtual void WillStopWorkerThread() {} virtual void WorkerContextCreated(const v8::Local& worker) {} + virtual void WorkerContextWillDestroy(const v8::Local& 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 96dacc97cac57a039f2506ab4d4e3ca2664e18ef..5a31664f44ec87d87e1500b00ec4732918ede625 100644 --- a/third_party/blink/renderer/core/workers/worker_thread.cc +++ b/third_party/blink/renderer/core/workers/worker_thread.cc @@ -558,6 +558,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);