package com.example;
public class ChromeAPIExample {
private static final String CHROME_APP_ID = "..."; // Replace with actual Chrome app id
public ChromeAPIExample() { initChromeListener(); }
private native void initChromeListener() /*-{ try { $wnd.example = new Object(); $wnd.example.isChrome = function() { var isChromeBrowser = false; try { isChromeBrowser = (typeof chrome !== 'undefined'); } catch (e) { console.log('isChrome: cannot determine if using chrome: ' + e); }
return isChromeBrowser; };
if (!$wnd.example.isChrome()) { console.log('initChromeListener: not using chrome; returning'); return; }
if ($wnd.example.chromePort && ($wnd.example.chromePort != null)) { console.log"initChromeListener: chromePort still exists, returning"); return; }
console.log('initChromeListener: this is chrome');
var thisInstance = this; var chromeAppId = @com.example.ChromeAPIExample::CHROME_APP_ID;
try {
// Check if the app is installed and enabled by opening a messaging port var port = chrome.runtime.connect(chromeAppId);
if (port) {
$wnd.example.chromePort = port;
console.log('initChromeListener: got port: ' + port);
port.onMessage.addListener(function(msg) { console.log('chrome listener: msg: ' + msg);
});
}
} catch (e) { console.log('initChromeListener: Inner Error: ' + e); } } catch (e2) { alert('initChromeListener: Outer Error: ' + e2); }
}-*/;
}
...
initialize();
function initialize() { chrome.runtime.onConnectExternal.addListener(onConnectExternal);
}
function onConnectExternal(port) {
logMsg('onConnectExternal: port=' + port);
port.onDisconnect.addListener(function() {
logMsg('Port disconnected'); });
}
--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/87a97383-b3a1-436a-832f-79594a4b1b3b%40googlegroups.com.
Maybe related to $wnd, but here we are basically shooting in the dark. You should debug your code and tell us where it behaves unexpectedly otherwise we cannot help much...