Closed Bug 1798960 Opened 2 years ago Closed 2 years ago

Allow frontend consumers to subscribe to cookie banner handling events via nsICookieBannerService

Categories

(Core :: Privacy: Anti-Tracking, task, P2)

task

Tracking

()

RESOLVED FIXED
109 Branch
Tracking Status
firefox109 --- fixed

People

(Reporter: pbz, Assigned: pbz)

References

(Blocks 1 open bug)

Details

Attachments

(7 files, 1 obsolete file)

We can use a similar pattern to nsIWebProgressListener. The frontend component subscribing to cookie banner handling signals can implement an interface with a method to be called whenever we handle a banner.

Since banners can be handled either via CookieBannerParent/Child (clicking) or nsICookieInjector, nsICookieBannerService needs to accept calls from both of these components:

Banner Clicking

For the clicking code we can simply call into the service from here: https://searchfox.org/mozilla-central/rev/49011d374b626d5f0e7dc751a8a57365878e65f1/toolkit/components/cookiebanners/CookieBannerChild.jsm#223

Cookie Injector

The cookie injector should only send this signal to the service if it sets a cookie that has previously not been set to avoid duplicate notifications for sites where we have already handled the banner. This is a bit tricky to determine since we usually only set session cookies. We might have to add a persistent store to keep track of which sites we handled via cookie injection. We can also consider it out of scope for now and focus only on the clicking component.

Would it make sense to also expose this as some state on gProtectionsHandler, since the UI is being integrated into the protections doorhanger and the glowing state of the shield toolbar button?

(In reply to Jared Hirsch [:jhirsch] (he/him) (Needinfo please) from comment #1)

Would it make sense to also expose this as some state on gProtectionsHandler, since the UI is being integrated into the protections doorhanger and the glowing state of the shield toolbar button?

Either that or gIdentityHandler, which I think is a slightly better fit since it handles the identity icons too.

After some good pointers from :emilio I'm actually considering dispatching a custom chrome-only event that these components can listen for on the chrome window. That should make the implementation a bit simpler.

Assignee: nobody → pbz
Status: NEW → ASSIGNED
Blocks: 1795075
No longer blocks: cookie-banners-android
Blocks: 1797568
Attachment #9301869 - Attachment is obsolete: true

I misunderstood the exact requirements here. Seems like we need multiple events.

A) A cookie banner is detected, but the handling feature is disabled => dispatch a "cookiebannerdetected" event
B) A cookie banner is detected and handled => First dispatch a "cookiebannerdetected" event, then a "cookiebannerhandled" event
C) The mechanism is turned off entirely, no events should be dispatched.

For A) to work we need to add a new cookie banner service mode, that enables the cookie banner service and serves rules, but prevents the click and the cookie injection component from acting on cookie banners. The click component should only perform the detection and dispatch events.

Blocks: 1800102
Blocks: 1800521
Pushed by pzuhlcke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/1810be532880 Dispatch a cookiebannerhandled event when the click component handled a banner. r=timhuang https://hg.mozilla.org/integration/autoland/rev/ddd6e63f05dc Add a new cookie banner service mode MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/3ab8c890086d Do not enable nsCookieInjector for service mode MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/9b95f762751a Dispatch cookiebannerdetected events when CookieBannerChild detects a banner and integrate with MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/d4d687020c42 Update tests for MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/955c6861b6df Add cookie banner clicking event tests. r=timhuang https://hg.mozilla.org/integration/autoland/rev/37160a6f6d6e Hide cookie banner handling per-site toggle in MODE_DETECT_ONLY. r=timhuang

Backed out for causing bc failures on browser_startup_content_subframe.js.

Push with failures

Failure log

Backout link

[task 2022-11-14T21:08:02.322Z] 21:08:02     INFO - GECKO(7346) | [Child 8921: Main Thread]: I/DocShellAndDOMWindowLeak ++DOMWINDOW == 3 (7fc8c5f36000) [pid = 8921] [serial = 3] [outer = 7fc8e1491d90]
[task 2022-11-14T21:08:02.337Z] 21:08:02     INFO - Console message: [JavaScript Warning: "This page is in Quirks Mode. Page layout may be impacted. For Standards Mode use “<!DOCTYPE html>”." {file: "http://example.com/browser/browser/base/content/test/performance/file_empty.html" line: 0}]
[task 2022-11-14T21:08:02.434Z] 21:08:02     INFO - TEST-INFO | started process screentopng
[task 2022-11-14T21:08:02.682Z] 21:08:02     INFO - TEST-INFO | screentopng: exit 0
[task 2022-11-14T21:08:02.686Z] 21:08:02     INFO - Buffered messages logged at 21:08:01
[task 2022-11-14T21:08:02.687Z] 21:08:02     INFO - Entering test bound 
[task 2022-11-14T21:08:02.687Z] 21:08:02     INFO - Buffered messages finished
[task 2022-11-14T21:08:02.688Z] 21:08:02     INFO - TEST-UNEXPECTED-FAIL | browser/base/content/test/performance/browser_startup_content_subframe.js | should have no unexpected modules loaded on content process startup - Got 1, expected +0
[task 2022-11-14T21:08:02.688Z] 21:08:02     INFO - Stack trace:
[task 2022-11-14T21:08:02.689Z] 21:08:02     INFO - chrome://mochikit/content/browser-test.js:test_is:1485
[task 2022-11-14T21:08:02.689Z] 21:08:02     INFO - chrome://mochitests/content/browser/browser/base/content/test/performance/head.js:checkLoadedScripts:898
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - chrome://mochitests/content/browser/browser/base/content/test/performance/browser_startup_content_subframe.js:null:146
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - Not taking screenshot here: see the one that was previously logged
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - TEST-UNEXPECTED-FAIL | browser/base/content/test/performance/browser_startup_content_subframe.js | Unexpected modules loaded during content process startup: resource://gre/modules/PrivateBrowsingUtils.sys.mjs - 
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - Stack trace:
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - 0 get #isPrivateBrowsing() ["resource://gre/actors/CookieBannerChild.jsm":89:4]
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - 1 get #isEnabled() ["resource://gre/actors/CookieBannerChild.jsm":100:8]
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - 2 handleEvent() ["resource://gre/actors/CookieBannerChild.jsm":70:8]
[task 2022-11-14T21:08:02.690Z] 21:08:02     INFO - Console message: [JavaScript Warning: "Partitioned cookie or storage access was provided to “http://example.com/browser/browser/base/content/test/performance/file_empty.html” because it is loaded in the third-party context and dynamic state partitioning is enabled."]
[task 2022-11-14T21:08:02.693Z] 21:08:02     INFO - TEST-PASS | browser/base/content/test/performance/browser_startup_content_subframe.js | intermittent entry resource://gre/modules/nsAsyncShutdown.jsm for content process startup must exist - 
Flags: needinfo?(pbz)
Pushed by pzuhlcke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c1319c1bb849 Dispatch a cookiebannerhandled event when the click component handled a banner. r=timhuang https://hg.mozilla.org/integration/autoland/rev/4faa3165085b Add a new cookie banner service mode MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/468b3bfd4d0a Do not enable nsCookieInjector for service mode MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/d4dcb9dc697f Dispatch cookiebannerdetected events when CookieBannerChild detects a banner and integrate with MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/a5961ee60155 Update tests for MODE_DETECT_ONLY. r=timhuang https://hg.mozilla.org/integration/autoland/rev/617a4ff0e8ad Add cookie banner clicking event tests. r=timhuang https://hg.mozilla.org/integration/autoland/rev/24083a0e31cf Hide cookie banner handling per-site toggle in MODE_DETECT_ONLY. r=timhuang
Flags: needinfo?(pbz)
Regressions: 1800653
Blocks: 1801084
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: