Merge pull request #1450 from lightpanda-io/pluginarray_placeholder
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
e2e-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled

Add Plugin and PluginArray placeholders
This commit is contained in:
Karl Seguin
2026-02-03 07:10:46 +08:00
committed by GitHub
3 changed files with 87 additions and 0 deletions

View File

@@ -761,6 +761,7 @@ pub const JsApis = flattenTypes(&.{
@import("../webapi/URL.zig"),
@import("../webapi/Window.zig"),
@import("../webapi/Performance.zig"),
@import("../webapi/PluginArray.zig"),
@import("../webapi/MutationObserver.zig"),
@import("../webapi/IntersectionObserver.zig"),
@import("../webapi/CustomElementRegistry.zig"),

View File

@@ -20,9 +20,11 @@ const std = @import("std");
const builtin = @import("builtin");
const js = @import("../js/js.zig");
const Page = @import("../Page.zig");
const PluginArray = @import("PluginArray.zig");
const Navigator = @This();
_pad: bool = false,
_plugins: PluginArray = .{},
pub const init: Navigator = .{};
@@ -96,6 +98,10 @@ pub fn getWebdriver(_: *const Navigator) bool {
return false;
}
pub fn getPlugins(self: *Navigator) *PluginArray {
return &self._plugins;
}
pub fn registerProtocolHandler(_: *const Navigator, scheme: []const u8, url: [:0]const u8, page: *const Page) !void {
try validateProtocolHandlerScheme(scheme);
try validateProtocolHandlerURL(url, page);
@@ -189,6 +195,7 @@ pub const JsApi = struct {
pub const vendor = bridge.accessor(Navigator.getVendor, null, .{});
pub const product = bridge.accessor(Navigator.getProduct, null, .{});
pub const webdriver = bridge.accessor(Navigator.getWebdriver, null, .{});
pub const plugins = bridge.accessor(Navigator.getPlugins, null, .{});
pub const registerProtocolHandler = bridge.function(Navigator.registerProtocolHandler, .{ .dom_exception = true });
pub const unregisterProtocolHandler = bridge.function(Navigator.unregisterProtocolHandler, .{ .dom_exception = true });

View File

@@ -0,0 +1,79 @@
// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
//
// Francis Bouvier <francis@lightpanda.io>
// Pierre Tachoire <pierre@lightpanda.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const js = @import("../js/js.zig");
pub fn registerTypes() []const type {
return &.{ PluginArray, Plugin };
}
const PluginArray = @This();
_pad: bool = false,
pub fn getLength(_: *const PluginArray) u32 {
return 0;
}
pub fn refresh(_: *const PluginArray) void {}
pub fn getAtIndex(_: *const PluginArray, index: usize) ?*Plugin {
_ = index;
return null;
}
pub fn getByName(_: *const PluginArray, name: []const u8) ?*Plugin {
_ = name;
return null;
}
// Cannot be constructed, and we currently never return any, so no reason to
// implement anything on it (for now)
const Plugin = struct {
pub const JsApi = struct {
pub const bridge = js.Bridge(Plugin);
pub const Meta = struct {
pub const name = "Plugin";
pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;
pub const empty_with_no_proto = true;
};
};
};
pub const JsApi = struct {
pub const bridge = js.Bridge(PluginArray);
pub const Meta = struct {
pub const name = "PluginArray";
pub const prototype_chain = bridge.prototypeChain();
pub var class_id: bridge.ClassId = undefined;
pub const empty_with_no_proto = true;
};
pub const length = bridge.accessor(PluginArray.getLength, null, .{});
pub const refresh = bridge.function(PluginArray.refresh, .{});
pub const @"[int]" = bridge.indexed(PluginArray.getAtIndex, .{ .null_as_undefined = true });
pub const @"[str]" = bridge.namedIndexed(PluginArray.getByName, null, null, .{ .null_as_undefined = true });
pub const item = bridge.function(_item, .{});
fn _item(self: *const PluginArray, index: i32) ?*Plugin {
if (index < 0) {
return null;
}
return self.getAtIndex(@intCast(index));
}
pub const namedItem = bridge.function(PluginArray.getByName, .{});
};