Open Bug 2049770 Opened 19 days ago Updated 16 days ago

Move the Tabbrowser class to a shared .sys.mjs module

Categories

(Firefox :: Tabbed Browser, task)

task

Tracking

()

People

(Reporter: dao, Unassigned)

References

(Blocks 1 open bug)

Details

Follow-up to bug 1979688.

Today browser/components/tabbrowser/content/tabbrowser.js is loaded into each browser window via Services.scriptloader.loadSubScript(...) (browser/base/content/browser-main.js), defining window.Tabbrowser = class { ... }. Because every window evaluates the script separately, each window gets a distinct Tabbrowser class identity.

This matters for # private fields: their brand checks are per-class-identity, so a field made #-private in one window's class can't be read on another window's gBrowser. Cross-window tab swapping (swapBrowsers, swapBrowsersAndCloseOther) reaches into the other window's tabbrowser, so bug 1979688 had to keep _-prefixed accessor methods (_getTabProgressListener, _getTabProgressFilter, _setTabProgressListener) as a workaround instead of accessing the # fields directly.

Loading Tabbrowser as a single shared .sys.mjs module would give one class identity across all windows, allowing those fields to be truly #-private with direct cross-window access and removing the accessor shims.

Cost / blockers:

  • The file closes over per-window globals pervasively (~135 document., ~131 gBrowser, ~69 window. references); in a shared module those resolve to the system global and would need to become instance-relative (this.ownerGlobal, etc.).
  • The sibling TabProgressListener class and the new otherTabBrowser.documentGlobal.TabProgressListener(...) construction pattern capture the window too.
  • window/document would need to be passed into the constructor and threaded through, since custom-element registries are per-window.
Depends on: 1979688
You need to log in before you can comment on or make changes to this bug.