Fix: 修复chromium相关事件回调函数参数

This commit is contained in:
杨红岩 2024-01-02 13:32:21 +08:00
parent bf6b4e7eb3
commit 099c8b3de3
9 changed files with 20 additions and 20 deletions

View File

@ -9,7 +9,7 @@ windows xp go 1.11.13
增加了特定版本支持 API
liblcl
CEFAppConfig_SpecificVersion
CEFAppConfig_SpecificVersion OK
修改字符串返回, 使用TString API
liblcl
@ -27,6 +27,8 @@ liblcl
增加参数 TCefWindowInfo
增加参数 TCefPopupFeatures
修复: Chromium OnExtension XXXX 相关函数没返回 Sender
@ -37,4 +39,5 @@ golcl 增加 支持 go1.10的打开文件接口
Go
移除 liblclbinres 在构建时生成二进制liblcl.go
移除 liblclbinres 在构建时生成二进制liblcl.go , 将go-bindata集成到energy命令行工具中
energy命令行工具中集成 go-bindata

View File

@ -55,7 +55,7 @@ func main() {
// 主窗口的扩展参数设置
window.SetCreateBrowserExtraInfo("", context, nil)
// 弹出窗口
event.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupWindow cef.IBrowserWindow, noJavascriptAccess *bool) bool {
event.SetOnBeforePopup(func(sender lcl.IObject, popupWindow cef.IBrowserWindow, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, resultClient *cef.ICefClient, settings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
// 弹出窗口的扩展参数设置
popupWindow.SetCreateBrowserExtraInfo("", context, nil)
return false

View File

@ -90,7 +90,7 @@ func mainBrowserInit() {
fmt.Println("主窗口初始化回调函数")
window.SetCenterWindow(true)
event.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupWindow cef.IBrowserWindow, noJavascriptAccess *bool) bool {
event.SetOnBeforePopup(func(sender lcl.IObject, popupWindow cef.IBrowserWindow, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, resultClient *cef.ICefClient, settings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
fmt.Println("OnBeforePopup: " + beforePopupInfo.TargetUrl)
popupWindow.SetTitle("改变了标题 - " + beforePopupInfo.TargetUrl)
return false

View File

@ -77,7 +77,7 @@ func main() {
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
// 弹出窗口处理
event.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupWindow cef.IBrowserWindow, noJavascriptAccess *bool) bool {
event.SetOnBeforePopup(func(sender lcl.IObject, popupWindow cef.IBrowserWindow, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, resultClient *cef.ICefClient, settings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
fmt.Println("BeforePopup", browser.Identifier())
popupWindow.RunOnMainThread(func() {
popupWindow.SetSize(800, 600)

View File

@ -114,7 +114,7 @@ func (m *WindowForm) chromiumEvent() {
m.bufferPanel.SetCursor(cef.CefCursorToWindowsCursor(cursorType))
return true
})
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, client *cef.ICefClient, noJavascriptAccess *bool) bool {
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, popupWindow cef.IBrowserWindow, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, resultClient *cef.ICefClient, settings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
return true // 阻止弹出窗口
})
m.chromium.SetOnTooltip(func(sender lcl.IObject, browser *cef.ICefBrowser, text *string) (result bool) {

View File

@ -110,7 +110,7 @@ func (m *WindowForm) chromiumEvent() {
m.bufferPanel.SetCursor(cef.CefCursorToWindowsCursor(cursorType))
return true
})
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, client *cef.ICefClient, noJavascriptAccess *bool) bool {
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, resultClient *cef.ICefClient, settings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
return true // 阻止弹出窗口
})
m.chromium.SetOnTooltip(func(sender lcl.IObject, browser *cef.ICefBrowser, text *string) (result bool) {

View File

@ -87,7 +87,7 @@ func main() {
}
}
//弹出子窗口
event.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupWindow cef.IBrowserWindow, noJavascriptAccess *bool) bool {
event.SetOnBeforePopup(func(sender lcl.IObject, popupWindow cef.IBrowserWindow, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, resultClient *cef.ICefClient, settings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
fmt.Println("beforePopupInfo-TargetUrl", beforePopupInfo.TargetUrl, strings.Index(beforePopupInfo.TargetUrl, "popup_1"), strings.Index(beforePopupInfo.TargetUrl, "popup_2"))
if strings.Index(beforePopupInfo.TargetUrl, "popup_1") > 0 {
popupWindow.SetSize(800, 600)

View File

@ -1,4 +1,5 @@
//go:build windows
// +build windows
package main
@ -124,7 +125,7 @@ func (m *MainWindowDemo) OnFormCreate(sender lcl.IObject) {
return true
})
//禁止弹出新窗口
chromiumBrowser.Chromium().SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, client *cef.ICefClient, noJavascriptAccess *bool) bool {
chromiumBrowser.Chromium().SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, resultClient *cef.ICefClient, settings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
fmt.Println("OnBeforePopup")
return true
})

View File

@ -61,26 +61,22 @@ func (m *BrowserWindow) OnFormCreate(sender lcl.IObject) {
// 3. 触发后将canClose设置为true, 发送消息到主窗口关闭,触发 m.SetOnCloseQuery
m.chromium.SetOnBeforeClose(m.chromiumBeforeClose)
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, client *cef.ICefClient, browserSettings *cef.TCefBrowserSettings, noJavascriptAccess *bool) bool {
m.chromium.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupFeatures *cef.TCefPopupFeatures, windowInfo *cef.TCefWindowInfo, client *cef.ICefClient, browserSettings *cef.TCefBrowserSettings, resultExtraInfo *cef.ICefDictionaryValue, noJavascriptAccess *bool) bool {
fmt.Println("beforePopupInfo:", beforePopupInfo.TargetUrl, beforePopupInfo.TargetDisposition, beforePopupInfo.TargetFrameName, beforePopupInfo.UserGesture)
fmt.Println(*noJavascriptAccess)
fmt.Println(browser.BrowserId(), frame.Identifier(), frame.Url(), frame.V8Context().Frame().Url())
fmt.Printf("windowInfo: %+v\n", windowInfo)
fmt.Printf("browserSettings: %+v\n", browserSettings)
fmt.Printf("popupFeatures: %+v\n", popupFeatures)
extraInfo := cef.DictionaryValueRef.New()
*resultExtraInfo = *extraInfo
return true
})
//m.chromium.SetOnOpenUrlFromTab(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, targetUrl string, targetDisposition consts.TCefWindowOpenDisposition, userGesture bool) bool {
// return true
//m.chromium.SetOnRenderCompMsg(func(sender lcl.IObject, message *types.TMessage, lResult *types.LRESULT, aHandled *bool) {
// fmt.Println("SetOnRenderCompMsg", *lResult, *aHandled)
// //*aHandled = true
//})
//m.chromium.SetOnTooltip(func(sender lcl.IObject, browser *cef.ICefBrowser, text *string) (result bool) {
// fmt.Println("text", *text)
// return true
//})
m.chromium.SetOnRenderCompMsg(func(sender lcl.IObject, message *types.TMessage, lResult *types.LRESULT, aHandled *bool) {
fmt.Println("SetOnRenderCompMsg", *lResult, *aHandled)
//*aHandled = true
})
}
func (m *BrowserWindow) show(sender lcl.IObject) {