Closed Bug 1597107 Opened 5 years ago Closed 5 years ago

listener not removed when removing permission with permissions.remove

Categories

(WebExtensions :: General, defect, P5)

defect

Tracking

(firefox-esr68 wontfix, firefox75 wontfix, firefox76 wontfix, firefox77 fixed)

RESOLVED FIXED
mozilla77
Tracking Status
firefox-esr68 --- wontfix
firefox75 --- wontfix
firefox76 --- wontfix
firefox77 --- fixed

People

(Reporter: kernp25, Assigned: mixedpuppy)

References

(Regression)

Details

(Keywords: polish, regression)

Attachments

(1 file)

1.47 KB, application/x-zip-compressed
Details

If you do:

browser.permissions.request({
  permissions: ["notifications"]
})

then

browser.notifications.onClicked.addListener(onClicked);

and finally

browser.permissions.remove({
  permissions: ["notifications"]
})

the listener will not be removed.

Because, after you do

browser.permissions.remove({
  permissions: ["notifications"]
})

browser.notifications is undefined and the listener added by the add-on should also be removed. Because the add-on can no longer use browser.notifications. So it doesn't make sense, to keep the listener alive.

Attached file background.zip
Flags: needinfo?(andrew.swan)

Should

browser.permissions.remove({
  permissions: ["notifications"]
})

also remove the listener?

I have a test add-on attached that shows the problem:
It should not log the message "already has listener" to the console.

Flags: needinfo?(hani.yacoub)

First, please don't needinfo multiple people without asking specific questions and waiting a reasonable time for a reply.

(In reply to kernp25 from comment #0)

browser.notifications is undefined and the listener added by the add-on should also be removed. Because the add-on can no longer use browser.notifications. So it doesn't make sense, to keep the listener alive.

I'm not sure "it doesn't make sense" is a strong enough reason to write and maintain more code to clean up a listener in this case -- it appears to me that the listener won't ever actually be invoked so does it do any actual harm to keep it around? If you want to propose a change to the current behavior, please include a more detailed explanation of why the change would be valuable and direct a question to a current member of the addons engineering team (I think :robwu has been the most active developer of the notifications api, he would be a good place to start)

Flags: needinfo?(hani.yacoub)
Flags: needinfo?(andrew.swan)

This is not specific to the notifications API, but a bindings issue.

The console shows the following error:

map.keys is not a function ExtensionChild.jsm:1033

https://searchfox.org/mozilla-central/rev/524bed6dfbc5ae21c62632d83b7573448b29e0ac/toolkit/components/extensions/ExtensionChild.jsm#1033

To fix this, we should iterate over map.listeners.keys() instead of map.keys(), and add a regression test. Use .hasListener to check whether a listener has been removed and/or trigger the event to check whether the event has been dispatched.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Regressed by: 1305217
Keywords: polish
Priority: -- → P5

This is actually fixed in the patch for bug 1630419, and the test in that patch would fail without the fix.

Depends on: 1630419
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Assignee: nobody → mixedpuppy
Target Milestone: --- → mozilla77
Has Regression Range: --- → yes
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: