@@ -17,6 +17,8 @@ const apiweb = @import("../apiweb.zig");
1717const Window = @import ("../html/window.zig" ).Window ;
1818const Walker = @import ("../dom/walker.zig" ).WalkerDepthFirst ;
1919
20+ const storage = @import ("../storage/storage.zig" );
21+
2022const FetchResult = std .http .Client .FetchResult ;
2123
2224const log = std .log .scoped (.browser );
@@ -69,6 +71,8 @@ pub const Session = struct {
6971 env : Env = undefined ,
7072 loop : Loop ,
7173 window : Window ,
74+ // TODO move the shed to the browser?
75+ storageShed : storage.Shed ,
7276
7377 jstypes : [Types .len ]usize = undefined ,
7478
@@ -81,6 +85,7 @@ pub const Session = struct {
8185 .window = Window .create (null ),
8286 .loader = Loader .init (alloc ),
8387 .loop = try Loop .init (alloc ),
88+ .storageShed = storage .Shed .init (alloc ),
8489 };
8590
8691 self .env = try Env .init (self .arena .allocator (), & self .loop );
@@ -95,6 +100,7 @@ pub const Session = struct {
95100
96101 self .loader .deinit ();
97102 self .loop .deinit ();
103+ self .storageShed .deinit ();
98104 self .alloc .destroy (self );
99105 }
100106
@@ -116,6 +122,7 @@ pub const Page = struct {
116122 // handle url
117123 rawuri : ? []const u8 = null ,
118124 uri : std.Uri = undefined ,
125+ origin : ? []const u8 = null ,
119126
120127 raw_data : ? []const u8 = null ,
121128
@@ -169,6 +176,15 @@ pub const Page = struct {
169176 self .rawuri = try alloc .dupe (u8 , uri );
170177 self .uri = std .Uri .parse (self .rawuri .? ) catch try std .Uri .parseWithoutScheme (self .rawuri .? );
171178
179+ // prepare origin value.
180+ var buf = std .ArrayList (u8 ).init (alloc );
181+ defer buf .deinit ();
182+ try self .uri .writeToStream (.{
183+ .scheme = true ,
184+ .authority = true ,
185+ }, buf .writer ());
186+ self .origin = try buf .toOwnedSlice ();
187+
172188 // TODO handle fragment in url.
173189
174190 // load the data
@@ -237,6 +253,9 @@ pub const Page = struct {
237253 // TODO set the referrer to the document.
238254
239255 self .session .window .replaceDocument (html_doc );
256+ self .session .window .setStorageShelf (
257+ try self .session .storageShed .getOrPut (self .origin orelse "null" ),
258+ );
240259
241260 // https://html.spec.whatwg.org/#read-html
242261
0 commit comments