Move new tab, new window, home button drag/drop handlers out of browser.js into a separate module
Categories
(Firefox :: General, task, P3)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox138 | --- | fixed |
People
(Reporter: Gijs, Assigned: shane.a.ziegler, Mentored)
References
(Blocks 1 open bug)
Details
(Keywords: good-first-bug)
Attachments
(1 file)
All of this code doesn't need to live in browser.js . There's also quite a bit of code duplication in there.
To fix this, I think we want to:
- create a ToolbarDropHandler module file (sys.mjs) in
browser/components/customizableui/, and add a lazy import for it at the top ofbrowser.js - move the
homeButtonObserver,newTabButtonObserverandnewWindowButtonObservercode (and any functions only called from there) into that module. It probably makes sense to only export 1 object from that module and expose whatever methods we need on there. Note that we'll need to update consumers in browser/base/content/navigator-toolbox.js and various other places. - update all the callsites of the various
browserDragAndDropmethods to callServices.droppedLinkHandler's methods directly, except foronDragOverwhich we can move toToolbarDropHandler. - check tests still pass
- update
browser.js.globals:-)
This should remove about 150 lines of code from browser.js and avoid that code being loaded until/unless the user actually uses drag/drop on the affected widgets.
| Reporter | ||
Comment 1•1 year ago
|
||
Shane, I'm assigning you this in lieu of bug 1882774, sorry for the confusion there and I hope this is OK. Let me know if you have questions / run into issues!
Comment 2•1 year ago
|
||
The Bugbug bot thinks this bug should belong to the 'Firefox::New Tab Page' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
| Reporter | ||
Updated•1 year ago
|
| Assignee | ||
Comment 3•1 year ago
|
||
Hi, I’m a new contributor, and I’ll be submitting a patch for this bug soon.
| Assignee | ||
Comment 4•1 year ago
|
||
For functions like browserDragAndDrop.dropLinks(), which simply call Services.droppedLinkHandler.dropLinks(), is it best practice to keep a _dropLinks() in our new ToolbarDropHandler object for the onDrop() or other internal object function calls or can we just get rid of dropLinks and also do direct calls to Services.droppedLinkHandler.dropLinks()?
| Assignee | ||
Comment 5•1 year ago
|
||
How do we find which tests to run?
| Reporter | ||
Comment 6•1 year ago
|
||
(In reply to Shane Ziegler from comment #4)
For functions like
browserDragAndDrop.dropLinks(), which simply callServices.droppedLinkHandler.dropLinks(), is it best practice to keep a_dropLinks()in our newToolbarDropHandlerobject for theonDrop()or other internal object function calls or can we just get rid ofdropLinksand also do direct calls toServices.droppedLinkHandler.dropLinks()?
I think where other places are currently calling browserDragAndDrop.dropLinks() they could simply call Services.droppedLinkHandler.dropLinks() directly instead.
(In reply to Shane Ziegler from comment #5)
How do we find which tests to run?
In this case I'm not sure there are many specific tests. For a trypush I'd probably just run with the mochitest-bc preset (./mach try fuzzy --preset mochitest-bc). I also ended up looking in searchfox, and from this query I think at least the following tests:
browser/base/content/test/general/browser_homeDrop.js
browser/base/content/test/general/browser_newTabDrop.js
browser/base/content/test/general/browser_newWindowDrop.js
browser/components/downloads/test/browser/browser_indicatorDrop.js
browser/components/downloads/test/browser/browser_libraryDrop.js
browser/components/tabbrowser/test/browser/tabs/browser_tab_dragdrop2.js
would be ones I'd suggest you run locally.
Let me know if you have any other questions or run into issues with that!
| Assignee | ||
Comment 7•1 year ago
|
||
How can I test the functionality these functions in Nightly? I am not sure what they do exactly or how to drag and drop a url and force some of them to get called.
I got some of the tests to run fine, but the others end up hanging on me and eventually timing out, so trying to figure out what is going on.
| Assignee | ||
Comment 8•1 year ago
|
||
Updated•1 year ago
|
| Assignee | ||
Comment 9•1 year ago
|
||
I used some maybe crude/manual ways to get at globals for use of some classes, window, and setTimeout. Like const win = aEvent.target.ownerGlobal is there a better way to get access to those?
The 6 tests you gave above are now passing and it passed a build on the try push server.
| Reporter | ||
Comment 10•1 year ago
|
||
(In reply to Shane Ziegler from comment #9)
I used some maybe crude/manual ways to get at globals for use of some classes, window, and setTimeout. Like
const win = aEvent.target.ownerGlobalis there a better way to get access to those?
If the event inherits from UIEvent then aEvent.view may be available (https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/view ), but aEvent.target.ownerGlobal may also be fine.
The 6 tests you gave above are now passing and it passed a build on the try push server.
Ah, can you share the link to try? I'm a bit surprised because as I noted on your patch not all the files appear to be there, which I'd expect to cause failures... but maybe not?
Updated•1 year ago
|
Updated•1 year ago
|
| Assignee | ||
Updated•1 year ago
|
| Assignee | ||
Comment 11•1 year ago
|
||
I noticed a change that still needs to be made on line 133 of ToolbarDropHandler.sys.mjs. I will be fixing it and re-submitting soon.
| Assignee | ||
Comment 12•1 year ago
|
||
I have made the requested changes.
The latest treeherder link is (https://treeherder.mozilla.org/jobs?repo=try&revision=54569b80420f1f3cd92ffb64825fe02b39cda00d)
The try push was still running at the time of this comment.
I have a couple questions:
-
In ToolbarDropHandler.sys.mjs, on line 19, the call to
this._canDropLinkcould be turned into a direct inline call and allow us to get rid of_canDropLinkon line 16, but the current way it's defined/used adds some readability to the code. Should it be kept how it is now or turned into a direct inline call? -
Lines 25-30 have calls to
win.gNavigatorBundle.getString,winis passed to the method by other code in this module. Is there a better way to access thegNavigatorBundleobject from browser.js?
| Reporter | ||
Comment 13•1 year ago
•
|
||
(In reply to Shane Ziegler from comment #12)
I have made the requested changes.
The latest treeherder link is (https://treeherder.mozilla.org/jobs?repo=try&revision=54569b80420f1f3cd92ffb64825fe02b39cda00d)
The try push was still running at the time of this comment.
Edit: nice! That looks good (there's some orange, ie failed tests, but none of it related to your change so they're intermittents + unfortunately this bug
I have a couple questions:
- In ToolbarDropHandler.sys.mjs, on line 19, the call to
this._canDropLinkcould be turned into a direct inline call and allow us to get rid of_canDropLinkon line 16, but the current way it's defined/used adds some readability to the code. Should it be kept how it is now or turned into a direct inline call?
Eh, yeah, I don't feel super strongly, so leaving it like this is also fine by me.
- Lines 25-30 have calls to
win.gNavigatorBundle.getString,winis passed to the method by other code in this module. Is there a better way to access thegNavigatorBundleobject from browser.js?
We could create our own reference to the bundle, but that's not really much better. I think instead, it would be nice to convert these strings to fluent, put them in a separate file (browser.properties which is what gNavigatorBundle points to, is kind of a dumping ground) and then we can remove this dependency entirely and source the strings from just inside the module when a drag/drop actually happens. But let's do that in a separate bug as a separate refactor, that will make it a bit easier to deal with. So I'll file that bug and then if you want you could work on that next if you fancied it?
| Assignee | ||
Comment 14•1 year ago
|
||
I removed the random 1; typo in the code and resubmitted it.
| Reporter | ||
Comment 15•1 year ago
|
||
(In reply to Shane Ziegler from comment #14)
I removed the random
1;typo in the code and resubmitted it.
Great! I've queued the patch for landing.
Comment 16•1 year ago
|
||
Comment 17•1 year ago
|
||
| bugherder | ||
Description
•