feat(port): add popup window support types and callbacks
Adds PopupRequest type, OnCreate/OnReadyToShow callbacks to WebViewCallbacks, and CreateRelated factory method to WebViewFactory interface. These enable popup window handling with shared session/cookie state.
- commit
- cc823acbcd11821553efae186b9201bb94bf9213
- author
- bnema · · 2025-12-09 22:57 UTC
- parent
- 25b2387
- signature
- unsigned
1 file · +18 -0
M internal/application/port/webview.go +18 -0
| @@ -52,6 +52,14 @@ type WebViewState struct { | |||
| 52 | 52 | ZoomLevel float64 | |
| 53 | 53 | } | |
| 54 | 54 | ||
| 55 | + | // PopupRequest contains metadata about a popup window request. | |
| 56 | + | type PopupRequest struct { | |
| 57 | + | TargetURI string | |
| 58 | + | FrameName string // e.g., "_blank", custom name, or empty | |
| 59 | + | IsUserGesture bool | |
| 60 | + | ParentViewID WebViewID | |
| 61 | + | } | |
| 62 | + | ||
| 55 | 63 | // WebViewCallbacks defines callback handlers for WebView events. | |
| 56 | 64 | // Implementations should invoke these on the main thread/goroutine. | |
| 57 | 65 | type WebViewCallbacks struct { | |
| @@ -65,6 +73,11 @@ type WebViewCallbacks struct { | |||
| 65 | 73 | OnProgressChanged func(progress float64) | |
| 66 | 74 | // OnClose is called when the WebView requests to close. | |
| 67 | 75 | OnClose func() | |
| 76 | + | // OnCreate is called when a popup window is requested. | |
| 77 | + | // Return a WebView to allow the popup, or nil to block it. | |
| 78 | + | OnCreate func(request PopupRequest) WebView | |
| 79 | + | // OnReadyToShow is called when a popup WebView is ready to display. | |
| 80 | + | OnReadyToShow func() | |
| 68 | 81 | } | |
| 69 | 82 | ||
| 70 | 83 | // WebView defines the port interface for browser view operations. | |
| @@ -175,4 +188,9 @@ type WebViewPool interface { | |||
| 175 | 188 | type WebViewFactory interface { | |
| 176 | 189 | // Create creates a new WebView instance. | |
| 177 | 190 | Create(ctx context.Context) (WebView, error) | |
| 191 | + | ||
| 192 | + | // CreateRelated creates a WebView that shares session/cookies with parent. | |
| 193 | + | // This is required for popup windows to maintain authentication state. | |
| 194 | + | // Popup WebViews bypass the pool since they must be related to a specific parent. | |
| 195 | + | CreateRelated(ctx context.Context, parentID WebViewID) (WebView, error) | |
| 178 | 196 | } | |
| @@ -52,6 +52,14 @@ type WebViewState struct { | |||||
| 52 | ZoomLevel float64 | 52 | ZoomLevel float64 | ||
| 53 | } | 53 | } | ||
| 54 | 54 | ||||
| 55 | + | // PopupRequest contains metadata about a popup window request. | |||
| 56 | + | type PopupRequest struct { | |||
| 57 | + | TargetURI string | |||
| 58 | + | FrameName string // e.g., "_blank", custom name, or empty | |||
| 59 | + | IsUserGesture bool | |||
| 60 | + | ParentViewID WebViewID | |||
| 61 | + | } | |||
| 62 | + | ||||
| 55 | // WebViewCallbacks defines callback handlers for WebView events. | 63 | // WebViewCallbacks defines callback handlers for WebView events. | ||
| 56 | // Implementations should invoke these on the main thread/goroutine. | 64 | // Implementations should invoke these on the main thread/goroutine. | ||
| 57 | type WebViewCallbacks struct { | 65 | type WebViewCallbacks struct { | ||
| @@ -65,6 +73,11 @@ type WebViewCallbacks struct { | |||||
| 65 | OnProgressChanged func(progress float64) | 73 | OnProgressChanged func(progress float64) | ||
| 66 | // OnClose is called when the WebView requests to close. | 74 | // OnClose is called when the WebView requests to close. | ||
| 67 | OnClose func() | 75 | OnClose func() | ||
| 76 | + | // OnCreate is called when a popup window is requested. | |||
| 77 | + | // Return a WebView to allow the popup, or nil to block it. | |||
| 78 | + | OnCreate func(request PopupRequest) WebView | |||
| 79 | + | // OnReadyToShow is called when a popup WebView is ready to display. | |||
| 80 | + | OnReadyToShow func() | |||
| 68 | } | 81 | } | ||
| 69 | 82 | ||||
| 70 | // WebView defines the port interface for browser view operations. | 83 | // WebView defines the port interface for browser view operations. | ||
| @@ -175,4 +188,9 @@ type WebViewPool interface { | |||||
| 175 | type WebViewFactory interface { | 188 | type WebViewFactory interface { | ||
| 176 | // Create creates a new WebView instance. | 189 | // Create creates a new WebView instance. | ||
| 177 | Create(ctx context.Context) (WebView, error) | 190 | Create(ctx context.Context) (WebView, error) | ||
| 191 | + | ||||
| 192 | + | // CreateRelated creates a WebView that shares session/cookies with parent. | |||
| 193 | + | // This is required for popup windows to maintain authentication state. | |||
| 194 | + | // Popup WebViews bypass the pool since they must be related to a specific parent. | |||
| 195 | + | CreateRelated(ctx context.Context, parentID WebViewID) (WebView, error) | |||
| 178 | } | 196 | } | ||