4

After updating to Firefox 17.0.1 PrivilegeManager is no longer supported. Various sources say, it is yet possible to simply remove the respective line from the code and everything should work just fine. Unfortunately this is not the case here.

I always get an error: TypeError: Components.classes is undefined. Are there changes concerning Components.classes as well? The Mozilla Code Snippets page (https://developer.mozilla.org/en-US/docs/Code_snippets/File_I_O) states the same syntax (without using FileUtils.jsm).

My code:

//netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var file = Components.classes["@mozilla.org/file/local;1"]
    .createInstance(Components.interfaces.nsILocalFile);

file.initWithPath(filePath);
Stefan Surkamp
  • 972
  • 1
  • 16
  • 31
  • 1
    Where are you running that code? If it's running with the system principal (as "chrome"), it should work. If you're putting this in webpages, then it won't work.... – Boris Zbarsky Jan 06 '13 at 06:21
  • It is implemented as regular code in the xul extension. I assume that makes it "put in a webpage", as it does not work. Any solutions for this? – Stefan Surkamp Jan 06 '13 at 11:28
  • 1
    I guess you don't build an extension but you open your xul from the local filesystem, right? If so, firefox considers it untrusted content, which is the reason why you had to invoke the Privilege Manager. Since the Privilege Manager is no more, you have to switch to developing a real extension. – paa Jan 06 '13 at 16:25
  • 1
    Regular code in a XUL extension would work here. So whatever you're doing it's _not_ regular extension code. Again, how exactly is this script ending up being run? – Boris Zbarsky Jan 06 '13 at 17:13

2 Answers2

0

As several commenters note, you might be running the code in the wrong place (i.e: unprivileged, web-page context). It could, however, simply be an issue of scoping.

If it is scoping, try this:

const {Cc,Ci,Cu} = require("chrome");

var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath(filePath);

If you're running in the wrong place, require will generate an error.

David-SkyMesh
  • 5,041
  • 1
  • 31
  • 38
  • what does it mean "running the code in the wrong place"? how to fix this if it is an issue? – peetonn Jul 29 '13 at 22:41
  • Basically, just follow the standard guidelines for building an extension (either with an overlay, or bootstrap). If you're trying remote XUL, or trying to run privileged code from a normal web page, don't bother -- these won't work any more in any practical sense. – David-SkyMesh Jul 30 '13 at 00:05
  • The problem is that I'm following these guidelines. With a lot of struggle after 3 days I've compiled my component (written in c++) and it successfully registered in Firefox. BUT I can't get an access to it from the web page! Do you know, how I can do this? – peetonn Jul 30 '13 at 00:42
  • Are you using XPCom or jsctypes? – David-SkyMesh Jul 30 '13 at 05:48
  • XPCOM. the whole idea briefly: i'm creating an add-on which is doing the same job Firefox's WebRTC implementation does, but it is based on different transport (not UDP/TCP as Firefox implementation). So i'm making it in a form of an c++ add-on which is linked against webrtc lib and custom transport lib. But I need user to have a very simple access to this functionality from JS - pretty much like standard peerconnection offers. – peetonn Jul 30 '13 at 17:42
  • You'd get much better response if you ask a new question that specifically deals with implementing and using XPCom from an addon. Show the code you're using that isn't working. Make sure to use XPCom in the tags. – David-SkyMesh Jul 30 '13 at 23:53
  • http://stackoverflow.com/questions/17955147/ideas-needed-javascriptxpcomc-add-on?noredirect=1#comment26247743_17955147 – peetonn Jul 31 '13 at 00:14
0

To finally resolve my problem: Initially I was still working with the out-of-date Privilege Manager. When I tried to simply remove this line from my code it did not work for me. The issue was: I was working at home, were the extension was not run as an extension, but - out of laziness - only as a regular xul file. As Boris Zbarsky and paa have already mentioned above, you have to run the code in the extension itself for getting "chrome" privileges.

After doing that, running the abovementioned code (with simply removing the PrivilegeManager line) works just fine!

Stefan Surkamp
  • 972
  • 1
  • 16
  • 31