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 { app, deprecate } = require('electron');
|
||||
const { fromPartition, Session, Cookies, Protocol, ServiceWorkerContext } = process.electronBinding('session');
|
||||
const { fromPartition, Session, Cookies, Protocol } = process.electronBinding('session');
|
||||
|
||||
// Public API.
|
||||
Object.defineProperties(exports, {
|
||||
|
@ -17,7 +17,6 @@ Object.defineProperties(exports, {
|
|||
});
|
||||
|
||||
Object.setPrototypeOf(Cookies.prototype, EventEmitter.prototype);
|
||||
Object.setPrototypeOf(ServiceWorkerContext.prototype, EventEmitter.prototype);
|
||||
Object.setPrototypeOf(Session.prototype, EventEmitter.prototype);
|
||||
|
||||
Session.prototype._init = function () {
|
||||
|
|
|
@ -12,10 +12,11 @@
|
|||
#include "content/public/browser/storage_partition.h"
|
||||
#include "gin/data_object_builder.h"
|
||||
#include "gin/handle.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "shell/browser/electron_browser_context.h"
|
||||
#include "shell/common/gin_converters/value_converter.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"
|
||||
|
||||
namespace electron {
|
||||
|
@ -67,11 +68,12 @@ v8::Local<v8::Value> ServiceWorkerRunningInfoToDict(
|
|||
|
||||
} // namespace
|
||||
|
||||
gin::WrapperInfo ServiceWorkerContext::kWrapperInfo = {gin::kEmbedderNativeGin};
|
||||
|
||||
ServiceWorkerContext::ServiceWorkerContext(
|
||||
v8::Isolate* isolate,
|
||||
ElectronBrowserContext* browser_context)
|
||||
: browser_context_(browser_context), weak_ptr_factory_(this) {
|
||||
Init(isolate);
|
||||
service_worker_context_ =
|
||||
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
|
||||
->GetServiceWorkerContext();
|
||||
|
@ -140,17 +142,20 @@ gin::Handle<ServiceWorkerContext> ServiceWorkerContext::Create(
|
|||
}
|
||||
|
||||
// static
|
||||
void ServiceWorkerContext::BuildPrototype(
|
||||
v8::Isolate* isolate,
|
||||
v8::Local<v8::FunctionTemplate> prototype) {
|
||||
prototype->SetClassName(gin::StringToV8(isolate, "ServiceWorkerContext"));
|
||||
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
||||
gin::ObjectTemplateBuilder ServiceWorkerContext::GetObjectTemplateBuilder(
|
||||
v8::Isolate* isolate) {
|
||||
return gin_helper::EventEmitterMixin<
|
||||
ServiceWorkerContext>::GetObjectTemplateBuilder(isolate)
|
||||
.SetMethod("getAllRunning",
|
||||
&ServiceWorkerContext::GetAllRunningWorkerInfo)
|
||||
.SetMethod("getFromVersionID",
|
||||
&ServiceWorkerContext::GetWorkerInfoFromID);
|
||||
}
|
||||
|
||||
const char* ServiceWorkerContext::GetTypeName() {
|
||||
return "ServiceWorkerContext";
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
||||
} // namespace electron
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
#include "content/public/browser/service_worker_context.h"
|
||||
#include "content/public/browser/service_worker_context_observer.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 {
|
||||
|
||||
|
@ -17,16 +18,14 @@ class ElectronBrowserContext;
|
|||
namespace api {
|
||||
|
||||
class ServiceWorkerContext
|
||||
: public gin_helper::TrackableObject<ServiceWorkerContext>,
|
||||
: public gin::Wrappable<ServiceWorkerContext>,
|
||||
public gin_helper::EventEmitterMixin<ServiceWorkerContext>,
|
||||
public content::ServiceWorkerContextObserver {
|
||||
public:
|
||||
static gin::Handle<ServiceWorkerContext> Create(
|
||||
v8::Isolate* isolate,
|
||||
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> GetWorkerInfoFromID(gin_helper::ErrorThrower thrower,
|
||||
int64_t version_id);
|
||||
|
@ -36,6 +35,12 @@ class ServiceWorkerContext
|
|||
const content::ConsoleMessage& message) 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:
|
||||
explicit ServiceWorkerContext(v8::Isolate* isolate,
|
||||
ElectronBrowserContext* browser_context);
|
||||
|
|
|
@ -1059,9 +1059,6 @@ 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