Intercepting download links for downloading and preventing default download dialog

We created a desktop application for download manager for windows. Now we want to add a function that intercepts download links and adds them to the application. We think we should write an addon for every browser starting with Firefox.

  • To intercept download links for the download manager, writes addons the best choice?
  • How can we do this?

Things that we have tried so far:
- Using Downloads.jsm to watch for new downloads, and then cancel them => We do not want the user to interact with the dialog download of Firefox
qaru.site/questions/1546406 / ...
- Addition click event listener for each tab and search for links => Download links do not differ.
https://stackoverflow.com/questions/1546421/ ...
After capturing a link, it is simply passed to our application using nsIProcess .

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

0
1

. , .

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);
0

Source: https://habr.com/ru/post/1546409/


All Articles