0

We have built a download manager desktop application for windows. Now we want to add a feature that intercepts download links and adds them to the application. We think we should write an addon for each browser starting from Firefox.

  1. To intercepts download links for a download manager, is writing addons the best choice?
  2. How can we do that?

Things we've tried so far:
- Using Downloads.jsm to observe new downloads, then cancel them => We don't want the user to interact with Firefox's download dialog
https://stackoverflow.com/a/24466197/2550529
- Adding a click event listener to each tab and looking for links => Download links are not distinguishable.
https://stackoverflow.com/a/10345358/2550529
After grabbing the link, it is just passed to our application using nsIProcess.

In one sentence: We want it to behave like IDM's new download dialog.

Community
  • 1
  • 1
SepehrM
  • 1,087
  • 2
  • 20
  • 44
  • The addon author of Torrent Tornado did this and helped a user here: http://forums.mozillazine.org/viewtopic.php?p=13929335#p13929335 his work method is a bit hacky i think though now that im reading it. – Noitidart May 09 '15 at 20:31

1 Answers1

0

Here's what we've done as of yet. It works as expected.

const {components, Cc, Ci} = require("chrome");
httpRequestObserver =
{
    observe : function(aSubject, aTopic, aData) {
        if (aTopic == "http-on-modify-request") {
            let url;

            aSubject.QueryInterface(Ci.nsIHttpChannel);
            url = aSubject.URI.spec;

            if(dlExtensions == null)
                return;

            var match = false;
            for(x in dlExtensions)
                if(url.endsWith(dlExtensions[x]))
                {
                    match = true;
                    break;
                }
            if(match == true) {
                aSubject.cancel(components.results.NS_BINDING_ABORTED);
                //Pass url to exe file
            }
        }
    }
};

var observerService = components.classes["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
observerService.addObserver(httpRequestObserver, "http-on-modify-request", false);
SepehrM
  • 1,087
  • 2
  • 20
  • 44