mirror of
https://github.com/electron/electron.git
synced 2026-01-08 23:18:06 -05:00
refactor: use gin_helper's gin::Wrappable-to-v8::Local converter (#48885)
* refactor: Session::NetLog() returns a NetLog* Use gin_helper's gin::Wrappable-to-v8::Local converter instead of rewriting it. * refactor: FromPath(base::FilePath&, gin::Arguments*) returns a Session* refactor: FromPartition(std::string&, gin::Arguments*) returns a Session* Use gin_helper's gin::Wrappable-to-v8::Local converter instead of rewriting it.
This commit is contained in:
@@ -1368,15 +1368,11 @@ v8::Local<v8::Value> Session::WebRequest(v8::Isolate* isolate) {
|
||||
return web_request_.Get(isolate);
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Session::NetLog(v8::Isolate* isolate) {
|
||||
NetLog* Session::NetLog(v8::Isolate* isolate) {
|
||||
if (!net_log_) {
|
||||
net_log_ = NetLog::Create(isolate, browser_context());
|
||||
}
|
||||
|
||||
v8::Local<v8::Object> wrapper;
|
||||
return net_log_->GetWrapper(isolate).ToLocal(&wrapper)
|
||||
? wrapper.As<v8::Value>()
|
||||
: v8::Null(isolate);
|
||||
return net_log_;
|
||||
}
|
||||
|
||||
static void StartPreconnectOnUI(ElectronBrowserContext* browser_context,
|
||||
@@ -1887,47 +1883,24 @@ namespace {
|
||||
|
||||
using electron::api::Session;
|
||||
|
||||
v8::Local<v8::Value> FromPartition(const std::string& partition,
|
||||
gin::Arguments* args) {
|
||||
Session* FromPartition(const std::string& partition, gin::Arguments* args) {
|
||||
if (!electron::Browser::Get()->is_ready()) {
|
||||
args->ThrowTypeError("Session can only be received when app is ready");
|
||||
return v8::Null(args->isolate());
|
||||
return {};
|
||||
}
|
||||
base::Value::Dict options;
|
||||
args->GetNext(&options);
|
||||
Session* session =
|
||||
Session::FromPartition(args->isolate(), partition, std::move(options));
|
||||
|
||||
if (session) {
|
||||
v8::Local<v8::Object> wrapper;
|
||||
if (!session->GetWrapper(args->isolate()).ToLocal(&wrapper)) {
|
||||
return v8::Null(args->isolate());
|
||||
}
|
||||
return wrapper;
|
||||
} else {
|
||||
return v8::Null(args->isolate());
|
||||
}
|
||||
return Session::FromPartition(args->isolate(), partition, std::move(options));
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> FromPath(const base::FilePath& path,
|
||||
gin::Arguments* args) {
|
||||
Session* FromPath(const base::FilePath& path, gin::Arguments* args) {
|
||||
if (!electron::Browser::Get()->is_ready()) {
|
||||
args->ThrowTypeError("Session can only be received when app is ready");
|
||||
return v8::Null(args->isolate());
|
||||
return {};
|
||||
}
|
||||
base::Value::Dict options;
|
||||
args->GetNext(&options);
|
||||
Session* session = Session::FromPath(args, path, std::move(options));
|
||||
|
||||
if (session) {
|
||||
v8::Local<v8::Object> wrapper;
|
||||
if (!session->GetWrapper(args->isolate()).ToLocal(&wrapper)) {
|
||||
return v8::Null(args->isolate());
|
||||
}
|
||||
return wrapper;
|
||||
} else {
|
||||
return v8::Null(args->isolate());
|
||||
}
|
||||
return Session::FromPath(args, path, std::move(options));
|
||||
}
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
|
||||
@@ -170,7 +170,7 @@ class Session final : public gin::Wrappable<Session>,
|
||||
v8::Local<v8::Value> Protocol(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> ServiceWorkerContext(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> WebRequest(v8::Isolate* isolate);
|
||||
v8::Local<v8::Value> NetLog(v8::Isolate* isolate);
|
||||
api::NetLog* NetLog(v8::Isolate* isolate);
|
||||
void Preconnect(const gin_helper::Dictionary& options, gin::Arguments* args);
|
||||
v8::Local<v8::Promise> CloseAllConnections();
|
||||
v8::Local<v8::Value> GetPath(v8::Isolate* isolate);
|
||||
|
||||
Reference in New Issue
Block a user