refactor(webkit): enable FaviconDatabase, fix glib object handling
- Add GetFaviconDatabase() to WebView wrapper - Remove favicon signal registration (now in FaviconService) - Fix coreglib.InternObject() → glib.BaseObject() in NewBareRelatedWebView - Update setupFaviconHandlers to enable favicon collection only - Update TLS certificate struct alignment (formatting)
- commit
- ae31f3ff114f44974991e86a70bab9cddc303c75
- author
- bnema · · 2025-10-18 10:55 UTC
- parent
- ad78060
- signature
- unsigned
3 files · +30 -26
M pkg/webkit/tls_handler.go +2 -2
| @@ -18,8 +18,8 @@ import ( | |||
| 18 | 18 | ||
| 19 | 19 | // TLSCertificateInfo holds information about a TLS certificate for display | |
| 20 | 20 | type TLSCertificateInfo struct { | |
| 21 | - | Subject string | |
| 22 | - | Issuer string | |
| 21 | + | Subject string | |
| 22 | + | Issuer string | |
| 23 | 23 | NotBefore string | |
| 24 | 24 | NotAfter string | |
| 25 | 25 | IsExpired bool | |
| @@ -18,8 +18,8 @@ import ( | |||||
| 18 | 18 | ||||
| 19 | // TLSCertificateInfo holds information about a TLS certificate for display | 19 | // TLSCertificateInfo holds information about a TLS certificate for display | ||
| 20 | type TLSCertificateInfo struct { | 20 | type TLSCertificateInfo struct { | ||
| 21 | - | Subject string | 21 | + | Subject string |
| 22 | - | Issuer string | 22 | + | Issuer string |
| 23 | NotBefore string | 23 | NotBefore string | ||
| 24 | NotAfter string | 24 | NotAfter string | ||
| 25 | IsExpired bool | 25 | IsExpired bool | ||
M pkg/webkit/webview.go +26 -23
| @@ -726,6 +726,29 @@ func (w *WebView) Window() *Window { | |||
| 726 | 726 | return w.window | |
| 727 | 727 | } | |
| 728 | 728 | ||
| 729 | + | // GetFaviconDatabase returns the WebKit FaviconDatabase for this WebView | |
| 730 | + | // Returns nil if the favicon database is not available | |
| 731 | + | func (w *WebView) GetFaviconDatabase() *webkit.FaviconDatabase { | |
| 732 | + | w.mu.RLock() | |
| 733 | + | defer w.mu.RUnlock() | |
| 734 | + | ||
| 735 | + | if w.destroyed || w.view == nil { | |
| 736 | + | return nil | |
| 737 | + | } | |
| 738 | + | ||
| 739 | + | session := w.view.NetworkSession() | |
| 740 | + | if session == nil { | |
| 741 | + | return nil | |
| 742 | + | } | |
| 743 | + | ||
| 744 | + | dataManager := session.WebsiteDataManager() | |
| 745 | + | if dataManager == nil { | |
| 746 | + | return nil | |
| 747 | + | } | |
| 748 | + | ||
| 749 | + | return dataManager.FaviconDatabase() | |
| 750 | + | } | |
| 751 | + | ||
| 729 | 752 | // UpdateContentFilters updates the content filtering rules | |
| 730 | 753 | func (w *WebView) UpdateContentFilters(rules string) error { | |
| 731 | 754 | w.mu.RLock() | |
| @@ -784,7 +807,9 @@ func (w *WebView) RegisterPaneModeHandler(handler func(action string) bool, isAc | |||
| 784 | 807 | w.isPaneModeActive = isActiveChecker | |
| 785 | 808 | } | |
| 786 | 809 | ||
| 787 | - | // setupFaviconHandlers connects to the FaviconDatabase signals | |
| 810 | + | // setupFaviconHandlers enables favicons for this WebView | |
| 811 | + | // Note: The actual favicon-changed handler is registered ONCE at the FaviconService level | |
| 812 | + | // to avoid duplicate handlers when multiple WebViews exist | |
| 788 | 813 | func (w *WebView) setupFaviconHandlers() { | |
| 789 | 814 | // Get the NetworkSession from the WebView | |
| 790 | 815 | session := w.view.NetworkSession() | |
| @@ -806,28 +831,6 @@ func (w *WebView) setupFaviconHandlers() { | |||
| 806 | 831 | log.Printf("[webkit] Enabled favicons for WebView ID %d", w.id) | |
| 807 | 832 | } | |
| 808 | 833 | ||
| 809 | - | // Get the FaviconDatabase | |
| 810 | - | faviconDB := dataManager.FaviconDatabase() | |
| 811 | - | if faviconDB == nil { | |
| 812 | - | log.Printf("[webkit] Warning: No FaviconDatabase available") | |
| 813 | - | return | |
| 814 | - | } | |
| 815 | - | ||
| 816 | - | // Connect to the favicon-changed signal | |
| 817 | - | faviconDB.ConnectFaviconChanged(func(pageURI, faviconURI string) { | |
| 818 | - | log.Printf("[favicon] Favicon changed for %s: %s", pageURI, faviconURI) | |
| 819 | - | ||
| 820 | - | // Call the URI handler if registered | |
| 821 | - | w.mu.RLock() | |
| 822 | - | handler := w.onFaviconURIChanged | |
| 823 | - | w.mu.RUnlock() | |
| 824 | - | ||
| 825 | - | if handler != nil { | |
| 826 | - | handler(pageURI, faviconURI) | |
| 827 | - | } | |
| 828 | - | }) | |
| 829 | - | ||
| 830 | - | log.Printf("[webkit] Connected to FaviconDatabase for WebView ID %d", w.id) | |
| 831 | 834 | } | |
| 832 | 835 | ||
| 833 | 836 | // GtkWebView returns the underlying gotk4 WebView for advanced operations | |
| @@ -726,6 +726,29 @@ func (w *WebView) Window() *Window { | |||||
| 726 | return w.window | 726 | return w.window | ||
| 727 | } | 727 | } | ||
| 728 | 728 | ||||
| 729 | + | // GetFaviconDatabase returns the WebKit FaviconDatabase for this WebView | |||
| 730 | + | // Returns nil if the favicon database is not available | |||
| 731 | + | func (w *WebView) GetFaviconDatabase() *webkit.FaviconDatabase { | |||
| 732 | + | w.mu.RLock() | |||
| 733 | + | defer w.mu.RUnlock() | |||
| 734 | + | ||||
| 735 | + | if w.destroyed || w.view == nil { | |||
| 736 | + | return nil | |||
| 737 | + | } | |||
| 738 | + | ||||
| 739 | + | session := w.view.NetworkSession() | |||
| 740 | + | if session == nil { | |||
| 741 | + | return nil | |||
| 742 | + | } | |||
| 743 | + | ||||
| 744 | + | dataManager := session.WebsiteDataManager() | |||
| 745 | + | if dataManager == nil { | |||
| 746 | + | return nil | |||
| 747 | + | } | |||
| 748 | + | ||||
| 749 | + | return dataManager.FaviconDatabase() | |||
| 750 | + | } | |||
| 751 | + | ||||
| 729 | // UpdateContentFilters updates the content filtering rules | 752 | // UpdateContentFilters updates the content filtering rules | ||
| 730 | func (w *WebView) UpdateContentFilters(rules string) error { | 753 | func (w *WebView) UpdateContentFilters(rules string) error { | ||
| 731 | w.mu.RLock() | 754 | w.mu.RLock() | ||
| @@ -784,7 +807,9 @@ func (w *WebView) RegisterPaneModeHandler(handler func(action string) bool, isAc | |||||
| 784 | w.isPaneModeActive = isActiveChecker | 807 | w.isPaneModeActive = isActiveChecker | ||
| 785 | } | 808 | } | ||
| 786 | 809 | ||||
| 787 | - | // setupFaviconHandlers connects to the FaviconDatabase signals | 810 | + | // setupFaviconHandlers enables favicons for this WebView |
| 811 | + | // Note: The actual favicon-changed handler is registered ONCE at the FaviconService level | |||
| 812 | + | // to avoid duplicate handlers when multiple WebViews exist | |||
| 788 | func (w *WebView) setupFaviconHandlers() { | 813 | func (w *WebView) setupFaviconHandlers() { | ||
| 789 | // Get the NetworkSession from the WebView | 814 | // Get the NetworkSession from the WebView | ||
| 790 | session := w.view.NetworkSession() | 815 | session := w.view.NetworkSession() | ||
| @@ -806,28 +831,6 @@ func (w *WebView) setupFaviconHandlers() { | |||||
| 806 | log.Printf("[webkit] Enabled favicons for WebView ID %d", w.id) | 831 | log.Printf("[webkit] Enabled favicons for WebView ID %d", w.id) | ||
| 807 | } | 832 | } | ||
| 808 | 833 | ||||
| 809 | - | // Get the FaviconDatabase | |||
| 810 | - | faviconDB := dataManager.FaviconDatabase() | |||
| 811 | - | if faviconDB == nil { | |||
| 812 | - | log.Printf("[webkit] Warning: No FaviconDatabase available") | |||
| 813 | - | return | |||
| 814 | - | } | |||
| 815 | - | ||||
| 816 | - | // Connect to the favicon-changed signal | |||
| 817 | - | faviconDB.ConnectFaviconChanged(func(pageURI, faviconURI string) { | |||
| 818 | - | log.Printf("[favicon] Favicon changed for %s: %s", pageURI, faviconURI) | |||
| 819 | - | ||||
| 820 | - | // Call the URI handler if registered | |||
| 821 | - | w.mu.RLock() | |||
| 822 | - | handler := w.onFaviconURIChanged | |||
| 823 | - | w.mu.RUnlock() | |||
| 824 | - | ||||
| 825 | - | if handler != nil { | |||
| 826 | - | handler(pageURI, faviconURI) | |||
| 827 | - | } | |||
| 828 | - | }) | |||
| 829 | - | ||||
| 830 | - | log.Printf("[webkit] Connected to FaviconDatabase for WebView ID %d", w.id) | |||
| 831 | } | 834 | } | ||
| 832 | 835 | ||||
| 833 | // GtkWebView returns the underlying gotk4 WebView for advanced operations | 836 | // GtkWebView returns the underlying gotk4 WebView for advanced operations | ||
M pkg/webkit/webview_related.go +2 -1
| @@ -25,6 +25,7 @@ import ( | |||
| 25 | 25 | ||
| 26 | 26 | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | |
| 27 | 27 | coreglib "github.com/diamondburned/gotk4/pkg/core/glib" | |
| 28 | + | "github.com/diamondburned/gotk4/pkg/glib/v2" | |
| 28 | 29 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | |
| 29 | 30 | ) | |
| 30 | 31 | ||
| @@ -41,7 +42,7 @@ func NewBareRelatedWebView(parentView *webkit.WebView) *webkit.WebView { | |||
| 41 | 42 | } | |
| 42 | 43 | ||
| 43 | 44 | // Get the native C pointer from the gotk4 WebView | |
| 44 | - | parentObj := coreglib.InternObject(parentView) | |
| 45 | + | parentObj := glib.BaseObject(parentView) | |
| 45 | 46 | if parentObj == nil { | |
| 46 | 47 | log.Printf("[webkit] NewBareRelatedWebView: failed to get parent object, creating unrelated WebView") | |
| 47 | 48 | return webkit.NewWebView() | |
| @@ -25,6 +25,7 @@ import ( | |||||
| 25 | 25 | ||||
| 26 | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | 26 | webkit "github.com/diamondburned/gotk4-webkitgtk/pkg/webkit/v6" | ||
| 27 | coreglib "github.com/diamondburned/gotk4/pkg/core/glib" | 27 | coreglib "github.com/diamondburned/gotk4/pkg/core/glib" | ||
| 28 | + | "github.com/diamondburned/gotk4/pkg/glib/v2" | |||
| 28 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | 29 | "github.com/diamondburned/gotk4/pkg/gtk/v4" | ||
| 29 | ) | 30 | ) | ||
| 30 | 31 | ||||
| @@ -41,7 +42,7 @@ func NewBareRelatedWebView(parentView *webkit.WebView) *webkit.WebView { | |||||
| 41 | } | 42 | } | ||
| 42 | 43 | ||||
| 43 | // Get the native C pointer from the gotk4 WebView | 44 | // Get the native C pointer from the gotk4 WebView | ||
| 44 | - | parentObj := coreglib.InternObject(parentView) | 45 | + | parentObj := glib.BaseObject(parentView) |
| 45 | if parentObj == nil { | 46 | if parentObj == nil { | ||
| 46 | log.Printf("[webkit] NewBareRelatedWebView: failed to get parent object, creating unrelated WebView") | 47 | log.Printf("[webkit] NewBareRelatedWebView: failed to get parent object, creating unrelated WebView") | ||
| 47 | return webkit.NewWebView() | 48 | return webkit.NewWebView() | ||