Customizing Firefox – Hiding Private Browsing - Continued
I was reminded that there is one more way to get to private browsing - typing about:privatebrowsing in the URL bar. This gives us a chance to talk about another thing you can do in chrome.manifest - override.
Override allows us to completely replace a built in URL in Firefox with another URL. I use this in my Rebrand extension to override certain images and other things. We can also use it to override built in URLs like about:config and about:privatebrowsing. There is a catch though.
When a URL begins with about, that's not the true URL; all about URLs map to a corresponding chrome URL. The easiest way to see this mapping is by looking at AboutRedirector.cpp or nsAboutRedirector.cpp. These files contain the mappings of just about every about command to a corresponding chrome URL. For about:privatebrowsing, that's chrome://browser/content/aboutPrivateBrowsing.xhtml
So to override the about:privatebrowsing, we just need to give it a suitable replacement. Put this line in your chrome.manifest:
override chrome://browser/content/aboutPrivateBrowsing.xhtml data:text/html,Disabled
You'll see the word "Disabled" when you type about:privatebrowsing.
Alternatively, you could create your own custom HTML file and place it in your content directory and point to that:
override chrome://browser/content/aboutPrivateBrowsing.xhtml chrome://myextension/content/myfile.html
This method can be used to override just about any of the about pages. For instance, to override about:config, do this:
override chrome://global/content/config.xul data:text/html,Disabled
Using override is a powerful way to prevent access to things you don't want your users messing around with.
Until someone opens a new tab, pops open the Web Console and pastes in
window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebNavigation).QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindow).gPrivateBrowsingUI.toggleMode();
So I guess you'd have to disable the Web Console too, although there's probably several other clever ways to run JavaScript in chrome context. It seems to me a bit like trying to plug holes in a dike with your fingers.
Yes, you probably would disable the Web Console.
It's also possible to completely remove private browsing by simply overriding gPrivateBrowsingUI, but I haven't gotten into that yet.
The goal here is to prevent the average user from being able to do these things. Obviously if someone is willing to go to those lengths to get private browsing, more power to them.
You seem to be arguing that since you can't do everything, you shouldn't do anything. If that was the case, every enterprise should use Internet Explorer.
do you have any idea on how to remove the option from the task bar jumplist?(open mozilla, click and hold on the task bar, then move mouse upward)
That's a good question. I didn't realize that one was there.
I'll check into it.
Yes I do.
There are two preferences you can set to false to remove it.
Setting browser.taskbar.lists.enabled to false removes everything from the jump list.
Setting browser.taskbar.lists.tasks.enabled to false just removes the tasks (leaves the history).
You can't remove just private browsing.
All these prefs take effect immediately, so you can test them in about:config
I've done some googling (and probably not enough).. Anyways, can I set either of these preferences to false via extension? If yes, please share.
yes. preferences are set via an extension by putting them in defaults/preferences/prefs.js and then just setting them as:
pref("foo", false);
I've tried this and for some reason
pref("browser.taskbar.lists.enabled", false);
yet if i attempt to set it to a string it will work.. any thoughts?
ex:
pref("browser.taskbar.lists.enabled", "HelloWorld");
I honestly have no idea. browser.taskbar.lists.enabled is definitely a preference.
Making it a string would just cause the code to fail (which is OK in this case).
What version of Firefox and where are you setting the pref?
Did you verify the new value is used in about:config?
Yes I have verified that it changes if I use a string value. However, if i use a bool value such as false it doesn't change.
I'm testing on FF 14.0.1, on my local computer.
I have to be honest, I'm at a loss.
When you create a new profile, does it say "Boolean" in about:config?
yes it does
So it appears something got broken in Firefox 14.
Can you try putting your files in defaults/preferences instead of defaults/prefs (you'll have to create the directory).
I'm trying to get to the bottom of what exactly happened.
Hey Mike,
thanks a lot for your guides on how to disable private browsing!
I know, these posts are already half a year old, but I still have
a question to ask:
How can I disable the possibility to clear the history by users?
I've searched on your links, google etc, but it seems like I'm
to stupid to find the correct prefs to do so.
Due to the fact, that hiding/disabling the privatebrowsing using
chrome.manifest and 'browseroverlay,xul' is working pretty well,
it would be great to hide/disable cleaning of history in that way
as well. Could you please help me out?
Thanks a lot in advance!
Disabling the clearing of history requires quite a view things. Besides handling the basic menu item and key stroke, you also have to handle the individual deletion of entries from history sidebar and window.
I'll be honest, though. Figuring this one out would take a few hours that I don't have time to spare. My suggestion would be you look through the Firefox code for Tools:Sanitize - that will cover the menus and keystrokes for history. Then you'll have to overlay chrome://browser/content/history/history-panel.xul and chrome://browser/content/places/places.xul to remove the delete key and the Delete menuitem. That should cover it.
Hope that helps.