From 26ff1da7ff536959cf7d5621885b8eace2e911db Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Mon, 6 Feb 2017 05:28:24 -0600 Subject: [PATCH] The master branch now completely belongs to web-greeter 3.0 :triumph: --- .doclets.yml | 9 +- .editorconfig | 30 +- README.md | 33 +- build/.gitignore | 0 build/utils.sh | 133 +- data/com.antergos.webkit2-greeter.appdata.xml | 104 - data/com.antergos.webkit2-greeter.desktop | 6 - data/meson.build | 19 - data/webkit2-greeter.conf | 35 - man/lightdm-webkit2-greeter.1 | 308 --- man/meson.build | 1 - meson.build | 105 - meson_options.txt | 24 - po/meson.build | 29 - src/greeter-config.c | 255 -- src/greeter-config.h | 58 - src/greeter.c | 434 ---- src/webkit2-extension.c | 2066 ----------------- themes/meson.build | 5 - ...m-webkit2-greeter.doap => web-greeter.doap | 6 +- web-greeter/meson.build | 41 - web-greeter/whither.yml | 3 +- 22 files changed, 134 insertions(+), 3570 deletions(-) delete mode 100644 build/.gitignore delete mode 100644 data/com.antergos.webkit2-greeter.appdata.xml delete mode 100644 data/com.antergos.webkit2-greeter.desktop delete mode 100644 data/meson.build delete mode 100644 data/webkit2-greeter.conf delete mode 100644 man/lightdm-webkit2-greeter.1 delete mode 100644 man/meson.build delete mode 100644 meson.build delete mode 100644 meson_options.txt delete mode 100644 po/meson.build delete mode 100644 src/greeter-config.c delete mode 100644 src/greeter-config.h delete mode 100644 src/greeter.c delete mode 100644 src/webkit2-extension.c delete mode 100644 themes/meson.build rename lightdm-webkit2-greeter.doap => web-greeter.doap (86%) delete mode 100644 web-greeter/meson.build diff --git a/.doclets.yml b/.doclets.yml index d14b175..dc860c9 100644 --- a/.doclets.yml +++ b/.doclets.yml @@ -1,8 +1,9 @@ files: - - src/gresource/js/LightDMObjects.js - - src/gresource/js/Greeter.js - - src/gresource/js/GreeterConfig.js - - src/gresource/js/ThemeUtils.js + - web-greeter/resources/js/docs/LightDMObjects.js + - web-greeter/resources/js/docs/Greeter.js + - web-greeter/resources/js/docs/GreeterConfig.js + - web-greeter/resources/js/ThemeUtils.js + - web-greeter/resources/js/bootstrap.js articles: - Overview: README.md branches: diff --git a/.editorconfig b/.editorconfig index 5d97ae7..f640174 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,25 +1,21 @@ # Top-most EditorConfig file root = true -# Unix-style newlines with a newline ending every file [*] -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true - -# Indent With Tabs -indent_style = tab -indent_size = tab -tab_width = 4 - -# UTF-8 -charset = utf-8 - - -max_line_length = 99 +charset = utf-8 continuation_indent_size = 4 -indent_brace_style = 1TBS -curly_bracket_next_line = false +curly_bracket_next_line = false +end_of_line = lf +indent_brace_style = 1TBS +indent_size = 4 +indent_style = tab +insert_final_newline = true +max_line_length = 99 +tab_width = 4 +trim_trailing_whitespace = true [*.py] indent_style = space + +[*.yml] +indent_style = space diff --git a/README.md b/README.md index b39612e..ec1c0ac 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# lightdm-webkit2-greeter +# Web Greeter for LightDM [![Latest Release](https://img.shields.io/github/release/Antergos/lightdm-webkit2-greeter.svg?style=flat-square)](https://github.com/Antergos/lightdm-webkit2-greeter/releases)  [![CircleCI](https://img.shields.io/circleci/project/Antergos/lightdm-webkit2-greeter/master.svg?style=flat-square)](https://circleci.com/gh/Antergos/lightdm-webkit2-greeter)  [![Coverity Scan Build Status](https://img.shields.io/coverity/scan/6871.svg?style=flat-square)](https://scan.coverity.com/projects/antergos-lightdm-webkit2-greeter)  [![Theme API Docs](https://img.shields.io/badge/API--Doc-ready-brightgreen.svg?style=flat-square)](https://doclets.io/Antergos/lightdm-webkit2-greeter/stable)  [![AUR Votes](https://img.shields.io/aur/votes/lightdm-webkit2-greeter.svg?maxAge=2592000&style=flat-square)](https://aur.archlinux.org/packages/lightdm-webkit2-greeter) ## Install It @@ -16,34 +16,23 @@ |![openSUSE](https://dl.dropboxusercontent.com/u/60521097/Geeko-button-bling7.png)|[1 Click Install](https://software.opensuse.org/ymp/home:antergos/openSUSE_Leap_42.1/lightdm-webkit2-greeter.ymp?base=openSUSE%3ALeap%3A42.1&query=lightdm-webkit2-greeter)  \|  [OBS Repo](https://software.opensuse.org/download.html?project=home:antergos&package=lightdm-webkit2-greeter)| |![ubuntu](https://dl.dropboxusercontent.com/u/60521097/ubuntu_orange_hex.png)|[OBS Repo](https://software.opensuse.org/download.html?project=home:antergos&package=lightdm-webkit2-greeter)| -## Build It +## Install It Manually ### Dependencies -| | ![antergos](https://dl.dropboxusercontent.com/u/60521097/logo-square26x26.png)    ![arch](https://dl.dropboxusercontent.com/u/60521097/archlogo26x26.png) | ![debian](https://dl.dropboxusercontent.com/u/60521097/openlogo-nd-25.png)    ![ubuntu](https://dl.dropboxusercontent.com/u/60521097/ubuntu_orange_hex.png) | ![fedora](https://dl.dropboxusercontent.com/u/60521097/fedora-logo.png) | ![openSUSE](https://dl.dropboxusercontent.com/u/60521097/Geeko-button-bling7.png) | +| | ![antergos](https://dl.dropboxusercontent.com/u/60521097/logo-square26x26.png)    ![arch](https://dl.dropboxusercontent.com/u/60521097/archlogo26x26.png) | ![debian](https://dl.dropboxusercontent.com/u/60521097/openlogo-nd-25.png)    ![ubuntu](https://dl.dropboxusercontent.com/u/60521097/ubuntu_orange_hex.png) | ![fedora](https://dl.dropboxusercontent.com/u/60521097/fedora-logo.png) | ![openSUSE](https://dl.dropboxusercontent.com/u/60521097/Geeko-button-bling7.png) | |-----------------------|-------------------------------------------------------------------------|----------------------------------------------------------------------------|-------------------------------------------------------------------------|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------| -|**liblightdm-gobject-1** |lightdm |liblightdm-gobject-dev | lightdm-gobject-devel | liblightdm-gobject-1-0 | -|**gtk+ 3** |gtk3 |libgtk-3-0 | gtk3 | gtk3 | -|**webkit2gtk-4.0** |webkit2gtk|libwebkit2gtk-4.0-dev | webkitgtk4 | libwebkit2gtk-4_0-37 | -|**dbus-glib-1** |dbus-glib|libdbus-glib-1-dev | dbus-glib | dbus-1-glib | +|**whither** |python-whither|python3-whither |python3-whither |python3-whither | +|**liblightdm-gobject** |lightdm |liblightdm-gobject-dev|lightdm-gobject-devel|liblightdm-gobject-1-0| +|**pygobject** |python-gobject|python3-gi |pygobject3 |python3-gobject | +|**pyqt5** |python-pyqt5 |python3-pyqt5 |python3-qt5 |python3-qt5 | +|**qt5-webengine** |qt5-webengine |libqt5webengine5 |qt5-qtwebengine |libqt5-qtwebengine | -#### Build Deps -| | ![antergos](https://dl.dropboxusercontent.com/u/60521097/logo-square26x26.png)    ![arch](https://dl.dropboxusercontent.com/u/60521097/archlogo26x26.png)    ![debian](https://dl.dropboxusercontent.com/u/60521097/openlogo-nd-25.png)    ![ubuntu](https://dl.dropboxusercontent.com/u/60521097/ubuntu_orange_hex.png)    ![fedora](https://dl.dropboxusercontent.com/u/60521097/fedora-logo.png)    ![openSUSE](https://dl.dropboxusercontent.com/u/60521097/Geeko-button-bling7.png) | -|-------------------|-------------------------------------------------------------------------|----------------------------------------------------------------------------|-------------------------------------------------------------------------|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------| -|**Meson Build System**|meson v0.37+| - -### How To Build -> ***Note:*** These instructions are for the `master` branch. To build the latest release, please see the `stable` branch. +> ***NOTE:*** These instructions are for the `master` branch. To build the latest release, please see the `stable` branch. ```sh git clone https://github.com/Antergos/lightdm-webkit2-greeter.git /tmp/greeter -cd /tmp/greeter/build -meson --prefix=/usr --libdir=lib .. -ninja -``` - -### How To Install -```sh -sudo ninja install +cd /tmp/greeter +sudo make install ``` ## Theme JavaScript API: diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/build/utils.sh b/build/utils.sh index 1909667..8b0a23f 100755 --- a/build/utils.sh +++ b/build/utils.sh @@ -1,71 +1,140 @@ #!/bin/bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BUILD_DIR="$(realpath $(dirname "${BASH_SOURCE[0]}"))" +REPO_DIR="$(dirname "${BUILD_DIR}")" +INSTALL_ROOT="${BUILD_DIR}/install_root" +PKGNAME='web-greeter' +DESTDIR='' +_handle_error() { + LASTLINE="$1" + LASTERR="$2" + echo "${BASH_SOURCE[0]}: line ${LASTLINE}: exit status of last command: ${LASTERR}" + exit 1 +} + clean_build_dir() { - (cd "${DIR}" \ - && find . -type f ! -path './ci*' ! -name '.gitignore' ! -name utils.sh -delete \ - && find . -type d ! -path './ci' -delete \ - && { rm ../src/gresource/js/bundle.js || true; }) + find "${BUILD_DIR}" -type f ! -path '*/ci/*' ! -name utils.sh -delete + find "${BUILD_DIR}" -type d ! -name build ! -path '*/ci' -delete } combine_javascript_sources() { - cd "${MESON_SOURCE_ROOT}/src/gresource/js" && { - cat _vendor/moment-with-locales.min.js \ - LightDMObjects.js \ - Greeter.js \ - GreeterConfig.js \ - ThemeUtils.js > "${MESON_SOURCE_ROOT}/src/gresource/js/bundle.js" - } + cd "${BUILD_DIR}/${PKGNAME}/resources/js" + cat _vendor/moment-with-locales.min.js \ + ThemeUtils.js \ + bootstrap.js > bundle.js } do_build() { - (cd "$(dirname "${DIR}")" \ - && meson build \ - && cd build \ - && ninja) + cd "${BUILD_DIR}" + + # Compile Resources + (combine_javascript_sources \ + && pyrcc5 -o ../../resources.py ../resources.qrc) + + # Create "Zip Application" + (cd "${PKGNAME}" \ + && mv greeter.py __main__.py \ + && zip -rq ../"${PKGNAME}.zip" . -x '**__pycache__**' 'resources/*' \ + && cd - >/dev/null \ + && mkdir -p "${INSTALL_ROOT}"/usr/{bin,share} \ + && echo '#!/bin/python' >> "${INSTALL_ROOT}/usr/bin/web-greeter" \ + && cat web-greeter.zip >> "${INSTALL_ROOT}/usr/bin/web-greeter" \ + && chmod +x "${INSTALL_ROOT}/usr/bin/web-greeter") +} + +do_install() { + cd "${BUILD_DIR}" + mkdir -p \ + "${INSTALL_ROOT}"/usr/share/{man/man1,metainfo,web-greeter,xgreeters} \ + "${INSTALL_ROOT}/etc/lightdm" + + # Themes + (cp -R "${REPO_DIR}/themes" "${INSTALL_ROOT}/usr/share/web-greeter" \ + && cd "${INSTALL_ROOT}/usr/share/web-greeter" \ + && mv themes/_vendor .) + + # Man Page + cp "${REPO_DIR}/dist/${PKGNAME}.1" "${INSTALL_ROOT}/usr/share/man/man1" + + # Greeter Config + cp "${REPO_DIR}/dist/${PKGNAME}.conf" "${INSTALL_ROOT}/etc/lightdm" + + # AppData File + cp "${REPO_DIR}/dist/com.antergos.${PKGNAME}.appdata.xml" "${INSTALL_ROOT}/usr/share/metainfo" + + # Desktop File + cp "${REPO_DIR}/dist/com.antergos.${PKGNAME}.desktop" "${INSTALL_ROOT}/usr/share/xgreeters" + + # Do Install! + [[ -e "${DESTDIR}" ]] || mkdir -p "${DESTDIR}" + cp -R "${INSTALL_ROOT}"/* "${DESTDIR}" + + # Fix Permissions + chown -R "${SUDO_UID}:${SUDO_GID}" "${BUILD_DIR}" } -do_quick_install() { - (cd "${DIR}/src" \ - && sudo cp lightdm-webkit2-greeter /usr/bin \ - && sudo cp liblightdm-webkit2-greeter-webext.so /usr/lib/lightdm-webkit2-greeter \ - && sudo cp -R ../../themes/antergos /usr/share/lightdm-webkit/themes) +do_success() { + NO_COLOR=\x1b[0m + SUCCESS_COLOR=\x1b[32;01m + SUCCESS="${SUCCESS_COLOR}[SUCCESS!]${NO_COLOR}" + echo "${SUCCESS}" } generate_pot_file() { - REPO_ROOT="$(dirname "${DIR}")" + REPO_ROOT="$(dirname "${REPO_DIR}")" xgettext --from-code UTF-8 -o "${REPO_ROOT}/po/lightdm-webkit2-greeter.pot" -d lightdm-webkit2-greeter "${REPO_ROOT}"/src/*.c } -list_javascript_sources() { - cd "${MESON_SOURCE_ROOT}/src" && find gresource/js -type f -name '*.js' -print +init_build_dir() { + [[ -e "${BUILD_DIR}/web-greeter" ]] && return 0 + cp -R "${REPO_DIR}/web-greeter" "${BUILD_DIR}" } +set_config() { + ( [[ -z "$1" ]] || [[ -z "$2" && -z "$3" ]] ) && return 1 + local KEY VALUE + + KEY="$1" + [[ '' != "$2" ]] && VALUE="$2" || VALUE="$3" + + sed -i "s|@${KEY}@|@${VALUE}@|g" "${BUILD_DIR}/web-greeter/whither.yml" +} + + +# Catch Command Errors +trap '_handle_error ${LINENO} ${$?}' ERR + +cd "${REPO_DIR}/build" >/dev/null case "$1" in combine-js) combine_javascript_sources ;; - get-js-files) - list_javascript_sources - ;; - - clean-build-dir) + clean) clean_build_dir ;; build) - clean_build_dir && do_build + do_build ;; - build-dev) - clean_build_dir && do_build && do_quick_install + build-init) + init_build_dir ;; gen-pot) generate_pot_file ;; + + install) + DESTDIR="$2" + do_install + ;; + + set-config) + set_config "$2" "$3" "$4" + ;; esac diff --git a/data/com.antergos.webkit2-greeter.appdata.xml b/data/com.antergos.webkit2-greeter.appdata.xml deleted file mode 100644 index 065549f..0000000 --- a/data/com.antergos.webkit2-greeter.appdata.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - com.antergos.webkit2-greeter - CC0-1.0 - GPL-3.0+ - LightDM WebKit2 Greeter - A greeter for LightDM - -

- LightDM WebKit2 Greeter supports themes built with HTML/JavaScript. -

-

- LightDM WebKit2 Greeter themes provide modern, visually appealing, and feature-rich - login screens. It includes two themes by default. There is also a growing number of - 3rd-Party themes available online. -

-
- - - https://github.com/Antergos/lightdm-webkit2-greeter/raw/master/themes/antergos/img/screenshot1.jpg - Login screen (default theme) - - - https://github.com/Antergos/lightdm-webkit2-greeter/raw/master/themes/antergos/img/screenshot2.jpg - Login screen background switcher (default theme) - - - https://github.com/Antergos/lightdm-webkit2-greeter/raw/master/themes/antergos/img/screenshot3.jpg - Login screen user selection (default theme) - - - - - - - - -

This is a maintenance release in the 2.2 series, with the following improvements:

-
    -
  • Increased the timeout for the "theme loaded" check to ensure themes are given enough time to load (when running on less powerful systems). (GH #98)
  • -
  • Fixed issue where users' custom .face image failed to load. (GH #98)
  • -
-
-
- - -

This is a milestone release with the following improvements:

-
    -
  • The JavaScript API for themes is now fully documented: https://goo.gl/0iPzA4
  • -
  • New Theme Error Recovery System that will alert the user when errors are detected during JavaScript execution and give them the option to to load a fallback theme.
  • -
  • New config option: secure_mode (enabled by default). When enabled, only local http requests are allowed in themes. All non-local requests will be blocked.
  • -
  • It is now possible to override the language and format used by the greeter when displaying the current time. See the greeter config file for details.
  • -
  • A new utility method for getting the current localized time is available to themes.
  • -
  • Simple theme now has a fade out exit animation.
  • -
-
    -
  • Switched build systems from Autotools to Meson.
  • -
  • Updated API usage for LightDM 1.19.2+.
  • -
  • Updated bundled JS & CSS vendor libs to their latest versions.
  • -
  • Updated translations with latest changes contributed by the Antergos Community on Transifex.
  • -
  • Default theme: -
      -
    • Buttons and user list-box items received some minor style enhancements.
    • -
    • Theme is now compatible with the latest jQuery.
    • -
    -
  • -
  • Simple theme: -
      -
    • Removed deprecated HTML4 tags.
    • -
    • Improved styles for the input field.
    • -
    -
  • -
-
    -
  • The ugly default X cursor will no longer be shown after the greeter exits.
  • -
  • Default theme: -
      -
    • The error messages container will now appear correctly (size and position).
    • -
    • It is now once again possible to skip straight to password entry by pressing either the spacebar or the enter key.
    • -
    -
  • -
-
-
-
- - ModernToolkit - - https://github.com/Antergos/lightdm-webkit2-greeter/issues - https://antergos.com/donate - - https://github.com/Antergos/lightdm-webkit2-greeter - https://www.transifex.com/faidoc/antergos/lightdm-webkit2-greeter - - apps.light-locker - - dustin_at_antergos.com - lightdm-webkit2-greeter - The Antergos Project -
- diff --git a/data/com.antergos.webkit2-greeter.desktop b/data/com.antergos.webkit2-greeter.desktop deleted file mode 100644 index c4641e9..0000000 --- a/data/com.antergos.webkit2-greeter.desktop +++ /dev/null @@ -1,6 +0,0 @@ -[Desktop Entry] -Name=LightDM WebKit2 Greeter -Comment=LightDM Greeter -Exec=lightdm-webkit2-greeter -Type=Application -X-Ubuntu-Gettext-Domain=lightdm-webkit2-greeter diff --git a/data/meson.build b/data/meson.build deleted file mode 100644 index 124dc65..0000000 --- a/data/meson.build +++ /dev/null @@ -1,19 +0,0 @@ -id = 'com.antergos.webkit2-greeter' -appdata_file = '@0@.appdata.xml'.format(id) -desktop_file = '@0@.desktop'.format(id) - - -install_data( - desktop_file, - install_dir: get_option('with-desktop-dir') -) - -install_data( - 'webkit2-greeter.conf', - install_dir: get_option('with-config-dir') -) - -install_data( - appdata_file, - install_dir: join_paths(get_option('datadir'), 'metainfo', appdata_file) -) diff --git a/data/webkit2-greeter.conf b/data/webkit2-greeter.conf deleted file mode 100644 index 8a8a7e6..0000000 --- a/data/webkit2-greeter.conf +++ /dev/null @@ -1,35 +0,0 @@ -# -# [greeter] -# debug_mode = Greeter theme debug mode. -# detect_theme_errors = Provide an option to load a fallback theme when theme errors are detected. -# screensaver_timeout = Blank the screen after this many seconds of inactivity. -# secure_mode = Don't allow themes to make remote http requests. -# time_format = A moment.js format string so the greeter can generate localized time for display. -# time_language = Language to use when displaying the time or "auto" to use the system's language. -# webkit_theme = Webkit theme to use. -# -# NOTE: See moment.js documentation for format string options: http://momentjs.com/docs/#/displaying/format/ -# - -[greeter] -debug_mode = false -detect_theme_errors = true -screensaver_timeout = 300 -secure_mode = true -time_format = LT -time_language = auto -webkit_theme = antergos - -# -# [branding] -# background_images = Path to directory that contains background images for use by themes. -# logo = Path to logo image for use by greeter themes. -# user_image = Default user image/avatar. This is used by themes for users that have no .face image. -# -# NOTE: Paths must be accessible to the lightdm system user account (so they cannot be anywhere in /home) -# - -[branding] -background_images = /usr/share/backgrounds -logo = /usr/share/lightdm-webkit/themes/antergos/img/antergos.png -user_image = /usr/share/lightdm-webkit/themes/antergos/img/antergos-logo-user.png diff --git a/man/lightdm-webkit2-greeter.1 b/man/lightdm-webkit2-greeter.1 deleted file mode 100644 index bba6802..0000000 --- a/man/lightdm-webkit2-greeter.1 +++ /dev/null @@ -1,308 +0,0 @@ -.TH "lightdm-webkit2-greeter" "1" "2016.01.10" -.nh -.ad l -.SH "NAME" -lightdm-webkit2-greeter -.SH "SYNOPSIS" -.PP -LightDM greeter that uses webkit2 for theming via HTML/JavaScript\&. -.PP -.SH "DESCRIPTION" -.PP -lightdm-webkit2-greeter is a LightDM greeter that uses webkit2 for theming\&. Themes can be written -using a combination of HTML and Javascript\&. -.PP -.SH "THEME JAVASCRIPT API" -Please note that all properties and functions which are marked as "deprecated" are -only available for backwards compatibility and will be removed in a future version of -lightdm-webkit2-greeter\&. Theme authors should not use any deprecated properties or -functions in new works and should update any existing works which make use of -deprecated properties and/or functions to ensure continued proper functionality\&. -.PP -The following functions \fBmust\fR be provided by the greeter theme and callable on the global "window" object\&. -.PP -\fBshow_prompt(text, type)\fR -.RS 4 -This will be called when LightDM needs to prompt the user for some reason, such -as asking for a password\&. The "text" parameter will be the text of the -prompt, and the "type" parameter will either be "text" for a visible prompt, or -"password" for a prompt that the input should be hidden\&. -.RE -.PP -\fBshow_message(text, type)\fR -.RS 4 -This will be called when LightDM needs to display some info for the user\&. -The "text" parameter will be the text of the -message, and the "type" parameter will either be "info" for an information -message, or "error" for an error message that LightDM has encountered\&. -.RE -.PP -\fBauthentication_complete()\fR -.RS 4 -This function is called by LightDM when authentication has completed\&. -.RE -.PP -\fBautologin_timer_expired()\fR -.RS 4 -This function is called by LightDM when an autologin user's login timer has -expired\&. The greeter should reset the authentication process\&. -.RE -.PP -The following functions are available for the greeter to call to execute -actions within LightDM\&. -.PP -\fBlightdm\&.authenticate(username)\fR -.RS 4 -Specifies the username of the user we'd like to start authenticating as\&. Note that -if you call lightdm.authenticate with no argument, LightDM (via PAM) will issue -a show_prompt() call to ask for the username\&. The older function -lightdm\&.start_authentication() has been deprecated\&. -.RE -.PP -\fBlightdm\&.authenticate_as_guest()\fR -.RS 4 -Authenticates as the guest user\&. -.RE -.PP -\fBlightdm\&.cancel_authentication()\fR -.RS 4 -Cancels the authentication of any user currently in the process of -authenticating\&. -.RE -.PP -\fBlightdm\&.cancel_autologin()\fR -.RS 4 -Cancels the authentication of the autologin user\&. The older function -lightdm\&.cancel_timed_login() has been deprecated. -.RE -.PP -\fBlightdm\&.get_hint(hint_name)\fR -.RS 4 -Returns the value of a named hint provided by LightDM\&. -.RE -.PP -\fBlightdm\&.suspend()\fR -.RS 4 -Suspends the system, if the greeter has the authority to do so\&. -.RE -.PP -\fBlightdm\&.hibernate()\fR -.RS 4 -Hibernates the system, if the greeter has the authority to do so\&. -.RE -.PP -\fBlightdm\&.start_session_sync(session)\fR -.RS 4 -Once LightDM has successfully authenticated the user, start the user's session -by calling this function\&. "session" is the authenticated user's session\&. -If no session is passed, start the authenticated user with the system default -session. The older function lightdm\&.login(user, session) has been -deprecated\&. -.RE -.PP -\fBlightdm\&.respond(text)\fR -.RS 4 -When LightDM has prompted for input, provide the response to LightDM\&. -The deprecated function was "provide_secret"\&. This is still available for -backwards compatibility, but authors of greeters should move to using -lightdm.respond()\&. -.RE -.PP -\fBlightdm\&.restart()\fR -.RS 4 -Restarts the system, if the greeter has the authority to do so\&. -.RE -.PP -\fBlightdm\&.set_language(lang)\fR -.RS 4 -Will set the language for the current LightDM session\&. -.RE -.PP -\fBlightdm\&.shutdown()\fR -.RS 4 -Shuts down the system, if the greeter has the authority to do so\&. -.RE -.PP -Variables available within the greeter are: -.PP -\fBlightdm\&.authentication_user\fR -.RS 4 -String\&. The username of the authentication user being authenticated or null if no -authentication is in progress\&. -.RE -.PP -\fBlightdm\&.autologin_guest\fR -.RS 4 -Boolean\&. Indicates the guest user should be used for autologin\&. -.RE -.PP -\fBlightdm\&.autologin_timeout\fR -.RS 4 -Number\&. The number of seconds to wait before automatically logging in\&. The -older variable lightdm\&.timed_user_delay has been deprecated\&. -.RE -.PP -\fBlightdm\&.autologin_user\fR -.RS 4 -String\&. The name of the user account that should be logged into -automatically after timed login delay has passed\&. The older variable -lightdm\&.timed_login_user has been deprecated\&. -.RE -.PP -\fBlightdm\&.can_hibernate\fR -.RS 4 -Boolean\&. Whether or not the system can be made to hibernate by the greeter\&. -.RE -.PP -\fBlightdm\&.can_restart\fR -.RS 4 -Boolean\&. Whether or not the system can be restarted by the greeter\&. -.RE -.PP -\fBlightdm\&.can_shutdown\fR -.RS 4 -Boolean\&. Whether or not the system can be shutdown by the greeter\&. -.RE -.PP -\fBlightdm\&.can_suspend\fR -.RS 4 -Boolean\&. Whether or not the system can be suspended by the greeter\&. -.RE -.PP -\fBlightdm\&.default_session\fR -.RS 4 -String\&. The name of the default session (as configured in lightdm.conf)\&. -.RE -.PP -\fBlightdm\&.has_guest_account\fR -.RS 4 -Boolean\&. A guest account is available for login\&. -.RE -.PP -\fBlightdm\&.hide_users\fR -.RS 4 -Boolean\&. The whole list of users should not be displayed\&. -.RE -.PP -\fBlightdm\&.hostname\fR -.RS 4 -String\&. The hostname of the system\&. -.RE -.PP -\fBlightdm\&.is_authenticated\fR -.RS 4 -Boolean\&. Indicates if the user has successfully authenticated\&. -.RE -.PP -\fBlightdm\&.in_authentication\fR -.RS 4 -Boolean\&. Indicates if lightdm is currently in the authentication phase\&. -.RE -.PP -\fBlightdm\&.language\fR -.RS 4 -String\&. The currently selected language\&. The older variable name -lightdm\&.default_language is deprecated\&. -.RE -.PP -\fBlightdm\&.layout\fR -.RS 4 -String\&. The name of the currently active keyboard layout\&. To change the -layout, assign a valid layout name to this variable\&. The older variable name -lightdm\&.default_layout is deprecated\&. -.RE -.PP -\fBlightdm\&.layouts\fR -.RS 4 -Array\&. The keyboard layouts that are available on the system\&. Returns an Array -of LightDMLayout objects\&. -.RE -.PP -\fBlightdm\&.num_users\fR -.RS 4 -Number\&. The number of users able to log in\&. -.RE -.PP -\fBlightdm\&.select_guest\fR -.RS 4 -Boolean\&. The guest user should be selected by default for login\&. -.RE -.PP -\fBlightdm\&.select_user\fR -.RS 4 -String\&. The username that should be selected by default for login\&. -.RE -.PP -\fBlightdm\&.sessions\fR -.RS 4 -Array\&. The sessions that are available on the system\&. Returns an Array of -LightDMSession objects\&. -.RE -.PP -\fBlightdm\&.users\fR -.RS 4 -Array\&. The users that are able to log in\&. Returns an Array of LightDMUser -objects\&. -.RE -.PP -The following calls can be made to read configuration keys out of the -lightdm-webkit2-greeter configuration file\&. -.PP -config\&.get_str(section, key)\fR -.RS 4 -Returns the string value associated with key under the "section" in the configuration file\&. -.RE -.PP -config\&.get_num(section, key)\fR -.RS 4 -Returns the numeric value associated with key under the "section" in the configuration file\&. -.RE -.PP -config\&.get_bool(section, key)\fR -.RS 4 -Returns the boolean value associated with key under the "section" in the configuration file\&. -.RE -.PP -The greeterutil object has some utility functions associated with it which -are intended to make a theme author's work easier\&. -.PP -greeterutil\&.dirlist(path)\fR -.RS 4 -Returns an array of strings of filenames present at "path", or Null if the -path does not exist\&. -.RE -.PP -greeterutil\&.txt2html(txt)\fR -.RS 4 -Returns a simple HTML conversion of the passed text\&. Newlines are replaced -with
, and the characters \&&, <, >, and " are replaced with their HTML -equivalents\&. -.RE -.PP -Please see the LightDM API documentation for the complete list of calls -available\&. The lightdm-webkit2-greeter implements all of the LightDM API\&. -.PP -.SH "CONFIGURATION" -.PP -\fB/etc/lightdm/lightdm-webkit2-greeter\&.conf\fR -.RS 4 -Keyfile that contains one key: webkit-theme\&. This should point to which -theme the greeter should use\&. -.RE -.SH "FILES" -.PP -\fB/usr/share/lightdm-webkit/themes\fR -.RS 4 -Directory where themes should be stored\&. -.RE -.SH "EXAMPLES" -.PP -Please see the "antergos" and "simple" themes that are shipped with lightdm-webkit2-greeter\&. -.SH "SEE ALSO" -.PP -http://people\&.ubuntu\&.com/~robert-ancell/lightdm/reference/core\&.html -.SH "AUTHOR" -.PP -The legacy lightdm-webkit-greeter was written by Robert Ancell \&. -It was ported to webkit2 by the Antergos Developers \&. Also includes code improvements -contributed by Scott Balneaves \&. diff --git a/man/meson.build b/man/meson.build deleted file mode 100644 index 884d220..0000000 --- a/man/meson.build +++ /dev/null @@ -1 +0,0 @@ -install_man('lightdm-webkit2-greeter.1') diff --git a/meson.build b/meson.build deleted file mode 100644 index ac3e1a4..0000000 --- a/meson.build +++ /dev/null @@ -1,105 +0,0 @@ -project('web-greeter', 'python', version: '3.0.0alpha1', license: 'GPL-3') - -# ================================== # -# ------->>> Version Vars <<<------- # -# ================================== # - -version = meson.project_version() -version_parts = as_version.split('.') - -major_version = version_parts[0] -minor_version = version_parts[1] -micro_version = version_parts[2] - - -# ======================================= # -# ------->>> Dependency Checks <<<------- # -# ======================================= # - -python_dep = join(meson.build_root(), 'python_dep.py') - -dbus_glib = dependency('dbus-glib-1') -lightdm_gobject = dependency('liblightdm-gobject-1') -x11 = dependency('x11') -web_engine = dependency('qt5', modules: ['WebEngine', 'WebEngineWidgets', 'WebChannel']) - - -pyqt5_check = run_command(python_dep, 'PyQt5') - -if pyqt5_check.return_code() == 0: - pyqt5 = declare_dependency(version: pyqt5_check.stdout().strip()) -else - pyqt5 = declare_dependency(version: '0.0.1') -endif - - -yaml_check = run_command(python_dep, 'ruamel.yaml') - -if yaml_check.return_code() == 0: - yaml = declare_dependency(version: yaml_check.stdout().strip()) -else - yaml = declare_dependency(version: '0.0.1') -endif - - -python_dependencies = [ - ['pyqt5', pyqt5], - ['ruamel.yaml', yaml] -] - -foreach dep: python_dependencies - if not dep.get(1).version().version_compare(>0.0.1): - error('Missing Dependency: @0@'.format(dep.get(0))) - endif -endforeach - - -greeter_deps = [dbus_glib, lightdm_gobject, web_engine, x11] -has_lightdm_1_19_2 = lightdm_gobject.version().version_compare('>=1.19.2') - - -# =================================== # -# ------->>> Configuration <<<------- # -# =================================== # - -conf = configuration_data() -config_file = 'whither.yaml' -logo_image = get_option('with-logo-image', join_paths(get_option('with-themes-dir'), 'antergos/img/antergos.png')) -user_image = get_option('with-user-image', join_paths(get_option('with-themes-dir'), 'antergos/img/antergos-logo-user.png')) - -conf.set('full_version', version) -conf.set('major_version', major_version) -conf.set('minor_version', minor_version) -conf.set('micro_version', micro_version) - -conf.set('locale_dir', get_option('with-locale-dir')) - -conf.set('themes_dir', get_option('with-themes-dir')) - -conf.set('config_dir', get_option('with-config-dir')) - -conf.set('greeters_dir', get_option('with-greeters-dir')) - -conf.set('background_images_dir', get_option('with-background-images-dir')) - -conf.set('logo_image', logo_image) - -conf.set('user_image', user_image) - -if has_lightdm_1_19_2 - conf.set('has_lightdm_1_19_2', 'True') -else - conf.set('has_lightdm_1_19_2', 'False') -endif - - -# ===================================== # -# ------->>> Sub Directories <<<------- # -# ===================================== # - -subdirs = ['web-greeter', 'man', 'themes', 'dist', 'po'] - -foreach s : subdirs - subdir(s) -endforeach - diff --git a/meson_options.txt b/meson_options.txt deleted file mode 100644 index 1823bc8..0000000 --- a/meson_options.txt +++ /dev/null @@ -1,24 +0,0 @@ -option('with-themes-dir', - type: 'string', - value: '/usr/share/lightdm-webkit/themes', - description: 'Directory to use for greeter themes') - -option('with-config-dir', - type: 'string', - value: '/etc/lightdm', - description: 'LightDM configuration directory') - -option('with-desktop-dir', - type: 'string', - value: '/usr/share/xgreeters', - description: 'LightDM greeters directory') - -option('with-webext-dir', - type: 'string', - value: '/usr/lib/lightdm-webkit2-greeter', - description: 'Directory for the greeter webkit extension') - -option('with-locale-dir', - type: 'string', - value: '/usr/share/locale', - description: 'Locale directory') diff --git a/po/meson.build b/po/meson.build deleted file mode 100644 index 33c8539..0000000 --- a/po/meson.build +++ /dev/null @@ -1,29 +0,0 @@ -i18n = import('i18n') - -i18n.gettext( - meson.project_name(), - args: [ - '--default-domain=' + meson.project_name(), - '--from-code=UTF-8', - '--add-comments', - - '--keyword=_', - '--keyword=N_', - '--keyword=C_:1c,2', - '--keyword=NC_:1c,2', - '--keyword=g_dcgettext:2', - '--keyword=g_dngettext:2,3', - '--keyword=g_dpgettext2:2c,3', - - '--flag=N_:1:pass-c-format', - '--flag=C_:2:pass-c-format', - '--flag=NC_:2:pass-c-format', - '--flag=g_dngettext:2:pass-c-format', - '--flag=g_strdup_printf:1:c-format', - '--flag=g_string_printf:2:c-format', - '--flag=g_string_append_printf:2:c-format', - '--flag=g_error_new:3:c-format', - '--flag=g_set_error:4:c-format', - ]) - - diff --git a/src/greeter-config.c b/src/greeter-config.c deleted file mode 100644 index 83328d3..0000000 --- a/src/greeter-config.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * greeter-config.c - * - * Copyright © 2017 Antergos Developers - * - * This file is part of lightdm-webkit2-greeter. - * - * lightdm-webkit2-greeter 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; either version 3 of the License, or - * (at your option) any later version. - * - * lightdm-webkit2-greeter 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. - * - * The following additional terms are in effect as per Section 7 of the license: - * - * The preservation of all legal notices and author attributions in - * the material or in the Appropriate Legal Notices displayed - * by works containing it is required. - * - * You should have received a copy of the GNU General Public License - * along with lightdm-webkit2-greeter; If not, see . - */ - -#include -#include - -#include "greeter-config.h" -#include "config.h" -#include "greeter-resources.h" - -/* Work-around CLion bug */ -#ifndef CONFIG_DIR -#include "../build/src/config.h" -#include "../build/src/greeter-resources.h" -#endif - -static Config config_instance; -static Config *config_instance_p = NULL; - - -static void -apply_defaults(void) { - config_instance.greeter->debug_mode = FALSE; - config_instance.greeter->detect_theme_errors = TRUE; - config_instance.greeter->secure_mode = TRUE; - config_instance.greeter->screensaver_timeout = 300; - config_instance.greeter->time_format = "LT"; - config_instance.greeter->time_language = "auto"; - config_instance.greeter->webkit_theme = "antergos"; - - config_instance.branding->background_images = BACKGROUND_IMAGES_DIR; - config_instance.branding->logo = LOGO_IMAGE; - config_instance.branding->user_image = USER_IMAGE; -} - - -static gchar * -rtrim_comments(gchar *str) { - gchar *ptr = NULL; - - ptr = strchr(str, '#'); - - if (NULL != ptr) { - *ptr = '\0'; - } - - return g_strstrip(str); -} - - -Config* -get_config(void) { - if (NULL != config_instance_p) { - return config_instance_p; - } - - // Apply default config. - apply_defaults(); - - GError *err = NULL; - GKeyFile *keyfile = g_key_file_new(); - - g_key_file_load_from_file(keyfile, CONFIG_FILE, G_KEY_FILE_NONE, &err); - - if (NULL != err) { - g_clear_error(&err); - g_key_file_load_from_file(keyfile, CONFIG_FILE_LEGACY, G_KEY_FILE_NONE, &err); - - if (NULL != err) { - // Can't load config file. Bail. - goto cleanup; - } - } - - - /* ----->>> WebKit Theme <<<----- */ - gchar *theme = g_key_file_get_string(keyfile, "greeter", "webkit_theme", &err); - - if (NULL != err) { - g_clear_error(&err); - theme = g_key_file_get_string(keyfile, "greeter", "webkit-theme", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.greeter->webkit_theme = rtrim_comments(theme); - } - - - /* ----->>> Screensaver Timeout <<<----- */ - gint screensaver_timeout = g_key_file_get_integer(keyfile, "greeter", "screensaver_timeout", &err); - - if (NULL != err) { - g_clear_error(&err); - screensaver_timeout = g_key_file_get_integer(keyfile, "greeter", "screensaver-timeout", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.greeter->screensaver_timeout = screensaver_timeout; - } - - - /* ----->>> Debug Mode <<<----- */ - gboolean debug_mode = g_key_file_get_boolean(keyfile, "greeter", "debug_mode", &err); - - if (NULL != err) { - g_clear_error(&err); - debug_mode = g_key_file_get_integer(keyfile, "greeter", "debug-mode", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.greeter->debug_mode = debug_mode; - } - - - /* ----->>> Secure Mode <<<----- */ - gboolean secure_mode = g_key_file_get_boolean(keyfile, "greeter", "secure_mode", &err); - - if (NULL != err) { - g_clear_error(&err); - secure_mode = g_key_file_get_integer(keyfile, "greeter", "secure-mode", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.greeter->secure_mode = secure_mode; - } - - - /* ----->>> Theme Error Detection <<<----- */ - gboolean detect_theme_errors = g_key_file_get_boolean(keyfile, "greeter", "detect_theme_errors", &err); - - if (NULL != err) { - g_clear_error(&err); - detect_theme_errors = g_key_file_get_integer(keyfile, "greeter", "detect-theme-errors", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.greeter->detect_theme_errors = detect_theme_errors; - } - - - /* ----->>> Time Format <<<----- */ - gchar *time_format = g_key_file_get_string(keyfile, "greeter", "time_format", &err); - - if (NULL != err) { - g_clear_error(&err); - time_format = g_key_file_get_string(keyfile, "greeter", "time-format", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.greeter->time_format = time_format; - } - - - /* ----->>> Time Language <<<----- */ - gchar *time_language = g_key_file_get_string(keyfile, "greeter", "time_language", &err); - - if (NULL != err) { - g_clear_error(&err); - time_language = g_key_file_get_string(keyfile, "greeter", "time-language", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.greeter->time_language = time_language; - } - - - /* ----->>> Background Images Directory <<<----- */ - gchar *background_images = g_key_file_get_string(keyfile, "branding", "background_images", &err); - - if (NULL != err) { - g_clear_error(&err); - background_images = g_key_file_get_string(keyfile, "branding", "background-images", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.branding->background_images = background_images; - } - - - /* ----->>> User Avatar Image <<<----- */ - gchar *user_image = g_key_file_get_string(keyfile, "branding", "user_image", &err); - - if (NULL != err) { - g_clear_error(&err); - user_image = g_key_file_get_string(keyfile, "branding", "user-image", &err); - } - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.branding->user_image = user_image; - } - - - /* ----->>> Logo <<<----- */ - gchar *logo = g_key_file_get_string(keyfile, "branding", "logo", &err); - - if (NULL != err) { - g_clear_error(&err); - } else { - config_instance.branding->logo = logo; - } - - goto cleanup; - - - cleanup: - config_instance_p = &config_instance; - - if (NULL != err) { - g_error_free(err); - } - - return config_instance_p; -} diff --git a/src/greeter-config.h b/src/greeter-config.h deleted file mode 100644 index 9db7755..0000000 --- a/src/greeter-config.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * greeter-config.h - * - * Copyright © 2017 Antergos Developers - * - * This file is part of lightdm-webkit2-greeter. - * - * lightdm-webkit2-greeter 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; either version 3 of the License, or - * (at your option) any later version. - * - * lightdm-webkit2-greeter 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. - * - * The following additional terms are in effect as per Section 7 of the license: - * - * The preservation of all legal notices and author attributions in - * the material or in the Appropriate Legal Notices displayed - * by works containing it is required. - * - * You should have received a copy of the GNU General Public License - * along with lightdm-webkit2-greeter; If not, see . - */ - -#ifndef LIGHTDM_WEBKIT2_GREETER_GREETER_CONFIG_H -#define LIGHTDM_WEBKIT2_GREETER_GREETER_CONFIG_H - -#include - -typedef struct greeter_config { - gboolean debug_mode; - gboolean detect_theme_errors; - gint screensaver_timeout; - gboolean secure_mode; - gchar *time_format; - gchar *time_language; - gchar *webkit_theme; -} Greeter_Config; - -typedef struct branding_config { - gchar *background_images; - gchar *logo; - gchar *user_image; -} Branding_Config; - -typedef struct config { - Greeter_Config *greeter; - Branding_Config *branding; -} Config; - - -Config* get_config(void); - - -#endif // LIGHTDM_WEBKIT2_GREETER_GREETER_CONFIG_H diff --git a/src/greeter.c b/src/greeter.c deleted file mode 100644 index d9a2936..0000000 --- a/src/greeter.c +++ /dev/null @@ -1,434 +0,0 @@ -/* - * greeter.c - * - * Copyright © 2014-2017 Antergos Developers - * - * Includes Code Contributed By: - * Copyright © 2016 Scott Balneaves - * - * Based on code from lightdm-webkit-greeter: - * Copyright © 2010-2015 Robert Ancell - * - * This file is part of lightdm-webkit2-greeter. - * - * lightdm-webkit2-greeter 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; either version 3 of the License, or - * (at your option) any later version. - * - * lightdm-webkit2-greeter 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. - * - * The following additional terms are in effect as per Section 7 of the license: - * - * The preservation of all legal notices and author attributions in - * the material or in the Appropriate Legal Notices displayed - * by works containing it is required. - * - * You should have received a copy of the GNU General Public License - * along with lightdm-webkit2-greeter; If not, see . - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" -#include "greeter-resources.h" -#include "greeter-config.h" - - -static GtkWidget *web_view; -static GtkWidget *window; -static WebKitSettings *webkit_settings; -static GdkDisplay *default_display; -static GResource *greeter_resources; -static WebKitUserContentManager *manager; - -/* Screensaver values */ -static int - timeout, - interval, - prefer_blanking, - allow_exposures; - -static Config *conf; - - -static void -initialize_web_extensions_cb(WebKitWebContext *context, gpointer user_data) { - webkit_web_context_set_web_extensions_directory(context, WEBEXT_DIR); -} - - -static void -create_new_webkit_settings_object(void) { - webkit_settings = webkit_settings_new_with_settings( - "enable-developer-extras", TRUE, - "javascript-can-open-windows-automatically", TRUE, - "allow-file-access-from-file-urls", TRUE, - "enable-write-console-messages-to-stdout", TRUE, - #ifdef HAS_WEBKITGTK_2_14 - "allow-universal-access-from-file-urls", TRUE, - #endif - NULL - ); -} - - -static gboolean -context_menu_cb(WebKitWebView *view, - WebKitContextMenu *context_menu, - GdkEvent *event, - WebKitHitTestResult *hit_test_result, - gpointer user_data) { - /* Returning true without creating a custom context menu results in no context - * menu being shown. Thus, we are returning the opposite of debug_mode to get - * desired result (which is only show menu when debug_mode is enabled. - */ - return (! conf->greeter->debug_mode); -} - - -/** - * Makes the greeter behave a bit more like a screensaver if it was launched as - * a lock-screen by blanking the screen. - */ -static void -lock_hint_enabled_handler(void) { - Display *display = gdk_x11_display_get_xdisplay(default_display); - - XGetScreenSaver(display, &timeout, &interval, &prefer_blanking, &allow_exposures); - XForceScreenSaver(display, ScreenSaverActive); - XSetScreenSaver(display, conf->greeter->screensaver_timeout, 0, PreferBlanking, DefaultExposures); -} - - -static void -show_theme_recovery_modal() { - GtkWidget - *dialog, - *label, - *content_area, - *button, - *button_box; - - dialog = gtk_dialog_new_with_buttons( - _("Greeter Theme Error Detected"), - GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - _("Load _Default Theme"), - GTK_RESPONSE_ACCEPT, - _("Load _Fallback Theme"), - GTK_RESPONSE_OK, - _("_Cancel"), - GTK_RESPONSE_REJECT, - NULL - ); - - content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - button = gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT); - button_box = gtk_widget_get_parent(button); - label = gtk_label_new( - _("An error was detected in the current theme that could interfere with the system login process.") - ); - - gtk_button_box_set_layout(GTK_BUTTON_BOX(button_box), GTK_BUTTONBOX_EXPAND); - gtk_container_add(GTK_CONTAINER(content_area), label); - gtk_widget_show_all(content_area); - - gint response = gtk_dialog_run(GTK_DIALOG(dialog)); - - if (GTK_RESPONSE_REJECT == response) { - gtk_widget_destroy(dialog); - return; - } - - gchar *log_msg = "[ERROR] :: A problem was detected with the current theme. Falling back to default theme..."; - gchar *fallback_theme; - - if (GTK_RESPONSE_ACCEPT == response) { - fallback_theme = "antergos"; - - } else { - fallback_theme = "simple"; - } - - g_warning("%s", log_msg); - gtk_widget_destroy(dialog); - - webkit_web_view_load_uri( - WEBKIT_WEB_VIEW(web_view), - g_strdup_printf("file://%s/%s/index.html", THEME_DIR, fallback_theme) - ); -} - - -static void -theme_function_exists_cb(GObject *object, - GAsyncResult *result, - gpointer user_data) { - - WebKitJavascriptResult *js_result; - GError *error = NULL; - JSValueRef value; - JSGlobalContextRef context; - gboolean result_as_bool; - - js_result = webkit_web_view_run_javascript_finish(WEBKIT_WEB_VIEW(object), result, &error); - - if (NULL != error) { - g_warning ("Error running javascript: %s", error->message); - g_error_free(error); - return; - - } else { - context = webkit_javascript_result_get_global_context(js_result); - value = webkit_javascript_result_get_value(js_result); - - result_as_bool = JSValueToBoolean(context, value); - } - - if (FALSE == result_as_bool) { - show_theme_recovery_modal(); - } - - webkit_javascript_result_unref(js_result); -} - - -gboolean -maybe_show_theme_fallback_dialog(void) { - /* Check for existence of a function that themes must add to window object */ - webkit_web_view_run_javascript( - WEBKIT_WEB_VIEW(web_view), - "(() => 'authentication_complete' in window)()", - NULL, - (GAsyncReadyCallback) theme_function_exists_cb, - NULL - ); - - return FALSE; -} - - -/** - * Message received callback. - * - * Receives messages from our web extension process and calls appropriate handlers. - * - * @param manager The user content manager instance that was created in #main. - * @param message The message sent from web extension process. - * @param user_data Data that is private to the current user. - */ -static void -message_received_cb(WebKitUserContentManager *manager, - WebKitJavascriptResult *message, - gpointer user_data) { - - gchar *message_str; - JSGlobalContextRef context; - JSValueRef message_val; - JSStringRef js_str_val; - gsize message_str_length; - - context = webkit_javascript_result_get_global_context(message); - message_val = webkit_javascript_result_get_value(message); - - if (JSValueIsString(context, message_val)) { - js_str_val = JSValueToStringCopy(context, message_val, NULL); - message_str_length = JSStringGetMaximumUTF8CStringSize(js_str_val); - message_str = (gchar *)g_malloc (message_str_length); - JSStringGetUTF8CString(js_str_val, message_str, message_str_length); - JSStringRelease(js_str_val); - - } else { - message_str = ""; - printf("Error running javascript: unexpected return value"); - } - - if (0 == g_strcmp0(message_str, "PageLoaded")) { - /* Register callback to check if theme loaded successfully */ - g_timeout_add_seconds(8, (GSourceFunc) maybe_show_theme_fallback_dialog, NULL); - - } else if (0 == g_strcmp0(message_str, "JavaScriptException")) { - show_theme_recovery_modal(); - - } else if (0 == g_strcmp0(message_str, "LockHint")) { - lock_hint_enabled_handler(); - - } else { - printf("UI PROCESS - message_received_cb(): no match for: %s", message_str); - } - - g_free(message_str); -} - - -static void -quit_cb(void) { - gtk_widget_destroy(window); - gtk_main_quit(); -} - - -static void -javascript_bundle_injection_setup() { - WebKitUserScript *bundle; - GBytes *data; - guint8 *data_as_guint; - gsize data_size; - gchar *script; - - data = g_resource_lookup_data( - greeter_resources, - GRESOURCE_PATH "/js/bundle.js", - G_RESOURCE_LOOKUP_FLAGS_NONE, - NULL - ); - - data_as_guint = g_bytes_unref_to_data(data, &data_size); - script = g_strdup_printf("%s", data_as_guint); - - bundle = webkit_user_script_new( - script, - WEBKIT_USER_CONTENT_INJECT_TOP_FRAME, - WEBKIT_USER_SCRIPT_INJECT_AT_DOCUMENT_START, - NULL, /* URL whitelist pattern */ - NULL /* URL blacklist pattern */ - ); - - webkit_user_content_manager_add_script(WEBKIT_USER_CONTENT_MANAGER(manager), bundle); -} - - -int -main(int argc, char **argv) { - GdkScreen *screen; - GdkWindow *root_window; - GdkRectangle geometry; - GdkRGBA bg_color; - WebKitWebContext *context; - GtkCssProvider *css_provider; - WebKitCookieManager *cookie_manager; - - /* Prevent memory from being swapped out, since we see unencrypted passwords. */ - mlockall (MCL_CURRENT | MCL_FUTURE); - - /* https://goo.gl/vDFwFe */ - g_setenv ("GDK_CORE_DEVICE_EVENTS", "1", TRUE); - - /* Temporary workaround until fixed upstream: https://goo.gl/wFJ4v7 */ - g_setenv("WEBKIT_DISABLE_COMPOSITING_MODE", "1", TRUE); - - /* Initialize i18n */ - bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - textdomain(GETTEXT_PACKAGE); - - gtk_init(&argc, &argv); - - g_unix_signal_add(SIGTERM, (GSourceFunc) quit_cb, NULL); - g_unix_signal_add(SIGINT, (GSourceFunc) quit_cb, NULL); - g_unix_signal_add(SIGHUP, (GSourceFunc) quit_cb, NULL); - - /* Initialize greeter config */ - conf = get_config(); - - /* Set default cursor */ - root_window = gdk_get_default_root_window(); - default_display = gdk_display_get_default(); - - gdk_window_set_cursor(root_window, gdk_cursor_new_for_display(default_display, GDK_LEFT_PTR)); - - /* Setup the main window */ - window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - screen = gtk_window_get_screen(GTK_WINDOW(window)); - - gtk_window_set_decorated(GTK_WINDOW(window), FALSE); - - #ifdef HAS_GTK_3_22 - GdkMonitor *monitor = gdk_display_get_primary_monitor(default_display); - gdk_monitor_get_geometry(monitor, &geometry); - #else - gdk_screen_get_monitor_geometry(screen, gdk_screen_get_primary_monitor(screen), &geometry); - #endif - - gtk_window_set_default_size(GTK_WINDOW(window), geometry.width, geometry.height); - gtk_window_move(GTK_WINDOW(window), geometry.x, geometry.y); - - /* Setup CSS provider. We use CSS to set the window background to black instead - * of default white so the screen doesnt flash during startup. - */ - greeter_resources = greeter_resources_get_resource(); - css_provider = gtk_css_provider_new(); - - g_resources_register(greeter_resources); - gtk_css_provider_load_from_resource( - GTK_CSS_PROVIDER(css_provider), - "/com/antergos/webkit2-greeter/css/style.css" - ); - gtk_style_context_add_provider_for_screen( - screen, - GTK_STYLE_PROVIDER(css_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION - ); - - /* Register and connect handler that will set the web extensions directory - * so webkit can find our extension. - */ - context = webkit_web_context_get_default(); - g_signal_connect(context, "initialize-web-extensions", G_CALLBACK(initialize_web_extensions_cb), NULL); - webkit_web_context_set_cache_model(context, WEBKIT_CACHE_MODEL_DOCUMENT_VIEWER); - - /* Set cookie policy */ - cookie_manager = webkit_web_context_get_cookie_manager(context); - webkit_cookie_manager_set_accept_policy(cookie_manager, WEBKIT_COOKIE_POLICY_ACCEPT_ALWAYS); - - /* Register and connect handler of any messages we send from our web extension process. */ - manager = webkit_user_content_manager_new(); - g_signal_connect(manager, "script-message-received::GreeterBridge", G_CALLBACK(message_received_cb), NULL); - webkit_user_content_manager_register_script_message_handler(manager, "GreeterBridge"); - - javascript_bundle_injection_setup(); - - /* Create the web_view */ - web_view = webkit_web_view_new_with_user_content_manager(manager); - - /* Set the web_view's settings. */ - create_new_webkit_settings_object(); - webkit_web_view_set_settings(WEBKIT_WEB_VIEW(web_view), WEBKIT_SETTINGS(webkit_settings)); - - /* The default background color of the web_view is white which causes a flash effect when the greeter starts. - * We make it black instead. This only applies when the theme hasn't set the body background via CSS. - */ - gdk_rgba_parse(&bg_color, "#000000"); - webkit_web_view_set_background_color(WEBKIT_WEB_VIEW(web_view), gdk_rgba_copy(&bg_color)); - - /* Maybe disable the context (right-click) menu. */ - g_signal_connect(WEBKIT_WEB_VIEW(web_view), "context-menu", G_CALLBACK(context_menu_cb), NULL); - - /* There's no turning back now, let's go! */ - gtk_container_add(GTK_CONTAINER(window), web_view); - webkit_web_view_load_uri(WEBKIT_WEB_VIEW(web_view), - g_strdup_printf("file://%s/%s/index.html", THEME_DIR, conf->greeter->webkit_theme)); - - gtk_widget_show_all(window); - gtk_widget_set_can_focus(GTK_WIDGET(web_view), TRUE); - gtk_widget_grab_focus(GTK_WIDGET(web_view)); - - g_debug("Entering Gtk loop..."); - gtk_main(); - g_debug("Exited Gtk loop."); - - return 0; -} diff --git a/src/webkit2-extension.c b/src/webkit2-extension.c deleted file mode 100644 index b1495c5..0000000 --- a/src/webkit2-extension.c +++ /dev/null @@ -1,2066 +0,0 @@ -/* - * webkit2-extension.c - * - * Copyright © 2014-2017 Antergos Developers - * - * Includes Code Contributed By: - * Copyright © 2016 Scott Balneaves - * - * Based on code from lightdm-webkit-greeter: - * Copyright © 2010-2014 Robert Ancell - * - * This file is part of lightdm-webkit2-greeter. - * - * lightdm-webkit2-greeter 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; either version 3 of the License, or - * (at your option) any later version. - * - * lightdm-webkit2-greeter 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. - * - * The following additional terms are in effect as per Section 7 of the license: - * - * The preservation of all legal notices and author attributions in - * the material or in the Appropriate Legal Notices displayed - * by works containing it is required. - * - * You should have received a copy of the GNU General Public License - * along with lightdm-webkit2-greeter; If not, see . - */ - -/* WebKitWebExtension - * This extension runs inside the web process allowing us to interact directly with - * the web page including the DOM and JavaScriptWorld. - */ - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "greeter-config.h" - -#include "config.h" - -/* Work-around CLion bug */ -#ifndef CONFIG_DIR -#include "../build/src/config.h" -#endif - - -/* Convenience macros for use in functions that can be called from JavaScript - * running in the web process. They are used to confirm that calls were made by one of - * the classes that we injected into the web page. - */ -#define USER ((LightDMUser *) JSObjectGetPrivate (thisObject)) -#define LAYOUT ((LightDMLayout *) JSObjectGetPrivate (thisObject)) -#define SESSION ((LightDMSession *) JSObjectGetPrivate (thisObject)) -#define GREETER ((LightDMGreeter *) JSObjectGetPrivate (thisObject)) -#define LANGUAGE ((LightDMLanguage *) JSObjectGetPrivate (thisObject)) - - -/* - * Error messages - */ -#define EXPECTSTRING "Expected a string" -#define ARGNOTSUPPLIED "Argument(s) not supplied" - -G_MODULE_EXPORT void webkit_web_extension_initialize(WebKitWebExtension *extension); - - -static guint64 page_id; - -static GSList* paths = NULL, *iter = NULL; - -static JSClassRef - lightdm_greeter_class, - gettext_class, - lightdm_user_class, - lightdm_language_class, - lightdm_layout_class, - lightdm_session_class, - greeter_config_class, - theme_utils_class; - -static gboolean SESSION_STARTING; - -static Config *conf; - -static JSObjectRef - config_greeter_obj, - config_branding_obj; - -static WebKitWebExtension *WEB_EXTENSION; - - -/* - * Returns either a string or null. - * - * When passed a const gchar string, either return a JSValueRef string or, - * if the string is NULL, a JSValueRef Null reference. Used to ensure functions - * return proper string args. - */ -static JSValueRef -string_or_null(JSContextRef context, const gchar *str) { - JSValueRef result; - JSStringRef string; - - if (str == NULL) { - return JSValueMakeNull(context); - } - - string = JSStringCreateWithUTF8CString(str); - result = JSValueMakeString(context, string); - JSStringRelease(string); - - return result; -} - - -static void -_mkexception(JSContextRef context, JSValueRef *exception, const gchar *str) { - JSValueRef result; - JSStringRef string = JSStringCreateWithUTF8CString(str); - JSValueRef exceptionString = JSValueMakeString(context, string); - JSStringRelease(string); - result = JSValueToObject(context, exceptionString, exception); - - if (result != NULL) { - *exception = result; - } -} - - -/* - * Makes an Exception. - * - * Convert a const string to an exception which can be passed back to webkit. - */ -static JSValueRef -mkexception(JSContextRef context, JSValueRef *exception, const gchar *str) { - _mkexception(context, exception, str); - - return JSValueMakeNull(context); -} - - -/* - * Converts an argument to a string. - * - * Convert a JSValueRef argument to a g_malloc'd gchar string. Calling function - * is responsible for g_freeing the string. - */ -static gchar * -arg_to_string(JSContextRef context, JSValueRef arg, JSValueRef *exception) { - JSStringRef string; - size_t size; - gchar *result; - - if (JSValueGetType(context, arg) != kJSTypeString) { - _mkexception(context, exception, EXPECTSTRING); - - return NULL; - } - - string = JSValueToStringCopy(context, arg, exception); - - if (!string) { - - return NULL; - } - - size = JSStringGetMaximumUTF8CStringSize(string); - result = g_malloc(size); - - if (!result) { - - return NULL; - } - - JSStringGetUTF8CString(string, result, size); - JSStringRelease(string); - - return result; -} - - -/* - * g_strreplace - * - * Replace one substring with another. NOTE: This has the side effect - * of freeing it's passed text. - */ -static gchar * -g_strreplace (gchar *txt, gchar *from, gchar *to) { - gchar **split; - gchar *result; - - split = g_strsplit (txt, from, -1); - g_free (txt); - result = g_strjoinv (to, split); - g_strfreev (split); - return result; -} - - -/* - * Escapes single quote characters in a string. - * - * Simple escape function to make sure strings have any/all single - * quote characters escaped. - */ -static char * -escape(const gchar *text) { - gchar *escaped; - gchar *result; - - /* Make sure all newlines, tabs, etc. are escaped. */ - escaped = g_strescape (text, NULL); - - /* Replace ' with \\' */ - result = g_strreplace (escaped, "'", "\\'"); - - return result; -} - - -static JSValueRef -get_user_name_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_user_get_name(USER)); -} - - -static JSValueRef -get_user_real_name_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_user_get_real_name(USER)); -} - - -static JSValueRef -get_user_display_name_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_user_get_display_name(USER)); -} - - -static JSValueRef -get_user_home_directory_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_user_get_home_directory(USER)); -} - - -static JSValueRef -get_user_image_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - const gchar *image = lightdm_user_get_image(USER); - gchar *image_path; - gint result; - - // Determine if we already checked this path - for (iter = paths; iter; iter = iter->next) { - if (0 == g_strcmp0(image, iter->data)) { - // We've already checked this path, no need to continue further. - return string_or_null(context, image); - } - } - - image_path = g_strdup(image); - result = g_access(image_path, R_OK); - - if (0 == result) { - // Path is accessible. Add it to our paths list. - paths = g_slist_prepend(paths, image_path); - - return string_or_null(context, image); - } - - // Path is not accessible. - g_free(image_path); - - return JSValueMakeNull(context); -} - - -static JSValueRef -get_user_language_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_user_get_language(USER)); -} - - -static JSValueRef -get_user_layout_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_user_get_layout(USER)); -} - - -static JSValueRef -get_user_session_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_user_get_session(USER)); -} - - -static JSValueRef -get_user_logged_in_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_user_get_logged_in(USER)); -} - - -static JSValueRef -get_language_code_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_language_get_code(LANGUAGE)); -} - - -static JSValueRef -get_language_name_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_language_get_name(LANGUAGE)); -} - - -static JSValueRef -get_language_territory_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_language_get_territory(LANGUAGE)); -} - - -static JSValueRef -get_layout_name_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_layout_get_name(LAYOUT)); -} - - -static JSValueRef -get_layout_short_description_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_layout_get_short_description(LAYOUT)); -} - - -static JSValueRef -get_layout_description_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_layout_get_description(LAYOUT)); -} - - -static JSValueRef -get_session_key_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_session_get_key(SESSION)); -} - - -static JSValueRef -get_session_name_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_session_get_name(SESSION)); -} - - -static JSValueRef -get_session_comment_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_session_get_comment(SESSION)); -} - - -static JSValueRef -get_hostname_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_get_hostname()); -} - - -static JSValueRef -get_num_users_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeNumber( - context, - g_list_length(lightdm_user_list_get_users(lightdm_user_list_get_instance())) - ); -} - - -static JSValueRef -get_users_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - JSObjectRef array; - const GList *users, *link; - guint i, n_users = 0; - JSValueRef *args; - - users = lightdm_user_list_get_users(lightdm_user_list_get_instance()); - n_users = g_list_length((GList *) users); - args = g_malloc(sizeof(JSValueRef) * ( n_users + 1 )); - - for (i = 0, link = users; link; i++, link = link->next) { - LightDMUser *user = link->data; - g_object_ref(user); - args[i] = JSObjectMake(context, lightdm_user_class, user); - } - - array = JSObjectMakeArray(context, n_users, args, exception); - g_free(args); - - if (array == NULL) { - return JSValueMakeNull(context); - } else { - return array; - } -} - - -static JSValueRef -get_languages_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - JSObjectRef array; - const GList *languages, *link; - guint i, n_languages = 0; - JSValueRef *args; - - languages = lightdm_get_languages(); - n_languages = g_list_length((GList *) languages); - args = g_malloc(sizeof(JSValueRef) * ( n_languages + 1 )); - - for (i = 0, link = languages; link; i++, link = link->next) { - LightDMLanguage *language = link->data; - g_object_ref(language); - args[i] = JSObjectMake(context, lightdm_language_class, language); - } - - array = JSObjectMakeArray(context, n_languages, args, exception); - g_free(args); - - if (array == NULL) { - return JSValueMakeNull(context); - } else { - return array; - } -} - - -static JSValueRef -get_language_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_language_get_name(lightdm_get_language())); -} - - -static JSValueRef -get_layouts_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - JSObjectRef array; - const GList *layouts, *link; - guint i, n_layouts = 0; - JSValueRef *args; - - layouts = lightdm_get_layouts(); - n_layouts = g_list_length((GList *) layouts); - args = g_malloc(sizeof(JSValueRef) * ( n_layouts + 1 )); - - for (i = 0, link = layouts; link; i++, link = link->next) { - LightDMLayout *layout = link->data; - g_object_ref(layout); - args[i] = JSObjectMake(context, lightdm_layout_class, layout); - } - - array = JSObjectMakeArray(context, n_layouts, args, exception); - g_free(args); - - if (array == NULL) { - return JSValueMakeNull(context); - } else { - return array; - } -} - - -static JSValueRef -get_layout_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_layout_get_name(lightdm_get_layout())); -} - - -static bool -set_layout_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef value, - JSValueRef *exception) { - - gchar *layout; - const GList *layouts, *link; - layout = arg_to_string(context, value, exception); - - if (!layout) { - return false; - } - - layouts = lightdm_get_layouts(); - - for (link = layouts; link; link = link->next) { - LightDMLayout *currlayout = link->data; - - if (!( g_strcmp0(lightdm_layout_get_name(currlayout), layout))) { - g_object_ref(currlayout); - lightdm_set_layout(currlayout); - break; - } - } - - g_free(layout); - - return true; -} - - -static JSValueRef -get_sessions_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - JSObjectRef array; - const GList *sessions, *link; - guint i, n_sessions = 0; - JSValueRef *args; - - sessions = lightdm_get_sessions(); - n_sessions = g_list_length((GList *) sessions); - args = g_malloc(sizeof(JSValueRef) * ( n_sessions + 1 )); - - for (i = 0, link = sessions; link; i++, link = link->next) { - LightDMSession *session = link->data; - g_object_ref(session); - - args[i] = JSObjectMake(context, lightdm_session_class, session); - } - - array = JSObjectMakeArray(context, n_sessions, args, exception); - g_free(args); - - if (array == NULL) { - return JSValueMakeNull(context); - } else { - return array; - } -} - - -static JSValueRef -get_session_starting_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - return JSValueMakeBoolean(context, SESSION_STARTING); -} - - -static JSValueRef -get_default_session_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_greeter_get_default_session_hint(GREETER)); -} - - -static JSValueRef -get_lock_hint_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_greeter_get_lock_hint(GREETER)); -} - - -static JSValueRef -get_autologin_timeout_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeNumber(context, lightdm_greeter_get_autologin_timeout_hint(GREETER)); -} - - -static JSValueRef -cancel_autologin_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - lightdm_greeter_cancel_autologin(GREETER); - - return JSValueMakeNull(context); -} - - -static JSValueRef -authenticate_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *name = NULL; - - if (argumentCount > 0) { - name = arg_to_string(context, arguments[0], exception); - } - - #ifdef HAS_LIGHTDM_1_19_2 - GError *err = NULL; - - lightdm_greeter_authenticate(GREETER, name, &err); - - if (NULL != err) { - _mkexception(context, exception, err->message); - g_error_free(err); - } - #else - lightdm_greeter_authenticate(GREETER, name); - #endif - - g_free(name); - - return JSValueMakeNull(context); -} - - -static JSValueRef -authenticate_as_guest_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - #ifdef HAS_LIGHTDM_1_19_2 - GError *err = NULL; - - lightdm_greeter_authenticate_as_guest(GREETER, &err); - - if (NULL != err) { - _mkexception(context, exception, err->message); - g_error_free(err); - } - #else - lightdm_greeter_authenticate_as_guest(GREETER); - #endif - - return JSValueMakeNull(context); -} - - -static JSValueRef -get_hint_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *hint_name = NULL; - JSValueRef result; - - if (argumentCount != 1) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - hint_name = arg_to_string(context, arguments[0], exception); - - if (!hint_name) { - return JSValueMakeNull(context); - } - - result = string_or_null(context, lightdm_greeter_get_hint(GREETER, hint_name)); - g_free(hint_name); - - return result; -} - - -static JSValueRef -respond_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *response = NULL; - - if (argumentCount != 1) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - response = arg_to_string(context, arguments[0], exception); - - if (!response) { - return JSValueMakeNull(context); - } - - #ifdef HAS_LIGHTDM_1_19_2 - GError *err = NULL; - - lightdm_greeter_respond(GREETER, response, &err); - - if (NULL != err) { - _mkexception(context, exception, err->message); - g_error_free(err); - } - #else - lightdm_greeter_respond(GREETER, response); - #endif - - g_free(response); - - return JSValueMakeNull(context); -} - - -static JSValueRef -cancel_authentication_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - #ifdef HAS_LIGHTDM_1_19_2 - GError *err = NULL; - - lightdm_greeter_cancel_authentication(GREETER, &err); - - if (NULL != err) { - _mkexception(context, exception, err->message); - g_error_free(err); - } - #else - lightdm_greeter_cancel_authentication(GREETER); - #endif - - return JSValueMakeNull(context); -} - - -static JSValueRef -get_authentication_user_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_greeter_get_authentication_user(GREETER)); -} - - -static JSValueRef -get_has_guest_account_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_greeter_get_has_guest_account_hint(GREETER)); -} - - -static JSValueRef -get_hide_users_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_greeter_get_hide_users_hint(GREETER)); -} - - -static JSValueRef -get_select_user_hint_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_greeter_get_select_user_hint(GREETER)); -} - - -static JSValueRef -get_select_guest_hint_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_greeter_get_select_guest_hint(GREETER)); -} - - -static JSValueRef -get_autologin_user_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return string_or_null(context, lightdm_greeter_get_autologin_user_hint(GREETER)); -} - - -static JSValueRef -get_autologin_guest_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_greeter_get_autologin_guest_hint(GREETER)); -} - - -static JSValueRef -get_is_authenticated_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_greeter_get_is_authenticated(GREETER)); -} - - -static JSValueRef -get_in_authentication_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - return JSValueMakeBoolean(context, lightdm_greeter_get_in_authentication(GREETER)); -} - - -static JSValueRef -get_can_suspend_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - return JSValueMakeBoolean(context, lightdm_get_can_suspend()); -} - - -static JSValueRef -suspend_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - lightdm_suspend(NULL); - - return JSValueMakeNull(context); -} - - -static JSValueRef -get_can_hibernate_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - return JSValueMakeBoolean(context, lightdm_get_can_hibernate()); -} - - -static JSValueRef -hibernate_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - lightdm_hibernate(NULL); - - return JSValueMakeNull(context); -} - - -static JSValueRef -get_can_restart_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - return JSValueMakeBoolean(context, lightdm_get_can_restart()); -} - - -static JSValueRef -restart_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - lightdm_restart(NULL); - - return JSValueMakeNull(context); -} - - -static JSValueRef -get_can_shutdown_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - return JSValueMakeBoolean(context, lightdm_get_can_shutdown()); -} - - -static JSValueRef -shutdown_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - lightdm_shutdown(NULL); - - return JSValueMakeNull(context); -} - - -static JSValueRef -start_session_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *session = NULL; - gboolean result; - GError *err = NULL; - - SESSION_STARTING = TRUE; - - /* TODO: Old API required lightdm.login(username, session), but the username - * was never actually used. At some point, deprecate the old usage. For now, - * simply work around it. - */ - if (argumentCount == 1) { - session = arg_to_string(context, arguments[0], exception); - } else if (argumentCount == 2) { - session = arg_to_string(context, arguments[1], exception); - } - - result = lightdm_greeter_start_session_sync(GREETER, session, &err); - g_free(session); - - if (err != NULL) { - SESSION_STARTING = FALSE; - _mkexception(context, exception, err->message); - g_error_free(err); - } - - return JSValueMakeBoolean(context, result); -} - - -static JSValueRef -set_language_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *language = NULL; - - if (argumentCount != 1) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - language = arg_to_string(context, arguments[0], exception); - - if (!language) { - return JSValueMakeNull(context); - } - - #ifdef HAS_LIGHTDM_1_19_2 - GError *err = NULL; - - lightdm_greeter_set_language(GREETER, language, &err); - - if (NULL != err) { - _mkexception(context, exception, err->message); - g_error_free(err); - } - #else - lightdm_greeter_set_language(GREETER, language); - #endif - - g_free(language); - - return JSValueMakeNull(context); -} - - -static JSValueRef -gettext_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *string = NULL; - JSValueRef result; - - if (argumentCount != 1) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - string = arg_to_string(context, arguments[0], exception); - - if (!string) { - return JSValueMakeNull(context); - } - - result = string_or_null(context, gettext(string)); - g_free(string); - - return result; -} - - -static JSValueRef -ngettext_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *string = NULL, *plural_string = NULL; - unsigned int n = 0; - JSValueRef result; - - if (argumentCount != 3) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - string = arg_to_string(context, arguments[0], exception); - - if (!string) { - return JSValueMakeNull(context); - } - - plural_string = arg_to_string(context, arguments[1], exception); - - if (!plural_string) { - return JSValueMakeNull(context); - } - - n = JSValueToNumber(context, arguments[2], exception); - result = string_or_null(context, ngettext(string, plural_string, n)); - - g_free(string); - g_free(plural_string); - - return result; -} - -/* - * Gets a key's value from config file. - * - * Returns value as a string. - */ -static JSValueRef -get_conf_str_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *section, *key, *value; - GError *err = NULL; - JSValueRef result; - - if (argumentCount != 2) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - section = arg_to_string(context, arguments[0], exception); - - if (NULL == section) { - return JSValueMakeNull(context); - } - - key = arg_to_string(context, arguments[1], exception); - - if (NULL == key) { - return JSValueMakeNull(context); - } - - if (0 == g_strcmp0(key, "themes_dir")) { - value = g_strdup_printf("%s", THEME_DIR); - - } else if (0 == g_strcmp0(key, "lightdm_data_dir")) { - #ifdef HAS_LIGHTDM_1_19_2 - value = lightdm_greeter_ensure_shared_data_dir_sync(GREETER, section, &err); - #else - value = lightdm_greeter_ensure_shared_data_dir_sync(GREETER, section); - #endif - - } else { - value = g_key_file_get_string(keyfile, section, key, &err); - } - - if (err) { - _mkexception(context, exception, err->message); - g_error_free(err); - return JSValueMakeNull(context); - } - - result = string_or_null(context, value); - - g_free(value); - - return result; -} - - -/* - * Gets a key's value from config file. - * - * Returns value as a number. - */ -static JSValueRef -get_conf_num_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *section, *key; - gint value; - GError *err = NULL; - - if (argumentCount != 2) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - section = arg_to_string(context, arguments[0], exception); - if (!section) { - return JSValueMakeNull(context); - } - - key = arg_to_string(context, arguments[1], exception); - if (!key) { - return JSValueMakeNull(context); - } - - value = g_key_file_get_integer(keyfile, section, key, &err); - - if (err) { - _mkexception(context, exception, err->message); - g_error_free(err); - return JSValueMakeNull(context); - } - - return JSValueMakeNumber(context, value); -} - - -/* - * Gets a key's value from config file. - * - * Returns value as a bool. - */ -static JSValueRef -get_conf_bool_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - gchar *section, *key; - gboolean value; - GError *err = NULL; - - if (argumentCount != 2) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - section = arg_to_string(context, arguments[0], exception); - if (!section) { - return JSValueMakeNull(context); - } - - key = arg_to_string(context, arguments[1], exception); - if (!key) { - return JSValueMakeNull(context); - } - - value = g_key_file_get_boolean(keyfile, section, key, &err); - - if (err) { - _mkexception(context, exception, err->message); - g_error_free(err); - return JSValueMakeNull(context); - } - - return JSValueMakeBoolean(context, value); -} - - -static JSValueRef -get_config_section_greeter_cb(JSContextRef context, - JSObjectRef thisObject, - JSStringRef propertyName, - JSValueRef *exception) { - - if (NULL != config_greeter_obj) { - goto finish; - } - - if (NULL == conf) { - conf = get_config(); - } - - config_greeter_obj = JSObjectMake(context, NULL, NULL); - - finish: - JSStringRef obj = JSValueCreateJSONString(context, config_greeter_obj, 0, NULL); - - return (NULL != obj) - ? JSValueMakeFromJSONString(context, obj) - : JSValueMakeNull(context); -} - - -static JSValueRef -get_dirlist_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - - JSObjectRef array; - guint n_entries = 0; - JSValueRef *args = NULL; - GDir *dir; - gchar *path, *fullpath; - const gchar *dirent; - GError *err = NULL; - - if (argumentCount != 1) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - path = arg_to_string(context, arguments[0], exception); - - if (!path) { - return JSValueMakeNull(context); - } - - dir = g_dir_open(path, 0, &err); - - if (err) { - _mkexception(context, exception, err->message); - g_error_free(err); - return JSValueMakeNull(context); - } - - /* - * Create the list of the directory entries - */ - while ( ( dirent = g_dir_read_name(dir) ) != NULL) { - n_entries++; - args = g_realloc( args, sizeof(JSValueRef) * ( n_entries + 1 ) ); - fullpath = g_build_filename(path, dirent, NULL); /* Give theme developer full pathname */ - args[( n_entries - 1 )] = string_or_null(context, fullpath); - g_free(fullpath); - } - - g_dir_close(dir); - - array = JSObjectMakeArray(context, n_entries, args, exception); - - g_free(args); - - if (array == NULL) { - return JSValueMakeNull(context); - } else { - return array; - } -} - - -static JSValueRef -txt2html_cb(JSContextRef context, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef *exception) { - gchar *txt; - JSValueRef result; - - if (argumentCount != 1) { - return mkexception(context, exception, ARGNOTSUPPLIED); - } - - txt = arg_to_string(context, arguments[0], exception); - if (!txt) { - return JSValueMakeNull(context); - } - - /* Replace & with & */ - txt = g_strreplace (txt, "&", "&"); - - /* Replace " with " */ - txt = g_strreplace (txt, "\"", """); - - /* Replace < with < */ - txt = g_strreplace (txt, "<", "<"); - - /* Replace > with > */ - txt = g_strreplace (txt, ">", ">"); - - /* Replace newlines with
*/ - txt = g_strreplace (txt, "\n", "
"); - - result = string_or_null (context, txt); - g_free (txt); - - return result; -} - - -static gchar * -remove_query_and_hash(gchar *str) { - gchar *ptr = NULL; - - ptr = strchr(str, '?'); - - if (NULL != ptr) { - *ptr = '\0'; - } - - ptr = strchr(str, '#'); - - if (NULL != ptr) { - *ptr = '\0'; - } - - return g_strstrip(str); -} - - -static const JSStaticValue lightdm_user_values[] = { - {"display_name", get_user_display_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"home_directory", get_user_home_directory_cb, NULL, kJSPropertyAttributeReadOnly}, - {"image", get_user_image_cb, NULL, kJSPropertyAttributeReadOnly}, - {"language", get_user_language_cb, NULL, kJSPropertyAttributeReadOnly}, - {"layout", get_user_layout_cb, NULL, kJSPropertyAttributeReadOnly}, - {"logged_in", get_user_logged_in_cb, NULL, kJSPropertyAttributeReadOnly}, - {"session", get_user_session_cb, NULL, kJSPropertyAttributeReadOnly}, - {"username", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly}, - /* ---->>> DEPRECATED! <<<------>>> DEPRECATED! <<<------->>> DEPRECATED! <<<----*/ - {"name", get_user_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"real_name", get_user_real_name_cb, NULL, kJSPropertyAttributeReadOnly}, - /* ---->>> DEPRECATED! <<<------>>> DEPRECATED! <<<------->>> DEPRECATED! <<<----*/ - {NULL, NULL, NULL, 0}}; - -static const JSStaticValue lightdm_language_values[] = { - {"code", get_language_code_cb, NULL, kJSPropertyAttributeReadOnly}, - {"name", get_language_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"territory", get_language_territory_cb, NULL, kJSPropertyAttributeReadOnly}, - {NULL, NULL, NULL, 0}}; - -static const JSStaticValue lightdm_layout_values[] = { - {"name", get_layout_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"short_description", get_layout_short_description_cb, NULL, kJSPropertyAttributeReadOnly}, - {"description", get_layout_description_cb, NULL, kJSPropertyAttributeReadOnly}, - {NULL, NULL, NULL, 0}}; - -static const JSStaticValue lightdm_session_values[] = { - {"key", get_session_key_cb, NULL, kJSPropertyAttributeReadOnly}, - {"name", get_session_name_cb, NULL, kJSPropertyAttributeReadOnly}, - {"comment", get_session_comment_cb, NULL, kJSPropertyAttributeReadOnly}, - {NULL, NULL, NULL, 0}}; - -static const JSStaticValue lightdm_greeter_values[] = { - {"authentication_user", get_authentication_user_cb, NULL, kJSPropertyAttributeReadOnly}, - {"autologin_guest", get_autologin_guest_cb, NULL, kJSPropertyAttributeReadOnly}, - {"autologin_timeout", get_autologin_timeout_cb, NULL, kJSPropertyAttributeReadOnly}, - {"autologin_user", get_autologin_user_cb, NULL, kJSPropertyAttributeReadOnly}, - {"can_hibernate", get_can_hibernate_cb, NULL, kJSPropertyAttributeReadOnly}, - {"can_restart", get_can_restart_cb, NULL, kJSPropertyAttributeReadOnly}, - {"can_shutdown", get_can_shutdown_cb, NULL, kJSPropertyAttributeReadOnly}, - {"can_suspend", get_can_suspend_cb, NULL, kJSPropertyAttributeReadOnly}, - {"default_session", get_default_session_cb, NULL, kJSPropertyAttributeReadOnly}, - {"has_guest_account", get_has_guest_account_cb, NULL, kJSPropertyAttributeReadOnly}, - {"hide_users", get_hide_users_cb, NULL, kJSPropertyAttributeReadOnly}, - {"hostname", get_hostname_cb, NULL, kJSPropertyAttributeReadOnly}, - {"in_authentication", get_in_authentication_cb, NULL, kJSPropertyAttributeReadOnly}, - {"is_authenticated", get_is_authenticated_cb, NULL, kJSPropertyAttributeReadOnly}, - {"language", get_language_cb, NULL, kJSPropertyAttributeReadOnly}, - {"languages", get_languages_cb, NULL, kJSPropertyAttributeReadOnly}, - {"layout", get_layout_cb, set_layout_cb, kJSPropertyAttributeNone}, - {"layouts", get_layouts_cb, NULL, kJSPropertyAttributeReadOnly}, - {"lock_hint", get_lock_hint_cb, NULL, kJSPropertyAttributeReadOnly}, - {"num_users", get_num_users_cb, NULL, kJSPropertyAttributeReadOnly}, - {"select_guest_hint", get_select_guest_hint_cb, NULL, kJSPropertyAttributeReadOnly}, - {"select_user_hint", get_select_user_hint_cb, NULL, kJSPropertyAttributeReadOnly}, - {"sessions", get_sessions_cb, NULL, kJSPropertyAttributeReadOnly}, - {"session_starting", get_session_starting_cb, NULL, kJSPropertyAttributeReadOnly}, - {"users", get_users_cb, NULL, kJSPropertyAttributeReadOnly}, - /* ------>>> DEPRECATED! <<<----------->>> DEPRECATED! <<<------------>>> DEPRECATED! <<<------*/ - {"default_language", get_language_cb, NULL, kJSPropertyAttributeReadOnly}, - {"default_layout", get_layout_cb, NULL, kJSPropertyAttributeReadOnly}, - {"select_guest", get_select_guest_hint_cb, NULL, kJSPropertyAttributeReadOnly}, - {"select_user", get_select_user_hint_cb, NULL, kJSPropertyAttributeReadOnly}, - {"timed_login_delay", get_autologin_timeout_cb, NULL, kJSPropertyAttributeReadOnly}, - {"timed_login_user", get_autologin_user_cb, NULL, kJSPropertyAttributeReadOnly}, - /* ------>>> DEPRECATED! <<<----------->>> DEPRECATED! <<<------------>>> DEPRECATED! <<<------*/ - {NULL, NULL, NULL, 0}}; - -static const JSStaticValue greeter_config_values[] = { - {"greeter", get_config_section_greeter_cb, NULL, kJSPropertyAttributeReadOnly}, - {"branding", get_config_section_branding_cb, NULL, kJSPropertyAttributeReadOnly}, - {NULL, NULL, NULL, 0}}; - -static const JSStaticFunction lightdm_greeter_functions[] = { - {"authenticate", authenticate_cb, kJSPropertyAttributeReadOnly}, - {"authenticate_as_guest", authenticate_as_guest_cb, kJSPropertyAttributeReadOnly}, - {"cancel_authentication", cancel_authentication_cb, kJSPropertyAttributeReadOnly}, - {"cancel_autologin", cancel_autologin_cb, kJSPropertyAttributeReadOnly}, - {"get_hint", get_hint_cb, kJSPropertyAttributeReadOnly}, - {"hibernate", hibernate_cb, kJSPropertyAttributeReadOnly}, - {"respond", respond_cb, kJSPropertyAttributeReadOnly}, - {"restart", restart_cb, kJSPropertyAttributeReadOnly}, - {"set_language", set_language_cb, kJSPropertyAttributeReadOnly}, - {"shutdown", shutdown_cb, kJSPropertyAttributeReadOnly}, - {"start_session", start_session_cb, kJSPropertyAttributeReadOnly}, - {"suspend", suspend_cb, kJSPropertyAttributeReadOnly}, - /* -------->>> DEPRECATED! <<<---------------------->>> DEPRECATED! <<<---------*/ - {"cancel_timed_login", cancel_autologin_cb, kJSPropertyAttributeReadOnly}, - {"login", start_session_cb, kJSPropertyAttributeReadOnly}, - {"provide_secret", respond_cb, kJSPropertyAttributeReadOnly}, - {"start_session_sync", start_session_cb, kJSPropertyAttributeReadOnly}, - /* -------->>> DEPRECATED! <<<---------------------->>> DEPRECATED! <<<---------*/ - {NULL, NULL, 0}}; - -static const JSStaticFunction gettext_functions[] = { - {"gettext", gettext_cb, kJSPropertyAttributeReadOnly}, - {"ngettext", ngettext_cb, kJSPropertyAttributeReadOnly}, - {NULL, NULL, 0}}; - -static const JSStaticFunction theme_utils_functions[] = { - {"dirlist", get_dirlist_cb, kJSPropertyAttributeReadOnly}, - {"txt2html", txt2html_cb, kJSPropertyAttributeReadOnly}, - {NULL, NULL, 0}}; - - -static const JSClassDefinition lightdm_user_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "LightDMUser", /* Class name */ - NULL, /* Parent class */ - lightdm_user_values, /* Static values */ -}; - -static const JSClassDefinition lightdm_language_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "LightDMLanguage", /* Class name */ - NULL, /* Parent class */ - lightdm_language_values, /* Static values */ -}; - -static const JSClassDefinition lightdm_layout_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "LightDMLayout", /* Class name */ - NULL, /* Parent class */ - lightdm_layout_values, /* Static values */ -}; - -static const JSClassDefinition lightdm_session_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "LightDMSession", /* Class name */ - NULL, /* Parent class */ - lightdm_session_values, /* Static values */ -}; - -static const JSClassDefinition lightdm_greeter_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "__LightDMGreeter", /* Class name */ - NULL, /* Parent class */ - lightdm_greeter_values, /* Static values */ - lightdm_greeter_functions, /* Static functions */ -}; - -static const JSClassDefinition gettext_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "GettextClass", /* Class name */ - NULL, /* Parent class */ - NULL, /* Static values */ - gettext_functions, /* Static functions */ -}; - -static const JSClassDefinition greeter_config_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "__GreeterConfig", /* Class name */ - NULL, /* Parent class */ - NULL, /* Static values */ - NULL, /* Static functions */ -}; - -static const JSClassDefinition theme_utils_definition = { - 0, /* Version */ - kJSClassAttributeNone, /* Attributes */ - "__ThemeUtils", /* Class name */ - NULL, /* Parent class */ - NULL, /* Static values */ - theme_utils_functions, /* Static functions */ -}; - - -static void -window_object_cleared_callback(WebKitScriptWorld *world, - WebKitWebPage *web_page, - WebKitFrame *frame, - LightDMGreeter *greeter) { - - JSGlobalContextRef jsContext; - WebKitDOMDOMWindow *dom_window; - WebKitDOMDocument *dom_document; - - JSObjectRef gettext_object, - lightdm_greeter_object, - greeter_config_object, - theme_utils_object, - globalObject; - - jsContext = webkit_frame_get_javascript_context_for_script_world(frame, world); - globalObject = JSContextGetGlobalObject(jsContext); - - gettext_class = JSClassCreate(&gettext_definition); - lightdm_greeter_class = JSClassCreate(&lightdm_greeter_definition); - lightdm_user_class = JSClassCreate(&lightdm_user_definition); - lightdm_language_class = JSClassCreate(&lightdm_language_definition); - lightdm_layout_class = JSClassCreate(&lightdm_layout_definition); - lightdm_session_class = JSClassCreate(&lightdm_session_definition); - greeter_config_class = JSClassCreate(&greeter_config_definition); - theme_utils_class = JSClassCreate(&theme_utils_definition); - - gettext_object = JSObjectMake(jsContext, gettext_class, NULL); - JSObjectSetProperty(jsContext, - globalObject, - JSStringCreateWithUTF8CString("gettext"), - gettext_object, - kJSPropertyAttributeNone, - NULL); - - lightdm_greeter_object = JSObjectMake(jsContext, lightdm_greeter_class, greeter); - JSObjectSetProperty(jsContext, - globalObject, - JSStringCreateWithUTF8CString("__LightDMGreeter"), - lightdm_greeter_object, - kJSPropertyAttributeNone, - NULL); - - greeter_config_object = JSObjectMake(jsContext, greeter_config_class, NULL); - JSObjectSetProperty(jsContext, - globalObject, - JSStringCreateWithUTF8CString("__GreeterConfig"), - greeter_config_object, - kJSPropertyAttributeDontEnum | kJSPropertyAttributeReadOnly, - NULL); - - theme_utils_object = JSObjectMake(jsContext, theme_utils_class, NULL); - JSObjectSetProperty(jsContext, - globalObject, - JSStringCreateWithUTF8CString("__ThemeUtils"), - theme_utils_object, - kJSPropertyAttributeDontEnum | kJSPropertyAttributeReadOnly, - NULL); - - dom_document = webkit_web_page_get_dom_document(web_page); - dom_window = webkit_dom_document_get_default_view(dom_document); - - if (dom_window) { - /* If the greeter was started as a lock-screen, notify our UI process. */ - if (lightdm_greeter_get_lock_hint(greeter)) { - webkit_dom_dom_window_webkit_message_handlers_post_message( - dom_window, "GreeterBridge", "LockHint" - ); - } - } -} - - -static void -show_prompt_cb(LightDMGreeter *greeter, - const gchar *text, - LightDMPromptType type, - WebKitWebExtension *extension) { - - WebKitWebPage *web_page; - WebKitFrame *web_frame; - JSGlobalContextRef jsContext; - JSStringRef command; - gchar *string; - gchar *etext; - const gchar *ct = ""; - - web_page = webkit_web_extension_get_page(extension, page_id); - - if (web_page != NULL) { - web_frame = webkit_web_page_get_main_frame(web_page); - jsContext = webkit_frame_get_javascript_global_context(web_frame); - - switch (type) { - case LIGHTDM_PROMPT_TYPE_QUESTION: - ct = "text"; - break; - case LIGHTDM_PROMPT_TYPE_SECRET: - ct = "password"; - break; - } - - etext = escape(text); - string = g_strdup_printf("show_prompt('%s', '%s')", etext, ct); - command = JSStringCreateWithUTF8CString(string); - - JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); - - g_free(string); - g_free(etext); - } -} - - -static void -show_message_cb(LightDMGreeter *greeter, - const gchar *text, - LightDMMessageType type, - WebKitWebExtension *extension) { - - WebKitWebPage *web_page; - WebKitFrame *web_frame; - JSGlobalContextRef jsContext; - JSStringRef command; - gchar *etext; - gchar *string; - const gchar *mt = ""; - - web_page = webkit_web_extension_get_page(extension, page_id); - - if (web_page != NULL) { - web_frame = webkit_web_page_get_main_frame(web_page); - jsContext = webkit_frame_get_javascript_global_context(web_frame); - - switch (type) { - case LIGHTDM_MESSAGE_TYPE_ERROR: - mt = "error"; - break; - case LIGHTDM_MESSAGE_TYPE_INFO: - mt = "info"; - break; - } - - etext = escape(text); - string = g_strdup_printf("show_prompt('%s', '%s')", etext, mt); - command = JSStringCreateWithUTF8CString(string); - - JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); - - g_free(string); - g_free(etext); - } -} - - -static void -authentication_complete_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) { - - WebKitWebPage *web_page; - WebKitFrame *web_frame; - JSGlobalContextRef jsContext; - JSStringRef command; - - web_page = webkit_web_extension_get_page(extension, page_id); - - if (web_page != NULL) { - web_frame = webkit_web_page_get_main_frame(web_page); - jsContext = webkit_frame_get_javascript_global_context(web_frame); - command = JSStringCreateWithUTF8CString("authentication_complete()"); - - JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); - } -} - - -static void -autologin_timer_expired_cb(LightDMGreeter *greeter, WebKitWebExtension *extension) { - - WebKitWebPage *web_page; - WebKitFrame *web_frame; - JSGlobalContextRef jsContext; - JSStringRef command; - - web_page = webkit_web_extension_get_page(extension, page_id); - - if (web_page != NULL) { - web_frame = webkit_web_page_get_main_frame(web_page); - jsContext = webkit_frame_get_javascript_global_context(web_frame); - command = JSStringCreateWithUTF8CString("autologin_timer_expired()"); - - JSEvaluateScript(jsContext, command, NULL, NULL, 0, NULL); - } -} - - -static gboolean -get_config_option_as_bool(const gchar *section, const gchar *key, GError **err) { - GError *err_tmp = NULL; - gboolean result = g_key_file_get_boolean(keyfile, section, key, &err_tmp); - - if (NULL != err_tmp) { - g_propagate_error(err, err_tmp); - } - - return result; -} - - -static gchar* -get_config_option_as_string(const gchar *section, const gchar *key) { - gchar *value; - GError *err = NULL; - - value = g_key_file_get_string(keyfile, section, key, &err); - - if (NULL != err) { - g_error("%s", err->message); - g_error_free(err); - g_free(value); - return ""; - } - - return value; -} - - -static gboolean -should_block_request(const char *file_path) { - gboolean result = TRUE; /* Blocked */ - char *canonical_path; - - if (NULL == file_path) { - return result; - } - - canonical_path = canonicalize_file_name(file_path); - - if (NULL != canonical_path) { - for (iter = paths; iter; iter = iter->next) { - if (0 == g_strcmp0(canonical_path, iter->data) || g_str_has_prefix(canonical_path, iter->data)) { - result = FALSE; /* Allowed */ - break; - } - } - } - - g_free(canonical_path); - - return result; -} - - -/** - * Callback for the "send-request" signal of a {@link WebKitWebPage} - * - * @see https://goo.gl/mmoHEx - * @return TRUE to stop other handlers from being invoked for the event (block the request). - * FALSE to continue emission of the event (allow the request). - */ -gboolean -web_page_send_request_cb(WebKitWebPage *web_page, - WebKitURIRequest *request, - WebKitURIResponse *redirected_response, - gpointer user_data) { - - char *request_scheme; - gchar *request_file_path; - char *request_file_path_without_query; - gboolean decision; - - const char *request_uri = webkit_uri_request_get_uri(request); - request_scheme = g_uri_parse_scheme(request_uri); - - /* NOTE: Returning TRUE blocks the request, while Returning FALSE allows it. - * :face_with_rolling_eyes: - */ - if (NULL != strstr(request_uri, "mock.js")) { - /* Never allow mock greeter script to be loaded in the greeter */ - decision = TRUE; /* Blocked */ - - } else if (FALSE == secure_mode && NULL != strstr(request_scheme, "http")) { - decision = FALSE; /* Allowed */ - - } else if (0 == strcmp(request_scheme, "data") || 0 == strcmp(request_scheme, "resource")) { - decision = FALSE; /* Allowed */ - - } else if (0 == strcmp(request_scheme, "file")) { - request_file_path = g_filename_from_uri(request_uri, NULL, NULL); - request_file_path_without_query = g_strdup(request_file_path); - - request_file_path_without_query = remove_query_and_hash(request_file_path_without_query); - - decision = should_block_request(request_file_path_without_query); - - } else { - /* In order to ensure the user's privacy & security, only local requests are allowed. */ - g_warning("request scheme error: %s", request_scheme); - decision = TRUE; /* Blocked */ - } - - g_free(request_scheme); - - return decision; -} - - -void -web_page_console_message_sent_cb(WebKitWebPage *web_page, - WebKitConsoleMessage *console_message, - gpointer user_data) { - WebKitDOMDOMWindow *dom_window; - WebKitDOMDocument *dom_document; - const gchar *msg_text; - gboolean is_error; - - msg_text = webkit_console_message_get_text(console_message); - is_error = - NULL != strstr(msg_text, "Uncaught") || - NULL != strstr(msg_text, "Error") || - NULL != strstr(msg_text, "error") || - NULL != strstr(msg_text, "Exception") || - NULL != strstr(msg_text, "exception") || - NULL != strstr(msg_text, "ERROR"); - - if (! is_error) { - return; - } - - /* This is an Uncaught JS Exception. Notify the UI process so it can show recovery dialog */ - dom_document = webkit_web_page_get_dom_document(web_page); - dom_window = webkit_dom_document_get_default_view(dom_document); - - if (dom_window) { - webkit_dom_dom_window_webkit_message_handlers_post_message( - dom_window, "GreeterBridge", "JavaScriptException" - ); - } -} - - -void -page_created_cb(WebKitWebExtension *extension, - WebKitWebPage *web_page, - gpointer user_data) { - - WebKitDOMDOMWindow *dom_window; - WebKitDOMDocument *dom_document; - - // save the page_id (global variable) - page_id = webkit_web_page_get_id(web_page); - - g_signal_connect(web_page, "send-request", G_CALLBACK(web_page_send_request_cb), NULL); - - if (TRUE == detect_theme_errors) { - g_signal_connect(web_page, "console-message-sent", G_CALLBACK(web_page_console_message_sent_cb), NULL); - } - - // Notify UI process that the page is loaded. - dom_document = webkit_web_page_get_dom_document(web_page); - dom_window = webkit_dom_document_get_default_view(dom_document); - - if (dom_window) { - webkit_dom_dom_window_webkit_message_handlers_post_message( - dom_window, "GreeterBridge", "PageLoaded" - ); - } -} - - -G_MODULE_EXPORT void -webkit_web_extension_initialize(WebKitWebExtension *extension) { - LightDMGreeter *greeter = lightdm_greeter_new(); - GError *err = NULL; - - WEB_EXTENSION = extension; - SESSION_STARTING = FALSE; - - conf = get_config(); - - secure_mode = get_config_option_as_bool("greeter", "secure_mode", &err); - if (NULL != err) { - // Use default value - secure_mode = TRUE; - g_clear_error(&err); - } - - detect_theme_errors = get_config_option_as_bool("greeter", "detect_theme_errors", &err); - if (NULL != err) { - // Use default value - detect_theme_errors = TRUE; - g_error_free(err); - } - - paths = g_slist_prepend(paths, THEME_DIR); - - background_images_dir = get_config_option_as_string("branding", "background_images"); - paths = g_slist_prepend(paths, background_images_dir); - - user_image = get_config_option_as_string("branding", "user_image"); - paths = g_slist_prepend(paths, user_image); - - logo = get_config_option_as_string("branding", "logo"); - paths = g_slist_prepend(paths, logo); - - g_signal_connect( - G_OBJECT(greeter), - "authentication-complete", - G_CALLBACK(authentication_complete_cb), - extension - ); - - g_signal_connect( - G_OBJECT(greeter), - "autologin-timer-expired", - G_CALLBACK(autologin_timer_expired_cb), - extension - ); - - g_signal_connect( - G_OBJECT(extension), - "page-created", - G_CALLBACK(page_created_cb), - NULL - ); - - g_signal_connect( - webkit_script_world_get_default(), - "window-object-cleared", - G_CALLBACK(window_object_cleared_callback), - greeter - ); - - g_signal_connect( - G_OBJECT(greeter), - "show-prompt", - G_CALLBACK(show_prompt_cb), - extension - ); - - g_signal_connect( - G_OBJECT(greeter), - "show-message", - G_CALLBACK(show_message_cb), - extension - ); - - /* TODO: This function was deprecated in lightdm 1.11.x. - * New function is lightdm_greeter_connect_to_daemon_sync - * Wait until it makes it into Debian Stable before making the change. - */ - lightdm_greeter_connect_sync(greeter, NULL); -} - -/* vim: set ts=4 sw=4 tw=0 noet : */ diff --git a/themes/meson.build b/themes/meson.build deleted file mode 100644 index fd572ba..0000000 --- a/themes/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -install_subdir('_vendor', install_dir : get_option('with-theme-dir')) - -install_subdir('antergos', install_dir : get_option('with-theme-dir')) - -install_subdir('simple', install_dir : get_option('with-theme-dir')) diff --git a/lightdm-webkit2-greeter.doap b/web-greeter.doap similarity index 86% rename from lightdm-webkit2-greeter.doap rename to web-greeter.doap index c679e3b..2ee205a 100644 --- a/lightdm-webkit2-greeter.doap +++ b/web-greeter.doap @@ -4,9 +4,9 @@ xmlns:gnome="http://api.gnome.org/doap-extensions#" xmlns="http://usefulinc.com/ns/doap#"> - lightdm-webkit2-greeter - LightDM Webkit2 Greeter - C + web-greeter + Web Greeter for LightDM + Python JavaScript diff --git a/web-greeter/meson.build b/web-greeter/meson.build deleted file mode 100644 index f1f06fe..0000000 --- a/web-greeter/meson.build +++ /dev/null @@ -1,41 +0,0 @@ -# ================================ # -# ------->>> Resources <<<-------- # -# ================================ # - -resource_dir = include_directories('resource') -qt5 = import('qt5') -utils = '@0@/utils.sh'.format(meson.build_root()) - -js_sources = run_command(utils, 'combine-js') - - - - -# ======================================= # -# ------->>> WebKit2 Extension <<<------- # -# ======================================= # - -webext_sources = ['webkit2-extension.c'] - -webext = library( - 'lightdm-webkit2-greeter-webext', - webext_sources, - dependencies: webext_deps, - install: true, - install_dir : extdir -) - - -# ============================= # -# ------->>> Greeter <<<------- # -# ============================= # - -greeter_sources = [gresources, 'greeter.c', 'greeter-config.c'] - -greeter = executable( - 'lightdm-webkit2-greeter', - greeter_sources, - dependencies: greeter_deps, - install: true -) - diff --git a/web-greeter/whither.yml b/web-greeter/whither.yml index a8627e0..a9bf168 100644 --- a/web-greeter/whither.yml +++ b/web-greeter/whither.yml @@ -26,10 +26,9 @@ WebGreeter: background_images_dir: '@background_images_dir@' config_dir: '@config_dir@' greeters_dir: '@greeters_dir@' - has_lightdm_1_19_2: '@has_lightdm_1_19_2@' locale_dir: '@locale_dir@' logo_image: '@logo_image@' - themes_dir: /home/dustin/github/antergos/lightdm-webkit2-greeter/themes + themes_dir: '@themes_dir@' user_image: '@user_image@' version: full: '@full_version@'