Open Bug 642457 Opened 13 years ago Updated 2 years ago

Too easy to misuse content-document-window-created notifications from a content script

Categories

(Core :: DOM: Core & HTML, defect, P5)

defect

Tracking

()

People

(Reporter: ted, Unassigned)

References

Details

In bug 549539, we added {chrome|content}-document-window-created observer service notifications. The intent was to provide a hook for third parties to add content-exposed APIs, so that they could transition away from enablePrivilege.

bug 582472 used that notification to add a SpecialPowers object to Mochitests. But, being forward-thinking, it also added support for e10s, so the observer was added in a content script.

In bug 641969, we discovered that this is broken, because the observer will get notifications about all windows, regardless of what tab they're in, but content scripts run per-tab.

This seems like a serious design flaw. Firefox is eventually going to move to e10s, and this API is broken by design in e10s. We shouldn't be encouraging people to rewrite enablePrivilege-using code to use an API that won't work with e10s. The SpecialPowers patch was reviewed by smaug, so if he didn't notice the problem initially, I have no faith that third parties will get it right.

Furthermore, bug 567357 added a DOM event that covers the same purpose, specifically for e10s usage. This seems like the thing we should be encouraging people to use, since it works correctly with e10s (and it's already in use in-tree: http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/content/extensions-content.js#211 )
Yesyes, the DOM event was for *exactly* this purpose.
I'm all for migrating existing code to the better API as well as documenting how other people should use it.

I don't know enough about e10s and event dispatch to know where and when to attach event listeners such that you get notified for all the relevant events here.
Priority: -- → P5
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.