/usr/lib/x86_64-linux-gnu/qt5/qml/Ubuntu/UnityWebApps/UnityWebAppsBackendComponents.js is in unity-webapps-qml 0.1+16.04.20160114-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | /*
* Copyright 2013 Canonical Ltd.
*
* This file is part of unity-webapps-qml.
*
* unity-webapps-qml is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 3.
*
* unity-webapps-qml is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
var _backends = {};
function __set(id, component) {
_backends[id] = component;
};
function __areValidParams(params) {
function __has(o,n) { return n in o && o[n] != null && (typeof o[n] === 'string' ? o[n] !== "" : true); };
return params && __has(params, 'name') && __has(params, 'displayName');
};
function __createQmlObject(qmlStatement, parentItem, params) {
var component = null;
var error = null;
try {
component = Qt.createQmlObject(qmlStatement, parentItem);
} catch(e) {
error = JSON.stringify(e.qmlErrors);
}
return { object: component, error: error};
};
//TODO: bad mechanism, it could possibly be that the "base" backend is
// ready after the "notify" one ... which is bad and could enable calls
// to notify w/o base ready
var _backendReadyListeners = {};
function __onBackendReady(name) {
if (!(name instanceof String) || name.length !== 0)
return;
var listeners = _backendReadyListeners[name];
if (listeners && listeners instanceof Array && listeners.length !== 0) {
listeners.forEach(function (listener) {
try {
listener(name);
} catch (e) {};
});
}
};
function signalOnBackendReady(name, func) {
if (typeof(name) != "string" || name.length === 0)
return;
if (!(func instanceof Function))
return;
// check if backend already ready
if (!!get(name)) {
console.debug('Backend ready: ' + name);
func(name);
return;
}
if (!_backendReadyListeners[name])
_backendReadyListeners[name] = [];
_backendReadyListeners[name].push(func);
}
function UnityActionsBackendAdaptor(parentItem, actionsContext) {
this._actions = {};
this._actionsContext = actionsContext;
};
UnityActionsBackendAdaptor.prototype.destroy = function () {
this.clearActions();
}
UnityActionsBackendAdaptor.prototype.__normalizeName = function (actionName) {
return actionName.replace(/^\/+/, '');
}
UnityActionsBackendAdaptor.prototype.__actionExists = function (actionName) {
if (!actionName || typeof(actionName) != 'string' || actionName.lenght === 0)
return false;
return this._actions[actionName] != null && this._actions[actionName].action != null;
};
UnityActionsBackendAdaptor.prototype.addAction = function (_actionText, callback, id) {
var actionText = this.__normalizeName(_actionText);
if (this.__actionExists(actionText))
this.clearAction(actionText);
var params = ' text: "' + actionText + '";'
+ ' enabled: true; ' +
(id ? ('name: ' + '"' + id + '"') : '');
var action = __createQmlObject('import Ubuntu.Unity.Action 1.0 as UnityActions; \
UnityActions.Action { ' + params + ' }',
this._actionsContext).object;
this._actionsContext.addAction(action);
action.triggered.connect(callback);
this._actions[actionText] = { action: action, callback: callback};
}
UnityActionsBackendAdaptor.prototype.clearAction = function (_actionName) {
var actionName = this.__normalizeName(_actionName);
if ( ! this.__actionExists(actionName))
return;
try {
this._actionsContext.removeAction(this._actions[actionName].action);
this._actions[actionName].action.enabled = false;
this._actions[actionName].action.triggered.disconnect(this._actions[actionName].callback);
this._actions[actionName] = null;
} catch(e) {
console.debug('Error while removing an action: ' + e);
}
}
UnityActionsBackendAdaptor.prototype.clearActions = function () {
for(var action in this._actions) {
if (this._actions.hasOwnProperty(action) && this._actions[action] != null)
this.clearAction(action);
}
}
/*!
\internal
Extracts the properties of a given js object and tries to
create a string for the definition of a QML object w/ those values.
e.g.
params = {name: "myname", version: 1}
->
"name: 'myname'; version: 1"
It assumes a lot and is fragile (no array, complex object support, error handling, etc,)
FIXME: Shamefully hacky
*/
function __extractParams(params) {
if (!params || !(params instanceof Object))
return "";
var extracted = "";
for (var p in params) {
if (params.hasOwnProperty(p) && params[p] != null) {
extracted += p + ":" + JSON.stringify(params[p]) + "; ";
}
}
return extracted;
}
function get(id) {
return _backends[id];
};
function UbuntuBindingBackendDelegate(parent) {
this._parent = parent;
this._id = 0;
this._objects = {};
this._last_proxy_id = 0;
}
UbuntuBindingBackendDelegate.prototype = {
createQmlObject: function(uri, version, component, properties) {
var statement = 'import ' + uri
+ ' ' + version + '; '
+ component + ' { '
+ __extractParams(properties)
+ ' }';
var result = __createQmlObject(statement,
this._parent);
if (result.error != null) {
console.debug('Error while creating object: '
+ uri
+ '.'
+ component
+ ' : '
+ result.error);
return null;
}
var id = this._generateObjectId(uri, component);
this._objects[id] = result.object;
return {object: this._objects[id], id: id};
},
parent: function() {
return this._parent;
},
parentView: function() {
return this._parent ? this._parent.bindee : null;
},
isObjectProxyInfo: function(info) {
return 'type' in info &&
info.type === 'object-proxy' &&
'apiid' in info &&
'objecttype' in info &&
'objectid' in info;
},
deleteId: function(id) {
if (this._objects[id] != null) {
delete this._objects[id];
this._objects[id] = null;
}
},
objectFromId: function(id) {
return id != null ? this._objects[id] : null;
},
storeQmlObject: function(object, uri, version, component, properties) {
var id = this._generateObjectId(uri, component);
console.debug('got an id: ' + id)
this._objects[id] = object;
return id;
},
createModelAdaptorFor: function(model) {
var adaptor = Qt.createQmlObject('import Ubuntu.UnityWebApps 0.1 \
as UW; UW.AbstractItemModelAdaptor {}', this._parent);
adaptor.itemModel = model;
return adaptor;
},
_generateObjectId: function(uri, name) {
var candidate = uri + name + this._id;
while (this._objects[candidate] != undefined) {
++this._last_proxy_id;
candidate = uri + name + this._last_proxy_id;
}
return candidate;
}
};
var backendDelegate;
function createBackendDelegate(parentItem) {
backendDelegate = new UbuntuBindingBackendDelegate(parentItem);
}
/**
* \brief creates all the backends
*
* \param
*/
function createAllWithAsync(parentItem, params, eventHandlers) {
if (!__areValidParams(params)) {
//TODO: error reporting
throw new Error("Invalid creation parameters");
}
var extracted = __extractParams(params);
function connectAppRaisedEvent(target) {
if (target && eventHandlers && eventHandlers.onAppRaised)
target.raised.connect(function() { try { eventHandlers.onAppRaised(); } catch(e){} });
}
//FIXME:!!! lots of duplicated stuff
var result = __createQmlObject('import Ubuntu.UnityWebApps 0.1 as Backends; \
Backends.UnityWebappsBase { }',
parentItem,
params);
if (result.error != null) {
console.debug('Could not create base backend: ' + result.error);
clearAll();
return false;
}
var apiBase = result.object;
apiBase.model = parentItem.model;
__set("base", apiBase);
__onBackendReady("base");
// notifications
result = __createQmlObject('import Ubuntu.UnityWebApps 0.1 as Backends; \
Backends.UnityWebappsNotificationsBinding { name: "' + params.name + '"; }',
parentItem,
params);
if (result.error != null) {
console.debug('Could not create notifications backend: ' + result.error);
clearAll();
return false;
}
__set("notify", result.object);
__onBackendReady("notify");
// launcher
result = __createQmlObject('import Ubuntu.UnityWebApps 0.1 as Backends; \
Backends.UnityWebappsLauncherBinding { }',
parentItem,
params);
if (result.error != null) {
console.debug('Could not create launcher backend: ' + result.error);
clearAll();
return false;
}
var launcher = result.object;
apiBase.appInfosChanged.connect(function(appInfos) {
launcher.onAppInfosChanged(appInfos);
});
__set("launcher", launcher);
__onBackendReady("launcher");
// media player
result = __createQmlObject('import Ubuntu.UnityWebApps 0.1 as Backends; \
Backends.UnityWebappsMediaPlayerBinding { }',
parentItem,
params);
if (result.error != null) {
console.debug('Could not create MediaPlayer backend: ' + result.error);
clearAll();
return false;
}
var mediaplayer = result.object;
apiBase.appInfosChanged.connect(function(appInfos) { mediaplayer.onAppInfosChanged(appInfos); });
__set("mediaplayer", mediaplayer);
__onBackendReady("mediaplayer");
connectAppRaisedEvent(mediaplayer);
// messaging menu
result = __createQmlObject('import Ubuntu.UnityWebApps 0.1 as Backends; \
Backends.UnityWebappsMessagingBinding { }',
parentItem,
params);
if (result.error != null) {
console.debug('Could not create messaging menu backend: ' + result.error);
clearAll();
return false;
}
// model have to be manuall set
var messagingmenu = result.object;
apiBase.appInfosChanged.connect(function(appInfos) { messagingmenu.onAppInfosChanged(appInfos); });
__set("messaging", messagingmenu);
__onBackendReady("messaging");
connectAppRaisedEvent(messagingmenu);
// extra actions set for the launcher/messaging-menu
if (parentItem.actionsContext) {
__set("indicator-actions", new UnityActionsBackendAdaptor(parentItem, parentItem.actionsContext));
__onBackendReady("indicator-actions");
}
// Unity actions/HUD
//FIXME: find a better way to access parentItem.actionsContext
if (parentItem.actionsContext) {
__set("hud", new UnityActionsBackendAdaptor(parentItem, parentItem.actionsContext));
__onBackendReady("hud");
}
}
function clearAll () {
if (_backends.base) {
_backends.base.destroy();
_backends['base'] = null;
}
if (_backends.hud) {
_backends.hud.destroy();
_backends['hud'] = null;
}
if (_backends.notify) {
_backends.notify.destroy();
_backends['notify'] = null;
}
if (_backends.launcher) {
_backends.launcher.destroy();
_backends['launcher'] = null;
}
if (_backends['indicator-actions']) {
_backends['indicator-actions'].destroy();
_backends['indicator-actions'] = null;
}
if (_backends.mediaplayer) {
_backends.mediaplayer.destroy();
_backends['mediaplayer'] = null;
}
if (_backends.messaging) {
_backends.messaging.destroy();
_backends['messaging'] = null;
}
};
|