feat: add protocol.handle (#36674)

This commit is contained in:
Jeremy Rose 2023-03-27 10:00:55 -07:00 committed by GitHub
parent 6a6908c4c8
commit fda8ea9277
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 1254 additions and 89 deletions

View file

@ -273,9 +273,17 @@ gin::Handle<Protocol> Protocol::Create(
isolate, new Protocol(isolate, browser_context->protocol_registry()));
}
gin::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return gin::Wrappable<Protocol>::GetObjectTemplateBuilder(isolate)
// static
gin::Handle<Protocol> Protocol::New(gin_helper::ErrorThrower thrower) {
thrower.ThrowError("Protocol cannot be created from JS");
return gin::Handle<Protocol>();
}
// static
v8::Local<v8::ObjectTemplate> Protocol::FillObjectTemplate(
v8::Isolate* isolate,
v8::Local<v8::ObjectTemplate> tmpl) {
return gin::ObjectTemplateBuilder(isolate, "Protocol", tmpl)
.SetMethod("registerStringProtocol",
&Protocol::RegisterProtocolFor<ProtocolType::kString>)
.SetMethod("registerBufferProtocol",
@ -304,7 +312,8 @@ gin::ObjectTemplateBuilder Protocol::GetObjectTemplateBuilder(
.SetMethod("interceptProtocol",
&Protocol::InterceptProtocolFor<ProtocolType::kFree>)
.SetMethod("uninterceptProtocol", &Protocol::UninterceptProtocol)
.SetMethod("isProtocolIntercepted", &Protocol::IsProtocolIntercepted);
.SetMethod("isProtocolIntercepted", &Protocol::IsProtocolIntercepted)
.Build();
}
const char* Protocol::GetTypeName() {
@ -333,6 +342,7 @@ void Initialize(v8::Local<v8::Object> exports,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
gin_helper::Dictionary dict(isolate, exports);
dict.Set("Protocol", electron::api::Protocol::GetConstructor(context));
dict.SetMethod("registerSchemesAsPrivileged", &RegisterSchemesAsPrivileged);
dict.SetMethod("getStandardSchemes", &electron::api::GetStandardSchemes);
}