From 22eb0ddc17173555c95f1b18040d0ea5475216f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 8 Dec 2022 10:30:37 -0800 Subject: [PATCH 1/6] Port to HdyTabBar --- src/CaptiveLogin.vala | 94 +++++++++++++++++++++--------------------- src/TabbedWebView.vala | 62 ++++++++++++---------------- 2 files changed, 73 insertions(+), 83 deletions(-) diff --git a/src/CaptiveLogin.vala b/src/CaptiveLogin.vala index c82533c4..836248a4 100644 --- a/src/CaptiveLogin.vala +++ b/src/CaptiveLogin.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) 2015-2017 elementary LLC. (http://launchpad.net/capnet-assist) +* Copyright 2015-2022 elementary, Inc. (https://elementary.io) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -23,8 +23,7 @@ public class CaptiveLogin : Hdy.ApplicationWindow { private CertButton cert_button; private Gtk.Label title_label; - - private Granite.Widgets.DynamicNotebook notebook; + private Hdy.TabView tabview; // When a download is passed to the browser, it triggers the load failed signal private bool download_requested = false; @@ -68,80 +67,79 @@ public class CaptiveLogin : Hdy.ApplicationWindow { }; header.get_style_context ().add_class ("default-decoration"); - notebook = new Granite.Widgets.DynamicNotebook () { - add_button_visible = false, - allow_drag = false, - allow_new_window = false, - allow_restoring = false, - expand = true, - tab_bar_behavior = Granite.Widgets.DynamicNotebook.TabBarBehavior.SINGLE + tabview = new Hdy.TabView () { + expand = true + }; + + var tabbar = new Hdy.TabBar () { + expand_tabs = false, + view = tabview }; - var grid = new Gtk.Grid (); - grid.attach (header, 0, 0); - grid.attach (notebook, 0, 1); + var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); + box.add (header); + box.add (tabbar); + box.add (tabview); - add (grid); + add (box); set_keep_above (true); skip_taskbar_hint = true; stick (); - connect_signals (); - } - - bool is_privacy_mode_enabled () { - var privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy"); - return !privacy_settings.get_boolean ("remember-recent-files") || - !privacy_settings.get_boolean ("remember-app-usage"); - } - - private void connect_signals () { this.destroy.connect (application.quit); - notebook.tab_switched.connect ((old_tab, new_tab) => { - var captive_view = (TabbedWebView) new_tab; - title_label.label = captive_view.label; - + tabview.notify["selected-page"].connect (() => { + var captive_view = (TabbedWebView) tabview.get_selected_page ().child; + title_label.label = captive_view.title; cert_button.security = captive_view.security; }); - notebook.close_tab_requested.connect ((tab) => { - if (notebook.n_tabs == 1) { + tabview.close_page.connect ((page) => { + tabview.close_page_finish (page, true); + + if (tabview.n_pages == 0) { application.quit (); - } else if (notebook.n_tabs == 2) { - notebook.show_tabs = false; } - return true; + return Gdk.EVENT_STOP; }); } + bool is_privacy_mode_enabled () { + var privacy_settings = new GLib.Settings ("org.gnome.desktop.privacy"); + return !privacy_settings.get_boolean ("remember-recent-files") || + !privacy_settings.get_boolean ("remember-app-usage"); + } private TabbedWebView create_tab (string uri) { - var tab = new TabbedWebView (uri, !is_privacy_mode_enabled ()); + var webview = new TabbedWebView (!is_privacy_mode_enabled ()); + webview.load_uri (uri); + + var tabpage = tabview.append (webview); + + show_all (); - notebook.insert_tab (tab, notebook.n_tabs); - notebook.show_tabs = notebook.n_tabs > 1; + webview.bind_property ("title", tabpage, "title"); - tab.notify["label"].connect ((view, param_spec) => { - if (tab == this.notebook.current) { - title_label.set_text (tab.label); + webview.notify["title"].connect ((view, param_spec) => { + if (tabpage == tabview.get_selected_page ()) { + title_label.set_text (webview.title); } }); - tab.notify["security"].connect ((view, param_spec) => { - if (tab == this.notebook.current) { - cert_button.security = tab.security; + webview.notify["security"].connect ((view, param_spec) => { + if (tabpage == tabview.get_selected_page ()) { + cert_button.security = webview.security; } }); - tab.web_view.create.connect ((navigation_action)=> { + webview.create.connect ((navigation_action)=> { create_tab (navigation_action.get_request ().get_uri ()); return null; }); - tab.web_view.decide_policy.connect ((decision, type) => { + webview.decide_policy.connect ((decision, type) => { switch (type) { case WebKit.PolicyDecisionType.NEW_WINDOW_ACTION: if (decision is WebKit.ResponsePolicyDecision) { @@ -169,17 +167,17 @@ public class CaptiveLogin : Hdy.ApplicationWindow { return true; }); - return tab; + return webview; } public bool get_tls_info (out TlsCertificate certificate, out TlsCertificateFlags errors) { - var web_view = ((TabbedWebView) notebook.current).web_view; + var web_view = (TabbedWebView) tabview.get_selected_page ().child; return web_view.get_tls_info (out certificate, out errors); } public string get_uri () { - var web_view = ((TabbedWebView) notebook.current).web_view; + var web_view = (TabbedWebView) tabview.get_selected_page ().child; return web_view.get_uri (); } @@ -187,7 +185,7 @@ public class CaptiveLogin : Hdy.ApplicationWindow { public void start (string? browser_url) { var default_tab = create_tab (browser_url ?? DUMMY_URL); - default_tab.web_view.load_failed.connect ((event, uri, error) => { + default_tab.load_failed.connect ((event, uri, error) => { // The user has canceled the page loading eg. by clicking on a link. if ((Error) error is WebKit.NetworkError.CANCELLED) { return true; diff --git a/src/TabbedWebView.vala b/src/TabbedWebView.vala index 2db8b014..abe3b19e 100644 --- a/src/TabbedWebView.vala +++ b/src/TabbedWebView.vala @@ -1,5 +1,5 @@ /* -* Copyright (c) 2016-2017 elementary LLC (http://launchpad.net/capnet-assist) +* Copyright 2016-2022 elementary, Inc. (https://elementary.io) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public @@ -18,26 +18,39 @@ * */ -public class TabbedWebView : Granite.Widgets.Tab { - public WebKit.WebView web_view; +public class TabbedWebView : WebKit.WebView { + public bool load_cookies { get; construct; } public CertButton.Security security { get; private set; } - public TabbedWebView (string uri, bool load_cookies) { - web_view = new WebKit.WebView (); + public TabbedWebView (bool load_cookies) { + Object (load_cookies: load_cookies); + } - page = web_view; + construct { + if (load_cookies) { + var cookies_db_path = Path.build_path ( + Path.DIR_SEPARATOR_S, + Environment.get_user_config_dir (), + "epiphany", + "cookies.sqlite" + ); - setup_web_view (load_cookies); + if (!FileUtils.test (cookies_db_path, FileTest.IS_REGULAR)) { + debug ("No cookies store found, not saving the cookies…"); + return; + } - web_view.insecure_content_detected.connect (() => { - security = CertButton.Security.MIXED_CONTENT; - }); + var cookie_manager = get_context ().get_cookie_manager (); - web_view.notify["title"].connect ((view, param_spec) => { - label = web_view.get_title (); + cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); + cookie_manager.set_persistent_storage (cookies_db_path, WebKit.CookiePersistentStorage.SQLITE); + } + + insecure_content_detected.connect (() => { + security = CertButton.Security.MIXED_CONTENT; }); - web_view.load_changed.connect ((view, event) => { + load_changed.connect ((view, event) => { switch (event) { case WebKit.LoadEvent.STARTED: security = CertButton.Security.LOADING; @@ -47,8 +60,6 @@ public class TabbedWebView : Granite.Widgets.Tab { break; } }); - - web_view.load_uri (uri); } private void update_tls_info () { @@ -56,7 +67,7 @@ public class TabbedWebView : Granite.Widgets.Tab { TlsCertificateFlags cert_flags; bool is_secure; - if (!web_view.get_tls_info (out cert, out cert_flags)) { + if (!get_tls_info (out cert, out cert_flags)) { // The page is served over HTTP is_secure = false; } else { @@ -71,23 +82,4 @@ public class TabbedWebView : Granite.Widgets.Tab { security = CertButton.Security.NONE; } } - - private void setup_web_view (bool load_cookies) { - if (load_cookies) { - var cookies_db_path = Path.build_path (Path.DIR_SEPARATOR_S, - Environment.get_user_config_dir (), - "epiphany", - "cookies.sqlite"); - - if (!FileUtils.test (cookies_db_path, FileTest.IS_REGULAR)) { - debug ("No cookies store found, not saving the cookies…"); - return; - } - - var cookie_manager = web_view.get_context ().get_cookie_manager (); - - cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); - cookie_manager.set_persistent_storage (cookies_db_path, WebKit.CookiePersistentStorage.SQLITE); - } - } } From dbf25fefec719a5dfb1ea433d645b145257336d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 7 Sep 2023 16:06:48 -0700 Subject: [PATCH 2/6] Fix tab button placement --- src/CaptiveLogin.vala | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CaptiveLogin.vala b/src/CaptiveLogin.vala index 836248a4..de0ebaf4 100644 --- a/src/CaptiveLogin.vala +++ b/src/CaptiveLogin.vala @@ -73,6 +73,7 @@ public class CaptiveLogin : Hdy.ApplicationWindow { var tabbar = new Hdy.TabBar () { expand_tabs = false, + inverted = true, view = tabview }; From e2d93856195d9a9bcdae7f47ebc2b0290ff33cfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 7 Sep 2023 16:10:02 -0700 Subject: [PATCH 3/6] bind with sync create --- src/CaptiveLogin.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CaptiveLogin.vala b/src/CaptiveLogin.vala index de0ebaf4..0bd4cba5 100644 --- a/src/CaptiveLogin.vala +++ b/src/CaptiveLogin.vala @@ -120,7 +120,7 @@ public class CaptiveLogin : Hdy.ApplicationWindow { show_all (); - webview.bind_property ("title", tabpage, "title"); + webview.bind_property ("title", tabpage, "title", SYNC_CREATE); webview.notify["title"].connect ((view, param_spec) => { if (tabpage == tabview.get_selected_page ()) { From 4d789934a64212e76680b5a13a918e02033ae1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 7 Sep 2023 16:30:40 -0700 Subject: [PATCH 4/6] Fix page security --- src/CaptiveLogin.vala | 14 +++++++------- src/TabbedWebView.vala | 15 +++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/CaptiveLogin.vala b/src/CaptiveLogin.vala index 0bd4cba5..f7243676 100644 --- a/src/CaptiveLogin.vala +++ b/src/CaptiveLogin.vala @@ -91,9 +91,9 @@ public class CaptiveLogin : Hdy.ApplicationWindow { this.destroy.connect (application.quit); tabview.notify["selected-page"].connect (() => { - var captive_view = (TabbedWebView) tabview.get_selected_page ().child; - title_label.label = captive_view.title; - cert_button.security = captive_view.security; + var webview = (TabbedWebView) tabview.get_selected_page ().child; + title_label.label = webview.title; + cert_button.security = webview.security; }); tabview.close_page.connect ((page) => { @@ -112,14 +112,11 @@ public class CaptiveLogin : Hdy.ApplicationWindow { return !privacy_settings.get_boolean ("remember-recent-files") || !privacy_settings.get_boolean ("remember-app-usage"); } + private TabbedWebView create_tab (string uri) { var webview = new TabbedWebView (!is_privacy_mode_enabled ()); - webview.load_uri (uri); - var tabpage = tabview.append (webview); - show_all (); - webview.bind_property ("title", tabpage, "title", SYNC_CREATE); webview.notify["title"].connect ((view, param_spec) => { @@ -168,6 +165,9 @@ public class CaptiveLogin : Hdy.ApplicationWindow { return true; }); + webview.load_uri (uri); + show_all (); + return webview; } diff --git a/src/TabbedWebView.vala b/src/TabbedWebView.vala index abe3b19e..afc2a5ed 100644 --- a/src/TabbedWebView.vala +++ b/src/TabbedWebView.vala @@ -35,15 +35,14 @@ public class TabbedWebView : WebKit.WebView { "cookies.sqlite" ); - if (!FileUtils.test (cookies_db_path, FileTest.IS_REGULAR)) { - debug ("No cookies store found, not saving the cookies…"); - return; - } - - var cookie_manager = get_context ().get_cookie_manager (); + if (FileUtils.test (cookies_db_path, FileTest.IS_REGULAR)) { + var cookie_manager = get_context ().get_cookie_manager (); - cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); - cookie_manager.set_persistent_storage (cookies_db_path, WebKit.CookiePersistentStorage.SQLITE); + cookie_manager.set_accept_policy (WebKit.CookieAcceptPolicy.ALWAYS); + cookie_manager.set_persistent_storage (cookies_db_path, WebKit.CookiePersistentStorage.SQLITE); + } else { + critical ("No cookies store found, not saving the cookies…"); + } } insecure_content_detected.connect (() => { From 5cabbce73c145f01d6ca0d1f833e3c2928891266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Sun, 10 Sep 2023 14:00:13 -0700 Subject: [PATCH 5/6] Apply suggestions from code review Co-authored-by: Leonhard <106322251+leolost2605@users.noreply.github.com> --- src/CaptiveLogin.vala | 2 +- src/TabbedWebView.vala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CaptiveLogin.vala b/src/CaptiveLogin.vala index f7243676..e034f03e 100644 --- a/src/CaptiveLogin.vala +++ b/src/CaptiveLogin.vala @@ -1,5 +1,5 @@ /* -* Copyright 2015-2022 elementary, Inc. (https://elementary.io) +* Copyright 2015-2023 elementary, Inc. (https://elementary.io) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public diff --git a/src/TabbedWebView.vala b/src/TabbedWebView.vala index afc2a5ed..4853b9c9 100644 --- a/src/TabbedWebView.vala +++ b/src/TabbedWebView.vala @@ -1,5 +1,5 @@ /* -* Copyright 2016-2022 elementary, Inc. (https://elementary.io) +* Copyright 2016-2023 elementary, Inc. (https://elementary.io) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public From bf4b1df2e9696e532c0ce46190793752c343b7b7 Mon Sep 17 00:00:00 2001 From: Leonhard <106322251+leolost2605@users.noreply.github.com> Date: Sun, 10 Sep 2023 23:07:48 +0200 Subject: [PATCH 6/6] Update src/CaptiveLogin.vala --- src/CaptiveLogin.vala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CaptiveLogin.vala b/src/CaptiveLogin.vala index e034f03e..ba855163 100644 --- a/src/CaptiveLogin.vala +++ b/src/CaptiveLogin.vala @@ -68,7 +68,8 @@ public class CaptiveLogin : Hdy.ApplicationWindow { header.get_style_context ().add_class ("default-decoration"); tabview = new Hdy.TabView () { - expand = true + hexpand = true, + vexpand = true }; var tabbar = new Hdy.TabBar () {