Chrome apps and GWT

172 views
Skip to first unread message

alucard

unread,
Feb 9, 2014, 6:12:33 AM2/9/14
to google-we...@googlegroups.com
Is it possible to develop Chrome Apps in GWT. I have tried and have encountered the dreaded CSP problem as described here. I couldn't make it work with the solution mentioned therein. Has someone succeed to make it work? If so a minimal "Hello world" example would be nice. Thanks in advance.

Andrew Mackenzie

unread,
Feb 9, 2014, 9:18:42 AM2/9/14
to google-we...@googlegroups.com
I've developed a Chrome extension using mainly GWT, but it's mostly loaded by the extension remotely (loading JS handcrafted). It's mainly a build/packaging problem. GWT will build the JS for you and the "loaders" then you have to include into your extension file hierarchy in your build, and load as you desire.

alucard

unread,
Feb 10, 2014, 2:51:56 AM2/10/14
to google-we...@googlegroups.com
I am not sure I understood well but it seems that you loaded the GWT app in a webview or something similar. That is not what I meant. I'd like to be able to invoke the chrome.* apis from my GWT app (after I wrap them). I tried this by modifying the Browser sample app. I modified the browser.html file to load the GWT app. The GWT app is trivial, just an entry point with a simple JSNI method that logs a simple message via console.log (this part shouldn't break CSP). I tried with and without the DirectInstallLinker, the result is a bit better with the linker (it reports fewer errors in the app console) but it does not work either way.
I didn't get the part about the "loaders".
Thanks for your help.

Andrew Mackenzie

unread,
Feb 10, 2014, 3:52:12 AM2/10/14
to google-we...@googlegroups.com

You might need to try a different GWT linker that supports cross-site requests. I'll look to see which one I used tonight.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/Y1pPOVZmeoU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-tool...@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

alucard

unread,
Feb 14, 2014, 3:29:52 PM2/14/14
to google-we...@googlegroups.com
This worked for me:

You have to add a new linker extended from DirectInstallLinker.

public class CspLinker extends DirectInstallLinker {

   
@Override
   
protected String getJsInstallLocation(LinkerContext context) {
       
return "path/to/modified/script/installLocationMainWindow.js";
   
}
}


then you need to modify the installLocationMainWindow.js script (the setupInstallLocation function) like so:

function setupInstallLocation() {
   
if (init) {
       
return;
   
}
//  var script = window.document.createElement('script');
//  script.language='javascript';
//  script.text = "var $wnd = window;";
//  window.document.body.appendChild(script);
    window
.$wnd = window;
    init
= true;
}


finally add this to your .gwt.xml file:

    <define-linker name="cspLinker" class="com.foo.bar.chrome.linker.CspLinker" />
   
<add-linker name="cspLinker" />




On Monday, February 10, 2014 9:52:12 AM UTC+1, Andrew Mackenzie wrote:

You might need to try a different GWT linker that supports cross-site requests. I'll look to see which one I used tonight.

On Feb 10, 2014 8:52 AM, "alucard" <slice.of...@gmail.com> wrote:
I am not sure I understood well but it seems that you loaded the GWT app in a webview or something similar. That is not what I meant. I'd like to be able to invoke the chrome.* apis from my GWT app (after I wrap them). I tried this by modifying the Browser sample app. I modified the browser.html file to load the GWT app. The GWT app is trivial, just an entry point with a simple JSNI method that logs a simple message via console.log (this part shouldn't break CSP). I tried with and without the DirectInstallLinker, the result is a bit better with the linker (it reports fewer errors in the app console) but it does not work either way.
I didn't get the part about the "loaders".
Thanks for your help.

On Sunday, February 9, 2014 3:18:42 PM UTC+1, Andrew Mackenzie wrote:
I've developed a Chrome extension using mainly GWT, but it's mostly loaded by the extension remotely (loading JS handcrafted). It's mainly a build/packaging problem. GWT will build the JS for you and the "loaders" then you have to include into your extension file hierarchy in your build, and load as you desire.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/Y1pPOVZmeoU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages