cleanup a not-so-great rebase

This commit is contained in:
Karl Seguin
2026-02-19 13:21:41 +08:00
parent bb01a5cb31
commit db2927eea7
4 changed files with 18 additions and 14 deletions

View File

@@ -226,7 +226,6 @@ frames_sorted: bool = true,
// DOM version used to invalidate cached state of "live" collections // DOM version used to invalidate cached state of "live" collections
version: usize = 0, version: usize = 0,
// This is maybe not great. It's a counter on the number of events that we're // This is maybe not great. It's a counter on the number of events that we're
// waiting on before triggering the "load" event. Essentially, we need all // waiting on before triggering the "load" event. Essentially, we need all
// synchronous scripts and all iframes to be loaded. Scripts are handled by the // synchronous scripts and all iframes to be loaded. Scripts are handled by the
@@ -236,7 +235,7 @@ _pending_loads: u32,
_parent_notified: if (IS_DEBUG) bool else void = if (IS_DEBUG) false else {}, _parent_notified: if (IS_DEBUG) bool else void = if (IS_DEBUG) false else {},
_type: enum { root, frame }, // only used for logs right now _type: enum { root, frame }, // only used for logs right now
_req_id: ?u32 = null, _req_id: u32 = 0,
_navigated_options: ?NavigatedOpts = null, _navigated_options: ?NavigatedOpts = null,
pub fn init(self: *Page, id: u32, session: *Session, parent: ?*Page) !void { pub fn init(self: *Page, id: u32, session: *Session, parent: ?*Page) !void {
@@ -1202,15 +1201,17 @@ pub fn iframeAddedCallback(self: *Page, iframe: *Element.Html.IFrame) !void {
return; return;
} }
const session = self._session;
iframe._executed = true; iframe._executed = true;
const page_frame = try self.arena.create(Page); const page_frame = try self.arena.create(Page);
try Page.init(page_frame, self._session, self); try Page.init(page_frame, session.nextPageId(), session, self);
self._pending_loads += 1; self._pending_loads += 1;
page_frame.iframe = iframe; page_frame.iframe = iframe;
iframe._content_window = page_frame.window; iframe._content_window = page_frame.window;
page_frame.navigate(src, .{.reason = .initialFrameNavigation}) catch |err| { page_frame.navigate(src, .{ .reason = .initialFrameNavigation }) catch |err| {
log.warn(.page, "iframe navigate failure", .{ .url = src, .err = err }); log.warn(.page, "iframe navigate failure", .{ .url = src, .err = err });
self._pending_loads -= 1; self._pending_loads -= 1;
iframe._content_window = null; iframe._content_window = null;

View File

@@ -91,12 +91,9 @@ pub fn deinit(self: *Session) void {
pub fn createPage(self: *Session) !*Page { pub fn createPage(self: *Session) !*Page {
lp.assert(self.page == null, "Session.createPage - page not null", .{}); lp.assert(self.page == null, "Session.createPage - page not null", .{});
const id = self.page_id_gen +% 1;
self.page_id_gen = id;
self.page = @as(Page, undefined); self.page = @as(Page, undefined);
const page = &self.page.?; const page = &self.page.?;
try Page.init(page, id, self, null); try Page.init(page, self.nextPageId(), self, null);
// Creates a new NavigationEventTarget for this page. // Creates a new NavigationEventTarget for this page.
try self.navigation.onNewPage(page); try self.navigation.onNewPage(page);
@@ -135,7 +132,7 @@ pub fn replacePage(self: *Session) !*Page {
var current = self.page.?; var current = self.page.?;
const page_id = current.id; const page_id = current.id;
const parent = current._parent; const parent = current.parent;
current.deinit(); current.deinit();
self.browser.env.memoryPressureNotification(.moderate); self.browser.env.memoryPressureNotification(.moderate);
@@ -335,12 +332,12 @@ fn processScheduledNavigation(self: *Session, current_page: *Page) !*Page {
const page_id, const parent = blk: { const page_id, const parent = blk: {
const page = &self.page.?; const page = &self.page.?;
const page_id = page.id; const page_id = page.id;
const parent = page._parent; const parent = page.parent;
browser.http_client.abort(); browser.http_client.abort();
self.removePage(); self.removePage();
break :blk .{page_id, parent}; break :blk .{ page_id, parent };
}; };
self.page = @as(Page, undefined); self.page = @as(Page, undefined);
@@ -361,3 +358,9 @@ fn processScheduledNavigation(self: *Session, current_page: *Page) !*Page {
return page; return page;
} }
pub fn nextPageId(self: *Session) u32 {
const id = self.page_id_gen +% 1;
self.page_id_gen = id;
return id;
}

View File

@@ -342,7 +342,6 @@ pub fn click(self: *HtmlElement, page: *Page) !void {
try page._event_manager.dispatch(self.asEventTarget(), event); try page._event_manager.dispatch(self.asEventTarget(), event);
} }
<<<<<<< HEAD
// TODO: Per spec, hidden is a tristate: true | false | "until-found". // TODO: Per spec, hidden is a tristate: true | false | "until-found".
// We only support boolean for now; "until-found" would need bridge union support. // We only support boolean for now; "until-found" would need bridge union support.
pub fn getHidden(self: *HtmlElement) bool { pub fn getHidden(self: *HtmlElement) bool {
@@ -374,7 +373,6 @@ pub fn setTabIndex(self: *HtmlElement, value: i32, page: *Page) !void {
try self.asElement().setAttributeSafe(comptime .wrap("tabindex"), .wrap(str), page); try self.asElement().setAttributeSafe(comptime .wrap("tabindex"), .wrap(str), page);
} }
pub fn getAttributeFunction( pub fn getAttributeFunction(
self: *HtmlElement, self: *HtmlElement,
listener_type: GlobalEventHandler, listener_type: GlobalEventHandler,

View File

@@ -250,9 +250,10 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
else => unreachable, else => unreachable,
}, },
.address_bar => null, .address_bar => null,
.initialFrameNavigation => "initialFrameNavigation",
}; };
if (reason_) |reason| { if (reason_) |reason| {
if (reason != .initialFrameNavigation) { if (event.opts.reason != .initialFrameNavigation) {
try cdp.sendEvent("Page.frameScheduledNavigation", .{ try cdp.sendEvent("Page.frameScheduledNavigation", .{
.frameId = frame_id, .frameId = frame_id,
.delay = 0, .delay = 0,
@@ -346,6 +347,7 @@ pub fn pageNavigated(arena: Allocator, bc: anytype, event: *const Notification.P
else => unreachable, else => unreachable,
}, },
.address_bar => null, .address_bar => null,
.initialFrameNavigation => "initialFrameNavigation",
}; };
if (reason_ != null) { if (reason_ != null) {