mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
cdp: ctx state has init and deinit now
This commit is contained in:
@@ -34,6 +34,7 @@ const IncomingMessage = @import("msg.zig").IncomingMessage;
|
||||
const Input = @import("msg.zig").Input;
|
||||
const inspector = @import("inspector.zig").inspector;
|
||||
const dom = @import("dom.zig").dom;
|
||||
const cdpdom = @import("dom.zig");
|
||||
const css = @import("css.zig").css;
|
||||
const security = @import("security.zig").security;
|
||||
|
||||
@@ -129,6 +130,33 @@ pub const State = struct {
|
||||
loaderID: []const u8 = LoaderID,
|
||||
|
||||
page_life_cycle_events: bool = false, // TODO; Target based value
|
||||
|
||||
// DOM
|
||||
nodelist: cdpdom.NodeList,
|
||||
nodesearchlist: cdpdom.NodeSearchList,
|
||||
|
||||
pub fn init(alloc: std.mem.Allocator) State {
|
||||
return .{
|
||||
.nodelist = cdpdom.NodeList.init(alloc),
|
||||
.nodesearchlist = cdpdom.NodeSearchList.init(alloc),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *State) void {
|
||||
self.nodelist.deinit();
|
||||
|
||||
// deinit all node searches.
|
||||
for (self.nodesearchlist.items) |*s| s.deinit();
|
||||
self.nodesearchlist.deinit();
|
||||
}
|
||||
|
||||
pub fn reset(self: *State) void {
|
||||
self.nodelist.reset();
|
||||
|
||||
// deinit all node searches.
|
||||
for (self.nodesearchlist.items) |*s| s.deinit();
|
||||
self.nodesearchlist.clearAndFree();
|
||||
}
|
||||
};
|
||||
|
||||
// Utils
|
||||
|
||||
@@ -259,6 +259,7 @@ fn navigate(
|
||||
log.debug("Req > id {d}, method {s}", .{ input.id, "page.navigate" });
|
||||
|
||||
// change state
|
||||
ctx.state.reset();
|
||||
ctx.state.url = input.params.url;
|
||||
// TODO: hard coded ID
|
||||
ctx.state.loaderID = "AF8667A203C5392DBE9AC290044AA4C2";
|
||||
|
||||
@@ -69,13 +69,17 @@ pub const Ctx = struct {
|
||||
last_active: ?std.time.Instant = null,
|
||||
|
||||
// CDP
|
||||
state: cdp.State = .{},
|
||||
state: cdp.State = undefined,
|
||||
|
||||
// JS fields
|
||||
browser: *Browser, // TODO: is pointer mandatory here?
|
||||
sessionNew: bool,
|
||||
// try_catch: jsruntime.TryCatch, // TODO
|
||||
|
||||
pub fn deinit(self: *Ctx) void {
|
||||
self.state.deinit();
|
||||
}
|
||||
|
||||
// callbacks
|
||||
// ---------
|
||||
|
||||
@@ -458,7 +462,10 @@ pub fn handle(
|
||||
.accept_completion = &accept_completion,
|
||||
.conn_completion = &conn_completion,
|
||||
.timeout_completion = &timeout_completion,
|
||||
.state = cdp.State.init(browser.session.alloc),
|
||||
};
|
||||
defer ctx.deinit();
|
||||
|
||||
try browser.session.initInspector(
|
||||
&ctx,
|
||||
Ctx.onInspectorResp,
|
||||
|
||||
Reference in New Issue
Block a user