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:
Samuel Attard 2020-02-20 15:19:06 -08:00 committed by GitHub
parent 2e6fff885d
commit e7b0a9ca8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 456 additions and 324 deletions

View file

@ -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);
}