refactor: ginify ServiceWorkerContext (#22756)
This commit is contained in:
parent
5d657dece4
commit
22c17bcc5b
4 changed files with 23 additions and 17 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
const { EventEmitter } = require('events');
|
const { EventEmitter } = require('events');
|
||||||
const { app, deprecate } = require('electron');
|
const { app, deprecate } = require('electron');
|
||||||
const { fromPartition, Session, Cookies, Protocol, ServiceWorkerContext } = process.electronBinding('session');
|
const { fromPartition, Session, Cookies, Protocol } = process.electronBinding('session');
|
||||||
|
|
||||||
// Public API.
|
// Public API.
|
||||||
Object.defineProperties(exports, {
|
Object.defineProperties(exports, {
|
||||||
|
@ -17,7 +17,6 @@ Object.defineProperties(exports, {
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype);
|
Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype);
|
||||||
Object.setPrototypeOf(ServiceWorkerContext.prototype, EventEmitter.prototype);
|
|
||||||
Object.setPrototypeOf(Session.prototype, EventEmitter.prototype);
|
Object.setPrototypeOf(Session.prototype, EventEmitter.prototype);
|
||||||
|
|
||||||
Session.prototype._init = function () {
|
Session.prototype._init = function () {
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
#include "content/public/browser/storage_partition.h"
|
#include "content/public/browser/storage_partition.h"
|
||||||
#include "gin/data_object_builder.h"
|
#include "gin/data_object_builder.h"
|
||||||
#include "gin/handle.h"
|
#include "gin/handle.h"
|
||||||
|
#include "gin/object_template_builder.h"
|
||||||
#include "shell/browser/electron_browser_context.h"
|
#include "shell/browser/electron_browser_context.h"
|
||||||
#include "shell/common/gin_converters/value_converter.h"
|
#include "shell/common/gin_converters/value_converter.h"
|
||||||
#include "shell/common/gin_helper/dictionary.h"
|
#include "shell/common/gin_helper/dictionary.h"
|
||||||
#include "shell/common/gin_helper/object_template_builder.h"
|
#include "shell/common/gin_helper/function_template_extensions.h"
|
||||||
#include "shell/common/node_includes.h"
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
@ -67,11 +68,12 @@ v8::Local<v8::Value> ServiceWorkerRunningInfoToDict(
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
gin::WrapperInfo ServiceWorkerContext::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||||
|
|
||||||
ServiceWorkerContext::ServiceWorkerContext(
|
ServiceWorkerContext::ServiceWorkerContext(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
ElectronBrowserContext* browser_context)
|
ElectronBrowserContext* browser_context)
|
||||||
: browser_context_(browser_context), weak_ptr_factory_(this) {
|
: browser_context_(browser_context), weak_ptr_factory_(this) {
|
||||||
Init(isolate);
|
|
||||||
service_worker_context_ =
|
service_worker_context_ =
|
||||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||||
->GetServiceWorkerContext();
|
->GetServiceWorkerContext();
|
||||||
|
@ -140,17 +142,20 @@ gin::Handle<ServiceWorkerContext> ServiceWorkerContext::Create(
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ServiceWorkerContext::BuildPrototype(
|
gin::ObjectTemplateBuilder ServiceWorkerContext::GetObjectTemplateBuilder(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate) {
|
||||||
v8::Local<v8::FunctionTemplate> prototype) {
|
return gin_helper::EventEmitterMixin<
|
||||||
prototype->SetClassName(gin::StringToV8(isolate, "ServiceWorkerContext"));
|
ServiceWorkerContext>::GetObjectTemplateBuilder(isolate)
|
||||||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
|
||||||
.SetMethod("getAllRunning",
|
.SetMethod("getAllRunning",
|
||||||
&ServiceWorkerContext::GetAllRunningWorkerInfo)
|
&ServiceWorkerContext::GetAllRunningWorkerInfo)
|
||||||
.SetMethod("getFromVersionID",
|
.SetMethod("getFromVersionID",
|
||||||
&ServiceWorkerContext::GetWorkerInfoFromID);
|
&ServiceWorkerContext::GetWorkerInfoFromID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* ServiceWorkerContext::GetTypeName() {
|
||||||
|
return "ServiceWorkerContext";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
||||||
} // namespace electron
|
} // namespace electron
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
#include "content/public/browser/service_worker_context.h"
|
#include "content/public/browser/service_worker_context.h"
|
||||||
#include "content/public/browser/service_worker_context_observer.h"
|
#include "content/public/browser/service_worker_context_observer.h"
|
||||||
#include "gin/handle.h"
|
#include "gin/handle.h"
|
||||||
#include "shell/common/gin_helper/trackable_object.h"
|
#include "gin/wrappable.h"
|
||||||
|
#include "shell/browser/event_emitter_mixin.h"
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
|
@ -17,16 +18,14 @@ class ElectronBrowserContext;
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class ServiceWorkerContext
|
class ServiceWorkerContext
|
||||||
: public gin_helper::TrackableObject<ServiceWorkerContext>,
|
: public gin::Wrappable<ServiceWorkerContext>,
|
||||||
|
public gin_helper::EventEmitterMixin<ServiceWorkerContext>,
|
||||||
public content::ServiceWorkerContextObserver {
|
public content::ServiceWorkerContextObserver {
|
||||||
public:
|
public:
|
||||||
static gin::Handle<ServiceWorkerContext> Create(
|
static gin::Handle<ServiceWorkerContext> Create(
|
||||||
v8::Isolate* isolate,
|
v8::Isolate* isolate,
|
||||||
ElectronBrowserContext* browser_context);
|
ElectronBrowserContext* browser_context);
|
||||||
|
|
||||||
static void BuildPrototype(v8::Isolate* isolate,
|
|
||||||
v8::Local<v8::FunctionTemplate> prototype);
|
|
||||||
|
|
||||||
v8::Local<v8::Value> GetAllRunningWorkerInfo(v8::Isolate* isolate);
|
v8::Local<v8::Value> GetAllRunningWorkerInfo(v8::Isolate* isolate);
|
||||||
v8::Local<v8::Value> GetWorkerInfoFromID(gin_helper::ErrorThrower thrower,
|
v8::Local<v8::Value> GetWorkerInfoFromID(gin_helper::ErrorThrower thrower,
|
||||||
int64_t version_id);
|
int64_t version_id);
|
||||||
|
@ -36,6 +35,12 @@ class ServiceWorkerContext
|
||||||
const content::ConsoleMessage& message) override;
|
const content::ConsoleMessage& message) override;
|
||||||
void OnDestruct(content::ServiceWorkerContext* context) override;
|
void OnDestruct(content::ServiceWorkerContext* context) override;
|
||||||
|
|
||||||
|
// gin::Wrappable
|
||||||
|
static gin::WrapperInfo kWrapperInfo;
|
||||||
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
v8::Isolate* isolate) override;
|
||||||
|
const char* GetTypeName() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit ServiceWorkerContext(v8::Isolate* isolate,
|
explicit ServiceWorkerContext(v8::Isolate* isolate,
|
||||||
ElectronBrowserContext* browser_context);
|
ElectronBrowserContext* browser_context);
|
||||||
|
|
|
@ -1059,9 +1059,6 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
dict.Set(
|
dict.Set(
|
||||||
"Protocol",
|
"Protocol",
|
||||||
Protocol::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
Protocol::GetConstructor(isolate)->GetFunction(context).ToLocalChecked());
|
||||||
dict.Set("ServiceWorkerContext", ServiceWorkerContext::GetConstructor(isolate)
|
|
||||||
->GetFunction(context)
|
|
||||||
.ToLocalChecked());
|
|
||||||
dict.SetMethod("fromPartition", &FromPartition);
|
dict.SetMethod("fromPartition", &FromPartition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue