2

I'm trying to write an addon for a certain file type, and I would like to add an "Send to MyAddonName" option to the download file dialog, under the "Open with" and "Save file" options. Not referring to the Download Manager.

Is there any way to achieve this using the Firefox Addon SDK? This is my first extension so I am not extremely familiar with the SDK or the more advanced XUL addons.

Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
Sierra C
  • 305
  • 1
  • 11

1 Answers1

2

I'm not sure how to do this with addon sdk. But this is how i would do it from a bootstrap addon.

I would use Services.wm.addEventListener to add this and listen to window load of chrome://mozapps/content/downloads/unknownContentType.xul

var windowListener = {
    //DO NOT EDIT HERE
    onOpenWindow: function(aXULWindow) {
        // Wait for the window to finish loading
        let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow);
        aDOMWindow.addEventListener('load', function() {
            aDOMWindow.removeEventListener('load', arguments.callee, false);
            windowListener.loadIntoWindow(aDOMWindow);
        }, false);
    },
    onCloseWindow: function(aXULWindow) {},
    onWindowTitleChange: function(aXULWindow, aNewTitle) {},
    register: function() {
        // Load into any existing windows
        let DOMWindows = Services.wm.getEnumerator(null);
        while (DOMWindows.hasMoreElements()) {
            let aDOMWindow = DOMWindows.getNext();
            windowListener.loadIntoWindow(aDOMWindow);
        }
        // Listen to new windows
        Services.wm.addListener(windowListener);
        registered = true;
    },
    unregister: function() {
        // Unload from any existing windows
        let DOMWindows = Services.wm.getEnumerator(null);
        while (DOMWindows.hasMoreElements()) {
            let aDOMWindow = DOMWindows.getNext();
            windowListener.unloadFromWindow(aDOMWindow);
        }
        for (var u in unloaders) {
            unloaders[u]();
        }
        //Stop listening so future added windows dont get this attached
        Services.wm.removeListener(windowListener);
    },
    //END - DO NOT EDIT HERE
    loadIntoWindow: function(aDOMWindow) {
        if (!aDOMWindow) {
            return;
        }
        if (aDOMWindow.location == 'chrome://mozapps/content/downloads/unknownContentType.xul'); {
            //check file type
            var fileName = aDOMWindow.document.getElementById('location').value;
            var fileType = fileName.substr(fileName.lastIndexOf('.'));

            if (fileType == 'zip') {
                var myxul = document.createElementNS('xul namescpae here look it up', 'element you want');
                aDOMWindow.document.insertBefore(elementToInsertBefore, myXul);
            }
        }
    },
    unloadFromWindow: function(aDOMWindow) {
        if (!aDOMWindow) {
            return;
        }
    }
}
};
Noitidart
  • 35,443
  • 37
  • 154
  • 323