8
8
var aWindow = currentWindow;
10
10
var service = null;
13
var webkitNotificationUnityBackend = {
14
showNotification: function (iconUrl, title, body) {
16
var notification = plugin.notification_new(title, body, null/*iconUrl*/);
17
plugin.notification_show(notification, null);
18
plugin.notification_destroy(notification);
21
// TODO decipher/inject proper & general logging policy for user side of API
12
init: function (options) {
13
options.url = window.location.href;
14
options.hostname = window.location.hostname;
15
options.host = window.location.host;
16
options.protocol = window.location.protocol;
17
chrome.runtime.sendMessage (
18
{method: "init_requested", options: options}
19
, function (response) {});
41
38
// 1. inject a piece of javascript proxying all the requests
42
39
// to the unity webapps api
43
insertScriptIntoWebpage('webkitnotif-wrapper-builder.js');
44
40
insertScriptIntoWebpage('unity-api-page-proxy-builder-gen.js');
45
41
insertScriptIntoWebpage('unity-api-page-proxy.js');
157
function initializePluginConnection (logger){
158
plugin = document.getElementById ("unityChromiumExtensionId");
160
logger ('Could not bind to the scriptable NPAPI plugin');
163
logger ("Got a plugin object: " + plugin);
165
// initialize webkitnotification backend & fallback
167
plugin.notification_init("chromium");
170
logger ("Error while trying to initialize notify OSD NPAPI connection");
171
// decide to bail out
174
UnityWebappsWebkitNotificationApiPageProxyBuilder(webkitNotificationUnityBackend, aWindow);
176
// initialize unity API binding
177
service = plugin.service_new ();
178
logger ("Service object created: " + service);
180
// global plugin initialization
181
// FIXME: there seem to be an issue that started w/ chromium 27+
182
// where NPobnject v8 bindings are looked up in the wrong
183
// JS world under some circumstances.
184
api = UnityGlobalPropertyInitializer.makeCallback (
186
return document.getElementById ("unityChromiumExtensionId");
193
initializePluginConnection (function (msg) {
194
if (consoleService && consoleService.logStringMessage) {
195
consoleService.logStringMessage ("Unity Webapps: " + msg);
199
149
// handle the proxy side of the api which is being injected on the
201
151
injectApiProxy();
203
var windowExternal = aWindow.external;
207
__proto__: windowExternal,
208
getUnityObject: function (version) {
209
console.log ('getUnityObject called with version ' + version);
212
throw new Error("incorrect version");
215
aWindow.external = new unity();