mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-16 08:18:59 +00:00
add NavigationKind to navigate
This commit is contained in:
@@ -58,6 +58,7 @@ const IntersectionObserver = @import("webapi/IntersectionObserver.zig");
|
|||||||
const CustomElementDefinition = @import("webapi/CustomElementDefinition.zig");
|
const CustomElementDefinition = @import("webapi/CustomElementDefinition.zig");
|
||||||
const storage = @import("webapi/storage/storage.zig");
|
const storage = @import("webapi/storage/storage.zig");
|
||||||
const PageTransitionEvent = @import("webapi/event/PageTransitionEvent.zig");
|
const PageTransitionEvent = @import("webapi/event/PageTransitionEvent.zig");
|
||||||
|
const NavigationKind = @import("webapi/navigation/root.zig").NavigationKind;
|
||||||
|
|
||||||
const timestamp = @import("../datetime.zig").timestamp;
|
const timestamp = @import("../datetime.zig").timestamp;
|
||||||
const milliTimestamp = @import("../datetime.zig").milliTimestamp;
|
const milliTimestamp = @import("../datetime.zig").milliTimestamp;
|
||||||
@@ -270,7 +271,7 @@ fn registerBackgroundTasks(self: *Page) !void {
|
|||||||
}.runMessageLoop, 250, .{ .name = "page.messageLoop" });
|
}.runMessageLoop, 250, .{ .name = "page.messageLoop" });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn navigate(self: *Page, request_url: [:0]const u8, opts: NavigateOpts) !void {
|
pub fn navigate(self: *Page, request_url: [:0]const u8, opts: NavigateOpts, kind: NavigationKind) !void {
|
||||||
const session = self._session;
|
const session = self._session;
|
||||||
|
|
||||||
const resolved_url = try URL.resolve(
|
const resolved_url = try URL.resolve(
|
||||||
@@ -292,7 +293,7 @@ pub fn navigate(self: *Page, request_url: [:0]const u8, opts: NavigateOpts) !voi
|
|||||||
self.window._location = try Location.init(self.url, self);
|
self.window._location = try Location.init(self.url, self);
|
||||||
self.document._location = self.window._location;
|
self.document._location = self.window._location;
|
||||||
|
|
||||||
try session.navigation.updateEntries("", .{ .push = null }, self, true);
|
try session.navigation.updateEntries(resolved_url, kind, self, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -353,6 +354,8 @@ pub fn navigate(self: *Page, request_url: [:0]const u8, opts: NavigateOpts) !voi
|
|||||||
.timestamp = timestamp(.monotonic),
|
.timestamp = timestamp(.monotonic),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
session.navigation._current_navigation_kind = kind;
|
||||||
|
|
||||||
http_client.request(.{
|
http_client.request(.{
|
||||||
.ctx = self,
|
.ctx = self,
|
||||||
.url = self.url,
|
.url = self.url,
|
||||||
|
|||||||
@@ -191,7 +191,11 @@ fn processQueuedNavigation(self: *Session) !bool {
|
|||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
|
||||||
page.navigate(qn.url, qn.opts) catch |err| {
|
page.navigate(
|
||||||
|
qn.url,
|
||||||
|
qn.opts,
|
||||||
|
self.navigation._current_navigation_kind orelse .{ .push = null },
|
||||||
|
) catch |err| {
|
||||||
log.err(.browser, "queued navigation error", .{ .err = err, .url = qn.url });
|
log.err(.browser, "queued navigation error", .{ .err = err, .url = qn.url });
|
||||||
return err;
|
return err;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ pub fn setHash(_: *const Location, hash: []const u8, page: *Page) !void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const duped_hash = try page.arena.dupeZ(u8, normalized_hash);
|
const duped_hash = try page.arena.dupeZ(u8, normalized_hash);
|
||||||
return page.navigate(duped_hash, .{ .reason = .script });
|
return page.navigate(duped_hash, .{ .reason = .script }, .{ .replace = null });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toString(self: *const Location, page: *const Page) ![:0]const u8 {
|
pub fn toString(self: *const Location, page: *const Page) ![:0]const u8 {
|
||||||
|
|||||||
@@ -92,7 +92,6 @@ pub fn back(self: *Navigation, page: *Page) !NavigationReturn {
|
|||||||
|
|
||||||
const new_index = self._index - 1;
|
const new_index = self._index - 1;
|
||||||
const next_entry = self._entries.items[new_index];
|
const next_entry = self._entries.items[new_index];
|
||||||
self._index = new_index;
|
|
||||||
|
|
||||||
return self.navigateInner(next_entry._url, .{ .traverse = new_index }, page);
|
return self.navigateInner(next_entry._url, .{ .traverse = new_index }, page);
|
||||||
}
|
}
|
||||||
@@ -108,7 +107,6 @@ pub fn forward(self: *Navigation, page: *Page) !NavigationReturn {
|
|||||||
|
|
||||||
const new_index = self._index + 1;
|
const new_index = self._index + 1;
|
||||||
const next_entry = self._entries.items[new_index];
|
const next_entry = self._entries.items[new_index];
|
||||||
self._index = new_index;
|
|
||||||
|
|
||||||
return self.navigateInner(next_entry._url, .{ .traverse = new_index }, page);
|
return self.navigateInner(next_entry._url, .{ .traverse = new_index }, page);
|
||||||
}
|
}
|
||||||
@@ -132,7 +130,10 @@ pub fn updateEntries(self: *Navigation, url: [:0]const u8, kind: NavigationKind,
|
|||||||
// This is only really safe to run in the `pageDoneCallback` where we can guarantee that the URL and NavigationKind are correct.
|
// This is only really safe to run in the `pageDoneCallback` where we can guarantee that the URL and NavigationKind are correct.
|
||||||
pub fn processNavigation(self: *Navigation, page: *Page) !void {
|
pub fn processNavigation(self: *Navigation, page: *Page) !void {
|
||||||
const url = page.url;
|
const url = page.url;
|
||||||
|
|
||||||
const kind: NavigationKind = self._current_navigation_kind orelse .{ .push = null };
|
const kind: NavigationKind = self._current_navigation_kind orelse .{ .push = null };
|
||||||
|
defer self._current_navigation_kind = null;
|
||||||
|
|
||||||
try self.updateEntries(url, kind, page, false);
|
try self.updateEntries(url, kind, page, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,9 +248,11 @@ pub fn navigateInner(
|
|||||||
const committed = try page.js.createPromiseResolver(.page);
|
const committed = try page.js.createPromiseResolver(.page);
|
||||||
const finished = try page.js.createPromiseResolver(.page);
|
const finished = try page.js.createPromiseResolver(.page);
|
||||||
|
|
||||||
const new_url = try URL.resolve(arena, url, page.url, .{});
|
const new_url = try URL.resolve(arena, page.url, url, .{});
|
||||||
const is_same_document = URL.eqlDocument(new_url, page.url);
|
const is_same_document = URL.eqlDocument(new_url, page.url);
|
||||||
|
|
||||||
|
const previous = self.getCurrentEntry();
|
||||||
|
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
.push => |state| {
|
.push => |state| {
|
||||||
if (is_same_document) {
|
if (is_same_document) {
|
||||||
@@ -261,8 +264,7 @@ pub fn navigateInner(
|
|||||||
|
|
||||||
_ = try self.pushEntry(url, .{ .source = .navigation, .value = state }, page, true);
|
_ = try self.pushEntry(url, .{ .source = .navigation, .value = state }, page, true);
|
||||||
} else {
|
} else {
|
||||||
// try page.navigate(url, .{ .reason = .navigation }, kind);
|
try page.navigate(url, .{ .reason = .navigation }, kind);
|
||||||
try page.navigate(url, .{ .reason = .navigation });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.replace => |state| {
|
.replace => |state| {
|
||||||
@@ -275,8 +277,7 @@ pub fn navigateInner(
|
|||||||
|
|
||||||
_ = try self.replaceEntry(url, .{ .source = .navigation, .value = state }, page, true);
|
_ = try self.replaceEntry(url, .{ .source = .navigation, .value = state }, page, true);
|
||||||
} else {
|
} else {
|
||||||
// try page.navigate(url, .{ .reason = .navigation }, kind);
|
try page.navigate(url, .{ .reason = .navigation }, kind);
|
||||||
try page.navigate(url, .{ .reason = .navigation });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.traverse => |index| {
|
.traverse => |index| {
|
||||||
@@ -289,16 +290,22 @@ pub fn navigateInner(
|
|||||||
// todo: Fire navigate event
|
// todo: Fire navigate event
|
||||||
finished.resolve("navigation traverse", {});
|
finished.resolve("navigation traverse", {});
|
||||||
} else {
|
} else {
|
||||||
// try page.navigate(url, .{ .reason = .navigation }, kind);
|
try page.navigate(url, .{ .reason = .navigation }, kind);
|
||||||
try page.navigate(url, .{ .reason = .navigation });
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.reload => {
|
.reload => {
|
||||||
// try page.navigate(url, .{ .reason = .navigation }, kind);
|
try page.navigate(url, .{ .reason = .navigation }, kind);
|
||||||
try page.navigate(url, .{ .reason = .navigation });
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we haven't navigated off, let us fire off an a currententrychange.
|
||||||
|
const event = try NavigationCurrentEntryChangeEvent.init(
|
||||||
|
"currententrychange",
|
||||||
|
.{ .from = previous, .navigationType = @tagName(kind) },
|
||||||
|
page,
|
||||||
|
);
|
||||||
|
try self._proto.dispatch(.{ .currententrychange = event }, page);
|
||||||
|
|
||||||
return .{
|
return .{
|
||||||
.committed = committed.promise(),
|
.committed = committed.promise(),
|
||||||
.finished = finished.promise(),
|
.finished = finished.promise(),
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ fn navigate(cmd: anytype) !void {
|
|||||||
try page.navigate(params.url, .{
|
try page.navigate(params.url, .{
|
||||||
.reason = .address_bar,
|
.reason = .address_bar,
|
||||||
.cdp_id = cmd.input.id,
|
.cdp_id = cmd.input.id,
|
||||||
});
|
}, .{ .push = null });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.PageNavigate) !void {
|
pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.PageNavigate) !void {
|
||||||
|
|||||||
@@ -179,9 +179,11 @@ fn createTarget(cmd: anytype) !void {
|
|||||||
try doAttachtoTarget(cmd, target_id);
|
try doAttachtoTarget(cmd, target_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
try page.navigate(params.url, .{
|
try page.navigate(
|
||||||
.reason = .address_bar,
|
params.url,
|
||||||
});
|
.{ .reason = .address_bar },
|
||||||
|
.{ .push = null },
|
||||||
|
);
|
||||||
|
|
||||||
try cmd.sendResult(.{
|
try cmd.sendResult(.{
|
||||||
.targetId = target_id,
|
.targetId = target_id,
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ const TestContext = struct {
|
|||||||
.{url},
|
.{url},
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
try page.navigate(full_url, .{});
|
try page.navigate(full_url, .{}, .{ .push = null });
|
||||||
bc.session.fetchWait(2000);
|
bc.session.fetchWait(2000);
|
||||||
}
|
}
|
||||||
return bc;
|
return bc;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ pub fn fetch(app: *App, url: [:0]const u8, opts: FetchOpts) !void {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
_ = try page.navigate(url, .{});
|
_ = try page.navigate(url, .{}, .{ .push = null });
|
||||||
_ = session.fetchWait(opts.wait_ms);
|
_ = session.fetchWait(opts.wait_ms);
|
||||||
|
|
||||||
const writer = opts.writer orelse return;
|
const writer = opts.writer orelse return;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ pub fn run(allocator: Allocator, file: []const u8, session: *lp.Session) !void {
|
|||||||
try_catch.init(js_context);
|
try_catch.init(js_context);
|
||||||
defer try_catch.deinit();
|
defer try_catch.deinit();
|
||||||
|
|
||||||
try page.navigate(url, .{});
|
try page.navigate(url, .{}, .{ .push = null });
|
||||||
session.fetchWait(2000);
|
session.fetchWait(2000);
|
||||||
|
|
||||||
page._session.browser.runMicrotasks();
|
page._session.browser.runMicrotasks();
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ fn run(
|
|||||||
defer session.removePage();
|
defer session.removePage();
|
||||||
|
|
||||||
const url = try std.fmt.allocPrintSentinel(arena, "http://localhost:9582/{s}", .{test_file}, 0);
|
const url = try std.fmt.allocPrintSentinel(arena, "http://localhost:9582/{s}", .{test_file}, 0);
|
||||||
try page.navigate(url, .{});
|
try page.navigate(url, .{}, .{ .push = null });
|
||||||
|
|
||||||
_ = page.wait(2000);
|
_ = page.wait(2000);
|
||||||
|
|
||||||
|
|||||||
@@ -403,7 +403,7 @@ fn runWebApiTest(test_file: [:0]const u8) !void {
|
|||||||
try_catch.init(js_context);
|
try_catch.init(js_context);
|
||||||
defer try_catch.deinit();
|
defer try_catch.deinit();
|
||||||
|
|
||||||
try page.navigate(url, .{});
|
try page.navigate(url, .{}, .{ .push = null });
|
||||||
test_session.fetchWait(2000);
|
test_session.fetchWait(2000);
|
||||||
|
|
||||||
page._session.browser.runMicrotasks();
|
page._session.browser.runMicrotasks();
|
||||||
@@ -428,7 +428,7 @@ pub fn pageTest(comptime test_file: []const u8) !*Page {
|
|||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
|
|
||||||
try page.navigate(url, .{});
|
try page.navigate(url, .{}, .{ .push = null });
|
||||||
test_session.fetchWait(2000);
|
test_session.fetchWait(2000);
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user