From c1e908793a0dfeb5ad5907771777d3d3c05bdfa5 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Tue, 2 Aug 2016 07:14:02 -0500 Subject: [PATCH] code cleanup and documentation --- src/lightdm-webkit2-greeter-ext.c | 6 +++- themes/_vendor/js/mock.js | 55 ++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/lightdm-webkit2-greeter-ext.c b/src/lightdm-webkit2-greeter-ext.c index 1ef5efc..f1be7db 100644 --- a/src/lightdm-webkit2-greeter-ext.c +++ b/src/lightdm-webkit2-greeter-ext.c @@ -1497,11 +1497,15 @@ window_object_cleared_callback(WebKitScriptWorld *world, greeter_util_object = JSObjectMake(jsContext, greeter_util_class, NULL); JSObjectSetProperty(jsContext, globalObject, - JSStringCreateWithUTF8CString("greeterutil"), + JSStringCreateWithUTF8CString("greeter_util"), greeter_util_object, kJSPropertyAttributeNone, NULL); + /* Keep previous variable name for backwards compatibility. Will remove at later date. */ + command = JSStringCreateWithUTF8CString("window.greeterutil = greeter_util;"); + JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); + /* If the greeter was started as a lock-screen, send message to our UI process. */ if (lightdm_greeter_get_lock_hint(greeter)) { diff --git a/themes/_vendor/js/mock.js b/themes/_vendor/js/mock.js index 9926ad0..acc06b5 100644 --- a/themes/_vendor/js/mock.js +++ b/themes/_vendor/js/mock.js @@ -25,7 +25,10 @@ * along with this program. If not, see . */ -let _greeter = null, MockData; +let lightdm = null, + greeter_util = null, + config = null, + MockData; if ('undefined' !== typeof lightdm) { throw new Error('Cannot use LightDM Mock while the greeter is running!'); @@ -209,6 +212,7 @@ let LightDMUser = ( user_info ) => ({ real_name: user_info.real_name || '' }); + /** * @ignore */ @@ -220,6 +224,46 @@ let MockObjects = { }; +/** + * Provides various utility methods for use by theme authors. The greeter will automatically + * create an instance of this class when it starts. The instance can be accessed + * with the global variable: `greeter_util`. + */ +class GreeterUtil { + + constructor() { + if (null !== greeter_util) { + return greeter_util; + } + + greeter_util = this; + this._mock_data = MockData(); + } + + /** + * Returns the contents of directory at `path`. + * + * @param path + * @returns {String[]} List of abs paths for the files and directories found in `path`. + */ + dirlist( path ) { + return this._mock_data.dirlist; + } + + /** + * Escape HTML entities in a string. + * + * @param {String} text + * @returns {String} + */ + txt2html( text ) { + let entities_map = { '"': '"', '&': '&', '<': '<', '>': '>' }; + + return text.replace(/[\"&<>]/g, a => entities_map[a] ); + } +} + + /** * Singleton class which implements the LightDMGreeter Interface. Greeter themes will * interact directly with this class to facilitate the user log in processes. @@ -229,11 +273,11 @@ let MockObjects = { class LightDMGreeter { constructor() { - if ( null !== _greeter ) { - return _greeter; + if ( null !== lightdm ) { + return lightdm; } - _greeter = this; + lightdm = this; this._mock_data = MockData(); this._initialize(); @@ -673,7 +717,8 @@ MockData = () => ({ ] }); -window.lightdm = new LightDMGreeter(); +new GreeterUtil(); +new LightDMGreeter(); // mock lighdm for testing