mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
@@ -20,6 +20,7 @@ const std = @import("std");
|
||||
const parser = @import("netsurf");
|
||||
const Node = @import("../Node.zig");
|
||||
const css = @import("../../dom/css.zig");
|
||||
const dom_node = @import("../../dom/node.zig");
|
||||
|
||||
pub fn processMessage(cmd: anytype) !void {
|
||||
const action = std.meta.stringToEnum(enum {
|
||||
@@ -28,6 +29,7 @@ pub fn processMessage(cmd: anytype) !void {
|
||||
performSearch,
|
||||
getSearchResults,
|
||||
discardSearchResults,
|
||||
resolveNode,
|
||||
}, cmd.input.action) orelse return error.UnknownMethod;
|
||||
|
||||
switch (action) {
|
||||
@@ -36,6 +38,7 @@ pub fn processMessage(cmd: anytype) !void {
|
||||
.performSearch => return performSearch(cmd),
|
||||
.getSearchResults => return getSearchResults(cmd),
|
||||
.discardSearchResults => return discardSearchResults(cmd),
|
||||
.resolveNode => return resolveNode(cmd),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +118,36 @@ fn getSearchResults(cmd: anytype) !void {
|
||||
return cmd.sendResult(.{ .nodeIds = node_ids[params.fromIndex..params.toIndex] }, .{});
|
||||
}
|
||||
|
||||
fn resolveNode(cmd: anytype) !void {
|
||||
const params = (try cmd.params(struct {
|
||||
nodeId: ?Node.Id = null,
|
||||
backendNodeId: ?u32 = null,
|
||||
objectGroup: ?[]const u8 = null,
|
||||
executionContextId: ?u32 = null,
|
||||
})) orelse return error.InvalidParams;
|
||||
if (params.nodeId == null or params.backendNodeId != null or params.executionContextId != null) {
|
||||
return error.NotYetImplementedParams;
|
||||
}
|
||||
|
||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||
const node = bc.node_registry.lookup_by_id.get(params.nodeId.?) orelse return error.UnknownNode;
|
||||
|
||||
// node._node is a *parser.Node we need this to be able to find its most derived type e.g. Node -> Element -> HTMLElement
|
||||
// So we use the Node.Union when retrieve the value from the environment
|
||||
const jsValue = try bc.session.env.findOrAddValue(try dom_node.Node.toInterface(node._node));
|
||||
const remoteObject = try bc.session.inspector.getRemoteObject(&bc.session.env, jsValue, params.objectGroup orelse "");
|
||||
defer remoteObject.deinit();
|
||||
|
||||
const arena = cmd.arena;
|
||||
return cmd.sendResult(.{ .object = .{
|
||||
.type = try remoteObject.getType(arena),
|
||||
.subtype = try remoteObject.getSubtype(arena),
|
||||
.className = try remoteObject.getClassName(arena),
|
||||
.description = try remoteObject.getDescription(arena),
|
||||
.objectId = try remoteObject.getObjectId(arena),
|
||||
} }, .{});
|
||||
}
|
||||
|
||||
const testing = @import("../testing.zig");
|
||||
|
||||
test "cdp.dom: getSearchResults unknown search id" {
|
||||
|
||||
@@ -60,6 +60,8 @@ const Browser = struct {
|
||||
self.session.?.* = .{
|
||||
.page = null,
|
||||
.arena = arena,
|
||||
.env = Env{},
|
||||
.inspector = Inspector{},
|
||||
};
|
||||
return self.session.?;
|
||||
}
|
||||
@@ -75,6 +77,8 @@ const Browser = struct {
|
||||
const Session = struct {
|
||||
page: ?Page = null,
|
||||
arena: Allocator,
|
||||
env: Env,
|
||||
inspector: Inspector,
|
||||
|
||||
pub fn currentPage(self: *Session) ?*Page {
|
||||
return &(self.page orelse return null);
|
||||
@@ -102,6 +106,54 @@ const Session = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const Env = struct {
|
||||
pub fn findOrAddValue(self: *Env, value: anytype) !@TypeOf(value) { // ?
|
||||
_ = self;
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
const Inspector = struct {
|
||||
pub fn getRemoteObject(self: Inspector, env: *Env, jsValue: anytype, groupName: []const u8) !RemoteObject {
|
||||
_ = self;
|
||||
_ = env;
|
||||
_ = jsValue;
|
||||
_ = groupName;
|
||||
return RemoteObject{};
|
||||
}
|
||||
};
|
||||
|
||||
const RemoteObject = struct {
|
||||
pub fn deinit(self: RemoteObject) void {
|
||||
_ = self;
|
||||
}
|
||||
pub fn getType(self: RemoteObject, alloc: std.mem.Allocator) ![:0]const u8 {
|
||||
_ = self;
|
||||
_ = alloc;
|
||||
return "TheType";
|
||||
}
|
||||
pub fn getSubtype(self: RemoteObject, alloc: std.mem.Allocator) ![:0]const u8 {
|
||||
_ = self;
|
||||
_ = alloc;
|
||||
return "TheSubtype";
|
||||
}
|
||||
pub fn getClassName(self: RemoteObject, alloc: std.mem.Allocator) ![:0]const u8 {
|
||||
_ = self;
|
||||
_ = alloc;
|
||||
return "TheClassName";
|
||||
}
|
||||
pub fn getDescription(self: RemoteObject, alloc: std.mem.Allocator) ![:0]const u8 {
|
||||
_ = self;
|
||||
_ = alloc;
|
||||
return "TheDescription";
|
||||
}
|
||||
pub fn getObjectId(self: RemoteObject, alloc: std.mem.Allocator) ![:0]const u8 {
|
||||
_ = self;
|
||||
_ = alloc;
|
||||
return "TheObjectId";
|
||||
}
|
||||
};
|
||||
|
||||
const Page = struct {
|
||||
session: *Session,
|
||||
rawuri: []const u8,
|
||||
|
||||
2
vendor/zig-js-runtime
vendored
2
vendor/zig-js-runtime
vendored
Submodule vendor/zig-js-runtime updated: f3a9e3d448...9b87782f1e
Reference in New Issue
Block a user