Reputation: 373
I am writing a Firefox Add-on that is supposed to add new bookmarks. I am thinking of employing some of the functionality that is already present in the Mozilla Firefox browser. As I understand, the Firefox browser is written in XUL and the code is open source. How can I find the code that performs any specific action, like in this case when I click the context menu item "Bookmark this link" a window appears "New Bookmark", how can I find the code that opens this window?
Thank you!
Upvotes: 2
Views: 136
Reputation: 32063
See Viewing and searching Mozilla source code online - there currently are two online tools for searching through the Mozilla's code: DXR and MXR. The former is newer and more advanced, the latter is simpler and more mature. Using any of these:
Find a localization file (usually .dtd
or .properties
), which maps an internal name to the human-readable label, in this case: browser/locales/en-US/chrome/browser/browser.dtd:
ENTITY bookmarkThisLinkCmd.label "Bookmark This Link">
Search for the internal name you found: bookmarkThisLinkCmd.label
Find the code that displays it in the UI, usually .xul
or .js*
, in this case browser/base/content/browser-context.inc - a file that's included in a number of XUL files via preprocessor. (Note that DXR also shows you a bunch of results under obj-x86_64-pc-linux-gnu
- these are results generated during the build, and not the original source code, and should usually be ignored.)
<menuitem id="context-bookmarklink"
label="&bookmarkThisLinkCmd.label;"
accesskey="&bookmarkThisLinkCmd.accesskey;"
oncommand="gContextMenu.bookmarkLink();"/>
Find the definition of gContextMenu
: regexp:gContextMenu[^A-Za-z.] - there's a bunch of hits, all of them doing
gContextMenu = new nsContextMenu(this, event.shiftKey);
Finally find the definition of .bookmarkLink
: browser/base/content/nsContextMenu.js#1690
Upvotes: 3