blackberry / BB10-Webworks-Packager

The BB10 WebWorks Packager bundles the App content with the BB10 WebWorks Framework to create a BAR to run on the BB10 Device (or simulator)
27 stars 18 forks source link

As a WebWorks developer, I can invoke other applications on the device from script #112

Closed kwallis closed 12 years ago

rwmtse commented 12 years ago

@kwallis @nukulb @cdelcol @EricLeiLi @tohman Please take a look at this client API design for bound and unbound invocation: http://wikis.rim.net/display/bbxwebworks/Client+API+to+allow+WebWorks+app+to+invoke+other+apps

rwmtse commented 12 years ago

The Invocation Framework takes the following attributes in an invoke target request, none of the attributes are required:

Bound Invocation - example 1

blackberry.invoke.invoke({
    target: "sys.browser", // in order to know what target & action to specify, the developer needs to first call blackberry.invoke.queryTargets() to find out the possible targets * actions (to be designed)
    action: "bb.action.VIEW",
    uri: "http://www.rim.com"
}, function (error) {
    if (error) {
        console.log(error);
    }
});

Unbound Invocation - example 1

blackberry.invoke.invoke({
    uri: "http://www.rim.com"
}, function (error) {
    if (error) {
        console.log(error);
    }
});

Unbound Invocation - example 2

blackberry.invoke.invoke({
    uri: "file://accounts/1000/shared/camera/IMG_000000001.jpg",
    action: "bb.action.OPEN"
}, function (error) {
    if (error) {
       console.log(error);
    }
});

Unbound Invocation - example 3

blackberry.invoke.invoke({
    type: "image/png"
    data: <blob>
}, function (error) {
    if (error) {
        console.log(error);
    }
});

Unbound Invocation - example 4

blackberry.invoke.invoke({
    type: "text/plain"
    data: "a string"
}, function (error) {
    if (error) {
        console.log(error);
    }
});
nukulb commented 12 years ago

How will the user convert data to a base64 string?

EricLeiLi commented 12 years ago

If they are lucky they will get the data in base64 string already; if not, they will have to google "Javascript: how to encode blob to base64 string".

nukulb commented 12 years ago

Ok @jeffheifetz and I had a discussion and we think data field should accept a blob or a String. So that if the user wants to pass in JSON string they can and if they want to read a Blob as in unknown binary data they can still do that by passing a blob. @kwallis

nukulb commented 12 years ago

@rwmtse - you should be able to use typeof to determine if data is blob or string and then act accordingly.

rwmtse commented 12 years ago

@kwallis @nukulb Question for the data field: whether it is a blob or a string, client.js is going to call window.btoa(data) on it so that it can pass the data as a base64 encoded string to the server side. Now window.btoa() does not accept unicode string, it would throw this error: Error: INVALID_CHARACTER_ERR: DOM Exception 5 Do I simply document this so that the user knows that it's his/her responsibility to convert the string first before calling the invoke function?

The alternative is to convert the string first so that it doesn't contain unicode characters (see MDN documentation), but that would affect the receiving end too.

My preference is to document it and leave it to the developer to convert the string prior to calling invoke.

nukulb commented 12 years ago

I think that is fine, just document it and we can move on.

rwmtse commented 12 years ago

Docs can be found here, note that "source" is not documented for now, b/c it's not clear how it works yet: http://ci0000001875214:9080/hudson/view/WebWorks-API-Docs/job/WebWorks-API-Docs-next-BB10-invoke-other-apps/ws/output/view/blackberry.invoke.html#.invoke^2

kwallis commented 12 years ago

What would be the implications of doing something like this for Unicode strings? http://ecmanaut.blogspot.ca/2006/07/encoding-decoding-utf8-in-javascript.html

rwmtse commented 12 years ago

Our code can do things to convert the string, but the bottom line is the handler app needs to know how to handle the string when it gets it from the invocation framework. If we do unescape( encodeURIComponent( s ) ), the app needs to know decodeURIComponent( escape( s ) ) when it gets it. (BTW, the MDN link that I sent uses the exact same way to deal with unicode strings)

kwallis commented 12 years ago

It seems like this is something that the receiver would have to handle anyway. Is there a way, once they decode the base64, to check if the payload is unicode, and that they then need to decode/escape?

nukulb commented 12 years ago

checking for unicode can be complicated if you have to check for all possible code points. The easiest solution is this but inefficient http://stackoverflow.com/questions/147824/javascript-how-to-find-whether-a-particular-string-has-unicode-characters-esp

Its atleast O(n) its not a big deal but still if the string is large it could be a big a hit. 8K being the maximum size for a data string, because it needs to be under 16K after being base64 for the invoke Framework.

@rwmtse - can you try a string of 8K length to see how much time it takes to go through an entire string? Simple experiment in a standalone WebWorks App is good enough that takes an 8K unicode string with the last character as unicode and everything else ASCII to tell us what the worst case scenario here is

kwallis commented 12 years ago

In terms of docs, can we put the new invoke method below the old one. Reason I am asking is that it is difficult to understand that the constants only apply to the old invoke method and not the new, so let's group all the old stuff together and put the new invoke at the end. I assume this is easier because the template probably defines that methods come after constants/properties, etc.

rwmtse commented 12 years ago

@kwallis Moved the new invoke method below the old one, also added a code snippet about passing unicode data, please take a look:

rwmtse commented 12 years ago

@kwallis http://ci0000001875214:9080/hudson/view/WebWorks-API-Docs/job/WebWorks-API-Docs-next-BB10-invoke-other-apps/ws/WebWorks-API-Docs-next-BB10-invoke-other-apps/view/blackberry.invoke.html#.invoke

kwallis commented 12 years ago

At the top of the page description, let's clarify that the passing of arguments is related to the BBOS and PlayBook implementations of invoke(), and not to the BB10 version.

Will the invoke framework only respond on an error?

Related but separate, could we use the callback to report back on the error around passing unicode, rather than throwing an exception?

Finally, I believe "openMP3File" is intended to illustrate a bound invocation, and "openAnotherApp" for bound, correct? Can we make the comments more explicit that we are illustrating allowing the system to choose the appropriate target, as opposed to telling the system exactly which app to use? I think it could be described a bit more explicitly, especially openMP3File, that the system will choose.

Thanks, this is looking good!

Ken Wallis

Product Manager – BlackBerry WebWorks

Research In Motion

(905) 629-4746 x14369


From: Rosa Tse [reply@reply.github.com] Sent: Thursday, June 07, 2012 6:35 PM To: Ken Wallis Subject: Re: [BB10-Webworks-Packager] As a WebWorks developer, I can invoke other applications on the device from script (#112)

@kwallis http://ci0000001875214:9080/hudson/view/WebWorks-API-Docs/job/WebWorks-API-Docs-next-BB10-invoke-other-apps/ws/WebWorks-API-Docs-next-BB10-invoke-other-apps/view/blackberry.invoke.html#.invoke


Reply to this email directly or view it on GitHub: https://github.com/blackberry/BB10-Webworks-Packager/issues/112#issuecomment-6190029


This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

rwmtse commented 12 years ago

@kwallis

  1. I can clarify about the passing of arguments for BBOS and PB
  2. Invoke framework will always respond, if there is no error, the string in the callback will be an empty string
  3. What I can do for the unicode error is to catch the error from window.btoa() and invoke the client callback directly. Sounds good?
  4. I will elaborate the comments in the code sample a little more

Can you also look at the docs (by @tohman) for the receiver side? Should we include cross-reference links in both docs? http://blackberry-webworks.github.com/WebWorks-API-Docs/WebWorks-API-Docs-next-BB10-onInvoked/view/blackberry.invoke.html#.event:invoked

kwallis commented 12 years ago
  1. Would it be worthwhile to separate into two callbacks, onSuccess, onError? Do we have precedents for this type of thing with other API (I can't think of one off the top of my head...)? Separating potential success and failure is all over Cordova, but if we have precedent in WebWorks for mixing in one callback, we can stick with this but perhaps rename the parameter from error...
  2. Sounds good.

In terms of onInvoked, I am not sure what we would cross-reference exactly? They will both end up on the same page in the API reference, correct?

Ken Wallis

Product Manager – BlackBerry WebWorks

Research In Motion

(905) 629-4746 x14369


From: Rosa Tse [reply@reply.github.com] Sent: Friday, June 08, 2012 10:20 AM To: Ken Wallis Subject: Re: [BB10-Webworks-Packager] As a WebWorks developer, I can invoke other applications on the device from script (#112)

@kwallis

  1. I can clarify about the passing of arguments for BBOS and PB
  2. Invoke framework will always respond, if there is no error, the string in the callback will be an empty string
  3. What I can do for the unicode error is to catch the error from window.btoa() and invoke the client callback directly. Sounds good?
  4. I will elaborate the comments in the code sample a little more

Can you also look at the docs (by @tohman) for the receiver side? Should we include cross-reference links in both docs? http://blackberry-webworks.github.com/WebWorks-API-Docs/WebWorks-API-Docs-next-BB10-onInvoked/view/blackberry.invoke.html#.event:invoked


Reply to this email directly or view it on GitHub: https://github.com/blackberry/BB10-Webworks-Packager/issues/112#issuecomment-6203871


This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

rwmtse commented 12 years ago
  1. We can do 2 callbacks onSuccess, onError. The reason why it's just one callback now is b/c that's the way native calls my JS. But I can easily turn that into 2 callbacks instead.

For onInvoked, I am specifically thinking about the unicode case. Do we need to have code sample there that illustrates what they have to do in their callback to get the unicode string back when they read from the blob?

onInvoked will be on the same page... Just thinking if the cross-reference (between sections) will make it easier for the developer to see the whole picture.

kwallis commented 12 years ago

@nukulb thoughts on the callback topic?

OnInvoked: Ok, I see the potential benefits of an example that ties the two together especially for the unicode case.

----- Original Message ----- From: Rosa Tse [mailto:reply@reply.github.com] Sent: Friday, June 08, 2012 12:07 PM To: Ken Wallis Subject: Re: [BB10-Webworks-Packager] As a WebWorks developer, I can invoke other applications on the device from script (#112)

  1. We can do 2 callbacks onSuccess, onError. The reason why it's just one callback now is b/c that's the way native calls my JS. But I can easily turn that into 2 callbacks instead.

For onInvoked, I am specifically thinking about the unicode case. Do we need to have code sample there that illustrates what they have to do in their callback to get the unicode string back when they read from the blob?

onInvoked will be on the same page... Just thinking if the cross-reference (between sections) will make it easier for the developer to see the whole picture.


Reply to this email directly or view it on GitHub: https://github.com/blackberry/BB10-Webworks-Packager/issues/112#issuecomment-6206626


This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

nukulb commented 12 years ago

@rwmtse @kwallis - I am ok with 2 callbacks, its an easy change and its more web like

For the overall example we should put together an example and a blog post a separate initiative. @kwallis - lets talk about it next week.

ronalag commented 12 years ago

@nukulb @kwallis @rwmtse

My design for the signature of the invoke target query function is as follows:

static void query(response, onSuccess, onError);

The request object is the query to be performed on the Invocation Framework (iF). It's value corresponds to the query targets request object in the in the client API design @rwmtse referenced above.

The onSuccess callback is called whenever the query on the iF was successful. The only argument is a response object which corresponds to the query targets response object in the client API design.

The onError callback is called whenever the query on the iF was unsuccessful. The only argument is a string which contains the error message.

Example:

    var request = {
            "action": "bb.action.SHARE",
            "type": "image/png",
            "target-type": "ALL"
        },
        onSuccess = function (response) {
            alert("response: " + JSON.stringify(response, null, 2);
        },
        onError = function (error) {
            alert("error: " + error);
        };

    blackberry.invoke.query(request, onSuccess, onError);
nukulb commented 12 years ago

@kwallis - can you give your blessing on the signature? We should expose actions as constants @kwallis - please comment on the constants as well.

kwallis commented 12 years ago

Signature looks good.

Does the invoke framework have any pre-defined actions? We should make those constants.

nukulb commented 12 years ago

yes, we should make them constants

kwallis commented 12 years ago

Do we know what the general predefined actions are?

----- Original Message ----- From: Nukul Bhasin [mailto:reply@reply.github.com] Sent: Friday, June 15, 2012 04:05 PM To: Ken Wallis Subject: Re: [BB10-Webworks-Packager] As a WebWorks developer, I can invoke other applications on the device from script (#112)

yes, we should make them constants


Reply to this email directly or view it on GitHub: https://github.com/blackberry/BB10-Webworks-Packager/issues/112#issuecomment-6365351


This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

ronalag commented 12 years ago

yes, we do. However, the iF wiki says this list will grow over the coming months. The list can be found at the Action Registry.

kwallis commented 12 years ago

I would recommend putting in the current list, and we can open another issue to track changes in future releases. Thoughts?

----- Original Message ----- From: Henry Aghaulor [mailto:reply@reply.github.com] Sent: Friday, June 15, 2012 04:35 PM To: Ken Wallis Subject: Re: [BB10-Webworks-Packager] As a WebWorks developer, I can invoke other applications on the device from script (#112)

yes, we do. However, the iF wiki says this list will grow over the coming months. The list can be found at the Action Registry.


Reply to this email directly or view it on GitHub: https://github.com/blackberry/BB10-Webworks-Packager/issues/112#issuecomment-6365947


This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

dansilivestru commented 12 years ago

I realize this comment comes really late, but it just struck me... Since we're changing this API completely, is there an opportunity to not have it be blackberry.invoke.invode(...)? Can we just make it blackberry.invoke(...)? I think it reads better :-)

kwallis commented 12 years ago

What would the feature id be for whitelisting then?

----- Original Message ----- From: Dan Silivestru [mailto:reply@reply.github.com] Sent: Sunday, June 24, 2012 10:56 PM To: Ken Wallis Subject: Re: [BB10-Webworks-Packager] As a WebWorks developer, I can invoke other applications on the device from script (#112)

I realize this comment comes really late, but it just struck me... Since we're changing this API completely, is there an opportunity to not have it be blackberry.invoke.invode(...)? Can we just make it blackberry.invoke(...)? I think it reads better :-)


Reply to this email directly or view it on GitHub: https://github.com/blackberry/BB10-Webworks-Packager/issues/112#issuecomment-6538848


This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

dansilivestru commented 12 years ago

Would blackberry.invoke not work?

kwallis commented 12 years ago

I believe the current implementation requires whitelisting on a "package", not an actual method.

Ken Wallis

Product Manager – BlackBerry WebWorks

Research In Motion

(905) 629-4746 x14369


From: Dan Silivestru [reply@reply.github.com] Sent: Monday, June 25, 2012 10:20 AM To: Ken Wallis Subject: Re: [BB10-Webworks-Packager] As a WebWorks developer, I can invoke other applications on the device from script (#112)

Would blackberry.invoke not work?


Reply to this email directly or view it on GitHub: https://github.com/blackberry/BB10-Webworks-Packager/issues/112#issuecomment-6548432


This transmission (including any attachments) may contain confidential information, privileged material (including material protected by the solicitor-client or other applicable privileges), or constitute non-public information. Any use of this information by anyone other than the intended recipient is prohibited. If you have received this transmission in error, please immediately reply to the sender and delete this information from your system. Use, dissemination, distribution, or reproduction of this transmission by unintended recipients is not authorized and may be unlawful.

tohman commented 12 years ago

This summary has moved from closed blackberry-webworks/WebWorks-API-Docs#138 as was logged by @ishneur :

Testing for cards is done on trunk 1741.

Here is a summary of outstanding issues. They all seem to be OS related:

  1. startPeek('root') doesn't work - it always peeks to the content (immediate parent) and not the root, and the callback value for event onChildCardStartPeek is also always "content"
  2. The onSuccess callback of blackberry.invoke.invoke is not being fired in the parent the first time a card is invoked. It only happens on a fresh OS install or after device reboot. After that, if you reopen the same card, it does fire.
  3. Event listeners stay running in cards even after the card is closed and after its parent app is closed. I also noticed that if I change the card's code/HTML and reinstall it, the old content is still shown until I reboot the device and reinstall the card.
  4. I cannot get the onCardClosed event to fire when a card is closed so I might not be able to test it.

Pull request tested: blackberry-webworks/BB10-Webworks-Packager#71