mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
browser: back on createPage returning a Page (pointer)
Signed-off-by: Francis Bouvier <francis@lightpanda.io>
This commit is contained in:
@@ -103,7 +103,7 @@ pub const Session = struct {
|
||||
window: Window,
|
||||
// TODO move the shed to the browser?
|
||||
storageShed: storage.Shed,
|
||||
_page: ?Page = null,
|
||||
page: ?Page = null,
|
||||
httpClient: HttpClient,
|
||||
|
||||
jstypes: [Types.len]usize = undefined,
|
||||
@@ -125,7 +125,7 @@ pub const Session = struct {
|
||||
}
|
||||
|
||||
fn deinit(self: *Session) void {
|
||||
if (self._page) |*p| p.end();
|
||||
if (self.page) |*p| p.end();
|
||||
|
||||
if (self.inspector) |inspector| {
|
||||
inspector.deinit(self.alloc);
|
||||
@@ -158,17 +158,14 @@ pub const Session = struct {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn createPage(self: *Session) !void {
|
||||
if (self._page != null) return error.SessionPageExists;
|
||||
// NOTE: the caller is not the owner of the returned value,
|
||||
// the pointer on Page is just returned as a convenience
|
||||
pub fn createPage(self: *Session) !*Page {
|
||||
if (self.page != null) return error.SessionPageExists;
|
||||
const p: Page = undefined;
|
||||
self._page = p;
|
||||
Page.init(&self._page.?, self.alloc, self);
|
||||
}
|
||||
|
||||
// shortcut
|
||||
pub fn page(self: *Session) *Page {
|
||||
if (self._page) |*p| return p;
|
||||
@panic("No Page on this session");
|
||||
self.page = p;
|
||||
Page.init(&self.page.?, self.alloc, self);
|
||||
return &self.page.?;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -341,7 +341,7 @@ fn navigate(
|
||||
try sendEvent(alloc, ctx, "Runtime.executionContextsCleared", void, {}, msg.sessionID);
|
||||
|
||||
// Launch navigate
|
||||
try ctx.browser.session.createPage();
|
||||
const p = try ctx.browser.session.createPage();
|
||||
ctx.state.executionContextId += 1;
|
||||
const auxData = try std.fmt.allocPrint(
|
||||
alloc,
|
||||
@@ -350,7 +350,7 @@ fn navigate(
|
||||
.{ctx.state.frameID},
|
||||
);
|
||||
defer alloc.free(auxData);
|
||||
try ctx.browser.session.page().navigate(params.url, auxData);
|
||||
try p.navigate(params.url, auxData);
|
||||
|
||||
// Events
|
||||
|
||||
|
||||
@@ -87,14 +87,13 @@ pub fn main() !void {
|
||||
try Browser.init(&browser, allocator, &loop, vm);
|
||||
defer browser.deinit();
|
||||
|
||||
try browser.session.createPage();
|
||||
const page = try browser.session.createPage();
|
||||
|
||||
try browser.session.page().navigate(url, null);
|
||||
defer browser.session.page().end();
|
||||
try page.navigate(url, null);
|
||||
|
||||
try browser.session.page().wait();
|
||||
try page.wait();
|
||||
|
||||
if (dump) {
|
||||
try browser.session.page().dump(std.io.getStdOut());
|
||||
try page.dump(std.io.getStdOut());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user