From 099a7ec60d5039663a33ae64ae611e201b59cab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Sun, 26 Feb 2023 23:21:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96&=E4=BF=AE=E5=A4=8D=20tag=20-?= =?UTF-8?q?>=20v14?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cef/cef-proc-def.go | 72 +++++++++--------- cef/cef-request.go | 75 ++++++------------- cef/cef-response.go | 10 +-- cef/cef-string-multi-map.go | 71 +++++++----------- cef/cef-types-post-data.go | 9 +++ cef/cef-types.go | 6 ++ .../src/browser-process.go | 13 ++-- 7 files changed, 113 insertions(+), 143 deletions(-) create mode 100644 cef/cef-types-post-data.go diff --git a/cef/cef-proc-def.go b/cef/cef-proc-def.go index 0b8fc9f4..4fbd6407 100644 --- a/cef/cef-proc-def.go +++ b/cef/cef-proc-def.go @@ -420,16 +420,18 @@ func init() { dllimports.NewEnergyImport("CEFWindowInfoAsWindowless", 0), dllimports.NewEnergyImport("CEFJSRegisterExtension", 0), //ICefRequest - dllimports.NewEnergyImport("cefRequest_IsReadOnly", 0), - dllimports.NewEnergyImport("cefRequest_SetUrl", 0), - dllimports.NewEnergyImport("cefRequest_SetMethod", 0), - dllimports.NewEnergyImport("cefRequest_SetReferrer", 0), - dllimports.NewEnergyImport("cefRequest_SetFlags", 0), - dllimports.NewEnergyImport("cefRequest_SetFirstPartyForCookies", 0), - dllimports.NewEnergyImport("cefRequest_GetHeaderByName", 0), - dllimports.NewEnergyImport("cefRequest_SetHeaderByName", 0), - dllimports.NewEnergyImport("cefRequest_GetHeaderMap", 0), - dllimports.NewEnergyImport("cefRequest_SetHeaderMap", 0), + dllimports.NewEnergyImport("CefRequest_IsReadOnly", 0), + dllimports.NewEnergyImport("CefRequest_SetUrl", 0), + dllimports.NewEnergyImport("CefRequest_SetMethod", 0), + dllimports.NewEnergyImport("CefRequest_SetReferrer", 0), + dllimports.NewEnergyImport("CefRequest_SetFlags", 0), + dllimports.NewEnergyImport("CefRequest_SetFirstPartyForCookies", 0), + dllimports.NewEnergyImport("CefRequest_GetHeaderByName", 0), + dllimports.NewEnergyImport("CefRequest_SetHeaderByName", 0), + dllimports.NewEnergyImport("CefRequest_GetHeaderMap", 0), + dllimports.NewEnergyImport("CefRequest_SetHeaderMap", 0), + dllimports.NewEnergyImport("CefRequest_GetPostData", 0), + dllimports.NewEnergyImport("CefRequest_SetPostData", 0), //ICefResponse dllimports.NewEnergyImport("cefResponse_IsReadOnly", 0), dllimports.NewEnergyImport("cefResponse_SetError", 0), @@ -442,13 +444,13 @@ func init() { dllimports.NewEnergyImport("cefResponse_SetURL", 0), dllimports.NewEnergyImport("cefResponse_GetHeaderMap", 0), //ICefStringMultiMap - dllimports.NewEnergyImport("cefHeaderMap_GetSize", 0), - dllimports.NewEnergyImport("cefHeaderMap_FindCount", 0), - dllimports.NewEnergyImport("cefHeaderMap_GetEnumerate", 0), - dllimports.NewEnergyImport("cefHeaderMap_GetKey", 0), - dllimports.NewEnergyImport("cefHeaderMap_GetValue", 0), - dllimports.NewEnergyImport("cefHeaderMap_Append", 0), - dllimports.NewEnergyImport("cefHeaderMap_Clear", 0), + dllimports.NewEnergyImport("StringMultimap_GetSize", 0), + dllimports.NewEnergyImport("StringMultimap_FindCount", 0), + dllimports.NewEnergyImport("StringMultimap_GetEnumerate", 0), + dllimports.NewEnergyImport("StringMultimap_GetKey", 0), + dllimports.NewEnergyImport("StringMultimap_GetValue", 0), + dllimports.NewEnergyImport("StringMultimap_Append", 0), + dllimports.NewEnergyImport("StringMultimap_Clear", 0), //ICefImage dllimports.NewEnergyImport("CEFImage_New", 0), dllimports.NewEnergyImport("CEFImage_AddPng", 0), @@ -1181,16 +1183,18 @@ const ( internale_CEFWindowInfoAsWindowless internale_CEFJSRegisterExtension //ICefRequest - internale_cefRequest_IsReadOnly - internale_cefRequest_SetUrl - internale_cefRequest_SetMethod - internale_cefRequest_SetReferrer - internale_cefRequest_SetFlags - internale_cefRequest_SetFirstPartyForCookies - internale_cefRequest_GetHeaderByName - internale_cefRequest_SetHeaderByName - internale_cefRequest_GetHeaderMap - internale_cefRequest_SetHeaderMap + internale_CefRequest_IsReadOnly + internale_CefRequest_SetUrl + internale_CefRequest_SetMethod + internale_CefRequest_SetReferrer + internale_CefRequest_SetFlags + internale_CefRequest_SetFirstPartyForCookies + internale_CefRequest_GetHeaderByName + internale_CefRequest_SetHeaderByName + internale_CefRequest_GetHeaderMap + internale_CefRequest_SetHeaderMap + internale_CefRequest_GetPostData + internale_CefRequest_SetPostData //ICefResponse internale_cefResponse_IsReadOnly internale_cefResponse_SetError @@ -1203,13 +1207,13 @@ const ( internale_cefResponse_SetURL internale_cefResponse_GetHeaderMap //ICefStringMultiMap - internale_cefHeaderMap_GetSize - internale_cefHeaderMap_FindCount - internale_cefHeaderMap_GetEnumerate - internale_cefHeaderMap_GetKey - internale_cefHeaderMap_GetValue - internale_cefHeaderMap_Append - internale_cefHeaderMap_Clear + internale_StringMultimap_GetSize + internale_StringMultimap_FindCount + internale_StringMultimap_GetEnumerate + internale_StringMultimap_GetKey + internale_StringMultimap_GetValue + internale_StringMultimap_Append + internale_StringMultimap_Clear //ICefImage internale_CEFImage_New internale_CEFImage_AddPng diff --git a/cef/cef-request.go b/cef/cef-request.go index 2f42e392..6393c796 100644 --- a/cef/cef-request.go +++ b/cef/cef-request.go @@ -18,103 +18,70 @@ import ( "unsafe" ) +// Instance 实例 func (m *ICefRequest) Instance() uintptr { return uintptr(m.instance) } // IsReadOnly 是否只读 func (m *ICefRequest) IsReadOnly() bool { - return api.GoBool(cefRequest_IsReadOnly(m.Instance())) + r1, _, _ := imports.Proc(internale_CefRequest_IsReadOnly).Call(m.Instance()) + return api.GoBool(r1) } // SetURL 设置URL func (m *ICefRequest) SetURL(url string) { - cefRequest_SetUrl(m.Instance(), url) + imports.Proc(internale_CefRequest_SetUrl).Call(m.Instance(), api.PascalStr(url)) } // SetMethod 设置请求方式 func (m *ICefRequest) SetMethod(method string) { - cefRequest_SetMethod(m.Instance(), method) + imports.Proc(internale_CefRequest_SetMethod).Call(m.Instance(), api.PascalStr(method)) } // SetReferrer 设置来源策略 func (m *ICefRequest) SetReferrer(referrerUrl string, policy TCefReferrerPolicy) { - cefRequest_SetReferrer(m.Instance(), referrerUrl, policy) + imports.Proc(internale_CefRequest_SetReferrer).Call(m.Instance(), api.PascalStr(referrerUrl), policy.ToPtr()) } // SetFlags 设置请求标记 func (m *ICefRequest) SetFlags(flags TCefUrlRequestFlags) { - cefRequest_SetFlags(m.Instance(), flags) + imports.Proc(internale_CefRequest_SetFlags).Call(m.Instance(), flags.ToPtr()) } // SetFirstPartyForCookies func (m *ICefRequest) SetFirstPartyForCookies(url string) { - cefRequest_SetFirstPartyForCookies(m.Instance(), url) + imports.Proc(internale_CefRequest_SetFirstPartyForCookies).Call(m.Instance(), api.PascalStr(url)) } // GetHeaderByName func (m *ICefRequest) GetHeaderByName(name string) string { - return api.GoStr(cefRequest_GetHeaderByName(m.Instance(), name)) + r1, _, _ := imports.Proc(internale_CefRequest_GetHeaderByName).Call(m.Instance(), api.PascalStr(name)) + return api.GoStr(r1) } // SetHeaderByName func (m *ICefRequest) SetHeaderByName(name, value string, overwrite bool) { - cefRequest_SetHeaderByName(m.Instance(), name, value, overwrite) + imports.Proc(internale_CefRequest_SetHeaderByName).Call(m.Instance(), api.PascalStr(name), api.PascalStr(value), api.PascalBool(overwrite)) } // GetHeaderMap func (m *ICefRequest) GetHeaderMap() *ICefStringMultiMap { - headerMap := &ICefStringMultiMap{} - headerMap.instance = cefRequest_GetHeaderMap(m.Instance()) - headerMap.ptr = unsafe.Pointer(headerMap.instance) - return headerMap + var result uintptr + imports.Proc(internale_CefRequest_GetHeaderMap).Call(m.Instance(), uintptr(unsafe.Pointer(&result))) + return &ICefStringMultiMap{instance: unsafe.Pointer(result)} } func (m *ICefRequest) SetHeaderMap(headerMap *ICefStringMultiMap) { - cefRequest_SetHeaderMap(m.Instance(), headerMap.instance) + imports.Proc(internale_CefRequest_SetHeaderMap).Call(m.Instance(), headerMap.Instance()) } -// request -func cefRequest_IsReadOnly(instance uintptr) uintptr { - r1, _, _ := imports.Proc(internale_cefRequest_IsReadOnly).Call(instance) - return r1 +func (m *ICefRequest) GetPostData() *ICefPostData { + var result uintptr + imports.Proc(internale_CefRequest_GetPostData).Call(m.Instance(), uintptr(unsafe.Pointer(&result))) + return &ICefPostData{instance: unsafe.Pointer(result)} } -func cefRequest_SetUrl(instance uintptr, url string) { - imports.Proc(internale_cefRequest_SetUrl).Call(instance, api.PascalStr(url)) -} - -func cefRequest_SetMethod(instance uintptr, method string) { - imports.Proc(internale_cefRequest_SetMethod).Call(instance, api.PascalStr(method)) -} - -func cefRequest_SetReferrer(instance uintptr, referrerUrl string, policy TCefReferrerPolicy) { - imports.Proc(internale_cefRequest_SetReferrer).Call(instance, api.PascalStr(referrerUrl), uintptr(policy)) -} - -func cefRequest_SetFlags(instance uintptr, flags TCefUrlRequestFlags) { - imports.Proc(internale_cefRequest_SetFlags).Call(instance, uintptr(flags)) -} - -func cefRequest_SetFirstPartyForCookies(instance uintptr, url string) { - imports.Proc(internale_cefRequest_SetFirstPartyForCookies).Call(instance, api.PascalStr(url)) -} - -func cefRequest_GetHeaderByName(instance uintptr, name string) uintptr { - r1, _, _ := imports.Proc(internale_cefRequest_GetHeaderByName).Call(instance, api.PascalStr(name)) - return r1 -} - -func cefRequest_SetHeaderByName(instance uintptr, url, value string, overwrite bool) { - imports.Proc(internale_cefRequest_SetHeaderByName).Call(instance, api.PascalStr(url), api.PascalStr(value), api.PascalBool(overwrite)) -} - -func cefRequest_GetHeaderMap(instance uintptr) uintptr { - r1, _, _ := imports.Proc(internale_cefRequest_GetHeaderMap).Call(instance) - return r1 -} - -func cefRequest_SetHeaderMap(instance, headerMap uintptr) uintptr { - r1, _, _ := imports.Proc(internale_cefRequest_SetHeaderMap).Call(instance, headerMap) - return r1 +func (m *ICefRequest) SetPostData(value *ICefPostData) { + imports.Proc(internale_CefRequest_SetPostData).Call(m.Instance(), value.Instance()) } diff --git a/cef/cef-response.go b/cef/cef-response.go index cf2fef29..fb1f7673 100644 --- a/cef/cef-response.go +++ b/cef/cef-response.go @@ -15,7 +15,6 @@ import ( "github.com/energye/energy/common/imports" . "github.com/energye/energy/consts" "github.com/energye/golcl/lcl/api" - "unsafe" ) // IsReadOnly 是否只读 @@ -65,10 +64,11 @@ func (m *ICefResponse) SetHeaderByName(name, value string, overwrite bool) { // GetHeaderMap func (m *ICefResponse) GetHeaderMap() *ICefStringMultiMap { - headerMap := &ICefStringMultiMap{} - headerMap.instance = cefResponse_GetHeaderMap(uintptr(m.instance)) - headerMap.ptr = unsafe.Pointer(headerMap.instance) - return headerMap + //headerMap := &ICefStringMultiMap{} + //headerMap.instance = cefResponse_GetHeaderMap(uintptr(m.instance)) + //headerMap.ptr = unsafe.Pointer(headerMap.instance) + //return headerMap + return nil // TODO dev } func cefResponse_IsReadOnly(instance uintptr) uintptr { diff --git a/cef/cef-string-multi-map.go b/cef/cef-string-multi-map.go index 9082b1d2..c67aa938 100644 --- a/cef/cef-string-multi-map.go +++ b/cef/cef-string-multi-map.go @@ -19,69 +19,54 @@ import ( // ICefStringMultiMap 实例 type ICefStringMultiMap struct { - instance uintptr - ptr unsafe.Pointer + instance unsafe.Pointer +} + +// Instance 实例 +func (m *ICefStringMultiMap) Instance() uintptr { + if m == nil { + return 0 + } + return uintptr(m.instance) } // GetSize 大小 -func (m *ICefStringMultiMap) GetSize() int { - return cefHeaderMap_GetSize(m.instance) +func (m *ICefStringMultiMap) GetSize() int32 { + r1, _, _ := imports.Proc(internale_StringMultimap_GetSize).Call(m.Instance()) + return int32(r1) } // FindCount key值数量 -func (m *ICefStringMultiMap) FindCount(key string) int { - return cefHeaderMap_FindCount(m.instance, key) +func (m *ICefStringMultiMap) FindCount(key string) int32 { + r1, _, _ := imports.Proc(internale_StringMultimap_FindCount).Call(m.Instance(), api.PascalStr(key)) + return int32(r1) } -// GetEnumerate 根据key & index获取枚举 -func (m *ICefStringMultiMap) GetEnumerate(key string, valueIndex int) string { - return api.GoStr(cefHeaderMap_GetEnumerate(m.instance, key, valueIndex)) +// GetEnumerate 根据 key and index 获取 +func (m *ICefStringMultiMap) GetEnumerate(key string, valueIndex int32) string { + r1, _, _ := imports.Proc(internale_StringMultimap_GetEnumerate).Call(m.Instance(), api.PascalStr(key), uintptr(valueIndex)) + return api.GoStr(r1) } // GetKey 根据 index 获取key -func (m *ICefStringMultiMap) GetKey(index int) string { - return api.GoStr(cefHeaderMap_GetKey(m.instance, index)) +func (m *ICefStringMultiMap) GetKey(index int32) string { + r1, _, _ := imports.Proc(internale_StringMultimap_GetKey).Call(m.Instance(), uintptr(index)) + return api.GoStr(r1) } // GetValue 根据 index 获取value -func (m *ICefStringMultiMap) GetValue(index int) string { - return api.GoStr(cefHeaderMap_GetValue(m.instance, index)) +func (m *ICefStringMultiMap) GetValue(index int32) string { + r1, _, _ := imports.Proc(internale_StringMultimap_GetValue).Call(m.Instance(), uintptr(index)) + return api.GoStr(r1) } // Append 给key追加值 func (m *ICefStringMultiMap) Append(key, value string) bool { - return api.GoBool(cefHeaderMap_Append(m.instance, key, value)) + r1, _, _ := imports.Proc(internale_StringMultimap_Append).Call(m.Instance(), api.PascalStr(key), api.PascalStr(value)) + return api.GoBool(r1) } // Clear 清空 func (m *ICefStringMultiMap) Clear() { - cefHeaderMap_Clear(m.instance) -} - -func cefHeaderMap_GetSize(instance uintptr) int { - r1, _, _ := imports.Proc(internale_cefHeaderMap_GetSize).Call(instance) - return int(r1) -} -func cefHeaderMap_FindCount(instance uintptr, key string) int { - r1, _, _ := imports.Proc(internale_cefHeaderMap_FindCount).Call(instance, api.PascalStr(key)) - return int(r1) -} -func cefHeaderMap_GetEnumerate(instance uintptr, key string, valueIndex int) uintptr { - r1, _, _ := imports.Proc(internale_cefHeaderMap_GetEnumerate).Call(instance, api.PascalStr(key), uintptr(valueIndex)) - return r1 -} -func cefHeaderMap_GetKey(instance uintptr, index int) uintptr { - r1, _, _ := imports.Proc(internale_cefHeaderMap_GetKey).Call(instance, uintptr(index)) - return r1 -} -func cefHeaderMap_GetValue(instance uintptr, index int) uintptr { - r1, _, _ := imports.Proc(internale_cefHeaderMap_GetValue).Call(instance, uintptr(index)) - return r1 -} -func cefHeaderMap_Append(instance uintptr, key, value string) uintptr { - r1, _, _ := imports.Proc(internale_cefHeaderMap_Append).Call(instance, api.PascalStr(key), api.PascalStr(value)) - return r1 -} -func cefHeaderMap_Clear(instance uintptr) { - imports.Proc(internale_cefHeaderMap_Clear).Call(instance) + imports.Proc(internale_StringMultimap_Clear).Call(m.Instance()) } diff --git a/cef/cef-types-post-data.go b/cef/cef-types-post-data.go new file mode 100644 index 00000000..028d6462 --- /dev/null +++ b/cef/cef-types-post-data.go @@ -0,0 +1,9 @@ +package cef + +// Instance 实例 +func (m *ICefPostData) Instance() uintptr { + if m == nil { + return 0 + } + return uintptr(m.instance) +} diff --git a/cef/cef-types.go b/cef/cef-types.go index 67f14821..7f53ac19 100644 --- a/cef/cef-types.go +++ b/cef/cef-types.go @@ -246,6 +246,11 @@ type ICefResponse struct { URL string } +// ICefPostData +type ICefPostData struct { + instance unsafe.Pointer +} + // ICefView type ICefView struct { instance unsafe.Pointer @@ -296,6 +301,7 @@ type ICefV8ArrayBufferReleaseCallback struct { instance unsafe.Pointer } +// Exception 异常返回信息 type Exception struct { message string } diff --git a/example/dev-test/combination-sundry-browser/src/browser-process.go b/example/dev-test/combination-sundry-browser/src/browser-process.go index 3ba18aa8..21e207f0 100644 --- a/example/dev-test/combination-sundry-browser/src/browser-process.go +++ b/example/dev-test/combination-sundry-browser/src/browser-process.go @@ -429,13 +429,12 @@ func AppBrowserInit() { } }) event.SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, request *cef.ICefRequest, callback *cef.ICefCallback, result *consts.TCefReturnValue) { - //fmt.Println("SetOnBeforeResourceLoad:", request.Url, request.Method, "headerMap:", request.GetHeaderMap().GetSize()) - //headerMap := request.GetHeaderMap() - //fmt.Println("\t", request.GetHeaderByName("energy"), headerMap.GetEnumerate("energy", 1), "size:", headerMap.GetSize()) - //for i := 0; i < headerMap.GetSize(); i++ { - // fmt.Println("\tkey:", headerMap.GetKey(i), "value:", headerMap.GetValue(i)) - //} - + fmt.Println("SetOnBeforeResourceLoad:", request.Url, request.Method, "headerMap:", request.GetHeaderMap().GetSize()) + headerMap := request.GetHeaderMap() + fmt.Println("\t", request.GetHeaderByName("energy"), headerMap.GetEnumerate("energy", 1), "size:", headerMap.GetSize()) + for i := 0; i < int(headerMap.GetSize()); i++ { + fmt.Println("\tkey:", headerMap.GetKey(int32(i)), "value:", headerMap.GetValue(int32(i))) + } }) }) //添加子窗口初始化