Embed SWF file in firefox add-on (no SDK) - firefox-addon

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]

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>

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?

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)

Related

Convert Uri to absolute path with dart

I only get one uri from the file_picker when saving. But so that I can display the correct path, I need the absolute path of the file. Unfortunately I haven't found a working solution. The library flutter_absolute_path unfortunately doesn't seem to work with the new Android versions anymore.
Does anyone have any idea how I could get the absolute path of the file.
example:
content://com.android.providers.downloads.documents/document/297
convert to:
/data/user/0/xxx/cache/dummy1.png
Check out the toFilePath() method of the dart:core package to see if it solves your problem.
I thought so too. But unfortunately I get an exception.
test code:
//uri output from file picker (fileInfo.identifier)
var uriPath = "content://com.android.providers.downloads.documents/document/297";
var uri = Uri.parse(uriPath);
print(uri.toFilePath());
exception
-> Unsupported operation: Cannot extract a file path from a content URI

How to access image from native URI (assets-library) in Cordova for iOS

I have a Cordova/PhoneGap app which uses the camera to capture a picture. I need to access this picture to send to my server.
For Android I simply use $cordovaFile.readAsDataURL(cordova.file.dataDirectory, fileName)
However; on iOS the filename does not come back as such. My return value for iOS shows the path as
assets-library://asset/asset.JPG?id=539425FE-43AA-48E7-9865-D76348208AC7&ext=JPG
How can I access and read this image? I'd prefer to stick with $cordovaFile but just want to get it to work.
I am using CordovaCameraPreview plugin and the best I can get back from the picture taker handler seems to be something formed similar to:
assets-library://asset/asset.JPG?id=990355E1-200A-4E35-AAA1-7D461E3999C8&ext=JPG
assets-library://asset/asset.JPG?id=C49FF0EB-CCCB-45B2-8577-B13868D8DB29&ext=JPG
How can I convert this to a filename and path that I can read with $cordovaFile? According to their documentation (http://ngcordova.com/docs/plugins/file/) it looks like I need to use one of their paths for File System Layout. It works fine on Android using cordova.file.dataDirectory but can't figure out how to access on iOS
I've also tried using window.resolveLocalFileSystemURL(path) but am getting undefined as my result.
Update
I feel like I'm getting closer... using window.resolveLocalFileSystemURL(path,resolveOnSuccess, resOnError); I get more information
name: "assets-library"
fullPath: "/asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
name: "asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
nativeURL: "assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG"
It looks like I now need to use the fullPath but still can't figure out how to access with $cordovaFile
If I try to use $cordovaFile.readAsDataURL(cordova.file.dataDirectory, data.name) where data.name is asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG I get a file not found error
Update 2
I have tried using every single File System Layout available at http://ngcordova.com/docs/plugins/file/ and receive the same File Not Found error on each one. Still no clue how to access a file in assets-library using $cordovaFile
I had success with a simple substitution, like this
fullPath = fullPath.replace("assets-library://", "cdvfile://localhost/assets-library/")
It works in iOS 9.3
I was struggling with a similar issue for a while, but I figured it out today. I also thought that the FileSystem APIs didn't work with assets-libary:// URIs -- but that is not the case.
You should be able to get access to the File object (as well as the actual image name) by using the following code:
resolveLocalFileSystemURL('assets-library://asset/asset.JPG?id=711B4C9D-97D6-455A-BC43-C73059A5C3E8&ext=JPG', function(fileEntry) {
fileEntry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(event) {
console.log(event.target.result.byteLength);
};
console.log('Reading file: ' + file.name);
reader.readAsArrayBuffer(file);
});
});

How to handle the URL protocol bundle://

I try to get a file in my bundle with:
File file = new File(bundleContext.getBundle().
getResource("image/logo.jpg").toURI());
The result is a IllegalArgumentException with the cause "URI scheme is not "file".
This is logical, but how should i open a file with this URL (bundle://28/image/logo.jpg)?
If i use the regular ClassLoader i get the same result.
EDIT:
My Solution:
URL url = this.getClass().getClassLoader().getResource("image/logo.jpg");
InputStream in = new BufferedInputstream(url.openStream());
You cannot open a file since there might not be a file ... So just get the input stream instead. That works for all URLs/URIs.

Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed

I have a .swf file which throws this error when I attempt to load it in a browser. Similar to other posts here this is the code:
var mySpite:Sprite = new Sprite();
var button:Loader = new Loader();
var url:String = "images/btnImage.png";
var urlReq:URLRequest = new URLRequest(url);
button.load(urlReq);
....
When I run the actionscript in Flex Build it works fine. Also when I double click the .swf file in the folder where it is stored, it works fine. I don't know why it only doesn't work and throws this error when I load it in a .jsp page.
It's most likely an issue with your path. Remember that the path to the image will be relative to the page which embeds the SWF.
In answer to your comment about having to change the paths when deploying, depending on how you're building and debugging your SWF, it might be possible to use Capabilities.playerType (see docs) to choose the correct path for the current environment. Another alternative might be to put all your image references in a couple of XML files (one local and one remote). As long as the path to the XML file is consistent between local and remote environments, you can update the SWF without worrying about the image paths.

system.io.directorynotfound -> But it works in Console

My files are referenced like so (it's all relative):
// WHERE YOU KEEP THE PAGE TITLE XML
public static string myPageTitleXML = "xml/pagetitles.xml";
and
using (StreamReader r = new StreamReader(myPageTitleXML))
{ //etc.. . .etc....etc..
}
I get system.io.directorynotfound, and "this problem needs to be shut down", when I double click the executable. But running it from the console works like a charm. What's wrong here?
I played around with attempting to set Environment.CurrentDirectory but couldn't get anything to work. Why should I have to do that anyway? It defeats the purpose of a relative path no?
responding.. .
"application" does not exist in the current context, i'll keep trying what people have mentioned, this is not a windows.form
testing
Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML); gives error URI formats are not supported, as does Path.GetFullPath(). Server.MapPath results in an error as well, this is currently offline
Well assuming this directory is somewhere under the directory in which your code is executing, it sounds like you can use ..
Application.ExecutablePath()
or
Application.StartUpPath()
.. to get an idea as to what your application is seeing when it goes in search of an 'xml' directory with the 'pagetitles.xml' file in it.
If the directory returned by one of these methods does not point where you thought it did, you'll need to move the location of your application or the location of this folder so that it is within the same directory as the app.
Hope this gets you on the right path.
So, when you run it from double clicking the executable, is there a file named pagetitles.xml in a folder named xml, where xml is a folder in the same location as the executable?
It's certainly possible to use relative paths like this, but I wouldn't really recommend it. Instead, maybe use something like:
string fileToOpen = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML);
using (StreamReader r = new StreamReader(fileToOpen))
{
//etc.. . .etc....etc..
}
Is this ASP.NET code? If so then you probably need to do MapPath("xml/pagetitles.xml")

Resources