mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-09-30 00:14:54 -04:00
make indexedb in-memory only (for now)
This commit is contained in:
4 files changed
+8
-74
No files matched your search
+1
-38
@@ -85,37 +85,7 @@ fn logLevelValidator(_: Allocator, args: *std.process.ArgIterator) !?log.Level {
|
||||
}
|
||||
|
||||
/// Common CLI args.
|
||||
const CommonOptions = .{
|
||||
.{ .name = "obey_robots", .type = bool },
|
||||
.{ .name = "proxy_bearer_token", .type = ?[:0]const u8 },
|
||||
.{ .name = "http_proxy", .type = ?[:0]const u8 },
|
||||
.{ .name = "http_max_concurrent", .type = ?u8 },
|
||||
.{ .name = "http_max_host_open", .type = ?u8 },
|
||||
.{ .name = "http_timeout", .type = ?u31 },
|
||||
.{ .name = "http_connect_timeout", .type = ?u31 },
|
||||
.{ .name = "http_max_response_size", .type = ?usize },
|
||||
.{ .name = "ws_max_concurrent", .type = ?u8 },
|
||||
.{ .name = "insecure_disable_tls_host_verification", .type = bool },
|
||||
.{ .name = "log_level", .type = ?log.Level, .validator = logLevelValidator },
|
||||
.{ .name = "log_format", .type = ?log.Format },
|
||||
.{ .name = "log_filter_scopes", .type = log.FilterRule, .multiple = true, .validator = logFilterScopesValidator },
|
||||
.{ .name = "user_agent_suffix", .type = ?[]const u8 },
|
||||
.{ .name = "http_cache_dir", .type = ?[]const u8 },
|
||||
.{ .name = "web_bot_auth_key_file", .type = ?[]const u8 },
|
||||
.{ .name = "web_bot_auth_keyid", .type = ?[]const u8 },
|
||||
.{ .name = "web_bot_auth_domain", .type = ?[]const u8 },
|
||||
.{ .name = "user_agent", .type = ?[]const u8 },
|
||||
.{ .name = "block_private_networks", .type = bool },
|
||||
.{ .name = "block_cidrs", .type = ?[]const u8 },
|
||||
.{ .name = "cookie", .type = ?[]const u8 },
|
||||
.{ .name = "cookie_jar", .type = ?[]const u8 },
|
||||
.{ .name = "storage_engine", .type = ?Storage.EngineType },
|
||||
.{ .name = "storage_sqlite_path", .type = ?[:0]const u8 },
|
||||
.{ .name = "disable_subframes", .type = bool },
|
||||
.{ .name = "disable_workers", .type = bool },
|
||||
.{ .name = "enable_external_stylesheets", .type = bool },
|
||||
.{ .name = "indexdb_dir", .type = ?[:0]const u8 },
|
||||
};
|
||||
const CommonOptions = .{ .{ .name = "obey_robots", .type = bool }, .{ .name = "proxy_bearer_token", .type = ?[:0]const u8 }, .{ .name = "http_proxy", .type = ?[:0]const u8 }, .{ .name = "http_max_concurrent", .type = ?u8 }, .{ .name = "http_max_host_open", .type = ?u8 }, .{ .name = "http_timeout", .type = ?u31 }, .{ .name = "http_connect_timeout", .type = ?u31 }, .{ .name = "http_max_response_size", .type = ?usize }, .{ .name = "ws_max_concurrent", .type = ?u8 }, .{ .name = "insecure_disable_tls_host_verification", .type = bool }, .{ .name = "log_level", .type = ?log.Level, .validator = logLevelValidator }, .{ .name = "log_format", .type = ?log.Format }, .{ .name = "log_filter_scopes", .type = log.FilterRule, .multiple = true, .validator = logFilterScopesValidator }, .{ .name = "user_agent_suffix", .type = ?[]const u8 }, .{ .name = "http_cache_dir", .type = ?[]const u8 }, .{ .name = "web_bot_auth_key_file", .type = ?[]const u8 }, .{ .name = "web_bot_auth_keyid", .type = ?[]const u8 }, .{ .name = "web_bot_auth_domain", .type = ?[]const u8 }, .{ .name = "user_agent", .type = ?[]const u8 }, .{ .name = "block_private_networks", .type = bool }, .{ .name = "block_cidrs", .type = ?[]const u8 }, .{ .name = "cookie", .type = ?[]const u8 }, .{ .name = "cookie_jar", .type = ?[]const u8 }, .{ .name = "storage_engine", .type = ?Storage.EngineType }, .{ .name = "storage_sqlite_path", .type = ?[:0]const u8 }, .{ .name = "disable_subframes", .type = bool }, .{ .name = "disable_workers", .type = bool }, .{ .name = "enable_external_stylesheets", .type = bool } };
|
||||
|
||||
fn dumpValidator(_: Allocator, args: *std.process.ArgIterator) !?DumpFormat {
|
||||
// Peek next argument.
|
||||
@@ -568,13 +538,6 @@ pub fn storageSqlitePath(self: *const Config) ?[:0]const u8 {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn indexDBDir(self: *const Config) ?[:0]const u8 {
|
||||
return switch (self.mode) {
|
||||
inline .serve, .fetch, .mcp, .agent => |opts| opts.indexdb_dir,
|
||||
else => unreachable,
|
||||
};
|
||||
}
|
||||
|
||||
pub const DumpFormat = enum {
|
||||
html,
|
||||
markdown,
|
||||
|
||||
@@ -159,7 +159,7 @@ pub fn init(self: *Session, browser: *Browser, notification: *Notification) !voi
|
||||
// The prototype (EventTarget) for Navigation is created when a Frame is created.
|
||||
.navigation = .{ ._proto = undefined },
|
||||
.storage_shed = .{},
|
||||
.idb = IdbManager.init(allocator, browser.app.config.indexDBDir()),
|
||||
.idb = IdbManager.init(allocator),
|
||||
.browser = browser,
|
||||
.notification = notification,
|
||||
.cookie_jar = storage.Cookie.Jar.init(allocator, notification),
|
||||
|
||||
@@ -27,11 +27,10 @@ const Allocator = std.mem.Allocator;
|
||||
const Manager = @This();
|
||||
|
||||
allocator: Allocator,
|
||||
base_dir: []const u8,
|
||||
engines: std.StringHashMapUnmanaged(*Engine) = .empty,
|
||||
|
||||
pub fn init(allocator: Allocator, base_dir: ?[]const u8) Manager {
|
||||
return .{ .allocator = allocator, .base_dir = base_dir orelse ":memory:" };
|
||||
pub fn init(allocator: Allocator) Manager {
|
||||
return .{ .allocator = allocator };
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Manager) void {
|
||||
@@ -55,7 +54,7 @@ pub fn engineForOrigin(self: *Manager, origin: []const u8) !*Engine {
|
||||
const engine = try self.allocator.create(Engine);
|
||||
errdefer self.allocator.destroy(engine);
|
||||
|
||||
engine.* = try self.open(origin);
|
||||
engine.* = try Engine.open(":memory:");
|
||||
errdefer engine.close();
|
||||
|
||||
gop.key_ptr.* = try self.allocator.dupe(u8, origin);
|
||||
@@ -63,29 +62,9 @@ pub fn engineForOrigin(self: *Manager, origin: []const u8) !*Engine {
|
||||
return engine;
|
||||
}
|
||||
|
||||
fn open(self: *Manager, origin: []const u8) !Engine {
|
||||
if (std.mem.eql(u8, self.base_dir, ":memory:")) {
|
||||
return Engine.open(":memory:");
|
||||
}
|
||||
|
||||
// we hash the origin for two reason:
|
||||
// 1 - it fixes the length, so we don't have to worry about illegally long filename
|
||||
// 2 - It removes any unsafe characters
|
||||
var digest: [16]u8 = undefined;
|
||||
std.crypto.hash.Blake3.hash(origin, &digest, .{});
|
||||
var name_buf: [64]u8 = undefined;
|
||||
const file_name = std.fmt.bufPrint(&name_buf, "idb-{x}.sqlite", .{&digest}) catch unreachable;
|
||||
|
||||
const path = try std.fs.path.joinZ(self.allocator, &.{ self.base_dir, file_name });
|
||||
defer self.allocator.free(path);
|
||||
|
||||
log.debug(.storage, "idb open", .{ .origin = origin, .path = path });
|
||||
return Engine.open(path);
|
||||
}
|
||||
|
||||
const testing = @import("../../../../testing.zig");
|
||||
test "IDB - Manager: same origin returns same engine, distinct origins differ" {
|
||||
var mgr = Manager.init(testing.allocator, null);
|
||||
var mgr = Manager.init(testing.allocator);
|
||||
defer mgr.deinit();
|
||||
|
||||
const a1 = try mgr.engineForOrigin("https://a.com");
|
||||
@@ -97,7 +76,7 @@ test "IDB - Manager: same origin returns same engine, distinct origins differ" {
|
||||
}
|
||||
|
||||
test "IDB - Manager: in-memory engines are origin-isolated" {
|
||||
var mgr = Manager.init(testing.allocator, null);
|
||||
var mgr = Manager.init(testing.allocator);
|
||||
defer mgr.deinit();
|
||||
|
||||
const a = try mgr.engineForOrigin("https://a.com");
|
||||
@@ -108,12 +87,7 @@ test "IDB - Manager: in-memory engines are origin-isolated" {
|
||||
}
|
||||
|
||||
test "IDB - Manager: on-disk engines hash to per-origin files, isolated" {
|
||||
var tmp = std.testing.tmpDir(.{});
|
||||
defer tmp.cleanup();
|
||||
const dir = try tmp.dir.realpathAlloc(testing.allocator, ".");
|
||||
defer testing.allocator.free(dir);
|
||||
|
||||
var mgr = Manager.init(testing.allocator, dir);
|
||||
var mgr = Manager.init(testing.allocator);
|
||||
defer mgr.deinit();
|
||||
|
||||
// A long origin (hostname near the 253-byte limit) must still open: the
|
||||
|
||||
@@ -367,8 +367,5 @@
|
||||
\\ --storage-sqlite-path <PATH>
|
||||
\\ Path to the SQLite database file for persistent storage.
|
||||
\\ Use ":memory:" for in-memory storage.
|
||||
\\ --indexdb_dir <PATH>
|
||||
\\ Directory to store an SQLite database for IndexDB.
|
||||
\\ Defaults to ":memory:"
|
||||
,
|
||||
}
|
||||
Reference in new issue
Block a user