chore: fix lint issues
- commit
- 56c300d6d10f778bdaceda9b5e9c74251dd93aff
- author
- brice · · 2026-04-21 17:18 UTC
- parent
- 266e0b8
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +71 -35
M internal/infrastructure/cef/scheme_handler.go +56 -33
| @@ -164,46 +164,69 @@ func (h *dumbSchemeHandler) handleAPI(browser purecef.Browser, method, path stri | |||
| 164 | 164 | if strings.EqualFold(method, http.MethodOptions) { | |
| 165 | 165 | return h.newAPIRawResourceHandler(http.StatusNoContent, "text/plain; charset=utf-8", nil) | |
| 166 | 166 | } | |
| 167 | - | ||
| 168 | - | switch { | |
| 169 | - | case path == "/api/message" && strings.EqualFold(method, "POST"): | |
| 170 | - | body := readBodyFromHeader(request) | |
| 171 | - | if body == nil { | |
| 172 | - | return h.newAPIJSONResourceHandler(http.StatusBadRequest, map[string]string{"error": "empty body"}) | |
| 167 | + | if isAPIGetMethod(method) { | |
| 168 | + | if handler, ok := h.handleAPIGet(path, request); ok { | |
| 169 | + | return handler | |
| 173 | 170 | } | |
| 174 | - | resp, err := h.messageRouter.HandleMessage(h.ctx, 0, body) | |
| 175 | - | if err != nil { | |
| 176 | - | return h.newAPIJSONResourceHandler(http.StatusInternalServerError, map[string]string{"error": err.Error()}) | |
| 171 | + | } | |
| 172 | + | if isAPIPostMethod(method) { | |
| 173 | + | if handler, ok := h.handleAPIPost(browser, path, request); ok { | |
| 174 | + | return handler | |
| 177 | 175 | } | |
| 178 | - | return h.newAPIRawResourceHandler(http.StatusOK, "application/json", resp) | |
| 179 | - | ||
| 180 | - | case path == "/api/config" && (method == "" || strings.EqualFold(method, "GET")): | |
| 181 | - | return h.handleConfigAPI(h.currentConfigPayload) | |
| 182 | - | ||
| 183 | - | case path == "/api/config/default" && (method == "" || strings.EqualFold(method, "GET")): | |
| 184 | - | return h.handleConfigAPI(h.defaultConfigPayload) | |
| 185 | - | ||
| 186 | - | case path == "/api/transcode" && (method == "" || strings.EqualFold(method, "GET")): | |
| 187 | - | return h.handleTranscodeAPI(request) | |
| 188 | - | ||
| 189 | - | case path == "/api/clipboard-set" && strings.EqualFold(method, "POST"): | |
| 190 | - | return h.handleClipboardSet(request, browser) | |
| 191 | - | ||
| 192 | - | case path == "/api/focus-sync" && strings.EqualFold(method, "POST"): | |
| 193 | - | return h.handleFocusSync(request, browser) | |
| 194 | - | ||
| 195 | - | case path == "/api/popup-open" && strings.EqualFold(method, "POST"): | |
| 196 | - | return h.handlePopupOpen(request, browser) | |
| 176 | + | } | |
| 177 | + | return h.newAPIJSONResourceHandler(http.StatusNotFound, map[string]string{"error": "not found"}) | |
| 178 | + | } | |
| 197 | 179 | ||
| 198 | - | case path == "/api/popup-navigate" && strings.EqualFold(method, "POST"): | |
| 199 | - | return h.handlePopupNavigate(request, browser) | |
| 180 | + | func isAPIGetMethod(method string) bool { | |
| 181 | + | return method == "" || strings.EqualFold(method, http.MethodGet) | |
| 182 | + | } | |
| 200 | 183 | ||
| 201 | - | case path == "/api/popup-close" && strings.EqualFold(method, "POST"): | |
| 202 | - | return h.handlePopupClose(request, browser) | |
| 184 | + | func isAPIPostMethod(method string) bool { | |
| 185 | + | return strings.EqualFold(method, http.MethodPost) | |
| 186 | + | } | |
| 203 | 187 | ||
| 188 | + | func (h *dumbSchemeHandler) handleAPIGet(path string, request purecef.Request) (purecef.ResourceHandler, bool) { | |
| 189 | + | switch path { | |
| 190 | + | case "/api/config": | |
| 191 | + | return h.handleConfigAPI(h.currentConfigPayload), true | |
| 192 | + | case "/api/config/default": | |
| 193 | + | return h.handleConfigAPI(h.defaultConfigPayload), true | |
| 194 | + | case "/api/transcode": | |
| 195 | + | return h.handleTranscodeAPI(request), true | |
| 196 | + | default: | |
| 197 | + | return nil, false | |
| 198 | + | } | |
| 199 | + | } | |
| 200 | + | ||
| 201 | + | func (h *dumbSchemeHandler) handleAPIPost(browser purecef.Browser, path string, request purecef.Request) (purecef.ResourceHandler, bool) { | |
| 202 | + | switch path { | |
| 203 | + | case "/api/message": | |
| 204 | + | return h.handleMessageAPI(request), true | |
| 205 | + | case "/api/clipboard-set": | |
| 206 | + | return h.handleClipboardSet(request, browser), true | |
| 207 | + | case "/api/focus-sync": | |
| 208 | + | return h.handleFocusSync(request, browser), true | |
| 209 | + | case "/api/popup-open": | |
| 210 | + | return h.handlePopupOpen(request, browser), true | |
| 211 | + | case "/api/popup-navigate": | |
| 212 | + | return h.handlePopupNavigate(request, browser), true | |
| 213 | + | case "/api/popup-close": | |
| 214 | + | return h.handlePopupClose(request, browser), true | |
| 204 | 215 | default: | |
| 205 | - | return h.newAPIJSONResourceHandler(http.StatusNotFound, map[string]string{"error": "not found"}) | |
| 216 | + | return nil, false | |
| 217 | + | } | |
| 218 | + | } | |
| 219 | + | ||
| 220 | + | func (h *dumbSchemeHandler) handleMessageAPI(request purecef.Request) purecef.ResourceHandler { | |
| 221 | + | body := readBodyFromHeader(request) | |
| 222 | + | if body == nil { | |
| 223 | + | return h.newAPIJSONResourceHandler(http.StatusBadRequest, map[string]string{"error": "empty body"}) | |
| 224 | + | } | |
| 225 | + | resp, err := h.messageRouter.HandleMessage(h.ctx, 0, body) | |
| 226 | + | if err != nil { | |
| 227 | + | return h.newAPIJSONResourceHandler(http.StatusInternalServerError, map[string]string{"error": err.Error()}) | |
| 206 | 228 | } | |
| 229 | + | return h.newAPIRawResourceHandler(http.StatusOK, "application/json", resp) | |
| 207 | 230 | } | |
| 208 | 231 | ||
| 209 | 232 | func (h *dumbSchemeHandler) handleTranscodeAPI(request purecef.Request) purecef.ResourceHandler { | |
| @@ -164,46 +164,69 @@ func (h *dumbSchemeHandler) handleAPI(browser purecef.Browser, method, path stri | |||||
| 164 | if strings.EqualFold(method, http.MethodOptions) { | 164 | if strings.EqualFold(method, http.MethodOptions) { | ||
| 165 | return h.newAPIRawResourceHandler(http.StatusNoContent, "text/plain; charset=utf-8", nil) | 165 | return h.newAPIRawResourceHandler(http.StatusNoContent, "text/plain; charset=utf-8", nil) | ||
| 166 | } | 166 | } | ||
| 167 | - | 167 | + | if isAPIGetMethod(method) { | |
| 168 | - | switch { | 168 | + | if handler, ok := h.handleAPIGet(path, request); ok { |
| 169 | - | case path == "/api/message" && strings.EqualFold(method, "POST"): | 169 | + | return handler |
| 170 | - | body := readBodyFromHeader(request) | |||
| 171 | - | if body == nil { | |||
| 172 | - | return h.newAPIJSONResourceHandler(http.StatusBadRequest, map[string]string{"error": "empty body"}) | |||
| 173 | } | 170 | } | ||
| 174 | - | resp, err := h.messageRouter.HandleMessage(h.ctx, 0, body) | 171 | + | } |
| 175 | - | if err != nil { | 172 | + | if isAPIPostMethod(method) { |
| 176 | - | return h.newAPIJSONResourceHandler(http.StatusInternalServerError, map[string]string{"error": err.Error()}) | 173 | + | if handler, ok := h.handleAPIPost(browser, path, request); ok { |
| 174 | + | return handler | |||
| 177 | } | 175 | } | ||
| 178 | - | return h.newAPIRawResourceHandler(http.StatusOK, "application/json", resp) | 176 | + | } |
| 179 | - | 177 | + | return h.newAPIJSONResourceHandler(http.StatusNotFound, map[string]string{"error": "not found"}) | |
| 180 | - | case path == "/api/config" && (method == "" || strings.EqualFold(method, "GET")): | 178 | + | } |
| 181 | - | return h.handleConfigAPI(h.currentConfigPayload) | |||
| 182 | - | ||||
| 183 | - | case path == "/api/config/default" && (method == "" || strings.EqualFold(method, "GET")): | |||
| 184 | - | return h.handleConfigAPI(h.defaultConfigPayload) | |||
| 185 | - | ||||
| 186 | - | case path == "/api/transcode" && (method == "" || strings.EqualFold(method, "GET")): | |||
| 187 | - | return h.handleTranscodeAPI(request) | |||
| 188 | - | ||||
| 189 | - | case path == "/api/clipboard-set" && strings.EqualFold(method, "POST"): | |||
| 190 | - | return h.handleClipboardSet(request, browser) | |||
| 191 | - | ||||
| 192 | - | case path == "/api/focus-sync" && strings.EqualFold(method, "POST"): | |||
| 193 | - | return h.handleFocusSync(request, browser) | |||
| 194 | - | ||||
| 195 | - | case path == "/api/popup-open" && strings.EqualFold(method, "POST"): | |||
| 196 | - | return h.handlePopupOpen(request, browser) | |||
| 197 | 179 | ||||
| 198 | - | case path == "/api/popup-navigate" && strings.EqualFold(method, "POST"): | 180 | + | func isAPIGetMethod(method string) bool { |
| 199 | - | return h.handlePopupNavigate(request, browser) | 181 | + | return method == "" || strings.EqualFold(method, http.MethodGet) |
| 182 | + | } | |||
| 200 | 183 | ||||
| 201 | - | case path == "/api/popup-close" && strings.EqualFold(method, "POST"): | 184 | + | func isAPIPostMethod(method string) bool { |
| 202 | - | return h.handlePopupClose(request, browser) | 185 | + | return strings.EqualFold(method, http.MethodPost) |
| 186 | + | } | |||
| 203 | 187 | ||||
| 188 | + | func (h *dumbSchemeHandler) handleAPIGet(path string, request purecef.Request) (purecef.ResourceHandler, bool) { | |||
| 189 | + | switch path { | |||
| 190 | + | case "/api/config": | |||
| 191 | + | return h.handleConfigAPI(h.currentConfigPayload), true | |||
| 192 | + | case "/api/config/default": | |||
| 193 | + | return h.handleConfigAPI(h.defaultConfigPayload), true | |||
| 194 | + | case "/api/transcode": | |||
| 195 | + | return h.handleTranscodeAPI(request), true | |||
| 196 | + | default: | |||
| 197 | + | return nil, false | |||
| 198 | + | } | |||
| 199 | + | } | |||
| 200 | + | ||||
| 201 | + | func (h *dumbSchemeHandler) handleAPIPost(browser purecef.Browser, path string, request purecef.Request) (purecef.ResourceHandler, bool) { | |||
| 202 | + | switch path { | |||
| 203 | + | case "/api/message": | |||
| 204 | + | return h.handleMessageAPI(request), true | |||
| 205 | + | case "/api/clipboard-set": | |||
| 206 | + | return h.handleClipboardSet(request, browser), true | |||
| 207 | + | case "/api/focus-sync": | |||
| 208 | + | return h.handleFocusSync(request, browser), true | |||
| 209 | + | case "/api/popup-open": | |||
| 210 | + | return h.handlePopupOpen(request, browser), true | |||
| 211 | + | case "/api/popup-navigate": | |||
| 212 | + | return h.handlePopupNavigate(request, browser), true | |||
| 213 | + | case "/api/popup-close": | |||
| 214 | + | return h.handlePopupClose(request, browser), true | |||
| 204 | default: | 215 | default: | ||
| 205 | - | return h.newAPIJSONResourceHandler(http.StatusNotFound, map[string]string{"error": "not found"}) | 216 | + | return nil, false |
| 217 | + | } | |||
| 218 | + | } | |||
| 219 | + | ||||
| 220 | + | func (h *dumbSchemeHandler) handleMessageAPI(request purecef.Request) purecef.ResourceHandler { | |||
| 221 | + | body := readBodyFromHeader(request) | |||
| 222 | + | if body == nil { | |||
| 223 | + | return h.newAPIJSONResourceHandler(http.StatusBadRequest, map[string]string{"error": "empty body"}) | |||
| 224 | + | } | |||
| 225 | + | resp, err := h.messageRouter.HandleMessage(h.ctx, 0, body) | |||
| 226 | + | if err != nil { | |||
| 227 | + | return h.newAPIJSONResourceHandler(http.StatusInternalServerError, map[string]string{"error": err.Error()}) | |||
| 206 | } | 228 | } | ||
| 229 | + | return h.newAPIRawResourceHandler(http.StatusOK, "application/json", resp) | |||
| 207 | } | 230 | } | ||
| 208 | 231 | ||||
| 209 | func (h *dumbSchemeHandler) handleTranscodeAPI(request purecef.Request) purecef.ResourceHandler { | 232 | func (h *dumbSchemeHandler) handleTranscodeAPI(request purecef.Request) purecef.ResourceHandler { | ||
M internal/infrastructure/cef/webview_popup_proxy_test.go +1 -1
| @@ -30,7 +30,7 @@ func TestHandleSyntheticPopupOpen_ReplaysQueuedNavigation(t *testing.T) { | |||
| 30 | 30 | id: port.WebViewID(17), | |
| 31 | 31 | callbacks: &port.WebViewCallbacks{ | |
| 32 | 32 | OnCreate: func(req port.PopupRequest) port.WebView { | |
| 33 | - | require.Equal(t, "", req.TargetURI) | |
| 33 | + | require.Empty(t, req.TargetURI) | |
| 34 | 34 | require.Equal(t, "_blank", req.FrameName) | |
| 35 | 35 | require.True(t, req.IsUserGesture) | |
| 36 | 36 | require.True(t, req.NoJavaScriptAccess) | |
| @@ -30,7 +30,7 @@ func TestHandleSyntheticPopupOpen_ReplaysQueuedNavigation(t *testing.T) { | |||||
| 30 | id: port.WebViewID(17), | 30 | id: port.WebViewID(17), | ||
| 31 | callbacks: &port.WebViewCallbacks{ | 31 | callbacks: &port.WebViewCallbacks{ | ||
| 32 | OnCreate: func(req port.PopupRequest) port.WebView { | 32 | OnCreate: func(req port.PopupRequest) port.WebView { | ||
| 33 | - | require.Equal(t, "", req.TargetURI) | 33 | + | require.Empty(t, req.TargetURI) |
| 34 | require.Equal(t, "_blank", req.FrameName) | 34 | require.Equal(t, "_blank", req.FrameName) | ||
| 35 | require.True(t, req.IsUserGesture) | 35 | require.True(t, req.IsUserGesture) | ||
| 36 | require.True(t, req.NoJavaScriptAccess) | 36 | require.True(t, req.NoJavaScriptAccess) | ||
M internal/ui/coordinator/content/popup.go +14 -1
| @@ -471,7 +471,20 @@ func (c *Coordinator) handlePopupCreate( | |||
| 471 | 471 | // Create popup pane entity | |
| 472 | 472 | paneID, popupPane := c.createPopupPane(popupID, parentPaneID, req.TargetURI) | |
| 473 | 473 | ||
| 474 | - | return c.finishPopupCreate(ctx, parentPaneID, parentID, parentURIAtOpen, popupID, popupWV, popupPane, paneID, popupType, behavior, placement, req) | |
| 474 | + | return c.finishPopupCreate( | |
| 475 | + | ctx, | |
| 476 | + | parentPaneID, | |
| 477 | + | parentID, | |
| 478 | + | parentURIAtOpen, | |
| 479 | + | popupID, | |
| 480 | + | popupWV, | |
| 481 | + | popupPane, | |
| 482 | + | paneID, | |
| 483 | + | popupType, | |
| 484 | + | behavior, | |
| 485 | + | placement, | |
| 486 | + | req, | |
| 487 | + | ) | |
| 475 | 488 | } | |
| 476 | 489 | ||
| 477 | 490 | func (c *Coordinator) reuseNamedPopup( | |
| @@ -471,7 +471,20 @@ func (c *Coordinator) handlePopupCreate( | |||||
| 471 | // Create popup pane entity | 471 | // Create popup pane entity | ||
| 472 | paneID, popupPane := c.createPopupPane(popupID, parentPaneID, req.TargetURI) | 472 | paneID, popupPane := c.createPopupPane(popupID, parentPaneID, req.TargetURI) | ||
| 473 | 473 | ||||
| 474 | - | return c.finishPopupCreate(ctx, parentPaneID, parentID, parentURIAtOpen, popupID, popupWV, popupPane, paneID, popupType, behavior, placement, req) | 474 | + | return c.finishPopupCreate( |
| 475 | + | ctx, | |||
| 476 | + | parentPaneID, | |||
| 477 | + | parentID, | |||
| 478 | + | parentURIAtOpen, | |||
| 479 | + | popupID, | |||
| 480 | + | popupWV, | |||
| 481 | + | popupPane, | |||
| 482 | + | paneID, | |||
| 483 | + | popupType, | |||
| 484 | + | behavior, | |||
| 485 | + | placement, | |||
| 486 | + | req, | |||
| 487 | + | ) | |||
| 475 | } | 488 | } | ||
| 476 | 489 | ||||
| 477 | func (c *Coordinator) reuseNamedPopup( | 490 | func (c *Coordinator) reuseNamedPopup( | ||