refactor(popup): isolate source navigation hosting
- commit
- cf4e6b23172836c5685766394d1fcbc6defade16
- author
- brice · · 2026-07-27 07:55 UTC
- parent
- 5992583
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
2 files · +33 -17
M internal/ui/coordinator/content/popup_hosting.go +31 -0
| @@ -60,6 +60,37 @@ func (pm *popupManager) openBrowserWindow( | |||
| 60 | 60 | return popupWV | |
| 61 | 61 | } | |
| 62 | 62 | ||
| 63 | + | func (pm *popupManager) navigatePopupSource( | |
| 64 | + | ctx context.Context, | |
| 65 | + | parentID port.WebViewID, | |
| 66 | + | parentWV port.WebView, | |
| 67 | + | req port.PopupRequest, | |
| 68 | + | request dto.NewBrowsingContextRequest, | |
| 69 | + | decision dto.HostDecision, | |
| 70 | + | ) { | |
| 71 | + | log := logging.FromContext(ctx) | |
| 72 | + | popupWV, err := pm.createPopupWebView(ctx, parentID, req.TargetURI, false) | |
| 73 | + | if err != nil { | |
| 74 | + | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |
| 75 | + | return | |
| 76 | + | } | |
| 77 | + | pm.setBrowsingContextDecision(popupWV, decision) | |
| 78 | + | popupWV.Destroy() | |
| 79 | + | if err := parentWV.LoadURI(ctx, req.TargetURI); err != nil { | |
| 80 | + | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |
| 81 | + | } | |
| 82 | + | } | |
| 83 | + | ||
| 84 | + | func (*popupManager) navigateSource(ctx context.Context, parentWV port.WebView, uri string) bool { | |
| 85 | + | if err := parentWV.LoadURI(ctx, uri); err != nil { | |
| 86 | + | logging.FromContext(ctx).Error().Err(err). | |
| 87 | + | Str("uri", logging.TruncateURL(uri, logURLMaxLen)). | |
| 88 | + | Msg("failed to load URI in source floating pane") | |
| 89 | + | return false | |
| 90 | + | } | |
| 91 | + | return true | |
| 92 | + | } | |
| 93 | + | ||
| 63 | 94 | func popupSupportsOpenerBridge(wv port.WebView) bool { | |
| 64 | 95 | _, ok := wv.(port.PopupOpenerCapable) | |
| 65 | 96 | return ok | |
| @@ -60,6 +60,37 @@ func (pm *popupManager) openBrowserWindow( | |||||
| 60 | return popupWV | 60 | return popupWV | ||
| 61 | } | 61 | } | ||
| 62 | 62 | ||||
| 63 | + | func (pm *popupManager) navigatePopupSource( | |||
| 64 | + | ctx context.Context, | |||
| 65 | + | parentID port.WebViewID, | |||
| 66 | + | parentWV port.WebView, | |||
| 67 | + | req port.PopupRequest, | |||
| 68 | + | request dto.NewBrowsingContextRequest, | |||
| 69 | + | decision dto.HostDecision, | |||
| 70 | + | ) { | |||
| 71 | + | log := logging.FromContext(ctx) | |||
| 72 | + | popupWV, err := pm.createPopupWebView(ctx, parentID, req.TargetURI, false) | |||
| 73 | + | if err != nil { | |||
| 74 | + | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |||
| 75 | + | return | |||
| 76 | + | } | |||
| 77 | + | pm.setBrowsingContextDecision(popupWV, decision) | |||
| 78 | + | popupWV.Destroy() | |||
| 79 | + | if err := parentWV.LoadURI(ctx, req.TargetURI); err != nil { | |||
| 80 | + | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |||
| 81 | + | } | |||
| 82 | + | } | |||
| 83 | + | ||||
| 84 | + | func (*popupManager) navigateSource(ctx context.Context, parentWV port.WebView, uri string) bool { | |||
| 85 | + | if err := parentWV.LoadURI(ctx, uri); err != nil { | |||
| 86 | + | logging.FromContext(ctx).Error().Err(err). | |||
| 87 | + | Str("uri", logging.TruncateURL(uri, logURLMaxLen)). | |||
| 88 | + | Msg("failed to load URI in source floating pane") | |||
| 89 | + | return false | |||
| 90 | + | } | |||
| 91 | + | return true | |||
| 92 | + | } | |||
| 93 | + | ||||
| 63 | func popupSupportsOpenerBridge(wv port.WebView) bool { | 94 | func popupSupportsOpenerBridge(wv port.WebView) bool { | ||
| 64 | _, ok := wv.(port.PopupOpenerCapable) | 95 | _, ok := wv.(port.PopupOpenerCapable) | ||
| 65 | return ok | 96 | return ok | ||
M internal/ui/coordinator/content/popup_manager.go +2 -17
| @@ -592,16 +592,7 @@ func (pm *popupManager) handlePopupCreate( | |||
| 592 | 592 | decision.ReuseContextName = "" | |
| 593 | 593 | decision.Reason = "named browsing context unavailable; creating replacement pane" | |
| 594 | 594 | case dto.HostDecisionNavigateSource: | |
| 595 | - | popupWV, err := pm.createPopupWebView(ctx, parentID, req.TargetURI, false) | |
| 596 | - | if err != nil { | |
| 597 | - | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |
| 598 | - | return nil | |
| 599 | - | } | |
| 600 | - | pm.setBrowsingContextDecision(popupWV, decision) | |
| 601 | - | popupWV.Destroy() | |
| 602 | - | if err := parentWV.LoadURI(ctx, req.TargetURI); err != nil { | |
| 603 | - | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |
| 604 | - | } | |
| 595 | + | pm.navigatePopupSource(ctx, parentID, parentWV, req, request, decision) | |
| 605 | 596 | return nil | |
| 606 | 597 | case dto.HostDecisionCreateBrowserWindow: | |
| 607 | 598 | return pm.openBrowserWindow(ctx, hooks, parentPaneID, parentID, req, decision, pm.readyOnCreate(req.Engine)) | |
| @@ -932,13 +923,7 @@ func (pm *popupManager) handleLinkMiddleClick( | |||
| 932 | 923 | Str("reason", decision.Reason). | |
| 933 | 924 | Msg("middle-click browsing context host decision") | |
| 934 | 925 | if decision.Kind == dto.HostDecisionNavigateSource { | |
| 935 | - | if err := parentWV.LoadURI(ctx, uri); err != nil { | |
| 936 | - | log.Error().Err(err). | |
| 937 | - | Str("uri", logging.TruncateURL(uri, logURLMaxLen)). | |
| 938 | - | Msg("failed to load URI in source floating pane") | |
| 939 | - | return false | |
| 940 | - | } | |
| 941 | - | return true | |
| 926 | + | return pm.navigateSource(ctx, parentWV, uri) | |
| 942 | 927 | } | |
| 943 | 928 | if decision.Kind == dto.HostDecisionCreateBrowserWindow { | |
| 944 | 929 | return pm.openMiddleClickBrowserWindow(ctx, hooks, parentPaneID, parentWV, uri, decision) | |
| @@ -592,16 +592,7 @@ func (pm *popupManager) handlePopupCreate( | |||||
| 592 | decision.ReuseContextName = "" | 592 | decision.ReuseContextName = "" | ||
| 593 | decision.Reason = "named browsing context unavailable; creating replacement pane" | 593 | decision.Reason = "named browsing context unavailable; creating replacement pane" | ||
| 594 | case dto.HostDecisionNavigateSource: | 594 | case dto.HostDecisionNavigateSource: | ||
| 595 | - | popupWV, err := pm.createPopupWebView(ctx, parentID, req.TargetURI, false) | 595 | + | pm.navigatePopupSource(ctx, parentID, parentWV, req, request, decision) |
| 596 | - | if err != nil { | |||
| 597 | - | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |||
| 598 | - | return nil | |||
| 599 | - | } | |||
| 600 | - | pm.setBrowsingContextDecision(popupWV, decision) | |||
| 601 | - | popupWV.Destroy() | |||
| 602 | - | if err := parentWV.LoadURI(ctx, req.TargetURI); err != nil { | |||
| 603 | - | logBrowsingContextFailure(*log, request, decision, dto.BrowsingContextFailureHostFailed, err) | |||
| 604 | - | } | |||
| 605 | return nil | 596 | return nil | ||
| 606 | case dto.HostDecisionCreateBrowserWindow: | 597 | case dto.HostDecisionCreateBrowserWindow: | ||
| 607 | return pm.openBrowserWindow(ctx, hooks, parentPaneID, parentID, req, decision, pm.readyOnCreate(req.Engine)) | 598 | return pm.openBrowserWindow(ctx, hooks, parentPaneID, parentID, req, decision, pm.readyOnCreate(req.Engine)) | ||
| @@ -932,13 +923,7 @@ func (pm *popupManager) handleLinkMiddleClick( | |||||
| 932 | Str("reason", decision.Reason). | 923 | Str("reason", decision.Reason). | ||
| 933 | Msg("middle-click browsing context host decision") | 924 | Msg("middle-click browsing context host decision") | ||
| 934 | if decision.Kind == dto.HostDecisionNavigateSource { | 925 | if decision.Kind == dto.HostDecisionNavigateSource { | ||
| 935 | - | if err := parentWV.LoadURI(ctx, uri); err != nil { | 926 | + | return pm.navigateSource(ctx, parentWV, uri) |
| 936 | - | log.Error().Err(err). | |||
| 937 | - | Str("uri", logging.TruncateURL(uri, logURLMaxLen)). | |||
| 938 | - | Msg("failed to load URI in source floating pane") | |||
| 939 | - | return false | |||
| 940 | - | } | |||
| 941 | - | return true | |||
| 942 | } | 927 | } | ||
| 943 | if decision.Kind == dto.HostDecisionCreateBrowserWindow { | 928 | if decision.Kind == dto.HostDecisionCreateBrowserWindow { | ||
| 944 | return pm.openMiddleClickBrowserWindow(ctx, hooks, parentPaneID, parentWV, uri, decision) | 929 | return pm.openMiddleClickBrowserWindow(ctx, hooks, parentPaneID, parentWV, uri, decision) | ||