Blame SOURCES/0003-shellEntry-Support-lockdown-of-Show-Text-menu-in-pas.patch

18fbde
From 9b861aa428c21c59e91d5b5a629a5308eb1d5246 Mon Sep 17 00:00:00 2001
18fbde
From: Ray Strode <rstrode@redhat.com>
18fbde
Date: Wed, 21 Aug 2019 15:06:46 -0400
18fbde
Subject: [PATCH 3/3] shellEntry: Support lockdown of "Show Text" menu in
18fbde
 password entries
18fbde
18fbde
Some deployments require being able to prevent users from showing
18fbde
the password they're currently typing.
18fbde
18fbde
This commit adds support for that kind of lockdown.
18fbde
---
18fbde
 js/ui/shellEntry.js | 33 +++++++++++++++++++++++++++------
18fbde
 1 file changed, 27 insertions(+), 6 deletions(-)
18fbde
18fbde
diff --git a/js/ui/shellEntry.js b/js/ui/shellEntry.js
18fbde
index 5ce0a40a0..f0ee1d9e0 100644
18fbde
--- a/js/ui/shellEntry.js
18fbde
+++ b/js/ui/shellEntry.js
18fbde
@@ -1,94 +1,115 @@
18fbde
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
18fbde
 
18fbde
 const Clutter = imports.gi.Clutter;
18fbde
 const Gtk = imports.gi.Gtk;
18fbde
+const Gio = imports.gi.Gio;
18fbde
 const Lang = imports.lang;
18fbde
 const St = imports.gi.St;
18fbde
 
18fbde
 const BoxPointer = imports.ui.boxpointer;
18fbde
 const Main = imports.ui.main;
18fbde
 const Params = imports.misc.params;
18fbde
 const PopupMenu = imports.ui.popupMenu;
18fbde
 
18fbde
+const LOCKDOWN_SCHEMA = 'org.gnome.desktop.lockdown';
18fbde
+const DISABLE_SHOW_PASSWORD_KEY = 'disable-show-password';
18fbde
+
18fbde
 var EntryMenu = new Lang.Class({
18fbde
     Name: 'ShellEntryMenu',
18fbde
     Extends: PopupMenu.PopupMenu,
18fbde
 
18fbde
     _init(entry) {
18fbde
         this.parent(entry, 0, St.Side.TOP);
18fbde
 
18fbde
+        this._lockdownSettings = new Gio.Settings({ schema_id: LOCKDOWN_SCHEMA });
18fbde
+        this._lockdownSettings.connect('changed::' + DISABLE_SHOW_PASSWORD_KEY, this._resetPasswordItem.bind(this));
18fbde
+
18fbde
         this._entry = entry;
18fbde
         this._clipboard = St.Clipboard.get_default();
18fbde
 
18fbde
         // Populate menu
18fbde
         let item;
18fbde
         item = new PopupMenu.PopupMenuItem(_("Copy"));
18fbde
         item.connect('activate', this._onCopyActivated.bind(this));
18fbde
         this.addMenuItem(item);
18fbde
         this._copyItem = item;
18fbde
 
18fbde
         item = new PopupMenu.PopupMenuItem(_("Paste"));
18fbde
         item.connect('activate', this._onPasteActivated.bind(this));
18fbde
         this.addMenuItem(item);
18fbde
         this._pasteItem = item;
18fbde
 
18fbde
         this._passwordItem = null;
18fbde
 
18fbde
         Main.uiGroup.add_actor(this.actor);
18fbde
         this.actor.hide();
18fbde
     },
18fbde
 
18fbde
     _makePasswordItem() {
18fbde
         let item = new PopupMenu.PopupMenuItem('');
18fbde
         item.connect('activate', this._onPasswordActivated.bind(this));
18fbde
         this.addMenuItem(item);
18fbde
         this._passwordItem = item;
18fbde
         this._updatePasswordItem();
18fbde
     },
18fbde
 
18fbde
+    _resetPasswordItem() {
18fbde
+        let passwordDisabled = this._lockdownSettings.get_boolean(DISABLE_SHOW_PASSWORD_KEY);
18fbde
+
18fbde
+        if (!this.isPassword || passwordDisabled) {
18fbde
+            if (this._passwordItem) {
18fbde
+                this._passwordItem.destroy();
18fbde
+                this._passwordItem = null;
18fbde
+            }
18fbde
+            if (this.isPassword)
18fbde
+                this._entry.clutter_text.set_password_char('\u25cf');
18fbde
+        } else if (this.isPassword && !passwordDisabled) {
18fbde
+            if (!this._passwordItem)
18fbde
+                this._makePasswordItem();
18fbde
+        }
18fbde
+    },
18fbde
+
18fbde
     get isPassword() {
18fbde
         return this._entry.input_purpose == Clutter.InputContentPurpose.PASSWORD;
18fbde
     },
18fbde
 
18fbde
     set isPassword(v) {
18fbde
         if (v == this.isPassword)
18fbde
             return;
18fbde
 
18fbde
-        if (v) {
18fbde
-            this._makePasswordItem();
18fbde
+        if (v)
18fbde
             this._entry.input_purpose = Clutter.InputContentPurpose.PASSWORD;
18fbde
-        } else {
18fbde
-            this._passwordItem.destroy();
18fbde
-            this._passwordItem = null;
18fbde
+        else
18fbde
             this._entry.input_purpose = Clutter.InputContentPurpose.NORMAL;
18fbde
-        }
18fbde
+
18fbde
+        this._resetPasswordItem();
18fbde
     },
18fbde
 
18fbde
     open(animate) {
18fbde
         this._updatePasteItem();
18fbde
         this._updateCopyItem();
18fbde
         if (this._passwordItem)
18fbde
             this._updatePasswordItem();
18fbde
 
18fbde
         this.parent(animate);
18fbde
         this._entry.add_style_pseudo_class('focus');
18fbde
 
18fbde
         let direction = Gtk.DirectionType.TAB_FORWARD;
18fbde
         if (!this.actor.navigate_focus(null, direction, false))
18fbde
             this.actor.grab_key_focus();
18fbde
     },
18fbde
 
18fbde
     _updateCopyItem() {
18fbde
         let selection = this._entry.clutter_text.get_selection();
18fbde
         this._copyItem.setSensitive(!this._entry.clutter_text.password_char &&
18fbde
                                     selection && selection != '');
18fbde
     },
18fbde
 
18fbde
     _updatePasteItem() {
18fbde
         this._clipboard.get_text(St.ClipboardType.CLIPBOARD,
18fbde
             (clipboard, text) => {
18fbde
                 this._pasteItem.setSensitive(text && text != '');
18fbde
             });
18fbde
     },
18fbde
 
18fbde
     _updatePasswordItem() {
18fbde
-- 
18fbde
2.21.0
18fbde