Closed Bug 1817443 Opened 2 years ago Closed 2 years ago

Move open*Link* and friends into a module instead of utilityOverlay.js

Categories

(Firefox :: Tabbed Browser, task)

Desktop
All
task

Tracking

()

RESOLVED FIXED
112 Branch
Tracking Status
firefox112 --- fixed

People

(Reporter: Gijs, Assigned: Gijs)

References

(Blocks 2 open bugs)

Details

Attachments

(5 files)

There are a few reasons I'd like to do this:

  • these functions (all very similarly named and somewhat confusing at this point) clutter up the global scope
  • openLinkIn is something like 500 lines long and has an eslint complexity rule disabled because it's massive, but factoring out that complexity in-place would add yet more globals.
  • these functions living in a per-window script is annoying for non-window-based code that wants to open URLs. Being able to call them from modules would help with reusing code (see also bug 1485961)
  • I'd like to (not in this bug) change some of these functions to also be able to take an nsIURI instead of just a string (so we can call loadURI instead of fixupAndLoadURIString on the other end, cf. bug 1810141). Because it's JS-only, adding the polymorphism is relatively straightforward -- but adding yet more complexity to these methods without being able to do clearer separation of concerns is really yucky. Having a dedicated module makes it easier to have the helper methods not be [inadvertently] exposed as API surface. These functions already create URIs internally, so having them work out the final URI (if an nsIURI doesn't get passed in) seems like a useful abstraction. See also the performance profile in bug 1800596 comment 27.

Initially I'll keep the utilityOverlay.js functions as simple forwarding calls to the module-based implementations. I'll file a follow-up to rewrite all the callers with jscodeshift.

openLinkIn would really benefit from being split up a bit, and adding more
globals to the browser window is icky. Also, the story for opening new tabs if
you're not inside a window is a nightmare right now. Moving this code
to a module is a first step to making that story nicer.

I kept wrappers for all the functions I'm moving, and added the window as the
first argument. In the future we can update these functions to support being
called without a window ref. The one exception is getTopWin, where I updated
the callers in this patch.

I had to tweak the parameter detection of the different arguments supported by
openUILinkIn because forwarding calls means arguments.length is always larger
than 3. This brought it in line with the other methods anyway.

When splitting out the window/tab/current cases, not all of them need all
these individual arguments. But it's hard to reason about which ones are used
where/how when we rename them all the time, and passing them all
individually is more verbose as a result of the renaming, so let's just not do
that at all.

There are a few "odd ones out" - private isn't a valid local variable name,
and some of the other items were easier to deal with by just referencing
directly on params.

Depends on D170210

'fromChrome' really meant "force tabs to open in the foreground", so let's
rename it accordingly.

This removes the attempt to document arguments for openUILinkIn.
I'll add documentation back on the end of this stack, for openLinkIn, when
various bits are reorganized anyway.

Depends on D170210

Depends on D170212

Pushed by gijskruitbosch@gmail.com: https://hg.mozilla.org/integration/autoland/rev/827855beb033 move url loading method implementations from utilityOverlay.js into their own helper module, r=mossop https://hg.mozilla.org/integration/autoland/rev/a74a52e93af4 remove openUILinkIn entirely and rename fromChrome, r=mossop,extension-reviewers,rpl https://hg.mozilla.org/integration/autoland/rev/2b39dee42948 tidy up parameter handling in openLinkIn, r=mossop https://hg.mozilla.org/integration/autoland/rev/07e3bccaeb6d split window and current tab parts of openLinkIn out into helpers so it's actually readable, r=mossop https://hg.mozilla.org/integration/autoland/rev/ba33c510d008 document all the params for openLinkIn, r=mossop
Flags: needinfo?(gijskruitbosch+bugs)
Pushed by gijskruitbosch@gmail.com: https://hg.mozilla.org/integration/autoland/rev/44fe1f033770 move url loading method implementations from utilityOverlay.js into their own helper module, r=mossop https://hg.mozilla.org/integration/autoland/rev/c1267fbfcb92 remove openUILinkIn entirely and rename fromChrome, r=mossop,extension-reviewers,rpl https://hg.mozilla.org/integration/autoland/rev/c7bdd75a316b tidy up parameter handling in openLinkIn, r=mossop https://hg.mozilla.org/integration/autoland/rev/c25910781954 split window and current tab parts of openLinkIn out into helpers so it's actually readable, r=mossop https://hg.mozilla.org/integration/autoland/rev/1e3a192261a8 document all the params for openLinkIn, r=mossop
Blocks: 1818776
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: