Presentation Screenshots Download Support Development Forum    

Welcome to the Community Forum.

Here you can discuss with other users or with the author, suggest new features, report bugs, ask for filters creation or correction, etc. Select the forum you wish to read or post below :

Forum > Development & Bug report > Help needed to develop the Add-on

Pages : [1] Add a reply
User info Help needed to develop the Add-on
Feb 13 2012, 9:44 am
I've tried to add some features in Automatic Save Folder but I don't have the knowledge to do it.
So I decided to post what I'm looking for here in hope that someone knows how to do it and could help me developing and fixing Automatic Save Folder.

1. Target Element
I need to access the clicked element (target event) on the browser windows from the UnknownContentType dialog (the save dialog). I guess it will be done by using nsIWindowMediator.
It will help for the next feature.

2. Retrieving the link's informations
I would like to read the target's URL informations myself instead of relying on the data used by UnknownContentType dialog which is providing the Source (file's name) and Location (File's Host).
I guess if I find a way to access the targeted element, I will be able to do it.
I could access other datas not retrieved by the save dialog, like link's URL and link's inner_html.

Currently (up to v1.0.4), the right-click use a different URL than the single-click event when retrieving the Full File's URL.
This is the differences when downloading a file from this page:

(See point 4 for more informations).

3. Suggested filename with single-click
I would like a way to change the suggested filename when using UnknownContentType.
I can access and edit the suggested filename when using the right-click saving method, but not single-click.

4. Suggested filename from HTTP_HEADER
Since Firefox 3.0, all redirection links are suggesting the filename provided by the HTTP_HEADER : "Content-Disposition: attachment; filename=fname.ext"

The header reading is slower and requires few milliseconds to retrieve the suggested filename. The delay is set by default to 1000 milliseconds.

When using right-click on a redirection link
with the active delay set to 1000, Automatic Save Folder is not triggered at all.
The download is working and the suggested file by fname.ext is correctly read from the HTTP_HEADER.

With the delay set to 0, Automatic Save Folder is triggered!
The download is working but the suggested file is not retrieved by the HTTP_HEADER.
The suggested file is download.php
Automatic Save Folder is checking the filters based on download.php and not fname.ext filename.

With the delay set to ~6-8 millisecond, Automatic Save folder is triggered!
The download is working AND the suggested file is correctly retrieved by the HTTP_HEADER.
The suggested file is fname.ext,
Automatic Save Folder is checking the filters based on download.php and not fname.ext filename, as if reading the header didn't work :/
It's un-friendly as the filters are not based on what the users are seeing.

I would like to find a way to trigger Automatic Save Folder with the delay set to 1000, so it can filter based on the suggested filename.

Maybe a tweak would be acceptable : Delay set to 0 to trigger the add-on, and check the HTTP_HEADER by the add-on instead of Firefox, then change the suggested filename manually.
Again, I don't know how yet to read HEADER from the target.

5. Stop being dependent of the save dialog
Automatic Save Folder is dependent of the save dialog (UnknownContentType dialog) to trigger the filter checking.
If the user set the MIME Type to always save instead of Always ask, then that dialog is not shown and the Add-on is not triggered.

It would be great to trigger the add-on on all downloads (single-click and left-click) with and without the save dialog.

Maybe it involves creating a new XPCOM?
Having ASF always in memory on all pages, and fill some variables when the user click on a link.

Currently, I'm looking the most for points 3 and 4.
Post #1
Oct 9 2012, 9:36 pm
1. Target Element
What I hacked together:


var focusedElement;
var openerWindow = Services.wm.getMostRecentWindow("navigator:browser");
var openerDoc = openerWindow.content.document;
focusedElement = openerDoc.activeElement;
catch (aError)
// no focusedElement found
if (focusedElement && focusedElement.tagName)
alert("url: " + focusedElement.getAttribute("href") + "\n" +
"link text: " + focusedElement.textContent);

Be aware that the download could also start from a background tab where this code would not work. The code Firefox uses is here, you can try to code something like this:

For most other questions, the binary implementation of the launch of the file picker is a drag. I think you would have to write it in JavaScript:
Post #2
Oct 16 2012, 8:43 am

Thank you for the help, I will test it.

For right-click, I'm dynamically rewriting firefox function to add ASF functions to it to prevent conflicting with other add-on also rewritting the same file.
But for automatic downloads I guess I'll still require the Save dialog to trigger ASF, if I need to physically rewrite nsHelperAppDlg.js it could break compatibility with other add-ons. That's what I wanted to avoid.

So it will be only a 50% fix, but that's already great if clicked link can work without the "always ask" setting.

Post #3
Aug 27 2013, 9:05 am

There is a similar addon but with different feature set. One important thing is that it work regardless of mime setting. Maybe you can analyse code and find out how it is done ?

ps: extension does not seem to be developed any more.
Post #4
Sep 24 2013, 7:42 pm
Download sort replaced the Firefox's default download script completely, and created conflict with other addons dependent of the default functions.
It was also not working with all downloads, that's why I created ASF (after testing Download Sort and seeing it was too limited).
Post #5
Edit / Delete
Pages : [1] Add a reply

Return to top