mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 23:23:28 +00:00
browsercontext arena
This commit is contained in:
@@ -126,6 +126,7 @@ pub const Session = struct {
|
||||
//
|
||||
// The arena is initialised with self.alloc allocator.
|
||||
// all others Session deps use directly self.alloc and not the arena.
|
||||
// The arena is also used in the BrowserContext
|
||||
arena: std.heap.ArenaAllocator,
|
||||
|
||||
window: Window,
|
||||
|
||||
@@ -284,6 +284,9 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
// RELATION TO SESSION_ID
|
||||
session: *CDP_T.Session,
|
||||
|
||||
// Points to the session arena
|
||||
arena: Allocator,
|
||||
|
||||
// Maps to our Page. (There are other types of targets, but we only
|
||||
// deal with "pages" for now). Since we only allow 1 open page at a
|
||||
// time, we only have 1 target_id.
|
||||
@@ -316,6 +319,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
var registry = Node.Registry.init(allocator);
|
||||
errdefer registry.deinit();
|
||||
|
||||
const session = try cdp.browser.newSession(self);
|
||||
self.* = .{
|
||||
.id = id,
|
||||
.cdp = cdp,
|
||||
@@ -324,7 +328,8 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
.security_origin = URL_BASE,
|
||||
.secure_context_type = "Secure", // TODO = enum
|
||||
.loader_id = LOADER_ID,
|
||||
.session = try cdp.browser.newSession(self),
|
||||
.session = session,
|
||||
.arena = session.arena.allocator(),
|
||||
.page_life_cycle_events = false, // TODO; Target based value
|
||||
.node_registry = registry,
|
||||
.node_search_list = undefined,
|
||||
@@ -365,7 +370,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
executor.context.exit(); // The default context should remain open
|
||||
|
||||
self.isolated_world = .{
|
||||
.name = try self.session.arena.allocator().dupe(u8, world_name), // TODO allocator
|
||||
.name = try self.arena.dupe(u8, world_name),
|
||||
.grant_universal_access = grant_universal_access,
|
||||
.executor = executor,
|
||||
};
|
||||
@@ -468,6 +473,7 @@ pub fn BrowserContext(comptime CDP_T: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
/// see: https://chromium.googlesource.com/chromium/src/+/master/third_party/blink/renderer/bindings/core/v8/V8BindingDesign.md#world
|
||||
/// The current understanding. An isolated world lives in the same isolate, but a separated context.
|
||||
/// Clients create this to be able to create variables and run code without interfering with the
|
||||
/// normal namespace and values of the webpage. Similar to the main context we need to pretend to recreate it after
|
||||
|
||||
@@ -117,8 +117,8 @@ fn createIsolatedWorld(cmd: anytype) !void {
|
||||
|
||||
// Create the auxdata json for the contextCreated event
|
||||
// Calling contextCreated will assign a Id to the context and send the contextCreated event
|
||||
const aux_json = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{params.frameId});
|
||||
bc.session.inspector.contextCreated(world.executor, world.name, "", aux_json, false);
|
||||
const aux_data = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{params.frameId});
|
||||
bc.session.inspector.contextCreated(world.executor, world.name, "", aux_data, false);
|
||||
|
||||
return cmd.sendResult(.{ .executionContextId = world.executor.context.debugContextId() }, .{});
|
||||
}
|
||||
@@ -213,16 +213,14 @@ pub fn pageNavigate(bc: anytype, event: *const Notification.PageNavigate) !void
|
||||
}, .{ .session_id = session_id });
|
||||
}
|
||||
|
||||
// Send Runtime.executionContextsCleared event
|
||||
// TODO: noop event, we have no env context at this point, is it necesarry?
|
||||
// When we actually recreated the context we should have the inspector send this event, see: resetContextGroup
|
||||
// Sending this event will tell the client that the context ids they had are invalid and the context shouls be dropped
|
||||
// The client will expect us to send new contextCreated events, such that the client has new id's for the active contexts.
|
||||
try cdp.sendEvent("Runtime.executionContextsCleared", null, .{ .session_id = session_id });
|
||||
|
||||
if (bc.isolated_world) |*isolated_world| {
|
||||
// TODO change the allocator
|
||||
const aux_json = try std.fmt.allocPrint(bc.session.arena.allocator(), "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{bc.target_id.?});
|
||||
var buffer: [256]u8 = undefined;
|
||||
const aux_json = try std.fmt.bufPrint(&buffer, "{{\"isDefault\":false,\"type\":\"isolated\",\"frameId\":\"{s}\"}}", .{bc.target_id.?});
|
||||
|
||||
// Calling contextCreated will assign a new Id to the context and send the contextCreated event
|
||||
bc.session.inspector.contextCreated(
|
||||
|
||||
Reference in New Issue
Block a user