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