Reputation: 257
I have a problem with a firefox extension i'm developing.
I need to add an SWF file in the page. If I load it from a remote server, it works fine:
myObj2.setAttribute("data",'http://www.mySite.com/myFile.swf');
myPar1.setAttribute("value",'http://www.mySite.com/myFile.swf');
It works fine but is not accepted for the review.
so I created a resource dir in the manifest:
resource ldvswf swf/
and changed the script into:
myObj2.setAttribute("data",'resource://ldvswf/myFile.swf');
myPar1.setAttribute("value",'resource://ldvswf/myFile.swf');
but it doesn't work. The folder resource://ldvswf is ok as i tested loading an image and I see it.
The reviewer wrote me that for flash file it "requires doing so via a file: URL", but I don't know how to manage, I tested:
'file: resource://ldvswf/myFile.swf'
'file://resource://ldvswf/myFile.swf'
'file://ldvswf/myFile.swf'
'file: ldvswf/myFile.swf'
And nothing works.
Any suggestion for the right path?
Thanks a lot!
Nadia
Update: the editor wrote me:
You need a file URL that points to an actual file. If your extension is unpacked, something like the following should do:
Services.io.newFileURI(Services.io.newURI("resource://ldvswf/myFile.swf", null, null)
.QueryInterface(Ci.nsIFileURL).file)
.spec
But I don't understand how to plce it to replace:
myObj2.setAttribute("data",'http://www.mySite.com/myFile.swf');
myPar1.setAttribute("value",'http://www.mySite.com/myFile.swf');
I made some test like:
var file = Services.io.newFileURI(Services.io.newURI("resource://ldvswf/myFile.swf", null, null).QueryInterface(Ci.nsIFileURL).file).spec ;
myObj2.setAttribute("data",file);
myPar1.setAttribute("value",file);
But I get this error message:
Error: NS_NOINTERFACE: Component returned failure code: 0x80004002 (NS_NOINTERFACE) [nsIFileURL.file]
Upvotes: 0
Views: 216
Reputation: 7945
make sure you have a line in package.json
:
"unpack": true,
at the same level as name, title, author etc. Note that true
does not have the quotes.
(https://developer.mozilla.org/en-US/Add-ons/SDK/Tools/package_json)
Upvotes: 0
Reputation: 346
try breaking the line like this:
var file = Services.io.newURI("resource://ldvswf/myFile.swf", null, null).QueryInterface(Ci.nsIFileURL).file;
alert(file.path)
var file = Services.io.newFileURI(file).spec ;
alert(file)
the first alert() should give a local system path like 'c:\folder\filename...' the second should give a file:// URI
so what do you get?
Upvotes: 0
Reputation: 346
Have you tried using contentaccessible=yes
in your chrome.manifest
, like this:
content package_name content/ contentaccessible=yes
I tested it with an image in a local web page and it worked, don't know for SWF:
<img src="chrome://package_name/skin/window.png"/>
Another approach is to get the file URI of the chrome:// (not resource://) file like this:
function chromeToPath (aPath){
if (!aPath || !(/^chrome:/.test(aPath))){
return null; //not a chrome url
}
var Cc = Components.classes, Ci = Components.interfaces;
var spec, url, file;
var ios = Cc['@mozilla.org/network/io-service;1'].getService(Ci["nsIIOService"]);
var uri = ios.newURI(aPath, "UTF-8", null);
var crs = Cc['@mozilla.org/chrome/chrome-registry;1'].getService(Ci["nsIChromeRegistry"]);
var fph = Cc["@mozilla.org/network/protocol;1?name=file"].createInstance(Ci.nsIFileProtocolHandler);
spec = crs.convertChromeURL(uri).spec;
return spec;
}
usage:
chromeToPath('chrome://package_name/skin/window.png')
and it will return the file:// URI of the file.
If you test this, better make sure the extension is unpacked (unzipped) on install:
in install.rdf
:
<em:unpack>true</em:unpack>
Upvotes: 1