Lightpanda: the headless browser designed for AI and automation
drop `is_subframe` and `notification`
Halil Durak486c88808023
diff --git a/src/network/HttpClient.zig b/src/network/HttpClient.zigindex ea9b35ffd..9430e00e5 100644--- a/src/network/HttpClient.zig+++ b/src/network/HttpClient.zig@@ -410,11 +410,7 @@ fn isUrlBlocked(self: *const Client, transfer: *const Transfer) bool {fn isAdblocked(self: *const Client, transfer: *const Transfer) bool {const blocker = if (self.network.adblocker) |*b| b else return false;var buffers: AdBlocker.Request.Buffers = undefined;- const target = AdBlocker.Request.fromHttp(- &transfer.req,- adblockSourceUrl(transfer),- &buffers,- ) orelse return false;+ const target = AdBlocker.Request.fromHttp(transfer, &buffers) orelse return false;const verdict = blocker.match(target);lp.metrics.adblock_verdicts.incr(verdict);return verdict == .blocked;@@ -1904,11 +1900,6 @@ pub const Request = struct {// Whether this request should (possibly) be throttled based on the RateLimiterthrottle: bool = false,- // Whether a `.document` request is loading a nested frame rather than the- // top-level page. The reason why is filter lists separate the two ($document vs- // $subdocument), and only ever block the latter.- is_subframe: bool = false,-// Set by syncRequest; only used to label the http_requests metric.sync: bool = false,@@ -2109,7 +2100,9 @@ pub const Owner = struct {// The parent frame's Owner; for a worker, its creating frame's. Outlives// this Owner: child frames are torn down before their parent, a worker- // before its frame.+ // before its frame. A `.document` request's owner is the frame it+ // navigates, so a parent here is what makes that load a nested frame's;+ // the adblocker tells $document from $subdocument by it.parent: ?*const Owner,// Copied onto every request made through this owner, see Request.@@ -4251,7 +4244,6 @@ const TestRequest = struct {/// The page embedding `document`, when the test wants a deeper chain.parent_document: [:0]const u8 = "",resource_type: Request.ResourceType = .document,- is_subframe: bool = false,internal: bool = false,};@@ -4282,7 +4274,6 @@ fn testIsUrlBlocked(client: *const Client, opts: TestRequest) bool {.method = .GET,.url = opts.url,.resource_type = opts.resource_type,- .is_subframe = opts.is_subframe,.internal = opts.internal,.shutdown_callback = noopShutdown,},@@ -4331,10 +4322,11 @@ test "HttpClient: adblock verdicts apply per request" {.resource_type = .xhr,}));- // A `.document` request is $subdocument only inside a nested frame.+ // A `.document` request is $subdocument only inside a nested frame,+ // which its owner chain tells: the navigated frame has a parent.try testing.expect(testIsUrlBlocked(&client, .{.url = "https://framed.example.com/",- .is_subframe = true,+ .document = "https://news.com/",}));try testing.expect(!testIsUrlBlocked(&client, .{ .url = "https://framed.example.com/" }));@@ -4352,16 +4344,13 @@ test "HttpClient: adblock verdicts apply per request" {}));// A top-level navigation is its own context: the page it was clicked on- // does not make it third-party...- try testing.expect(!testIsUrlBlocked(&client, .{- .url = "https://partied.example.com/",- .document = "https://news.com/",- }));+ // is not in its owner chain (it only travels as cookie_origin, which the+ // adblocker never reads), so nothing makes it third-party...+ try testing.expect(!testIsUrlBlocked(&client, .{ .url = "https://partied.example.com/" }));// ...but a subframe loading the same URL keeps its document's context.try testing.expect(testIsUrlBlocked(&client, .{.url = "https://partied.example.com/",.document = "https://news.com/",- .is_subframe = true,}));// The context is the issuing frame's document even under a cross-sitediff --git a/src/network/adblock/Engine.zig b/src/network/adblock/Engine.zigindex c92f7c146..37ef51cd2 100644--- a/src/network/adblock/Engine.zig+++ b/src/network/adblock/Engine.zig@@ -118,29 +118,31 @@ pub const Request = struct {return request;}- /// Builds the request `req` is matched as, `source` being the URL (or- /// origin serialization) of the document it was issued from. null when- /// there is none.- pub fn fromHttp(- req: *const HttpClient.Request,- source_url: ?[]const u8,- buffers: *Buffers,- ) ?Request {+ pub fn fromHttp(transfer: *const HttpClient.Transfer, buffers: *Buffers) ?Request {+ const req = &transfer.req;const url = normalizeUrl(req.url, &buffers.url) orelse return null;- // Matching top-level nav against the page it was clicked on would make- // every link third party.- const top_level = req.resource_type == .document and !req.is_subframe;- const source_host = if (top_level)- ""- else if (source_url) |u|- URL.getOriginHostname(u)- else- "";+ var owner: ?*const HttpClient.Owner = transfer.owner;+ var subframe = false;+ if (req.resource_type == .document) {+ owner = if (owner) |o| o.parent else null;+ subframe = owner != null;+ }+ const source_url = if (owner) |o| o.documentUrl() else null;+ const source_host = if (source_url) |u| URL.getOriginHostname(u) else "";if (source_host.len > buffers.source.len) return null;const source = std.ascii.lowerString(&buffers.source, source_host);- return .init(url, source, resourceType(req));+ const resource_type: NetworkFilter.ResourceTypes = switch (req.resource_type) {+ .document => if (subframe) .{ .subdocument = true } else .{ .document = true },+ .script => .{ .script = true },+ .stylesheet => .{ .stylesheet = true },+ .xhr, .fetch => .{ .xmlhttprequest = true },+ .image => .{ .image = true },+ .eventsource => .{ .other = true },+ };++ return .init(url, source, resource_type);}inline fn tokens(self: *const Request) []const u32 {@@ -163,17 +165,6 @@ pub const Request = struct {_ = std.ascii.lowerString(out[upper..], trimmed[upper..]);return out;}-- fn resourceType(req: *const HttpClient.Request) NetworkFilter.ResourceTypes {- return switch (req.resource_type) {- .document => if (req.is_subframe) .{ .subdocument = true } else .{ .document = true },- .script => .{ .script = true },- .stylesheet => .{ .stylesheet = true },- .xhr, .fetch => .{ .xmlhttprequest = true },- .image => .{ .image = true },- .eventsource => .{ .other = true },- };- }};/// How often each token appears across every indexed filter. Shared by the