Documentation
¶
Index ¶
- Constants
- Variables
- type ContentInjector
- func (ci *ContentInjector) InjectFindHighlightCSS(ctx context.Context, css string) error
- func (ci *ContentInjector) InjectScripts(ctx context.Context, ucm *webkit.UserContentManager, webviewID WebViewID)
- func (ci *ContentInjector) InjectThemeCSS(ctx context.Context, css string) error
- func (ci *ContentInjector) PrefersDark() bool
- func (ci *ContentInjector) RefreshScripts(ctx context.Context, wv port.WebView) error
- func (ci *ContentInjector) SetAutoCopyConfigGetter(getter func() bool)
- type DownloadHandler
- type DumbSchemeHandler
- type Engine
- func (e *Engine) Close() error
- func (e *Engine) ConfigureDownloads(ctx context.Context, downloadPath string, ...) error
- func (e *Engine) ContentInjector() port.ContentInjector
- func (e *Engine) Factory() port.WebViewFactory
- func (e *Engine) FaviconDatabase() port.FaviconDatabase
- func (e *Engine) FilterApplier() port.FilterApplier
- func (e *Engine) InternalFilterManager() port.FilterManager
- func (e *Engine) InternalSchemePath() string
- func (e *Engine) OnToolkitReady(ctx context.Context) error
- func (e *Engine) Pool() port.WebViewPool
- func (e *Engine) RegisterAccentHandlers(ctx context.Context, handler port.AccentKeyHandler) error
- func (e *Engine) RegisterHandlers(ctx context.Context, deps port.HandlerDependencies) error
- func (e *Engine) SetHandlerContext(ctx context.Context)
- func (e *Engine) SettingsApplier() port.SettingsApplier
- func (e *Engine) UpdateAppearance(_ context.Context, r, g, b, alpha float64) error
- func (e *Engine) UpdateSettings(ctx context.Context, update port.EngineSettingsUpdate) error
- type FaviconDatabase
- type FilterApplier
- type LoadEvent
- type MemoryPressureApplier
- type Message
- type MessageHandler
- type MessageHandlerFunc
- type MessageRouter
- func (r *MessageRouter) RegisterHandler(msgType string, handler MessageHandler) error
- func (r *MessageRouter) RegisterHandlerWithCallbacks(msgType, callback, errorCallback, worldName string, handler MessageHandler) error
- func (r *MessageRouter) SetBaseContext(ctx context.Context)
- func (r *MessageRouter) SetupMessageHandler(ucm *webkit.UserContentManager, _ string) (uint, error)
- type PageHandler
- type PageHandlerFunc
- type PoolConfig
- type PopupRequest
- type SchemeRequest
- type SchemeResponse
- type SettingsManager
- type WebKitContext
- func (c *WebKitContext) CacheDir() string
- func (c *WebKitContext) Close() error
- func (c *WebKitContext) Context() *webkit.WebContext
- func (c *WebKitContext) DataDir() string
- func (c *WebKitContext) FaviconDatabase() *webkit.FaviconDatabase
- func (c *WebKitContext) IsInitialized() bool
- func (c *WebKitContext) NetworkSession() *webkit.NetworkSession
- func (c *WebKitContext) PrefetchDNS(hostname string)
- func (c *WebKitContext) SetDownloadHandler(ctx context.Context, handler *DownloadHandler)
- type WebKitEngineConfig
- type WebView
- func LookupWebView(id WebViewID) *WebView
- func LookupWebViewByUCMPointer(ptr uintptr) *WebView
- func NewWebView(ctx context.Context, wkCtx *WebKitContext, settings *SettingsManager, ...) (*WebView, error)
- func NewWebViewWithRelated(ctx context.Context, parent *WebView, settings *SettingsManager) (*WebView, error)
- func (wv *WebView) AddCloseCallback(fn func())
- func (wv *WebView) AddNavigationCallback(fn func(uri string))
- func (wv *WebView) AttachFrontend(ctx context.Context, injector *ContentInjector, router *MessageRouter) error
- func (wv *WebView) CanGoBack() bool
- func (wv *WebView) CanGoForward() bool
- func (wv *WebView) Close()
- func (wv *WebView) Destroy()
- func (wv *WebView) DestroyWithPolicy(policy string)
- func (wv *WebView) DisconnectSignals()
- func (wv *WebView) EstimatedProgress() float64
- func (wv *WebView) Favicon() port.Texture
- func (wv *WebView) FaviconGdk() *gdk.Texture
- func (wv *WebView) Generation() uint64
- func (wv *WebView) GetFindController() port.FindController
- func (wv *WebView) GetZoomLevel() float64
- func (wv *WebView) GoBack(ctx context.Context) error
- func (wv *WebView) GoBackDirect()
- func (wv *WebView) GoForward(ctx context.Context) error
- func (wv *WebView) GoForwardDirect()
- func (wv *WebView) HasNavigationActivity() bool
- func (wv *WebView) ID() WebViewID
- func (wv *WebView) IsDestroyed() bool
- func (wv *WebView) IsFullscreen() bool
- func (wv *WebView) IsLoading() bool
- func (wv *WebView) IsPlayingAudio() bool
- func (wv *WebView) IsRelated() bool
- func (wv *WebView) LoadHTML(ctx context.Context, content, baseURI string) error
- func (wv *WebView) LoadURI(ctx context.Context, uri string) error
- func (wv *WebView) NativeWidget() uintptr
- func (wv *WebView) OpenDevTools()
- func (wv *WebView) Print() error
- func (wv *WebView) PrintPage()
- func (wv *WebView) ReconnectSignals()
- func (wv *WebView) Reload(ctx context.Context) error
- func (wv *WebView) ReloadBypassCache(ctx context.Context) error
- func (wv *WebView) ResetBackgroundToDefault()
- func (wv *WebView) ResetForPoolReuse()
- func (wv *WebView) RunJavaScript(ctx context.Context, script string)
- func (wv *WebView) RunJavaScriptInWorld(ctx context.Context, script, worldName string)
- func (wv *WebView) SetBackgroundColor(r, g, b, a float64)
- func (wv *WebView) SetCallbacks(callbacks *port.WebViewCallbacks)
- func (wv *WebView) SetOnClose(fn func())
- func (wv *WebView) SetOnReadyToShow(fn func())
- func (wv *WebView) SetZoomLevel(ctx context.Context, level float64) error
- func (wv *WebView) Show()
- func (wv *WebView) ShowDevTools() error
- func (wv *WebView) State() port.WebViewState
- func (wv *WebView) Stop(ctx context.Context) error
- func (wv *WebView) Title() string
- func (wv *WebView) URI() string
- func (wv *WebView) UserContentManager() *webkit.UserContentManager
- func (wv *WebView) Widget() *webkit.WebView
- type WebViewFactory
- func (f *WebViewFactory) Create(ctx context.Context) (*WebView, error)
- func (f *WebViewFactory) CreateRelated(ctx context.Context, parentID port.WebViewID) (*WebView, error)
- func (f *WebViewFactory) Release(ctx context.Context, wv *WebView)
- func (f *WebViewFactory) SetBackgroundColor(r, g, b, a float32)
- func (f *WebViewFactory) SetFilterApplier(applier FilterApplier)
- type WebViewID
- type WebViewPool
- func (p *WebViewPool) Acquire(ctx context.Context) (*WebView, error)
- func (p *WebViewPool) Close(ctx context.Context)
- func (p *WebViewPool) Prewarm(ctx context.Context, count int)
- func (p *WebViewPool) PrewarmAsync(ctx context.Context, count int)
- func (p *WebViewPool) PrewarmFirst(ctx context.Context) error
- func (p *WebViewPool) RefreshScripts(ctx context.Context)
- func (p *WebViewPool) Release(ctx context.Context, wv *WebView)
- func (p *WebViewPool) SetBackgroundColor(r, g, b, a float32)
- func (p *WebViewPool) SetFilterApplier(applier FilterApplier)
- func (p *WebViewPool) Size() int
Constants ¶
const ( // ScriptWorldName is the isolated world used for the injected UI. ScriptWorldName = "dumber" // MessageHandlerName is the name of the script message handler registered with WebKit. MessageHandlerName = "dumber" )
const ( HomePath = "home" ConfigPath = "config" WebRTCPath = "webrtc" ErrorPath = "error" CrashPath = "crash" IndexHTML = "index.html" )
Scheme path constants
Variables ¶
var ErrPoolClosed = errors.New("webview pool is closed")
ErrPoolClosed is returned when operations are attempted on a closed pool.
Functions ¶
This section is empty.
Types ¶
type ContentInjector ¶
type ContentInjector struct {
// contains filtered or unexported fields
}
ContentInjector encapsulates script injection into WebViews. It injects dark mode detection scripts for internal pages (dumb://) and theme CSS variables for WebUI styling. External pages receive dark mode preference via libadwaita's StyleManager. Implements port.ContentInjector interface.
func NewContentInjector ¶
func NewContentInjector(resolver port.ColorSchemeResolver) *ContentInjector
NewContentInjector creates a new injector instance. The resolver is used to dynamically determine dark mode preference.
func (*ContentInjector) InjectFindHighlightCSS ¶
func (ci *ContentInjector) InjectFindHighlightCSS(ctx context.Context, css string) error
InjectFindHighlightCSS stores CSS for find-in-page highlight styling.
func (*ContentInjector) InjectScripts ¶
func (ci *ContentInjector) InjectScripts(ctx context.Context, ucm *webkit.UserContentManager, webviewID WebViewID)
InjectScripts adds scripts to the given content manager. For internal pages (dumb://*):
- Injects dark mode detection (class on <html>, matchMedia patch)
- Injects theme CSS variables for WebUI styling
For external pages:
- Only injects find highlight CSS
- Dark mode is handled natively via libadwaita's StyleManager
func (*ContentInjector) InjectThemeCSS ¶
func (ci *ContentInjector) InjectThemeCSS(ctx context.Context, css string) error
InjectThemeCSS stores CSS variables for injection into internal pages. Implements port.ContentInjector interface. The CSS will be injected when InjectScripts is called on WebView creation.
func (*ContentInjector) PrefersDark ¶
func (ci *ContentInjector) PrefersDark() bool
PrefersDark returns the current dark mode preference from the resolver.
func (*ContentInjector) RefreshScripts ¶ added in v0.28.0
RefreshScripts clears and re-injects user scripts for a single WebView. Implements port.ContentInjector. Returns nil for "not applicable" cases (nil wv, wrong engine type, nil UCM).
func (*ContentInjector) SetAutoCopyConfigGetter ¶ added in v0.24.0
func (ci *ContentInjector) SetAutoCopyConfigGetter(getter func() bool)
SetAutoCopyConfigGetter sets the function to dynamically check if auto-copy is enabled. This is called during script injection to determine whether to inject the selection listener.
type DownloadHandler ¶ added in v0.25.0
type DownloadHandler struct {
// contains filtered or unexported fields
}
DownloadHandler manages WebKit downloads and notifies the UI layer.
func NewDownloadHandler ¶ added in v0.25.0
func NewDownloadHandler( downloadPath string, handler port.DownloadEventHandler, preparer port.DownloadPreparer, ) *DownloadHandler
NewDownloadHandler creates a new download handler. Panics if preparer is nil (fail fast on misconfiguration).
func (*DownloadHandler) HandleDownload ¶ added in v0.25.0
func (h *DownloadHandler) HandleDownload(ctx context.Context, download *webkit.Download)
HandleDownload sets up signal handlers for a new download.
func (*DownloadHandler) SetDownloadPath ¶ added in v0.25.0
func (h *DownloadHandler) SetDownloadPath(path string)
SetDownloadPath updates the download directory.
type DumbSchemeHandler ¶
type DumbSchemeHandler struct {
// contains filtered or unexported fields
}
DumbSchemeHandler handles dumb:// URI scheme requests.
func NewDumbSchemeHandler ¶
func NewDumbSchemeHandler(ctx context.Context) *DumbSchemeHandler
NewDumbSchemeHandler creates a new handler for the dumb:// scheme.
func (*DumbSchemeHandler) HandleRequest ¶
func (h *DumbSchemeHandler) HandleRequest(reqPtr uintptr)
HandleRequest processes a scheme request and sends the response.
func (*DumbSchemeHandler) RegisterPage ¶
func (h *DumbSchemeHandler) RegisterPage(path string, handler PageHandler)
RegisterPage registers a handler for a specific path.
func (*DumbSchemeHandler) RegisterWithContext ¶
func (h *DumbSchemeHandler) RegisterWithContext(wkCtx *WebKitContext)
RegisterWithContext registers the dumb:// scheme with a WebKitContext. The scheme is always registered on the default WebContext to ensure WebViews (which use the default WebContext) can load dumb:// URLs.
func (*DumbSchemeHandler) SetAssets ¶
func (h *DumbSchemeHandler) SetAssets(assets embed.FS)
SetAssets sets the embedded filesystem containing webui assets.
type Engine ¶ added in v0.28.0
type Engine struct {
// contains filtered or unexported fields
}
Engine implements port.Engine for the WebKit browser engine.
func NewEngine ¶ added in v0.28.0
func NewEngine( ctx context.Context, cfg *config.Config, opts port.EngineOptions, wkCfg WebKitEngineConfig, themeManager *theme.Manager, colorResolver port.ColorSchemeResolver, logger zerolog.Logger, handlerRegistrar func(ctx context.Context, router *MessageRouter, deps port.HandlerDependencies) error, accentHandlerRegistrar func(ctx context.Context, router *MessageRouter, handler port.AccentKeyHandler) error, ) (*Engine, error)
NewEngine creates and initializes all WebKit engine components. It absorbs the initialization logic previously found in bootstrap.BuildWebKitStack.
func (*Engine) ConfigureDownloads ¶ added in v0.28.0
func (e *Engine) ConfigureDownloads( ctx context.Context, downloadPath string, eventHandler port.DownloadEventHandler, preparer port.DownloadPreparer, ) error
ConfigureDownloads sets up download handling.
func (*Engine) ContentInjector ¶ added in v0.28.0
func (e *Engine) ContentInjector() port.ContentInjector
ContentInjector returns the ContentInjector implementing port.ContentInjector.
func (*Engine) Factory ¶ added in v0.28.0
func (e *Engine) Factory() port.WebViewFactory
Factory returns the WebViewFactory wrapped as a port.WebViewFactory.
func (*Engine) FaviconDatabase ¶ added in v0.28.0
func (e *Engine) FaviconDatabase() port.FaviconDatabase
FaviconDatabase returns a port.FaviconDatabase adapter for async favicon lookups.
func (*Engine) FilterApplier ¶ added in v0.28.0
func (e *Engine) FilterApplier() port.FilterApplier
FilterApplier returns a port.FilterApplier adapter, or nil if filtering is disabled.
func (*Engine) InternalFilterManager ¶ added in v0.28.0
func (e *Engine) InternalFilterManager() port.FilterManager
InternalFilterManager returns the FilterManager for content filter lifecycle. This is on the concrete *Engine type (not the port.Engine interface) because FilterManager is a webkit-specific concern used only during dependency wiring.
func (*Engine) InternalSchemePath ¶ added in v0.28.0
InternalSchemePath returns the URI scheme used for internal app resources.
func (*Engine) OnToolkitReady ¶ added in v0.28.0
OnToolkitReady refreshes pooled WebViews after toolkit init.
func (*Engine) Pool ¶ added in v0.28.0
func (e *Engine) Pool() port.WebViewPool
Pool returns the WebViewPool wrapped as a port.WebViewPool.
func (*Engine) RegisterAccentHandlers ¶ added in v0.28.0
RegisterAccentHandlers registers accent/dead-key input handlers.
func (*Engine) RegisterHandlers ¶ added in v0.28.0
RegisterHandlers registers all WebUI message bridge handlers.
func (*Engine) SetHandlerContext ¶ added in v0.28.0
SetHandlerContext sets the base context for message handler dispatch.
func (*Engine) SettingsApplier ¶ added in v0.28.0
func (e *Engine) SettingsApplier() port.SettingsApplier
SettingsApplier returns a port.SettingsApplier adapter for the SettingsManager.
func (*Engine) UpdateAppearance ¶ added in v0.28.0
UpdateAppearance updates default background color for pool and factory.
func (*Engine) UpdateSettings ¶ added in v0.28.0
UpdateSettings applies runtime config changes to engine settings.
type FaviconDatabase ¶
type FaviconDatabase = webkit.FaviconDatabase
FaviconDatabase is a type alias for webkit.FaviconDatabase. Re-exported for use by UI layer without direct puregotk-webkit import.
type FilterApplier ¶
type FilterApplier interface {
ApplyTo(ctx context.Context, ucm *webkit.UserContentManager)
}
FilterApplier applies content filters to a UserContentManager. This interface decouples the pool from the filtering package.
type LoadEvent ¶
type LoadEvent int
LoadEvent represents WebKit load events.
const ( LoadStarted LoadEvent = LoadEvent(webkit.LoadStartedValue) LoadRedirected LoadEvent = LoadEvent(webkit.LoadRedirectedValue) LoadCommitted LoadEvent = LoadEvent(webkit.LoadCommittedValue) LoadFinished LoadEvent = LoadEvent(webkit.LoadFinishedValue) )
type MemoryPressureApplier ¶ added in v0.23.0
type MemoryPressureApplier struct{}
MemoryPressureApplier implements port.MemoryPressureApplier for WebKitGTK.
func NewMemoryPressureApplier ¶ added in v0.23.0
func NewMemoryPressureApplier() *MemoryPressureApplier
NewMemoryPressureApplier creates a new MemoryPressureApplier.
func (*MemoryPressureApplier) ApplyNetworkProcessSettings ¶ added in v0.23.0
func (*MemoryPressureApplier) ApplyNetworkProcessSettings(ctx context.Context, cfg *port.MemoryPressureConfig) error
ApplyNetworkProcessSettings applies memory pressure settings to the network process. Must be called BEFORE creating any NetworkSession.
func (*MemoryPressureApplier) ApplyWebProcessSettings ¶ added in v0.23.0
func (*MemoryPressureApplier) ApplyWebProcessSettings(ctx context.Context, cfg *port.MemoryPressureConfig) (any, error)
ApplyWebProcessSettings applies memory pressure settings to web processes. Returns an opaque settings object that should be passed to WebContext creation. Returns nil if no settings are configured.
type Message ¶
type Message struct {
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
WebViewID uint64 `json:"webview_id,omitempty"`
WebViewIDAlt uint64 `json:"webviewId,omitempty"`
}
Message represents a JS -> Go message envelope sent via postMessage.
type MessageHandler ¶
type MessageHandler interface {
Handle(ctx context.Context, webviewID WebViewID, payload json.RawMessage) (any, error)
}
MessageHandler handles a decoded message payload.
type MessageHandlerFunc ¶
type MessageHandlerFunc func(ctx context.Context, webviewID WebViewID, payload json.RawMessage) (any, error)
MessageHandlerFunc adapts a function to the MessageHandler interface.
func (MessageHandlerFunc) Handle ¶
func (f MessageHandlerFunc) Handle(ctx context.Context, webviewID WebViewID, payload json.RawMessage) (any, error)
Handle calls f(ctx, webviewID, payload).
type MessageRouter ¶
type MessageRouter struct {
// contains filtered or unexported fields
}
MessageRouter dispatches script-message events to registered handlers.
func NewMessageRouter ¶
func NewMessageRouter(ctx context.Context) *MessageRouter
NewMessageRouter creates a new message router.
func (*MessageRouter) RegisterHandler ¶
func (r *MessageRouter) RegisterHandler(msgType string, handler MessageHandler) error
RegisterHandler registers a handler for a message type.
func (*MessageRouter) RegisterHandlerWithCallbacks ¶
func (r *MessageRouter) RegisterHandlerWithCallbacks(msgType, callback, errorCallback, worldName string, handler MessageHandler) error
RegisterHandlerWithCallbacks registers a handler and response callbacks. callback is invoked on success, errorCallback (optional) on failure. worldName allows targeting a specific script world (empty for main world).
func (*MessageRouter) SetBaseContext ¶ added in v0.22.0
func (r *MessageRouter) SetBaseContext(ctx context.Context)
SetBaseContext updates the base context used for logging and handler execution.
func (*MessageRouter) SetupMessageHandler ¶
func (r *MessageRouter) SetupMessageHandler(ucm *webkit.UserContentManager, _ string) (uint, error)
SetupMessageHandler wires the router into the given UserContentManager. It registers the script message handler in the MAIN world (not isolated). WebKit's messageHandlers is only available in main world. The isolated world GUI scripts dispatch CustomEvents to main world, which forwards to this handler.
type PageHandler ¶
type PageHandler interface {
Handle(req *SchemeRequest) *SchemeResponse
}
PageHandler generates content for a specific page path.
type PageHandlerFunc ¶
type PageHandlerFunc func(req *SchemeRequest) *SchemeResponse
PageHandlerFunc is an adapter to allow use of ordinary functions as PageHandlers.
func (PageHandlerFunc) Handle ¶
func (f PageHandlerFunc) Handle(req *SchemeRequest) *SchemeResponse
type PoolConfig ¶
type PoolConfig struct {
// MinSize is the minimum number of warm WebViews to maintain.
MinSize int
// MaxSize is the maximum number of WebViews to keep in the pool.
MaxSize int
// PrewarmCount is the number of WebViews to pre-create on startup.
PrewarmCount int
// IdleTimeout is how long idle views stay in the pool before being destroyed.
IdleTimeout time.Duration
// ReusePolicy controls if/when released WebViews are returned to pool.
// Values: off, safe, aggressive.
ReusePolicy string
// TerminatePolicy controls whether Destroy() should terminate web process.
// Values: auto, always, never.
TerminatePolicy string
}
PoolConfig configures the WebView pool behavior.
func DefaultPoolConfig ¶
func DefaultPoolConfig() PoolConfig
DefaultPoolConfig returns sensible defaults for the pool.
type PopupRequest ¶
type PopupRequest struct {
TargetURI string
FrameName string // e.g., "_blank", custom name, or empty
IsUserGesture bool
ParentID WebViewID
}
PopupRequest contains information about a popup window request from the create signal.
type SchemeRequest ¶
type SchemeRequest struct {
URI string
Path string
Method string
Scheme string
// contains filtered or unexported fields
}
SchemeRequest represents a request to a custom URI scheme.
type SchemeResponse ¶
SchemeResponse represents a response to a scheme request.
type SettingsManager ¶
type SettingsManager struct {
// contains filtered or unexported fields
}
SettingsManager creates and manages WebKit Settings instances from config.
func NewSettingsManager ¶
func NewSettingsManager(ctx context.Context, cfg *config.Config) *SettingsManager
NewSettingsManager creates a new SettingsManager with the given config.
func (*SettingsManager) ApplyToWebView ¶
func (sm *SettingsManager) ApplyToWebView(ctx context.Context, wv *webkit.WebView)
ApplyToWebView applies current settings to an existing WebView. This can be used to update a WebView's settings after config hot-reload.
func (*SettingsManager) CreateSettings ¶
func (sm *SettingsManager) CreateSettings(ctx context.Context) *webkit.Settings
CreateSettings creates a new webkit.Settings instance configured from the current config.
func (*SettingsManager) UpdateFromConfig ¶
func (sm *SettingsManager) UpdateFromConfig(ctx context.Context, cfg *config.Config)
UpdateFromConfig updates the manager with a new config (for hot-reload). Note: This doesn't update already-created Settings instances. New WebViews will use the updated config.
type WebKitContext ¶
type WebKitContext struct {
// contains filtered or unexported fields
}
WebKitContext manages the shared WebContext and persistent NetworkSession. IMPORTANT: This MUST be initialized before creating any WebViews.
func NewWebKitContext ¶
func NewWebKitContext(ctx context.Context, dataDir, cacheDir string) (*WebKitContext, error)
NewWebKitContext creates and initializes a WebKitContext with a persistent NetworkSession. The dataDir and cacheDir are used for cookie storage, cache, and other persistent data. This MUST be called before creating any WebViews to ensure they use persistent storage.
func NewWebKitContextWithOptions ¶ added in v0.23.0
func NewWebKitContextWithOptions(ctx context.Context, opts webKitContextOptions) (*WebKitContext, error)
NewWebKitContextWithOptions creates and initializes a WebKitContext with the given options. This allows configuring memory pressure settings for web and network processes.
func (*WebKitContext) CacheDir ¶
func (c *WebKitContext) CacheDir() string
CacheDir returns the cache directory path.
func (*WebKitContext) Close ¶
func (c *WebKitContext) Close() error
Close performs cleanup. Currently a no-op as WebKit handles cleanup internally.
func (*WebKitContext) Context ¶
func (c *WebKitContext) Context() *webkit.WebContext
Context returns the shared WebContext.
func (*WebKitContext) DataDir ¶
func (c *WebKitContext) DataDir() string
DataDir returns the data directory path.
func (*WebKitContext) FaviconDatabase ¶
func (c *WebKitContext) FaviconDatabase() *webkit.FaviconDatabase
FaviconDatabase returns the favicon database for persistent favicon storage.
func (*WebKitContext) IsInitialized ¶
func (c *WebKitContext) IsInitialized() bool
IsInitialized returns true if the context has been successfully initialized.
func (*WebKitContext) NetworkSession ¶
func (c *WebKitContext) NetworkSession() *webkit.NetworkSession
NetworkSession returns the persistent NetworkSession.
func (*WebKitContext) PrefetchDNS ¶
func (c *WebKitContext) PrefetchDNS(hostname string)
PrefetchDNS prefetches DNS for the given hostname to speed up future requests.
func (*WebKitContext) SetDownloadHandler ¶ added in v0.25.0
func (c *WebKitContext) SetDownloadHandler(ctx context.Context, handler *DownloadHandler)
SetDownloadHandler configures download handling for this context. The handler will be notified of all download events from the NetworkSession.
type WebKitEngineConfig ¶ added in v0.28.0
type WebKitEngineConfig struct {
// Skia
SkiaCPUPaintingThreads int
SkiaGPUPaintingThreads int
SkiaEnableCPURendering bool
// WebKit compositor
DisableDMABufRenderer bool
ForceCompositingMode bool
DisableCompositingMode bool
// GTK/GSK
GSKRenderer string
DisableMipmaps bool
PreferGL bool
// Debug
ShowFPS bool
SampleMemory bool
DebugFrames bool
DrawCompositingIndicators bool
// Privacy
ITPEnabled bool
// GStreamer
ForceVSync bool
GLRenderingMode string
GStreamerDebugLevel int
// Runtime
Prefix string
// Memory pressure (all fields from config)
WebProcessMemoryLimitMB int
WebProcessMemoryPollIntervalSec float64
WebProcessMemoryConservativeThreshold float64
WebProcessMemoryStrictThreshold float64
NetworkProcessMemoryLimitMB int
NetworkProcessMemoryPollIntervalSec float64
NetworkProcessMemoryConservativeThreshold float64
NetworkProcessMemoryStrictThreshold float64
}
WebKitEngineConfig holds all WebKit-specific engine configuration. This is the infrastructure-side version (no TOML tags).
func EngineConfigFromConfig ¶ added in v0.28.0
func EngineConfigFromConfig(cfg config.WebKitEngineConfig) WebKitEngineConfig
EngineConfigFromConfig converts config.WebKitEngineConfig to the infra type.
type WebView ¶
type WebView struct {
// Callbacks (set by UI layer)
OnLoadChanged func(LoadEvent)
OnTitleChanged func(string)
OnURIChanged func(string)
OnProgressChanged func(float64)
OnFaviconChanged func(*gdk.Texture) // Called when page favicon changes
OnClose func()
OnCreate func(PopupRequest) *WebView // Return new WebView or nil to block popup
OnReadyToShow func() // Called when popup is ready to display
OnLinkMiddleClick func(uri string) bool // Return true if handled (blocks navigation)
OnEnterFullscreen func() bool // Return true to prevent fullscreen
OnLeaveFullscreen func() bool // Return true to prevent leaving fullscreen
OnAudioStateChanged func(playing bool) // Called when audio playback starts/stops
OnLinkHover func(uri string) // Called when hovering over a link/image/media (empty string when leaving)
OnWebProcessTerminated func(reason webkit.WebProcessTerminationReason, reasonLabel string, uri string)
// PermissionRequest is called when a site requests permission (mic, camera, screen sharing).
// Return true to indicate the request was handled. Call allow()/deny() to respond.
// The permission types are determined from the request object.
// The metadata map carries permission-type-specific context; for website_data_access both
// entity.PermissionMetadataKeyRequestingDomain and entity.PermissionMetadataKeyCurrentDomain are populated.
OnPermissionRequest func(origin string, permTypes []string, metadata map[string]string, allow, deny func()) bool
// contains filtered or unexported fields
}
WebView wraps webkit.WebView with Go-level state tracking and callbacks.
func LookupWebView ¶
LookupWebView returns a WebView by ID from the global registry.
func LookupWebViewByUCMPointer ¶ added in v0.23.0
LookupWebViewByUCMPointer returns a WebView by its UserContentManager pointer.
func NewWebView ¶
func NewWebView(ctx context.Context, wkCtx *WebKitContext, settings *SettingsManager, bgColor *gdk.RGBA) (*WebView, error)
NewWebView creates a new WebView with the given context and settings. Uses the persistent NetworkSession from wkCtx for cookie/data persistence. bgColor is optional - if provided, sets background immediately to prevent white flash.
func NewWebViewWithRelated ¶
func NewWebViewWithRelated(ctx context.Context, parent *WebView, settings *SettingsManager) (*WebView, error)
NewWebViewWithRelated creates a WebView that shares session/cookies with parent. This is required for popup windows to maintain authentication state.
func (*WebView) AddCloseCallback ¶ added in v0.28.0
func (wv *WebView) AddCloseCallback(fn func())
AddCloseCallback implements port.OAuthCallbackCapable. It composes fn with any existing OnClose handler so multiple callers can register close callbacks without overwriting one another.
func (*WebView) AddNavigationCallback ¶ added in v0.28.0
AddNavigationCallback implements port.OAuthCallbackCapable. fn is invoked when the URI changes (OnURIChanged) and when a page load is committed (OnLoadChanged with LoadCommitted), covering both redirect-based and postMessage OAuth flows.
func (*WebView) AttachFrontend ¶
func (wv *WebView) AttachFrontend(ctx context.Context, injector *ContentInjector, router *MessageRouter) error
AttachFrontend injects scripts/styles and wires the message router once per WebView.
func (*WebView) CanGoForward ¶
CanGoForward returns true if forward navigation is possible.
func (*WebView) Close ¶
func (wv *WebView) Close()
Close triggers the close callback as if window.close() was called. This is used for programmatic popup closure (e.g., OAuth auto-close).
func (*WebView) Destroy ¶
func (wv *WebView) Destroy()
Destroy cleans up the WebView resources and terminates the web process. This must be called when a WebView is no longer needed to free GPU resources, VA-API decoder contexts, and DMA-BUF buffers held by the web process.
func (*WebView) DestroyWithPolicy ¶ added in v0.27.0
DestroyWithPolicy cleans up the WebView resources with explicit process policy. Valid policies: auto, always, never.
func (*WebView) DisconnectSignals ¶
func (wv *WebView) DisconnectSignals()
DisconnectSignals disconnects all GLib signal handlers from the WebView. This must be called before releasing the WebView to the pool or destroying it to prevent callbacks from firing on freed/pooled WebViews.
func (*WebView) EstimatedProgress ¶
EstimatedProgress returns the estimated load progress (0.0 to 1.0).
func (*WebView) Favicon ¶
Favicon returns the current page favicon as a Texture. Returns nil if no favicon is available.
func (*WebView) FaviconGdk ¶ added in v0.28.0
FaviconGdk returns the current page favicon as a *gdk.Texture. Used by internal WebKit code that needs the concrete type.
func (*WebView) Generation ¶ added in v0.28.0
Generation returns the current reuse generation of this WebView. Used by callback holders to detect stale closures after pool reuse.
func (*WebView) GetFindController ¶
func (wv *WebView) GetFindController() port.FindController
GetFindController returns the WebKit FindController wrapped in the port interface. The adapter is cached to prevent the Go wrapper from being garbage collected.
func (*WebView) GetZoomLevel ¶
GetZoomLevel returns the current zoom level.
func (*WebView) GoBackDirect ¶ added in v0.27.0
func (wv *WebView) GoBackDirect()
GoBackDirect calls WebKit's go_back directly without any wrappers. This is intended for use from gesture handlers where preserving user gesture context is critical for SPA popstate handling. Matches Epiphany: webkit_web_view_go_back(web_view) directly in gesture callback.
func (*WebView) GoForwardDirect ¶ added in v0.27.0
func (wv *WebView) GoForwardDirect()
GoForwardDirect calls WebKit's go_forward directly without any wrappers. This is intended for use from gesture handlers where preserving user gesture context is critical for SPA popstate handling.
func (*WebView) HasNavigationActivity ¶ added in v0.27.0
HasNavigationActivity reports whether this WebView has been used for content navigation.
func (*WebView) IsDestroyed ¶
IsDestroyed returns true if the WebView has been destroyed.
func (*WebView) IsFullscreen ¶ added in v0.21.0
IsFullscreen returns true if the WebView is currently in fullscreen mode.
func (*WebView) IsPlayingAudio ¶ added in v0.21.0
IsPlayingAudio returns true if the WebView is currently playing audio.
func (*WebView) IsRelated ¶ added in v0.27.0
IsRelated returns true when this WebView shares process/session with a parent popup.
func (*WebView) NativeWidget ¶ added in v0.28.0
NativeWidget returns the underlying GTK widget pointer for UI embedding. Implements port.NativeWidgetProvider.
func (*WebView) OpenDevTools ¶ added in v0.28.0
func (wv *WebView) OpenDevTools()
OpenDevTools implements port.DevToolsOpener.
func (*WebView) PrintPage ¶ added in v0.28.0
func (wv *WebView) PrintPage()
PrintPage implements port.Printer.
func (*WebView) ReconnectSignals ¶ added in v0.28.0
func (wv *WebView) ReconnectSignals()
ReconnectSignals re-establishes GLib signal handlers after pool reuse. Must be called after acquiring a WebView from the pool and before setting up callbacks.
func (*WebView) ReloadBypassCache ¶
ReloadBypassCache reloads the current page, bypassing the cache.
func (*WebView) ResetBackgroundToDefault ¶ added in v0.26.0
func (wv *WebView) ResetBackgroundToDefault()
ResetBackgroundToDefault sets WebView background to white (browser default). Used for external pages to prevent dark background from bleeding through.
func (*WebView) ResetForPoolReuse ¶ added in v0.27.0
func (wv *WebView) ResetForPoolReuse()
ResetForPoolReuse sanitizes callbacks/state so the WebView can be safely reused.
func (*WebView) RunJavaScript ¶
RunJavaScript executes script in the main world (port.WebView interface). This is fire-and-forget: it does not block and errors are logged asynchronously.
func (*WebView) RunJavaScriptInWorld ¶ added in v0.28.0
RunJavaScriptInWorld executes script in the specified world (empty for main world). This is fire-and-forget: it does not block and errors are logged asynchronously. Safe to call from any context including GTK signal handlers.
func (*WebView) SetBackgroundColor ¶ added in v0.20.1
SetBackgroundColor sets the WebView background color (port.WebView interface). This color is shown before content is painted, eliminating white flash. Values are in range 0.0-1.0 for red, green, blue, alpha.
func (*WebView) SetCallbacks ¶
func (wv *WebView) SetCallbacks(callbacks *port.WebViewCallbacks)
SetCallbacks registers callback handlers for WebView events. Pass nil to clear all callbacks.
func (*WebView) SetOnClose ¶ added in v0.28.0
func (wv *WebView) SetOnClose(fn func())
SetOnClose composes fn with any existing OnClose handler so multiple callers can each register a close callback without overwriting one another. It implements port.PopupCapable.
func (*WebView) SetOnReadyToShow ¶ added in v0.28.0
func (wv *WebView) SetOnReadyToShow(fn func())
SetOnReadyToShow sets the callback invoked when the popup WebView is ready to display. It implements port.PopupCapable.
func (*WebView) SetZoomLevel ¶
SetZoomLevel sets the zoom level (1.0 = 100%).
func (*WebView) Show ¶ added in v0.26.0
func (wv *WebView) Show()
Show makes the WebView widget visible. This should be called after the WebView is ready to be displayed.
func (*WebView) ShowDevTools ¶
ShowDevTools opens the WebKit inspector/developer tools.
func (*WebView) State ¶
func (wv *WebView) State() port.WebViewState
State returns the current WebView state as a snapshot.
func (*WebView) UserContentManager ¶
func (wv *WebView) UserContentManager() *webkit.UserContentManager
UserContentManager returns the content manager associated with this WebView.
type WebViewFactory ¶
type WebViewFactory struct {
// contains filtered or unexported fields
}
WebViewFactory creates WebView instances for the application. It supports creating regular WebViews (optionally via pool) and related WebViews that share session/cookies with a parent (for popups).
func NewWebViewFactory ¶
func NewWebViewFactory( wkCtx *WebKitContext, settings *SettingsManager, pool *WebViewPool, injector *ContentInjector, router *MessageRouter, ) *WebViewFactory
NewWebViewFactory creates a new WebViewFactory. The pool parameter is optional; if nil, WebViews are created directly.
func (*WebViewFactory) Create ¶
func (f *WebViewFactory) Create(ctx context.Context) (*WebView, error)
Create creates a new WebView instance. If a pool is configured, it will try to acquire from the pool first.
func (*WebViewFactory) CreateRelated ¶
func (f *WebViewFactory) CreateRelated(ctx context.Context, parentID port.WebViewID) (*WebView, error)
CreateRelated creates a WebView that shares session/cookies with the parent. This is required for popup windows to maintain authentication state (OAuth). Related WebViews bypass the pool since they must be linked to a specific parent.
func (*WebViewFactory) Release ¶
func (f *WebViewFactory) Release(ctx context.Context, wv *WebView)
Release returns a WebView to the pool if available, otherwise destroys it. Related WebViews (popups) should be destroyed directly, not released to pool.
func (*WebViewFactory) SetBackgroundColor ¶ added in v0.20.1
func (f *WebViewFactory) SetBackgroundColor(r, g, b, a float32)
SetBackgroundColor sets the background color for newly created WebViews. This color is shown before content is painted, eliminating white flash.
func (*WebViewFactory) SetFilterApplier ¶
func (f *WebViewFactory) SetFilterApplier(applier FilterApplier)
SetFilterApplier sets the content filter applier. Filters will be applied to all newly created WebViews.
type WebViewID ¶
WebViewID is an alias to port.WebViewID for clean architecture compliance. Infrastructure layer uses the type defined in the application port.
type WebViewPool ¶
type WebViewPool struct {
// contains filtered or unexported fields
}
WebViewPool manages a pool of pre-created WebViews for fast tab creation.
func NewWebViewPool ¶
func NewWebViewPool( ctx context.Context, wkCtx *WebKitContext, settings *SettingsManager, cfg PoolConfig, injector *ContentInjector, router *MessageRouter, ) *WebViewPool
NewWebViewPool creates a new WebView pool.
func (*WebViewPool) Acquire ¶
func (p *WebViewPool) Acquire(ctx context.Context) (*WebView, error)
Acquire gets a WebView from the pool or creates a new one.
func (*WebViewPool) Close ¶
func (p *WebViewPool) Close(ctx context.Context)
Close shuts down the pool and destroys all pooled WebViews.
func (*WebViewPool) Prewarm ¶
func (p *WebViewPool) Prewarm(ctx context.Context, count int)
Prewarm creates WebViews synchronously to populate the pool. Must be called from the GTK main thread (after GTK application is initialized).
func (*WebViewPool) PrewarmAsync ¶ added in v0.22.0
func (p *WebViewPool) PrewarmAsync(ctx context.Context, count int)
PrewarmAsync schedules WebView creation on the GTK idle loop. This avoids blocking startup (especially cold-start navigation) while still warming up WebViews for subsequent tab creation.
func (*WebViewPool) PrewarmFirst ¶ added in v0.22.0
func (p *WebViewPool) PrewarmFirst(ctx context.Context) error
PrewarmFirst creates exactly one WebView synchronously. Call this during startup (before GTK activate) to ensure first Acquire() is instant. This is the most impactful optimization for cold start since WebView creation is the heaviest operation (spawns WebKit web process). Returns error if WebView creation fails; caller should log and continue.
func (*WebViewPool) RefreshScripts ¶ added in v0.23.0
func (p *WebViewPool) RefreshScripts(ctx context.Context)
RefreshScripts clears and re-injects scripts to all pooled WebViews. This is needed after adw.Init() to update dark mode preference that was injected with the wrong value during early prewarming.
func (*WebViewPool) Release ¶
func (p *WebViewPool) Release(ctx context.Context, wv *WebView)
Release returns a WebView to the pool when configured and safe. Default behavior remains conservative (`reuse_policy=off`) and destroys on release.
func (*WebViewPool) SetBackgroundColor ¶ added in v0.20.1
func (p *WebViewPool) SetBackgroundColor(r, g, b, a float32)
SetBackgroundColor sets the background color for newly created WebViews. This color is shown before content is painted, eliminating white flash.
func (*WebViewPool) SetFilterApplier ¶
func (p *WebViewPool) SetFilterApplier(applier FilterApplier)
SetFilterApplier sets the content filter applier. Filters will be applied to all newly created WebViews.
func (*WebViewPool) Size ¶
func (p *WebViewPool) Size() int
Size returns the current number of WebViews in the pool.