From b89c3bd57cd65b6457557919b287ba298fda1d57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Fri, 14 Jul 2023 09:28:58 +0800 Subject: [PATCH] Fix: Chromium & DialogHandler onFileDialog callback args:acceptFiltersList --- cef/events-def.go | 2 +- cef/events.go | 22 +++++++++++----------- cef/types-dialog-handler.go | 15 +++------------ cef/types-filedialog-callback.go | 8 +++++--- consts/consts.go | 3 --- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/cef/events-def.go b/cef/events-def.go index f6adc62e..41f0f50c 100644 --- a/cef/events-def.go +++ b/cef/events-def.go @@ -61,7 +61,7 @@ type chromiumEventOnExtensionLoaded func(sender lcl.IObject, extension *ICefExte type chromiumEventOnExtensionLoadFailed func(sender lcl.IObject, result consts.TCefErrorCode) type chromiumEventOnExtensionUnloaded func(sender lcl.IObject, extension *ICefExtension) type chromiumEventOnFavIconUrlChange func(sender lcl.IObject, browser *ICefBrowser, iconUrls []string) // TStrings => []string -type chromiumEventOnFileDialog func(sender lcl.IObject, browser *ICefBrowser, mode consts.TCefFileDialogMode, title, defaultFilePath string, acceptFilters []string, callback *ICefFileDialogCallback) bool +type chromiumEventOnFileDialog func(sender lcl.IObject, browser *ICefBrowser, mode consts.FileDialogMode, title, defaultFilePath string, acceptFilters *lcl.TStrings, callback *ICefFileDialogCallback) bool type chromiumEventOnGetAccessibilityHandler func(sender lcl.IObject, accessibilityHandler *ICefAccessibilityHandler) type chromiumEventOnGetAudioParameters func(sender lcl.IObject, browser *ICefBrowser, params *TCefAudioParameters) bool type chromiumEventOnGetResourceHandler func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest) (resourceHandler *ICefResourceHandler) diff --git a/cef/events.go b/cef/events.go index 928c0eea..0c25a56c 100644 --- a/cef/events.go +++ b/cef/events.go @@ -310,22 +310,22 @@ func init() { fn.(chromiumEventOnFavIconUrlChange)(lcl.AsObject(getPtr(0)), browse, iconUrls) case chromiumEventOnFileDialog: browse := &ICefBrowser{instance: getPtr(1)} - mode := consts.TCefFileDialogMode(getVal(2)) + mode := consts.FileDialogMode(getVal(2)) title := api.GoStr(getVal(3)) defaultFilePath := api.GoStr(getVal(4)) acceptFiltersList := lcl.AsStrings(getVal(5)) callback := &ICefFileDialogCallback{instance: getPtr(6)} result := (*bool)(getPtr(7)) - var acceptFilters []string - if acceptFiltersList.IsValid() { - count := int(acceptFiltersList.Count()) - acceptFilters = make([]string, count, count) - for i := 0; i < count; i++ { - acceptFilters[i] = acceptFiltersList.Strings(int32(i)) - } - acceptFiltersList.Free() - } - *result = fn.(chromiumEventOnFileDialog)(lcl.AsObject(getPtr(0)), browse, mode, title, defaultFilePath, acceptFilters, callback) + //var acceptFilters []string + //if acceptFiltersList.IsValid() { + // count := int(acceptFiltersList.Count()) + // acceptFilters = make([]string, count, count) + // for i := 0; i < count; i++ { + // acceptFilters[i] = acceptFiltersList.Strings(int32(i)) + // } + // //acceptFiltersList.Free() + //} + *result = fn.(chromiumEventOnFileDialog)(lcl.AsObject(getPtr(0)), browse, mode, title, defaultFilePath, acceptFiltersList, callback) case chromiumEventOnGetAccessibilityHandler: accessibilityHandler := &ICefAccessibilityHandler{instance: getPtr(1)} fn.(chromiumEventOnGetAccessibilityHandler)(lcl.AsObject(getPtr(0)), accessibilityHandler) diff --git a/cef/types-dialog-handler.go b/cef/types-dialog-handler.go index 6e5fa55b..08c1df4b 100644 --- a/cef/types-dialog-handler.go +++ b/cef/types-dialog-handler.go @@ -68,7 +68,7 @@ func (m *ICefDialogHandler) SetOnFileDialog(fn onFileDialog) { // ************************** events ************************** // -type onFileDialog func(browser *ICefBrowser, mode consts.TCefFileDialogMode, title, defaultFilePath string, acceptFilters []string, callback *ICefFileDialogCallback) bool +type onFileDialog func(browser *ICefBrowser, mode consts.FileDialogMode, title, defaultFilePath string, acceptFilters *lcl.TStrings, callback *ICefFileDialogCallback) bool func init() { lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool { @@ -78,22 +78,13 @@ func init() { switch fn.(type) { case onFileDialog: browse := &ICefBrowser{instance: getPtr(0)} - mode := consts.TCefFileDialogMode(getVal(1)) + mode := consts.FileDialogMode(getVal(1)) title := api.GoStr(getVal(2)) defaultFilePath := api.GoStr(getVal(3)) acceptFiltersList := lcl.AsStrings(getVal(4)) callback := &ICefFileDialogCallback{instance: getPtr(5)} result := (*bool)(getPtr(6)) - var acceptFilters []string - if acceptFiltersList.IsValid() { - count := int(acceptFiltersList.Count()) - acceptFilters = make([]string, count, count) - for i := 0; i < count; i++ { - acceptFilters[i] = acceptFiltersList.Strings(int32(i)) - } - acceptFiltersList.Free() - } - *result = fn.(onFileDialog)(browse, mode, title, defaultFilePath, acceptFilters, callback) + *result = fn.(onFileDialog)(browse, mode, title, defaultFilePath, acceptFiltersList, callback) default: return false } diff --git a/cef/types-filedialog-callback.go b/cef/types-filedialog-callback.go index 4c064ae9..e36e2ecd 100644 --- a/cef/types-filedialog-callback.go +++ b/cef/types-filedialog-callback.go @@ -42,9 +42,11 @@ func (m *ICefFileDialogCallback) Cont(filePaths []string) { if !m.IsValid() { return } - fps := lcl.NewStrings() - for _, fp := range filePaths { - fps.Add(fp) + fps := lcl.NewStringList() + if filePaths != nil { + for _, fp := range filePaths { + fps.Add(fp) + } } imports.Proc(def.FileDialogCallback_Cont).Call(m.Instance(), fps.Instance()) fps.Free() diff --git a/consts/consts.go b/consts/consts.go index 42b50af0..8b8e2947 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -1201,9 +1201,6 @@ const ( // /include/internal/cef_types.h (cef_quick_menu_edit_state_flags_t) type TCefQuickMenuEditStateFlags = types.Int32 -// /include/internal/cef_types.h (cef_file_dialog_mode_t) -type TCefFileDialogMode = types.Cardinal - // /include/internal/cef_types.h (cef_log_severity_t) type TCefLogSeverity = types.Cardinal