mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
Merge branch 'zigdom-history-fixes' into zigdom
This commit is contained in:
@@ -75,7 +75,7 @@ pub fn init(self: *Session, browser: *Browser) !void {
|
||||
.storage_shed = .{},
|
||||
.arena = session_allocator,
|
||||
.cookie_jar = storage.Cookie.Jar.init(allocator),
|
||||
.navigation = Navigation.init(session_allocator),
|
||||
.navigation = .{},
|
||||
.history = .{},
|
||||
.transfer_arena = browser.transfer_arena.allocator(),
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
testing.expectEqual('auto', history.scrollRestoration);
|
||||
testing.expectEqual(null, history.state)
|
||||
|
||||
history.pushState({ testInProgress: true }, null, 'http://127.0.0.1:9589/html/history/history_after_nav.html');
|
||||
history.pushState({ testInProgress: true }, null, 'http://127.0.0.1:9589/html/history/history_after_nav.skip.html');
|
||||
testing.expectEqual({ testInProgress: true }, history.state);
|
||||
|
||||
history.pushState({ testInProgress: false }, null, 'http://127.0.0.1:9589/xhr/json');
|
||||
|
||||
@@ -2,16 +2,13 @@
|
||||
<script src="../../testing.js"></script>
|
||||
|
||||
<script id=history2>
|
||||
history.pushState(
|
||||
{"new": "field", testComplete: true },
|
||||
null,
|
||||
'http://127.0.0.1:9589/html/history/history_after_nav.html'
|
||||
);
|
||||
let state = { "new": "field", testComplete: true, testInProgress: true };
|
||||
history.replaceState(state, "");
|
||||
history.pushState(null, null, 'http://127.0.0.1:9589/html/history/history_after_nav.skip.html');
|
||||
|
||||
let popstateEventFired = false;
|
||||
let popstateEventState = null;
|
||||
|
||||
// uses the window event listener.
|
||||
window.onpopstate = (event) => {
|
||||
popstateEventFired = true;
|
||||
popstateEventState = event.state;
|
||||
@@ -19,7 +16,7 @@
|
||||
|
||||
testing.eventually(() => {
|
||||
testing.expectEqual(true, popstateEventFired);
|
||||
testing.expectEqual(true, popstateEventState.testComplete);
|
||||
testing.expectEqual(state, popstateEventState);
|
||||
})
|
||||
|
||||
history.back();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../../testing.js"></script>
|
||||
|
||||
<script id=history2>
|
||||
<script id=history-after-nav>
|
||||
testing.expectEqual(true, history.state && history.state.testInProgress);
|
||||
</script>
|
||||
@@ -12,7 +12,7 @@
|
||||
const currentIndex = navigation.currentEntry.index;
|
||||
|
||||
navigation.navigate(
|
||||
'http://localhost:9589/html/navigation/navigation2.html',
|
||||
'http://localhost:9589/html/navigation/navigation_after_nav.skip.html',
|
||||
{ state: { currentIndex: currentIndex, navTestInProgress: true } }
|
||||
);
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<script src="../../testing.js"></script>
|
||||
|
||||
<script id=navigation2>
|
||||
<script id=navigation-after-nav>
|
||||
const state = navigation.currentEntry.getState();
|
||||
testing.expectEqual(true, state.navTestInProgress);
|
||||
testing.expectEqual(state.currentIndex + 1, navigation.currentEntry.index);
|
||||
@@ -38,7 +38,6 @@ const NavigationCurrentEntryChangeEvent = @import("../event/NavigationCurrentEnt
|
||||
const NavigationEventTarget = @import("NavigationEventTarget.zig");
|
||||
|
||||
_proto: *NavigationEventTarget = undefined,
|
||||
_arena: std.mem.Allocator,
|
||||
_current_navigation_kind: ?NavigationKind = null,
|
||||
|
||||
_index: usize = 0,
|
||||
@@ -47,10 +46,6 @@ _entries: std.ArrayList(*NavigationHistoryEntry) = .empty,
|
||||
_next_entry_id: usize = 0,
|
||||
_activation: ?NavigationActivation = null,
|
||||
|
||||
pub fn init(arena: std.mem.Allocator) Navigation {
|
||||
return Navigation{ ._arena = arena };
|
||||
}
|
||||
|
||||
fn asEventTarget(self: *Navigation) *EventTarget {
|
||||
return self._proto.asEventTarget();
|
||||
}
|
||||
@@ -171,7 +166,7 @@ pub fn pushEntry(
|
||||
page: *Page,
|
||||
dispatch: bool,
|
||||
) !*NavigationHistoryEntry {
|
||||
const arena = self._arena;
|
||||
const arena = page._session.arena;
|
||||
const url = try arena.dupeZ(u8, _url);
|
||||
|
||||
// truncates our history here.
|
||||
@@ -220,7 +215,7 @@ pub fn replaceEntry(
|
||||
page: *Page,
|
||||
dispatch: bool,
|
||||
) !*NavigationHistoryEntry {
|
||||
const arena = self._arena;
|
||||
const arena = page._session.arena;
|
||||
const url = try arena.dupeZ(u8, _url);
|
||||
|
||||
const previous = self.getCurrentEntry();
|
||||
@@ -263,7 +258,7 @@ pub fn navigateInner(
|
||||
kind: NavigationKind,
|
||||
page: *Page,
|
||||
) !NavigationReturn {
|
||||
const arena = self._arena;
|
||||
const arena = page._session.arena;
|
||||
const url = _url orelse return error.MissingURL;
|
||||
|
||||
// https://github.com/WICG/navigation-api/issues/95
|
||||
@@ -289,7 +284,7 @@ pub fn navigateInner(
|
||||
|
||||
_ = try self.pushEntry(url, .{ .source = .navigation, .value = state }, page, true);
|
||||
} else {
|
||||
try page.navigate(url, .{ .reason = .navigation, .kind = kind });
|
||||
try page.scheduleNavigation(url, .{ .reason = .navigation, .kind = kind }, .script);
|
||||
}
|
||||
},
|
||||
.replace => |state| {
|
||||
@@ -302,7 +297,7 @@ pub fn navigateInner(
|
||||
|
||||
_ = try self.replaceEntry(url, .{ .source = .navigation, .value = state }, page, true);
|
||||
} else {
|
||||
try page.navigate(url, .{ .reason = .navigation, .kind = kind });
|
||||
try page.scheduleNavigation(url, .{ .reason = .navigation, .kind = kind }, .script);
|
||||
}
|
||||
},
|
||||
.traverse => |index| {
|
||||
@@ -315,11 +310,11 @@ pub fn navigateInner(
|
||||
// todo: Fire navigate event
|
||||
finished.resolve("navigation traverse", {});
|
||||
} else {
|
||||
try page.navigate(url, .{ .reason = .navigation, .kind = kind });
|
||||
try page.scheduleNavigation(url, .{ .reason = .navigation, .kind = kind }, .script);
|
||||
}
|
||||
},
|
||||
.reload => {
|
||||
try page.navigate(url, .{ .reason = .navigation, .kind = kind });
|
||||
try page.scheduleNavigation(url, .{ .reason = .navigation, .kind = kind }, .script);
|
||||
},
|
||||
}
|
||||
|
||||
@@ -338,8 +333,9 @@ pub fn navigateInner(
|
||||
}
|
||||
|
||||
pub fn navigate(self: *Navigation, _url: [:0]const u8, _opts: ?NavigateOptions, page: *Page) !NavigationReturn {
|
||||
const arena = page._session.arena;
|
||||
const opts = _opts orelse NavigateOptions{};
|
||||
const json = if (opts.state) |state| state.toJson(self._arena) catch return error.DataClone else null;
|
||||
const json = if (opts.state) |state| state.toJson(arena) catch return error.DataClone else null;
|
||||
|
||||
const kind: NavigationKind = if (opts.history) |history|
|
||||
if (std.mem.eql(u8, "replace", history)) .{ .replace = json } else .{ .push = json }
|
||||
@@ -355,7 +351,7 @@ pub const ReloadOptions = struct {
|
||||
};
|
||||
|
||||
pub fn reload(self: *Navigation, _opts: ?ReloadOptions, page: *Page) !NavigationReturn {
|
||||
const arena = self._arena;
|
||||
const arena = page._session.arena;
|
||||
|
||||
const opts = _opts orelse ReloadOptions{};
|
||||
const entry = self.getCurrentEntry();
|
||||
@@ -397,7 +393,7 @@ pub const UpdateCurrentEntryOptions = struct {
|
||||
};
|
||||
|
||||
pub fn updateCurrentEntry(self: *Navigation, options: UpdateCurrentEntryOptions, page: *Page) !void {
|
||||
const arena = self._arena;
|
||||
const arena = page._session.arena;
|
||||
|
||||
const previous = self.getCurrentEntry();
|
||||
self.getCurrentEntry()._state = .{
|
||||
|
||||
@@ -62,13 +62,9 @@ pub fn main() !void {
|
||||
continue;
|
||||
}
|
||||
|
||||
// These are crashing, comment this out to skip them.
|
||||
// if (std.mem.indexOf(u8, entry.basename, "navigation") != null) {
|
||||
// continue;
|
||||
// }
|
||||
// if (std.mem.indexOf(u8, entry.basename, "history") != null) {
|
||||
// continue;
|
||||
// }
|
||||
if (std.mem.endsWith(u8, entry.basename, ".skip.html")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filter) |f| {
|
||||
if (std.mem.indexOf(u8, entry.path, f) == null) {
|
||||
|
||||
Reference in New Issue
Block a user