Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
ftt
Contributor
Posts: 10
Registered: ‎02-24-2012
My Device: none
My Carrier: none
Accepted Solution

WebWorks and setControlledAccess

I have a JS extension which I include as part of my app. That extension encrypts some downloaded pictures using setControlledAccess. However, I can't open those pictures in the WebWorks part of my app! That is, I can't simply say: 

<img src="file:///SDCard/…/precious_picture.jpg"/>

The picture just won't show up.

 

At the same time, I'm able to open those pictures in the extension itself. I sign the whole app during build (set up WebSigner).

 

So… What's the problem?

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: WebWorks and setControlledAccess

Hello,

 

The ControlledAccess class wraps a Java Object to secure it. It's typically used with the Runtime or Persistent Stores to securely share data between modules signed with the same key.

 

In your question, you are referring to the file system though. How are you setting the ControlledAccess on this file? If you are able to open the files from your extension, you could try exposing them through a JavaScript call.

Tim Windsor
Open Source Technical Lead
ftt
Contributor
Posts: 10
Registered: ‎02-24-2012
My Device: none
My Carrier: none

Re: WebWorks and setControlledAccess

I don't use ControlledAccess. As I've said above, I use setControlledAccess (a method of ExtendedFileConnection). And, well, I encrypt (and can decrypt) files via a JS call, but that's no use to me! I need to be able to display encrypted images. If I sign the whole app with the key that is used for encryption, why can't I simply display those pictures in the HTML part of my app?

Retired
Posts: 856
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: WebWorks and setControlledAccess

I don't think the application can read the file because it's not actually the application module (signed with your key) that is doing the reading. When you set the src of an image to the file system path, the Browser Rendering engine is the module that is going to do the reading, and I think that's where it falls apart. 

 

However, since you can read your files direction in your extension, why not add a method that returns your files as Data URLs? You can encode your byte[] of the image as Base 64 like so:

 

byte[] encoded = Base64OutputStream.encode( data, 0, data.length, false, false );
String encodedStr = new String( encoded, UTF8_ENCODING );

 Then append the data values, like "data:image/png;base64," to the front of the result and you can set this string as the src of your image object, or even use it in your css.

Tim Windsor
Open Source Technical Lead
ftt
Contributor
Posts: 10
Registered: ‎02-24-2012
My Device: none
My Carrier: none

Re: WebWorks and setControlledAccess

Thank you! I've completely forgotten about data URLs!