feat: support registering MV3 extension service workers (#27562)

* feat: support registering MV3 extension service workers

* feat: load chrome extension APIs in worker context

* feat: add more ContentRendererClient service worker overrides

* fix: lint error

* refactor: emit object for 'registration-completed'

* docs: clarify when registration-completed emits
This commit is contained in:
Samuel Maddock 2021-02-11 10:58:03 -05:00 committed by GitHub
parent 6681f8f507
commit 3250ef551c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 152 additions and 6 deletions

View file

@ -15,6 +15,7 @@
#include "gin/object_template_builder.h"
#include "shell/browser/electron_browser_context.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/gin_helper/dictionary.h"
#include "shell/common/gin_helper/function_template_extensions.h"
@ -102,6 +103,13 @@ void ServiceWorkerContext::OnReportConsoleMessage(
.Build());
}
void ServiceWorkerContext::OnRegistrationCompleted(const GURL& scope) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
Emit("registration-completed",
gin::DataObjectBuilder(isolate).Set("scope", scope).Build());
}
void ServiceWorkerContext::OnDestruct(content::ServiceWorkerContext* context) {
if (context == service_worker_context_) {
delete this;

View file

@ -34,6 +34,7 @@ class ServiceWorkerContext
void OnReportConsoleMessage(int64_t version_id,
const GURL& scope,
const content::ConsoleMessage& message) override;
void OnRegistrationCompleted(const GURL& scope) override;
void OnDestruct(content::ServiceWorkerContext* context) override;
// gin::Wrappable