Blob Blame History Raw
From 9b861aa428c21c59e91d5b5a629a5308eb1d5246 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Wed, 21 Aug 2019 15:06:46 -0400
Subject: [PATCH 3/3] shellEntry: Support lockdown of "Show Text" menu in
 password entries

Some deployments require being able to prevent users from showing
the password they're currently typing.

This commit adds support for that kind of lockdown.
---
 js/ui/shellEntry.js | 33 +++++++++++++++++++++++++++------
 1 file changed, 27 insertions(+), 6 deletions(-)

diff --git a/js/ui/shellEntry.js b/js/ui/shellEntry.js
index 5ce0a40a0..f0ee1d9e0 100644
--- a/js/ui/shellEntry.js
+++ b/js/ui/shellEntry.js
@@ -1,94 +1,115 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 
 const Clutter = imports.gi.Clutter;
 const Gtk = imports.gi.Gtk;
+const Gio = imports.gi.Gio;
 const Lang = imports.lang;
 const St = imports.gi.St;
 
 const BoxPointer = imports.ui.boxpointer;
 const Main = imports.ui.main;
 const Params = imports.misc.params;
 const PopupMenu = imports.ui.popupMenu;
 
+const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
+const DISABLE_SHOW_PASSWORD_KEY = 'disable-show-password';
+
 var EntryMenu = new Lang.Class({
     Name: 'ShellEntryMenu',
     Extends: PopupMenu.PopupMenu,
 
     _init(entry) {
         this.parent(entry, 0, St.Side.TOP);
 
+        this._lockdownSettings = new Gio.Settings({ schema_id: LOCKDOWN_SCHEMA });
+        this._lockdownSettings.connect('changed::' + DISABLE_SHOW_PASSWORD_KEY, this._resetPasswordItem.bind(this));
+
         this._entry = entry;
         this._clipboard = St.Clipboard.get_default();
 
         // Populate menu
         let item;
         item = new PopupMenu.PopupMenuItem(_("Copy"));
         item.connect('activate', this._onCopyActivated.bind(this));
         this.addMenuItem(item);
         this._copyItem = item;
 
         item = new PopupMenu.PopupMenuItem(_("Paste"));
         item.connect('activate', this._onPasteActivated.bind(this));
         this.addMenuItem(item);
         this._pasteItem = item;
 
         this._passwordItem = null;
 
         Main.uiGroup.add_actor(this.actor);
         this.actor.hide();
     },
 
     _makePasswordItem() {
         let item = new PopupMenu.PopupMenuItem('');
         item.connect('activate', this._onPasswordActivated.bind(this));
         this.addMenuItem(item);
         this._passwordItem = item;
         this._updatePasswordItem();
     },
 
+    _resetPasswordItem() {
+        let passwordDisabled = this._lockdownSettings.get_boolean(DISABLE_SHOW_PASSWORD_KEY);
+
+        if (!this.isPassword || passwordDisabled) {
+            if (this._passwordItem) {
+                this._passwordItem.destroy();
+                this._passwordItem = null;
+            }
+            if (this.isPassword)
+                this._entry.clutter_text.set_password_char('\u25cf');
+        } else if (this.isPassword && !passwordDisabled) {
+            if (!this._passwordItem)
+                this._makePasswordItem();
+        }
+    },
+
     get isPassword() {
         return this._entry.input_purpose == Clutter.InputContentPurpose.PASSWORD;
     },
 
     set isPassword(v) {
         if (v == this.isPassword)
             return;
 
-        if (v) {
-            this._makePasswordItem();
+        if (v)
             this._entry.input_purpose = Clutter.InputContentPurpose.PASSWORD;
-        } else {
-            this._passwordItem.destroy();
-            this._passwordItem = null;
+        else
             this._entry.input_purpose = Clutter.InputContentPurpose.NORMAL;
-        }
+
+        this._resetPasswordItem();
     },
 
     open(animate) {
         this._updatePasteItem();
         this._updateCopyItem();
         if (this._passwordItem)
             this._updatePasswordItem();
 
         this.parent(animate);
         this._entry.add_style_pseudo_class('focus');
 
         let direction = Gtk.DirectionType.TAB_FORWARD;
         if (!this.actor.navigate_focus(null, direction, false))
             this.actor.grab_key_focus();
     },
 
     _updateCopyItem() {
         let selection = this._entry.clutter_text.get_selection();
         this._copyItem.setSensitive(!this._entry.clutter_text.password_char &&
                                     selection && selection != '');
     },
 
     _updatePasteItem() {
         this._clipboard.get_text(St.ClipboardType.CLIPBOARD,
             (clipboard, text) => {
                 this._pasteItem.setSensitive(text && text != '');
             });
     },
 
     _updatePasswordItem() {
-- 
2.21.0