1

I've set a ondrop event on my drop area and it receives an event when I drag an image from my desktop to the drop area.

However, according to the Recommended_Drag_Types document:

https://developer.mozilla.org/en/DragDrop/Recommended_Drag_Types

A local file is dragged using the application/x-moz-file type with a data value that is an nsIFile object. Non-privileged web pages are not able to retrieve or modify data of this type.

That makes sense, but how do I prompt the user to escalate privileges to get access to the file data and send it via an XMLHttpRequest?

If I try it without escalating privileges when I do this code:

event.dataTransfer.mozSetDataAt("application/x-moz-file", file, 0);

Javascript returns this error:

Permission denied for domain.com to create wrapper for object of class UnnamedClass

The only article I can find on this is one from 2005 but I can't tell if the directions still apply to Firefox 3, it suggest doing this:

netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

which doesn't seem to work.

Stu Thompson
  • 38,370
  • 19
  • 110
  • 156
bertrandom
  • 2,131
  • 2
  • 13
  • 8
  • did you find an answer to this?? I would like to be able to at least capture the local url. any ideas? thx man – Lance Nov 12 '09 at 04:17
  • Its possible now! See my answer: http://stackoverflow.com/a/33431704/195216 – dforce Oct 30 '15 at 08:40

2 Answers2

0

If you haven't upgraded to 3.5 yet, you can use the dragdropupload extension.

MiffTheFox
  • 21,302
  • 14
  • 69
  • 94
  • Thanks, but I'm thinking of this from more of a web developer perspective, I figure most people will upgrade to Firefox v3.5 but much fewer will have this extension installed. – bertrandom Jul 01 '09 at 09:04
0

I found out that if instead of escalating privileges globally:

    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    ...
    function doDrop(event) {
       ...
       var file = event.dataTransfer.mozGetDataAt("application/x-moz-file", 0);
       ...
    }

I escalate privileges in the function's body:

    ...
    function doDrop(event) {

       netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
       ...
       var file = event.dataTransfer.mozGetDataAt("application/x-moz-file", 0);
       ...
    }

I get rid of the error you described and gain access to the nsIFile instance I was looking for.

Guillaume G.
  • 385
  • 1
  • 5
  • Firefox 33 says "netscape.security.PrivilegeManager is undefined". Looks like it was removed in FF15: https://support.mozilla.org/en-US/questions/936845 – EricP Oct 27 '14 at 21:46