Closed Bug 1890547 Opened 1 year ago Closed 7 months ago

[meta] eliminate inline event handlers from the browser window

Categories

(Firefox :: General, task)

Desktop
All
task

Tracking

()

RESOLVED FIXED

People

(Reporter: Gijs, Unassigned)

References

(Blocks 2 open bugs)

Details

(Keywords: meta)

The practice of oncommand and onclick inline event handlers in browser.xhtml (browser.xul as-was) dates back to the Netscape days.

As one might expect, in a quarter of a century some stuff has changed. This practice is anachronistic, makes linting more difficult, automated tools like searchfox less effective (as they can't find symbols in the JS-in-HTML) and stops us adding a restrictive CSP to browser windows which would help defence in depth against various types of browser exploits.

We should move away from doing this.

Discussing with :Mossop, I think for an initial pass we'll likely move listeners that are in markup that ends up attached to the main DOM immediately to a single DOMContentLoaded handler or similar.

For the things in e.g. https://searchfox.org/mozilla-central/source/browser/base/content/appmenu-viewcache.inc.xhtml that isn't immediately accessible using getElementById, we'd likely either take a more case-by-case approach or use PanelMultiView.getViewNode to get hold of the nodes to add listeners at the same time.

This isn't ideal in that it creates a bit of a giant list of listeners (which also ends up being a single point of failure), and it would be nicer if all these listeners ended up somewhere related to their individual purposes, but the size of the problem is such that to make progress this is likely the expedient way of addressing this (with follow-up bugs used to perhaps distribute some of these listeners to more topical/lazy places in the code).

Depends on: 1890718
Depends on: 1891782
Depends on: 1891792

If we want to do this for the sake of hardening our parent process, do we need to ensure that other windows are also cleaned up? I'm not sure what other windows might exist, but I can think of the bookmarks manager, maybe printing preview and all sorts of prompts being in the parent.

(In reply to Frederik Braun [:freddy] from comment #1)

If we want to do this for the sake of hardening our parent process, do we need to ensure that other windows are also cleaned up?

Yes.

I'm not sure what other windows might exist, but I can think of the bookmarks manager, maybe printing preview and all sorts of prompts being in the parent.

Print-preview is normally tab-modal now. I don't know if we still have/support any other way of opening that. But we definitely have a few more, like the about dialog, the webrtc indicator window, etc. etc.

Anyway, the other windows I think would also be helpful and it would probably be useful to get a metabug on file for that. But I think the focus should be on the main browser window initially, both because it's large enough that it needs a dedicated burndown effort (can't easily be done in one giant patch) and because it is the main thing that also interacts with untrusted content processes (unlike the about dialog and bookmarks manager etc.).

Depends on: 1893068
Depends on: 1895490
Depends on: 1897477
Depends on: 1898764
Depends on: 1899518
Depends on: 1900381
Depends on: 1904302
Depends on: 1904798
Depends on: 1905632
Depends on: 1905692
Depends on: 1912403
Depends on: 1918615
Depends on: 1918723
Depends on: 1924466
Depends on: 1924971
Depends on: 1925488
Depends on: 1926815
Depends on: 1927155
Depends on: 1927408
Depends on: 1927475
Depends on: 1930841
Depends on: 1933915
Depends on: 1933917
Depends on: 1934875
Depends on: 1934922
Depends on: 1935378
Depends on: 1935670
Depends on: 1935688
Depends on: 1935945
Depends on: 1935959
Depends on: 1935974
Depends on: 1935992
No longer depends on: 1935992
Depends on: 1935994
No longer depends on: 1935994
Depends on: 1936231
Blocks: 1936336
No longer blocks: 1936336
Depends on: 1936336
Depends on: 1936519
Depends on: 1936523
Depends on: 1936525
Depends on: 1936573
Depends on: 1937533
Depends on: 1937545
Depends on: 1937548
Depends on: 1938075
Depends on: 1938883
Depends on: 1939553
Depends on: 1939582
Blocks: 1939584
See Also: → 1940445
Blocks: 1939582
No longer depends on: 1939582
Depends on: 1940921
No longer blocks: 1939584
Blocks: 1939584

Judging by our telemetry results we most likely found all inline event handlers in our own code.

Status: NEW → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.