How can I find Firefox code that opens “Add new Bookmark” window?

你说的曾经没有我的故事 提交于 2019-12-14 02:15:46

问题


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!


回答1:


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:

  1. Search for the label you're looking for: "Bookmark this link"
  2. 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">
    
  3. Search for the internal name you found: bookmarkThisLinkCmd.label

  4. 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();"/>
    
  5. 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); 
    
  6. Finally find the definition of .bookmarkLink: browser/base/content/nsContextMenu.js#1690



来源:https://stackoverflow.com/questions/36507832/how-can-i-find-firefox-code-that-opens-add-new-bookmark-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!