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,
|
window: Window,
|
||||||
// TODO move the shed to the browser?
|
// TODO move the shed to the browser?
|
||||||
storageShed: storage.Shed,
|
storageShed: storage.Shed,
|
||||||
_page: ?Page = null,
|
page: ?Page = null,
|
||||||
httpClient: HttpClient,
|
httpClient: HttpClient,
|
||||||
|
|
||||||
jstypes: [Types.len]usize = undefined,
|
jstypes: [Types.len]usize = undefined,
|
||||||
@@ -125,7 +125,7 @@ pub const Session = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn deinit(self: *Session) void {
|
fn deinit(self: *Session) void {
|
||||||
if (self._page) |*p| p.end();
|
if (self.page) |*p| p.end();
|
||||||
|
|
||||||
if (self.inspector) |inspector| {
|
if (self.inspector) |inspector| {
|
||||||
inspector.deinit(self.alloc);
|
inspector.deinit(self.alloc);
|
||||||
@@ -158,17 +158,14 @@ pub const Session = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createPage(self: *Session) !void {
|
// NOTE: the caller is not the owner of the returned value,
|
||||||
if (self._page != null) return error.SessionPageExists;
|
// 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;
|
const p: Page = undefined;
|
||||||
self._page = p;
|
self.page = p;
|
||||||
Page.init(&self._page.?, self.alloc, self);
|
Page.init(&self.page.?, self.alloc, self);
|
||||||
}
|
return &self.page.?;
|
||||||
|
|
||||||
// shortcut
|
|
||||||
pub fn page(self: *Session) *Page {
|
|
||||||
if (self._page) |*p| return p;
|
|
||||||
@panic("No Page on this session");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ fn navigate(
|
|||||||
try sendEvent(alloc, ctx, "Runtime.executionContextsCleared", void, {}, msg.sessionID);
|
try sendEvent(alloc, ctx, "Runtime.executionContextsCleared", void, {}, msg.sessionID);
|
||||||
|
|
||||||
// Launch navigate
|
// Launch navigate
|
||||||
try ctx.browser.session.createPage();
|
const p = try ctx.browser.session.createPage();
|
||||||
ctx.state.executionContextId += 1;
|
ctx.state.executionContextId += 1;
|
||||||
const auxData = try std.fmt.allocPrint(
|
const auxData = try std.fmt.allocPrint(
|
||||||
alloc,
|
alloc,
|
||||||
@@ -350,7 +350,7 @@ fn navigate(
|
|||||||
.{ctx.state.frameID},
|
.{ctx.state.frameID},
|
||||||
);
|
);
|
||||||
defer alloc.free(auxData);
|
defer alloc.free(auxData);
|
||||||
try ctx.browser.session.page().navigate(params.url, auxData);
|
try p.navigate(params.url, auxData);
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|
||||||
|
|||||||
@@ -87,14 +87,13 @@ pub fn main() !void {
|
|||||||
try Browser.init(&browser, allocator, &loop, vm);
|
try Browser.init(&browser, allocator, &loop, vm);
|
||||||
defer browser.deinit();
|
defer browser.deinit();
|
||||||
|
|
||||||
try browser.session.createPage();
|
const page = try browser.session.createPage();
|
||||||
|
|
||||||
try browser.session.page().navigate(url, null);
|
try page.navigate(url, null);
|
||||||
defer browser.session.page().end();
|
|
||||||
|
|
||||||
try browser.session.page().wait();
|
try page.wait();
|
||||||
|
|
||||||
if (dump) {
|
if (dump) {
|
||||||
try browser.session.page().dump(std.io.getStdOut());
|
try page.dump(std.io.getStdOut());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user