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

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