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

Native Development

Reply
Regular Contributor
derekpapworth
Posts: 56
Registered: ‎06-30-2010
My Device: 9700
My Carrier: T-Mobile UK

blackberry.invoke.invoke from browser

Hi there,

 

I'm using oauth to access Dropbox from a C++/Cascades app which invokes the browser to authenticate in Dropbox and then uses the url callback mechanism to httpserver/listener which then displays message in the browser to say success and ask the user to return to the app .. ideally I'd like the message displayed in the browser to have a button which when clicked invokes the app for them and I've managed to put in what I think is the required html content which works partly but it doesn't respond to the blackberry.invoke.invoke call itself ..

 

I suspect that it's because it needs the webworks.js which I assume has the blackberry.invoke.invoke code in it and I've included a line from a webworks example to load this but either that's wrong or I somehow need to include that library in the C++/Cascades project maybe?

 

here's the html I'm writing into the browser, can anyone help to get this to work? Let me know if more detail needed ..

 

p.s. the button is displayed and when I click on it it does call the invokeApp() function as I see the first debug alert message displayed but nothing after that

 

QByteArray content;

content.append("<HTML><h1>Account linked, go ahead back to the app and check the status!</h1>");

content.append("<script src=\"local:///chrome/webworks.js\" type=\"text/javascript\"></script>");

content.append("<script type=\"text/javascript\">");

content.append("function onInvokeSuccess() {");

content.append(" alert(\"Invocation successful!\");");

content.append("}");

content.append("function onInvokeError(error) {");

content.append(" alert(\"Invocation failed, error: \" + error);");

content.append("}");

content.append("function invokeApp() {");

content.append(" alert(\"debug in invokeApp 1 \");");

content.append(" blackberry.invoke.invoke({");

content.append(" target: \"com.example.MyApp.view\",");

content.append(" action: \"bb.action.OPEN\",");

content.append(" type: \"text/plain\",");

content.append(" data&colon; \"Hello, I invoked you\"");

content.append(" }, onInvokeSuccess, onInvokeError);");

content.append(" alert(\"debug in invokeApp 2 \");");

content.append("}");

content.append("</script>");

content.append("<input id=\"clickMe\" type=\"button\" value=\"clickme\" onclick=\"invokeApp();\" />");

content.append("</HTML>");

reply.append("HTTP/1.0 200 OK \r\n");

reply.append("Content-Type: text/html; charset=\"utf-8\"\r\n");

reply.append(QString("Content-Length: %1\r\n").arg(content.size()));

reply.append("\r\n");

reply.append(content);

socket->write(reply);

 

Thanks,

 

Derek

Please use plain text.
Developer
Innovatology
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: blackberry.invoke.invoke from browser

Of course that won't work.

 

Allowing Invoke calls from the browser would be a huge security breach. Any website could embed javascript do do funky stuff on your device...

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Please use plain text.
Regular Contributor
derekpapworth
Posts: 56
Registered: ‎06-30-2010
My Device: 9700
My Carrier: T-Mobile UK

Re: blackberry.invoke.invoke from browser

thanks for response .. I appreciate the security problem of allowing invoke calls from external site but I guess I was hoping that having the url that generates the script being from http://localhost .. would've allowed more as it's then known to be coming from localhost

 

As it happens though your point got me thinking and I've now switched from invoking the browser to do the authorise portion of the oauth process and simply loaded a QML page with a webview in it within the app itself and hence it's actually much cleaner and neater, doesn't require an http server thread etc. and so is much better approach in general!

 

Best regards,


Derek

Please use plain text.