diff --git a/src/browser/html/location.zig b/src/browser/html/location.zig
index 743375d9..af865141 100644
--- a/src/browser/html/location.zig
+++ b/src/browser/html/location.zig
@@ -29,10 +29,6 @@ pub const Location = struct {
/// Chrome -> chrome://new-tab-page/
/// Firefox -> about:newtab
/// Safari -> favorites://
- pub const default = Location{
- .url = .initWithoutSearchParams(Uri.parse("about:blank") catch unreachable),
- };
-
pub fn get_href(self: *Location, page: *Page) ![]const u8 {
return self.url.get_href(page);
}
@@ -45,16 +41,16 @@ pub const Location = struct {
return self.url.get_protocol();
}
- pub fn get_host(self: *Location, page: *Page) ![]const u8 {
- return self.url.get_host(page);
+ pub fn get_host(self: *Location) []const u8 {
+ return self.url.get_host();
}
pub fn get_hostname(self: *Location) []const u8 {
return self.url.get_hostname();
}
- pub fn get_port(self: *Location, page: *Page) ![]const u8 {
- return self.url.get_port(page);
+ pub fn get_port(self: *Location) []const u8 {
+ return self.url.get_port();
}
pub fn get_pathname(self: *Location) []const u8 {
@@ -65,8 +61,8 @@ pub const Location = struct {
return self.url.get_search(page);
}
- pub fn get_hash(self: *Location, page: *Page) ![]const u8 {
- return self.url.get_hash(page);
+ pub fn get_hash(self: *Location) []const u8 {
+ return self.url.get_hash();
}
pub fn get_origin(self: *Location, page: *Page) ![]const u8 {
diff --git a/src/browser/html/window.zig b/src/browser/html/window.zig
index 5e03c022..88647d0a 100644
--- a/src/browser/html/window.zig
+++ b/src/browser/html/window.zig
@@ -36,6 +36,8 @@ const Screen = @import("screen.zig").Screen;
const domcss = @import("../dom/css.zig");
const Css = @import("../css/css.zig").Css;
const EventHandler = @import("../events/event.zig").EventHandler;
+const URL = @import("../../url.zig").URL;
+const WebApiURL = @import("../url/url.zig").URL;
const Request = @import("../fetch/Request.zig");
const fetchFn = @import("../fetch/fetch.zig").fetch;
@@ -52,7 +54,7 @@ pub const Window = struct {
document: *parser.DocumentHTML,
target: []const u8 = "",
- location: Location = .default,
+ location: Location,
storage_shelf: ?*storage.Shelf = null,
// counter for having unique timer ids
@@ -75,17 +77,30 @@ pub const Window = struct {
const doc = parser.documentHTMLToDocument(html_doc);
try parser.documentSetDocumentURI(doc, "about:blank");
+ const native_url = URL.parse("about:blank", null) catch unreachable;
+
+ // Here we manually initialize; this is a special case and
+ // one should prefer constructor functions instead.
+ const url = WebApiURL{
+ .internal = native_url.internal,
+ .search_params = .{},
+ };
+
return .{
.document = html_doc,
+ .location = .{ .url = url },
.target = target orelse "",
.navigator = navigator orelse .{},
.performance = Performance.init(),
};
}
- pub fn replaceLocation(self: *Window, loc: Location) !void {
- self.location = loc;
- try parser.documentHTMLSetLocation(Location, self.document, &self.location);
+ pub fn replaceLocation(self: *Window, location: Location) !void {
+ // Remove current.
+ self.location.url.destructor();
+ // Put the new one.
+ self.location = location;
+ return parser.documentHTMLSetLocation(Location, self.document, &self.location);
}
pub fn replaceDocument(self: *Window, doc: *parser.DocumentHTML) !void {
diff --git a/src/browser/page.zig b/src/browser/page.zig
index 4355724d..25c883ff 100644
--- a/src/browser/page.zig
+++ b/src/browser/page.zig
@@ -861,7 +861,7 @@ pub const Page = struct {
self.window.setStorageShelf(
try self.session.storage_shed.getOrPut(try self.origin(self.arena)),
);
- //try self.window.replaceLocation(.{ .url = try self.url.toWebApi(self.arena) });
+ try self.window.replaceLocation(.{ .url = try self.url.toWebApi(self.arena) });
}
pub const MouseEvent = struct {
diff --git a/src/browser/storage/cookie.zig b/src/browser/storage/cookie.zig
index 4a821678..d104ec36 100644
--- a/src/browser/storage/cookie.zig
+++ b/src/browser/storage/cookie.zig
@@ -1,5 +1,4 @@
const std = @import("std");
-const Uri = std.Uri;
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;
@@ -209,7 +208,7 @@ pub const Cookie = struct {
// Invalid attribute values? Ignore.
// Duplicate attributes - use the last valid
// Value-less attributes with a value? Ignore the value
- pub fn parse(allocator: Allocator, uri: *const std.Uri, str: []const u8) !Cookie {
+ pub fn parse(allocator: Allocator, url: URL, str: []const u8) !Cookie {
try validateCookieString(str);
const cookie_name, const cookie_value, const rest = parseNameValue(str) catch {
@@ -396,7 +395,7 @@ pub const Cookie = struct {
pub fn parseDomain(arena: Allocator, maybe_url: ?URL, explicit_domain: ?[]const u8) ![]const u8 {
var encoded_host: ?[]const u8 = null;
if (maybe_url) |url| {
- const url_host = url.hostname();
+ const url_host = url.getHostname();
encoded_host = url_host;
}
diff --git a/src/browser/url/url.zig b/src/browser/url/url.zig
index 837a1560..d95a9871 100644
--- a/src/browser/url/url.zig
+++ b/src/browser/url/url.zig
@@ -127,9 +127,6 @@ pub const URL = struct {
pub fn _toString(self: *const URL, page: *Page) ![]const u8 {
return self.get_href(page);
}
- pub fn _toString(self: *const URL) []const u8 {
- return ada.getHref(self.internal);
- }
// Getters.
@@ -152,7 +149,13 @@ pub const URL = struct {
pub fn get_href(self: *const URL, page: *Page) ![]const u8 {
var w: Writer.Allocating = .init(page.arena);
- const href = ada.getHref(self.internal);
+ const maybe_href = ada.getHrefNullable(self.internal);
+ if (maybe_href.data == null) {
+ return "";
+ }
+
+ const href = maybe_href.data[0..maybe_href.length];
+
const comps = ada.getComponents(self.internal);
const has_hash = comps.hash_start != ada.URLOmitted;
diff --git a/src/tests/html/element.html b/src/tests/html/element.html
index 4de1f058..29f230b3 100644
--- a/src/tests/html/element.html
+++ b/src/tests/html/element.html
@@ -29,10 +29,11 @@