Webconverger - Disabling File Save/Download Dialogs
One of the reasons that I enjoy my work customizing Firefox and building add-ons so much is that just about every request I get is a puzzle. They usually start with a question like "Is it possible for Firefox to..." or "Can you make Firefox..." When one of these questions is asked, I start going down the rabbitfox hole and usually end up with some way to do what the client has asked. A lot of the same questions are asked so often that most of the time the answer involves giving them something I've already done or piecing together things I've already built. Occasionally, though, I get asked to do something that I've never done before. And that's a lot of fun.
Lately I've been helping out a project called Webconverger which is an open source web kiosk. There's also an add-on on AMO. Recently Kai Hendry, the maintainer, asked an interesting question - "Can you prevent Firefox from automatically downloading unknown files from web pages?" To understand why that is an issue, you need to understand what Firefox does when you click on a link to download a file.
When you go to a page that has an EXE or an ISO or something like that and you click the link, a dialog is displayed to ask you what to do with the file, but in the background, Firefox has already begun the download. After you make your selection, Firefox will move the file to the appropriate place. What this means is that even if you cancel the download, the bandwidth is already used. There are some kiosks that are in limited bandwidth situations, so they want to prevent this from happening at all.
As I began to investigate the problem, I looked into common things like nsIContentPolicy to see if I could just stop the files from being downloaded. Unfortunately at that point, we don't have mime types or anything interesting that will help us determine that it's not a file we want to download. So I turned my focus to the dialogs themselves. When you download an unknown file you get a dialog that asks you what to do. I could override that dialog and not display it, but that still doesn't cancel the download. It also doesn't help in cases where you are presented with a save dialog immediately. As I dug deeper into the problem, I discovered that one interface controlled both of those cases - nsIHelperAppLauncherDialog.
And that solved the puzzle.
If there's anything I've learned as I've worked with Firefox over the years, there's many ways to solve the same problem, so if you have a better way that I could have done this, please let me know.
Hi!
I would love to know if it is possible to make firefox fetch its configuration
data from an LDAP server instead of locally. In scenarios. where you'd
compare firefox to IE when it comes to central management of a large installbase firefox still lacks behind IE which makes it very much less of an option on corporate desktops.
Thanks,
Andreas.
Andreas,
I don't know of any products that allow Firefox to read it's configuration from an LDAP server. Group policy support is something that has been requested for a while.
Hi Andreas
FF won't (AFAIK) pull from an LDAP server but it will from a web server which is a step in the right direction. Have a look at setting:
lockPref("autoadmin.global_config_url","http://yourdomain/xxxxxx/autoadmin.cfg");
in a local cfg file.
Regards
Simon.
IIRC Webconverger was blocking downloads before 2010 using *BrowserLoadURL* which broke in some version of Firefox.
http://source.webconverger-org.branchable.com/?p=source.git;a=blob;f=kiosk.mdwn;hb=00a5e45ddfcccd088659c2a48d07e748e475607a
Despite having an open bug for years, I must thank you Mike for figuring out the solution.
https://bugzilla.mozilla.org/show_bug.cgi?id=524949
As far as I can tell from nsExternalHelperAppService.cpp, nsIHelperAppLauncherDialog does indeed exist just to give embedders this sort of flexibility.
This might not completely disable file download. For example, alt+click downloads a link without showing a file picker.
Thanks, Jesse. I'll check into that.
Hello Mike,
I'm able to use this extension. But the "new window" button in the navigator toolbar is disabled, after I installed this. I have added the button previously by editing the localstore.rdf. Could you please tell me how to enable it again, by keeping the extension?
Thanks,
Webconverger is a kiosk extension, so in that scenario you wouldn't want a new window button. That's why it is removed.
I understand that. But I'm trying for a partially kiosk environment. So in my case it is needed and I have enabled it by setting .
Thanks
So if you'd like that button back, you can edit the webconverger.xul file.
Remove these two lines:
<command id="cmd_newNavigator" disabled="true"/>
<key id="key_newNavigator" disabled="true"/>
And you'll get that back.
Yes, I have already turned that "true" to "false" and enabled the new window button. I have replied about it, but for some reason that statement is removed from my reply.
Thanks for your reply.
Another problem, I have enabled the Bookmark toolbar and added some bookmark items. But the right-click context menu of the Bookmark Toolbar is also getting enabled. Can I disable the context menu alone and display the Bookmark Toolbar ? I don't want the user to modify the Bookmark Toolbar, but just use the already available bookmark items.
Thanks,
(Replying here since WordPress won't let me nest)
To do that, put this in the XUL
<toolbar id="PersonalToolbar" context="">
That should do it.
It's saying "for the toolbar with the id of PersonalToolbar, don't have a context menu"
It doesn't work. I have added that line for PersonalToolbar in the wc.xul. But the context menu is still coming. Please help.
I found a method that works in my testing:
<toolbar id="PersonalToolbar" oncontextmenu="event.preventDefault();"/>
Thanks a lot. It works.
---
I have set my homepage manually by modifying the browserconfig.properties file in the en-US.jar. Is it possible for me to do this with your extension, so that I don't want to modify the en-US.jar.
Please advise.
Thanks.
Yes, it's unfortunate but if you set the homepage via a pref, you have to point it to a properties file because it is a complex pref. There's really no easy way around that. I think I'll open a bug against Mozilla for that.
Maybe webconverger can be modified to do that better as well.
Mike,
So there is no way to move the changes made in the en-US.jar to the webconverger extension, right? (for setting the homepage)
I did the following in the .properties file inside en-US.jar
browser.startup.homepage=http://yahoo.com
Please help,
Thanks
I just remembered there is a hack to getting this to work.
Try:
pref("browser.startup.homepage",
"data:text/plain,browser.startup.homepage=http://www.yahoo.com/");
Webconverger doesn't currently user properties files at all.
But you could certainly add one for this specific purpose.
Then you could point the homepage preference to that properties file to get the homepage URL.
There are two ways I recommend setting a homepage. One is to use a distribution.ini:
http://mike.kaply.com/2012/03/26/customizing-firefox-distribution-ini/
Two is to use a config file:
http://mike.kaply.com/2012/03/16/customizing-firefox-autoconfig-files/
In the config file, you must set it as a pref() not a defaultPref()
Mike,
Thanks for the reply.
I'm using iceweasel and that's the reason I had to modify the en-US.jar. I have also made the following change to firefox.js file.
pref("browser.startup.homepage", "chrome://branding/locale/browserconfig.properties");
pref("browser.startup.page", 1);
I believe that the methods you suggest (distribution.ini and config file) are supposed to be done outside the KIOSK plugin. Am I correct? But I thought of making it as part of the KIOSK plugin.
Please reply.
Thanks
Just curious, did you try:
pref("browser.startup.homepage", "http://mike.kaply.com");
in the firefox.js?
I just tested and it is working for me. I have no idea when it started working (it didn't used to).
Yes, I tried that. As I'm using iceweasel branding, the following displayed a blank page in the iceweasel.
pref(“browser.startup.homepage”, “http://mike.kaply.com”);
So I found that firefox.js should be as below.
pref(“browser.startup.homepage”, “chrome://branding/locale/browserconfig.properties”);
And I modified en-US.jar, which has a browser.startup.homepage. I set this to "http://www.yahoo.com".
Hello Mike,
Is it possible to disable the tab window feature in firefox using your extension? Just displaying one window, without the tab feature.
Thanks,
netboy
There are methods to hide tabbed browsing from the user. I'll cover that in a new blog post.
Could you please let me know, so that I can do it for my project now itself ?
Thanks.
That would be absolutely splendid. Looking forward to your post. I have searched tirelessly for this answer
Hello Mike,
I want to disable the File Upload dialogs that are initiated from the webpages (Browse button). So I did the following code in userContent.css. It works fine ( There is a small problem. It hides the Browse buttons in the webpages. But that is ok).
The main issue is that in gmail -> Compose Mail, there is an "Attach a File" option. The following code is not disabling it. Can you suggest your opinion , how to make this working in gmail? Thanks.
Code:
-----
input[type="file"]
{
display: none !important;
}
Hi,
I've just found your solution and I'd like to use it in my project, what the license of your code ? (public domain, BSD...)
TIA,
mod
Webconverger is licensed under the MIT license.
https://github.com/Webconverger/iceweasel-webconverger/blob/master/LICENSE
Go for it.
is it possible that if i open a .xpi in chrome and firefox is not yet installed.then firs it install the browser and then installs the xpi without any confirmation with default settings.
Thanks
Sahil kakkat
You would have to bundle your XPI as part of a Firefox executable.