feat: add API for receiving logs from service workers (#20624)
* feat: add API for receiving logs from service workers * feat: add new serviceWorkerContext APIs * chore: add missing #include's * refactor: rename serviceWorkerContext to serviceWorkers * chore: clean up based on review * chore: remove native_mate * chore: add tests for the service worker module * Update spec-main/api-service-workers-spec.ts Co-Authored-By: Jeremy Apthorp <jeremya@chromium.org> * chore: fix linting * chore: handle renames Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net>
This commit is contained in:
parent
2e6fff885d
commit
e7b0a9ca8f
19 changed files with 456 additions and 324 deletions
|
@ -46,6 +46,7 @@
|
|||
#include "shell/browser/api/electron_api_download_item.h"
|
||||
#include "shell/browser/api/electron_api_net_log.h"
|
||||
#include "shell/browser/api/electron_api_protocol.h"
|
||||
#include "shell/browser/api/electron_api_service_worker_context.h"
|
||||
#include "shell/browser/api/electron_api_web_request.h"
|
||||
#include "shell/browser/browser.h"
|
||||
#include "shell/browser/electron_browser_context.h"
|
||||
|
@ -721,6 +722,15 @@ v8::Local<v8::Value> Session::Protocol(v8::Isolate* isolate) {
|
|||
return v8::Local<v8::Value>::New(isolate, protocol_);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Session::ServiceWorkerContext(v8::Isolate* isolate) {
|
||||
if (service_worker_context_.IsEmpty()) {
|
||||
v8::Local<v8::Value> handle;
|
||||
handle = ServiceWorkerContext::Create(isolate, browser_context()).ToV8();
|
||||
service_worker_context_.Reset(isolate, handle);
|
||||
}
|
||||
return v8::Local<v8::Value>::New(isolate, service_worker_context_);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
|
||||
if (web_request_.IsEmpty()) {
|
||||
auto handle = WebRequest::Create(isolate, browser_context());
|
||||
|
@ -958,6 +968,7 @@ void Session::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetProperty("cookies", &Session::Cookies)
|
||||
.SetProperty("netLog", &Session::NetLog)
|
||||
.SetProperty("protocol", &Session::Protocol)
|
||||
.SetProperty("serviceWorkers", &Session::ServiceWorkerContext)
|
||||
.SetProperty("webRequest", &Session::WebRequest);
|
||||
}
|
||||
|
||||
|
@ -970,6 +981,7 @@ namespace {
|
|||
using electron::api::Cookies;
|
||||
using electron::api::NetLog;
|
||||
using electron::api::Protocol;
|
||||
using electron::api::ServiceWorkerContext;
|
||||
using electron::api::Session;
|
||||
|
||||
v8::Local<v8::Value> FromPartition(const std::string& partition,
|
||||
|
@ -1002,6 +1014,9 @@ void Initialize(v8::Local<v8::Object> exports,
|
|||
dict.Set(
|
||||
"Protocol",
|
||||
Protocol::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||
dict.Set("ServiceWorkerContext", ServiceWorkerContext::GetConstructor(isolate)
|
||||
->GetFunction(context)
|
||||
.ToLocalChecked());
|
||||
dict.SetMethod("fromPartition", &FromPartition);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue