portalHelper: Adjust coding style

Most of the file already complies with the new style. Quickly change
the last remaining bits of legacy style before making further changes.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2690>
This commit is contained in:
Florian Müllner 2023-03-08 19:51:54 +01:00 committed by Marge Bot
parent 6c6e3a8e76
commit f7c8ff7a0c

View File

@ -4,12 +4,12 @@ imports.gi.versions.Gtk = '3.0';
imports.gi.versions.WebKit2 = '4.1'; imports.gi.versions.WebKit2 = '4.1';
const Gettext = imports.gettext; const Gettext = imports.gettext;
const { Gio, GLib, GObject, Gtk, Pango, WebKit2: WebKit } = imports.gi; const {Gio, GLib, GObject, Gtk, Pango, WebKit2: WebKit} = imports.gi;
const _ = Gettext.gettext; const _ = Gettext.gettext;
const Config = imports.misc.config; const Config = imports.misc.config;
const { loadInterfaceXML } = imports.misc.fileUtils; const {loadInterfaceXML} = imports.misc.fileUtils;
const PortalHelperResult = { const PortalHelperResult = {
CANCELLED: 0, CANCELLED: 0,
@ -40,7 +40,7 @@ const HelperDBusInterface = loadInterfaceXML('org.gnome.Shell.PortalHelper');
var PortalHeaderBar = GObject.registerClass( var PortalHeaderBar = GObject.registerClass(
class PortalHeaderBar extends Gtk.HeaderBar { class PortalHeaderBar extends Gtk.HeaderBar {
_init() { _init() {
super._init({ show_close_button: true }); super._init({show_close_button: true});
// See ephy-title-box.c in epiphany for the layout // See ephy-title-box.c in epiphany for the layout
const vbox = new Gtk.Box({ const vbox = new Gtk.Box({
@ -98,12 +98,12 @@ class PortalHeaderBar extends Gtk.HeaderBar {
break; break;
case PortalHelperSecurityLevel.SECURE: case PortalHelperSecurityLevel.SECURE:
this._lockImage.show(); this._lockImage.show();
this._lockImage.set_from_icon_name("channel-secure-symbolic", Gtk.IconSize.MENU); this._lockImage.set_from_icon_name('channel-secure-symbolic', Gtk.IconSize.MENU);
this._lockImage.set_tooltip_text(null); this._lockImage.set_tooltip_text(null);
break; break;
case PortalHelperSecurityLevel.INSECURE: case PortalHelperSecurityLevel.INSECURE:
this._lockImage.show(); this._lockImage.show();
this._lockImage.set_from_icon_name("channel-insecure-symbolic", Gtk.IconSize.MENU); this._lockImage.set_from_icon_name('channel-insecure-symbolic', Gtk.IconSize.MENU);
this._lockImage.set_tooltip_text(_('Your connection to this hotspot login is not secure. Passwords or other information you enter on this page can be viewed by people nearby.')); this._lockImage.set_tooltip_text(_('Your connection to this hotspot login is not secure. Passwords or other information you enter on this page can be viewed by people nearby.'));
break; break;
} }
@ -113,7 +113,7 @@ class PortalHeaderBar extends Gtk.HeaderBar {
var PortalWindow = GObject.registerClass( var PortalWindow = GObject.registerClass(
class PortalWindow extends Gtk.ApplicationWindow { class PortalWindow extends Gtk.ApplicationWindow {
_init(application, url, timestamp, doneCallback) { _init(application, url, timestamp, doneCallback) {
super._init({ application }); super._init({application});
this._headerBar = new PortalHeaderBar(); this._headerBar = new PortalHeaderBar();
this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.NOT_YET_DETERMINED); this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.NOT_YET_DETERMINED);
@ -181,13 +181,13 @@ class PortalWindow extends Gtk.ApplicationWindow {
} }
_onLoadChanged(view, loadEvent) { _onLoadChanged(view, loadEvent) {
if (loadEvent == WebKit.LoadEvent.STARTED) { if (loadEvent === WebKit.LoadEvent.STARTED) {
this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.NOT_YET_DETERMINED); this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.NOT_YET_DETERMINED);
} else if (loadEvent == WebKit.LoadEvent.COMMITTED) { } else if (loadEvent === WebKit.LoadEvent.COMMITTED) {
let tlsInfo = this._webView.get_tls_info(); let tlsInfo = this._webView.get_tls_info();
let ret = tlsInfo[0]; let ret = tlsInfo[0];
let flags = tlsInfo[2]; let flags = tlsInfo[2];
if (ret && flags == 0) if (ret && flags === 0)
this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.SECURE); this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.SECURE);
else else
this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.INSECURE); this._headerBar.setSecurityIcon(PortalHelperSecurityLevel.INSECURE);
@ -207,7 +207,7 @@ class PortalWindow extends Gtk.ApplicationWindow {
} }
_onDecidePolicy(view, decision, type) { _onDecidePolicy(view, decision, type) {
if (type == WebKit.PolicyDecisionType.NEW_WINDOW_ACTION) { if (type === WebKit.PolicyDecisionType.NEW_WINDOW_ACTION) {
let navigationAction = decision.get_navigation_action(); let navigationAction = decision.get_navigation_action();
if (navigationAction.is_user_gesture()) { if (navigationAction.is_user_gesture()) {
// Even though the portal asks for a new window, // Even though the portal asks for a new window,
@ -224,19 +224,19 @@ class PortalWindow extends Gtk.ApplicationWindow {
return true; return true;
} }
if (type != WebKit.PolicyDecisionType.NAVIGATION_ACTION) if (type !== WebKit.PolicyDecisionType.NAVIGATION_ACTION)
return false; return false;
let request = decision.get_request(); let request = decision.get_request();
const uri = GLib.Uri.parse(request.get_uri(), HTTP_URI_FLAGS); const uri = GLib.Uri.parse(request.get_uri(), HTTP_URI_FLAGS);
if (uri.get_host() !== this._uri.get_host() && this._originalUrlWasGnome) { if (uri.get_host() !== this._uri.get_host() && this._originalUrlWasGnome) {
if (uri.get_host() == CONNECTIVITY_CHECK_HOST && this._everSeenRedirect) { if (uri.get_host() === CONNECTIVITY_CHECK_HOST && this._everSeenRedirect) {
// Yay, we got to gnome! // Yay, we got to gnome!
decision.ignore(); decision.ignore();
this._doneCallback(PortalHelperResult.COMPLETED); this._doneCallback(PortalHelperResult.COMPLETED);
return true; return true;
} else if (uri.get_host() != CONNECTIVITY_CHECK_HOST) { } else if (uri.get_host() !== CONNECTIVITY_CHECK_HOST) {
this._everSeenRedirect = true; this._everSeenRedirect = true;
} }
} }
@ -286,7 +286,7 @@ class WebPortalHelper extends Gtk.Application {
this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(HelperDBusInterface, this); this._dbusImpl = Gio.DBusExportedObject.wrapJSObject(HelperDBusInterface, this);
this._queue = []; this._queue = [];
let action = new Gio.SimpleAction({ name: 'quit' }); let action = new Gio.SimpleAction({name: 'quit'});
action.connect('activate', () => this.active_window.destroy()); action.connect('activate', () => this.active_window.destroy());
this.add_action(action); this.add_action(action);
} }
@ -309,7 +309,7 @@ class WebPortalHelper extends Gtk.Application {
} }
Authenticate(connection, url, timestamp) { Authenticate(connection, url, timestamp) {
this._queue.push({ connection, url, timestamp }); this._queue.push({connection, url, timestamp});
this._processQueue(); this._processQueue();
} }
@ -318,7 +318,7 @@ class WebPortalHelper extends Gtk.Application {
for (let i = 0; i < this._queue.length; i++) { for (let i = 0; i < this._queue.length; i++) {
let obj = this._queue[i]; let obj = this._queue[i];
if (obj.connection == connection) { if (obj.connection === connection) {
if (obj.window) if (obj.window)
obj.window.destroy(); obj.window.destroy();
this._queue.splice(i, 1); this._queue.splice(i, 1);
@ -333,7 +333,7 @@ class WebPortalHelper extends Gtk.Application {
for (let i = 0; i < this._queue.length; i++) { for (let i = 0; i < this._queue.length; i++) {
let obj = this._queue[i]; let obj = this._queue[i];
if (obj.connection == connection) { if (obj.connection === connection) {
if (obj.window) if (obj.window)
obj.window.refresh(); obj.window.refresh();
break; break;
@ -342,7 +342,7 @@ class WebPortalHelper extends Gtk.Application {
} }
_processQueue() { _processQueue() {
if (this._queue.length == 0) if (this._queue.length === 0)
return; return;
let top = this._queue[0]; let top = this._queue[0];
@ -355,6 +355,9 @@ class WebPortalHelper extends Gtk.Application {
} }
}); });
/**
* @param {string[]} argv - command line arguments
*/
function main(argv) { function main(argv) {
if (!WebKit.WebContext.new_ephemeral) { if (!WebKit.WebContext.new_ephemeral) {
log('WebKitGTK 2.16 is required for the portal-helper, see https://bugzilla.gnome.org/show_bug.cgi?id=780453'); log('WebKitGTK 2.16 is required for the portal-helper, see https://bugzilla.gnome.org/show_bug.cgi?id=780453');