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:
parent
6681f8f507
commit
3250ef551c
10 changed files with 152 additions and 6 deletions
|
@ -116,9 +116,6 @@ RendererClientBase::RendererClientBase() {
|
|||
ParseSchemesCLISwitch(command_line, switches::kSecureSchemes);
|
||||
for (const std::string& scheme : secure_schemes_list)
|
||||
url::AddSecureScheme(scheme.data());
|
||||
// In Chrome we should set extension's origins to match the pages they can
|
||||
// work on, but in Electron currently we just let extensions do anything.
|
||||
url::AddSecureScheme(extensions::kExtensionScheme);
|
||||
// We rely on the unique process host id which is notified to the
|
||||
// renderer process via command line switch from the content layer,
|
||||
// if this switch is removed from the content layer for some reason,
|
||||
|
@ -411,6 +408,63 @@ void RendererClientBase::RunScriptsAtDocumentEnd(
|
|||
#endif
|
||||
}
|
||||
|
||||
bool RendererClientBase::AllowScriptExtensionForServiceWorker(
|
||||
const url::Origin& script_origin) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
return script_origin.scheme() == extensions::kExtensionScheme;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void RendererClientBase::DidInitializeServiceWorkerContextOnWorkerThread(
|
||||
blink::WebServiceWorkerContextProxy* context_proxy,
|
||||
const GURL& service_worker_scope,
|
||||
const GURL& script_url) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
extensions_renderer_client_->GetDispatcher()
|
||||
->DidInitializeServiceWorkerContextOnWorkerThread(
|
||||
context_proxy, service_worker_scope, script_url);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RendererClientBase::WillEvaluateServiceWorkerOnWorkerThread(
|
||||
blink::WebServiceWorkerContextProxy* context_proxy,
|
||||
v8::Local<v8::Context> v8_context,
|
||||
int64_t service_worker_version_id,
|
||||
const GURL& service_worker_scope,
|
||||
const GURL& script_url) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
extensions_renderer_client_->GetDispatcher()
|
||||
->WillEvaluateServiceWorkerOnWorkerThread(
|
||||
context_proxy, v8_context, service_worker_version_id,
|
||||
service_worker_scope, script_url);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RendererClientBase::DidStartServiceWorkerContextOnWorkerThread(
|
||||
int64_t service_worker_version_id,
|
||||
const GURL& service_worker_scope,
|
||||
const GURL& script_url) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
extensions_renderer_client_->GetDispatcher()
|
||||
->DidStartServiceWorkerContextOnWorkerThread(
|
||||
service_worker_version_id, service_worker_scope, script_url);
|
||||
#endif
|
||||
}
|
||||
|
||||
void RendererClientBase::WillDestroyServiceWorkerContextOnWorkerThread(
|
||||
v8::Local<v8::Context> context,
|
||||
int64_t service_worker_version_id,
|
||||
const GURL& service_worker_scope,
|
||||
const GURL& script_url) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
extensions_renderer_client_->GetDispatcher()
|
||||
->WillDestroyServiceWorkerContextOnWorkerThread(
|
||||
context, service_worker_version_id, service_worker_scope, script_url);
|
||||
#endif
|
||||
}
|
||||
|
||||
v8::Local<v8::Context> RendererClientBase::GetContext(
|
||||
blink::WebLocalFrame* frame,
|
||||
v8::Isolate* isolate) const {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue