Closed Bug 2064185 Opened 2 days ago Closed 12 hours ago

Remove the remaining bare ChromeUtils uses in urlbar content code

Categories

(Firefox :: Address Bar, task)

task

Tracking

()

RESOLVED FIXED
156 Branch
Tracking Status
firefox156 --- fixed

People

(Reporter: dao, Assigned: dao)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sng][mcab-hnt])

Attachments

(3 files)

Bug 2053780 and bug 2064036 removed the lazy getters that ChromeUtils and XPCOMUtils defined in browser/components/urlbar/content/, and bug 2062987 gates the system module imports on ChromeUtils being available. What neither covers is a handful of direct ChromeUtils calls, each of which throws in a content realm where ChromeUtils is undefined:

  • ChromeUtils.generateQI -- SearchModeSwitcher.mjs (in the constructor, so it runs for every switcher, content included) and UrlbarInputBase.mjs, both to implement nsIObserver/nsISupportsWeakReference.
  • ChromeUtils.encodeURIForSrcset -- UrlbarInputBase.mjs and SmartbarInput.mjs, both when setting an engine icon.
  • ChromeUtils.now -- UrlbarChildTelemetry.mjs, which is the content-side engagement collector used on the message path.

At least the SearchModeSwitcher constructor and UrlbarChildTelemetry sit on paths a content-realm <moz-urlbar> reaches, so these are functional blockers rather than tidiness.

Notes toward fixes: generateQI is there because these objects are XPCOM observers, so if the observer registration moves to the parent the QueryInterface goes with it. ChromeUtils.now has performance.now() as a content-safe equivalent, modulo the time base. encodeURIForSrcset has no content-realm equivalent and would need the actor, or a different way to set the icon.

Assignee: nobody → dao+bmo
Status: NEW → ASSIGNED
Whiteboard: [sng][mcab-hnt]

SearchModeSwitcher's QueryInterface is dead -- nothing registers it with the
observer service anymore, and Cu.getWeakReference, which is what
UrlbarPrefs.addObserver uses, works on a plain object. UrlbarInputBase's
observer was a field initializer, so it ran generateQI for every input;
building it where it's registered keeps it in the branch that needs the observer
service anyway.

The telemetry event.timeStamp || ChromeUtils.now() fallback is unreachable:
every caller passes a DOM event, and even the undispatched CustomEvent the
tab-switch path constructs carries a timeStamp. Both copies drop it. It read from
a different clock than event.timeStamp does, so it would have been off by the
window's time origin had it ever fired.

The two encodeURIForSrcset calls stay: they build XUL, so a content realm never
reaches them.

observe matches the notification's subject against the input's own window, so a
content-realm input could never match it -- and generateQI and the observer
service are chrome-only, so reaching for them threw before the engine-store
observer below could be registered. That one a content realm does need.

UrlbarQueryContext's constructor normalizes the container id, so this sits on
the path of every query -- a content-realm input couldn't run one at all. The
value is spelled out beside the private-window sentinel the same file already
carries.

Pushed by dgottwald@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/6fc6b8b80356 https://hg.mozilla.org/integration/autoland/rev/df9ba132e2a0 Remove the bare ChromeUtils uses in urlbar content code. r=mbeier,urlbar-reviewers

Reverted this because it was causing mochitests failures in browser_searchbar_new.js.

  • Revert link
  • Push with failures
  • Failure Log
  • Failure line: TEST-UNEXPECTED-FAIL | accessible/tests/browser/tree/browser_searchbar_new.js | test_searchbar_a11y_tree - [DOM node id: searchbar-new, role: grouping, address: [xpconnect wrapped nsIAccessible]] has an extra child at index 1 : [role: section, address: [xpconnect wrapped nsIAccessible]]
Status: ASSIGNED → RESOLVED
Closed: 12 hours ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: