mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-03-29 16:10:04 +00:00
In https://github.com/lightpanda-io/browser/pull/1774 we started to track Ranges in the page in order to correctly make them "live". But, without correct lifetime, they would continue to be "live" even if out of scope in JS. This commit adds finalizers to Range via reference counting similar to Events. It _is_ possible for a Range to outlive its page, so we can't just remove the range from the Page's _live_range list - the page might not be valid. This commit gives every page an unique id and the ability to try and get the page by id from the session. By capturing the page_id at creation-time, a Range can defensively remove itself from the page's list. If the page is already gone, then there's no need to do anything.
67 lines
2.3 KiB
Zig
67 lines
2.3 KiB
Zig
// Copyright (C) 2023-2024 Lightpanda (Selecy SAS)
|
|
//
|
|
// Francis Bouvier <francis@lightpanda.io>
|
|
// Pierre Tachoire <pierre@lightpanda.io>
|
|
//
|
|
// 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 <https://www.gnu.org/licenses/>.
|
|
|
|
const std = @import("std");
|
|
const id = @import("../id.zig");
|
|
|
|
pub fn processMessage(cmd: anytype) !void {
|
|
const action = std.meta.stringToEnum(enum {
|
|
enable,
|
|
disable,
|
|
getFullAXTree,
|
|
}, cmd.input.action) orelse return error.UnknownMethod;
|
|
|
|
switch (action) {
|
|
.enable => return enable(cmd),
|
|
.disable => return disable(cmd),
|
|
.getFullAXTree => return getFullAXTree(cmd),
|
|
}
|
|
}
|
|
fn enable(cmd: anytype) !void {
|
|
return cmd.sendResult(null, .{});
|
|
}
|
|
|
|
fn disable(cmd: anytype) !void {
|
|
return cmd.sendResult(null, .{});
|
|
}
|
|
|
|
fn getFullAXTree(cmd: anytype) !void {
|
|
const params = (try cmd.params(struct {
|
|
depth: ?i32 = null,
|
|
frameId: ?[]const u8 = null,
|
|
})) orelse return error.InvalidParams;
|
|
|
|
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
|
const session = bc.session;
|
|
|
|
const page = blk: {
|
|
const frame_id = params.frameId orelse {
|
|
break :blk session.currentPage() orelse return error.PageNotLoaded;
|
|
};
|
|
const page_frame_id = try id.toPageId(.frame_id, frame_id);
|
|
break :blk session.findPageByFrameId(page_frame_id) orelse {
|
|
return cmd.sendError(-32000, "Frame with the given id does not belong to the target.", .{});
|
|
};
|
|
};
|
|
|
|
const doc = page.window._document.asNode();
|
|
const node = try bc.node_registry.register(doc);
|
|
|
|
return cmd.sendResult(.{ .nodes = try bc.axnodeWriter(node, .{}) }, .{});
|
|
}
|