Before we get started on this next topic, I need to make one correction. In earlier posts, I said to use
collapsed="true" to hide XUL menuitems. A better option is to use
hidden="true" instead. Using collapsed doesn’t hide the margins, so you get a lot of whitespace in your menus.
I also mentioned customizing the toolbar in my last post. We’ll actually save that for a future post.
Now that we’ve seen how to create XUL overlays to modify menus, let’s try out a real world scenario to see what else we might need to do. Let’s say we want to remove the user’s access to “Full Screen” mode. (I have no idea why you would ever want to do this, but Microsoft provides it as a customization in their group policy, so someone must want it.) Removing the menu is the easy part. We look in the file browser-menubar.inc and see that the ID of the menu is fullScreenItem. So by adding this code to our overlay:
we make the menu go away.
But we have a problem. The user could also press F11 to use “Full Screen” mode. How do we stop that? Luckily key commands are also defined in XUL, so we can modify those. Most key commands are defined in the file browser-sets.inc. Searching through this file, we find:
<key id="key_fullScreen" keycode="VK_F11" command="View:FullScreen"/>
By simply adding this line to our overlay:
<key id="key_fullScreen" command=""/>
we prevent the keystroke from working.
That was an easy one. Let’s try something harder. Let’s remove access to “View Source.” View Source can be accessed three different ways, the View menu, the keystroke Ctrl+U, and View Page Source on the page’s context menu. Let’s remove all three. We already learned how to remove the keystroke:
What about the context menu? Removing items from the context menu can be done exactly the same way as removing items from any other menu – with hidden. The question is where do we get the IDs for items on the context menu. Similar to the main main and they keystrokes, it is stored it its own file, browser-context.inc. Here we see that the ID for the view source item on the context menu is context-viewsource so we can just add
<menuitem id="context-viewsource" hidden="true">
to our overlay. OK, one last thing. Let’s remove the actual View Source menuitem. Looking in browser-menubar.inc we see:
<menuitem accesskey="&pageSourceCmd.accesskey;" label="&pageSourceCmd.label;" key="key_viewSource" command="View:PageSource"/>
So now you should have most of the tools in your toolbox to remove functionality from the Firefox menus using the CCK to create the XUL overlay.