From 55891aa5f81f6b8f2a06baa57ba27a4322f37d14 Mon Sep 17 00:00:00 2001 From: Karl Seguin Date: Sat, 31 Jan 2026 07:05:10 +0800 Subject: [PATCH] Add Plugin and PluginArray placeholders --- src/browser/js/bridge.zig | 1 + src/browser/webapi/Navigator.zig | 7 +++ src/browser/webapi/PluginArray.zig | 79 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 src/browser/webapi/PluginArray.zig diff --git a/src/browser/js/bridge.zig b/src/browser/js/bridge.zig index a5ce1fae..e761824c 100644 --- a/src/browser/js/bridge.zig +++ b/src/browser/js/bridge.zig @@ -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"), diff --git a/src/browser/webapi/Navigator.zig b/src/browser/webapi/Navigator.zig index 451c7521..3c639f5d 100644 --- a/src/browser/webapi/Navigator.zig +++ b/src/browser/webapi/Navigator.zig @@ -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 }); diff --git a/src/browser/webapi/PluginArray.zig b/src/browser/webapi/PluginArray.zig new file mode 100644 index 00000000..a437ea68 --- /dev/null +++ b/src/browser/webapi/PluginArray.zig @@ -0,0 +1,79 @@ +// Copyright (C) 2023-2026 Lightpanda (Selecy SAS) +// +// Francis Bouvier +// Pierre Tachoire +// +// 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 . + +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, .{}); +};