mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
Merge pull request #1347 from lightpanda-io/registerProtocolHandler
Add Navigator.registerProtocolHandler and unregisterProtocolHandler p…
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
testing.expectEqual(1, navigator.languages.length);
|
testing.expectEqual(1, navigator.languages.length);
|
||||||
testing.expectEqual('en-US', navigator.languages[0]);
|
testing.expectEqual('en-US', navigator.languages[0]);
|
||||||
testing.expectEqual(true, navigator.onLine);
|
testing.expectEqual(true, navigator.onLine);
|
||||||
testing.expectEqual(false, navigator.cookieEnabled);
|
testing.expectEqual(true, navigator.cookieEnabled);
|
||||||
testing.expectEqual(true, navigator.hardwareConcurrency > 0);
|
testing.expectEqual(true, navigator.hardwareConcurrency > 0);
|
||||||
testing.expectEqual(4, navigator.hardwareConcurrency);
|
testing.expectEqual(4, navigator.hardwareConcurrency);
|
||||||
testing.expectEqual(0, navigator.maxTouchPoints);
|
testing.expectEqual(0, navigator.maxTouchPoints);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
const std = @import("std");
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const js = @import("../js/js.zig");
|
const js = @import("../js/js.zig");
|
||||||
const Page = @import("../Page.zig");
|
const Page = @import("../Page.zig");
|
||||||
@@ -64,8 +65,7 @@ pub fn getOnLine(_: *const Navigator) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getCookieEnabled(_: *const Navigator) bool {
|
pub fn getCookieEnabled(_: *const Navigator) bool {
|
||||||
// TODO: Implement cookie support
|
return true;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn getHardwareConcurrency(_: *const Navigator) u32 {
|
pub fn getHardwareConcurrency(_: *const Navigator) u32 {
|
||||||
@@ -96,6 +96,74 @@ pub fn getWebdriver(_: *const Navigator) bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn registerProtocolHandler(_: *const Navigator, scheme: []const u8, url: [:0]const u8, page: *const Page) !void {
|
||||||
|
try validateProtocolHandlerScheme(scheme);
|
||||||
|
try validateProtocolHandlerURL(url, page);
|
||||||
|
}
|
||||||
|
pub fn unregisterProtocolHandler(_: *const Navigator, scheme: []const u8, url: [:0]const u8, page: *const Page) !void {
|
||||||
|
try validateProtocolHandlerScheme(scheme);
|
||||||
|
try validateProtocolHandlerURL(url, page);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validateProtocolHandlerScheme(scheme: []const u8) !void {
|
||||||
|
const allowed = std.StaticStringMap(void).initComptime(.{
|
||||||
|
.{ "bitcoin", {} },
|
||||||
|
.{ "cabal", {} },
|
||||||
|
.{ "dat", {} },
|
||||||
|
.{ "did", {} },
|
||||||
|
.{ "dweb", {} },
|
||||||
|
.{ "ethereum", .{} },
|
||||||
|
.{ "ftp", {} },
|
||||||
|
.{ "ftps", {} },
|
||||||
|
.{ "geo", {} },
|
||||||
|
.{ "im", {} },
|
||||||
|
.{ "ipfs", {} },
|
||||||
|
.{ "ipns", .{} },
|
||||||
|
.{ "irc", {} },
|
||||||
|
.{ "ircs", {} },
|
||||||
|
.{ "hyper", {} },
|
||||||
|
.{ "magnet", {} },
|
||||||
|
.{ "mailto", {} },
|
||||||
|
.{ "matrix", {} },
|
||||||
|
.{ "mms", {} },
|
||||||
|
.{ "news", {} },
|
||||||
|
.{ "nntp", {} },
|
||||||
|
.{ "openpgp4fpr", {} },
|
||||||
|
.{ "sftp", {} },
|
||||||
|
.{ "sip", {} },
|
||||||
|
.{ "sms", {} },
|
||||||
|
.{ "smsto", {} },
|
||||||
|
.{ "ssb", {} },
|
||||||
|
.{ "ssh", {} },
|
||||||
|
.{ "tel", {} },
|
||||||
|
.{ "urn", {} },
|
||||||
|
.{ "webcal", {} },
|
||||||
|
.{ "wtai", {} },
|
||||||
|
.{ "xmpp", {} },
|
||||||
|
});
|
||||||
|
if (allowed.has(scheme)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scheme.len < 5 or !std.mem.startsWith(u8, scheme, "web+")) {
|
||||||
|
return error.SecurityError;
|
||||||
|
}
|
||||||
|
for (scheme[4..]) |b| {
|
||||||
|
if (std.ascii.isLower(b) == false) {
|
||||||
|
return error.SecurityError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn validateProtocolHandlerURL(url: [:0]const u8, page: *const Page) !void {
|
||||||
|
if (std.mem.indexOf(u8, url, "%s") == null) {
|
||||||
|
return error.SyntaxError;
|
||||||
|
}
|
||||||
|
if (try page.isSameOrigin(url) == false) {
|
||||||
|
return error.SyntaxError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub const JsApi = struct {
|
pub const JsApi = struct {
|
||||||
pub const bridge = js.Bridge(Navigator);
|
pub const bridge = js.Bridge(Navigator);
|
||||||
|
|
||||||
@@ -121,6 +189,8 @@ pub const JsApi = struct {
|
|||||||
pub const vendor = bridge.accessor(Navigator.getVendor, null, .{});
|
pub const vendor = bridge.accessor(Navigator.getVendor, null, .{});
|
||||||
pub const product = bridge.accessor(Navigator.getProduct, null, .{});
|
pub const product = bridge.accessor(Navigator.getProduct, null, .{});
|
||||||
pub const webdriver = bridge.accessor(Navigator.getWebdriver, null, .{});
|
pub const webdriver = bridge.accessor(Navigator.getWebdriver, null, .{});
|
||||||
|
pub const registerProtocolHandler = bridge.function(Navigator.registerProtocolHandler, .{ .dom_exception = true });
|
||||||
|
pub const unregisterProtocolHandler = bridge.function(Navigator.unregisterProtocolHandler, .{ .dom_exception = true });
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
pub const javaEnabled = bridge.function(Navigator.javaEnabled, .{});
|
pub const javaEnabled = bridge.function(Navigator.javaEnabled, .{});
|
||||||
|
|||||||
Reference in New Issue
Block a user