energy/cef/cef-events.go

550 lines
22 KiB
Go
Raw Normal View History

2022-10-04 13:21:05 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
2022-10-04 16:38:43 +08:00
// Licensed under GNU General Public License v3.0
2022-10-04 13:21:05 +08:00
//
//----------------------------------------
package cef
import (
. "github.com/energye/energy/common"
2022-10-04 22:34:57 +08:00
. "github.com/energye/energy/consts"
"github.com/energye/energy/ipc"
"github.com/energye/energy/logger"
2022-10-04 13:21:05 +08:00
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/api"
"github.com/energye/golcl/lcl/types"
"unsafe"
)
func init() {
var resourceEventGet = func(fn interface{}, getVal func(idx int) uintptr, resp bool) (sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, response *ICefResponse) {
var (
instance uintptr
ptr unsafe.Pointer
)
// 指针
getPtr := func(i int) unsafe.Pointer {
return unsafe.Pointer(getVal(i))
}
senderPtr := getPtr(0)
2022-10-04 13:21:05 +08:00
browser = &ICefBrowser{browseId: int32(getVal(1)), chromium: senderPtr}
tempFrame := (*cefFrame)(getPtr(2))
frame = &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
cefRequest := (*rICefRequest)(getPtr(3))
instance, ptr = GetInstancePtr(cefRequest.Instance)
request = &ICefRequest{
instance: instance,
ptr: ptr,
2022-12-03 21:56:51 +08:00
Url: api.GoStr(cefRequest.Url),
Method: api.GoStr(cefRequest.Method),
ReferrerUrl: api.GoStr(cefRequest.ReferrerUrl),
2022-10-04 13:21:05 +08:00
ReferrerPolicy: int32(cefRequest.ReferrerPolicy),
Flags: int(cefRequest.Flags),
2022-12-03 21:56:51 +08:00
FirstPartyForCookies: api.GoStr(cefRequest.FirstPartyForCookies),
2022-10-04 13:21:05 +08:00
ResourceType: int32(cefRequest.ResourceType),
TransitionType: int(cefRequest.TransitionType),
2022-10-04 22:34:57 +08:00
Identifier: *(*uint64)(GetParamPtr(cefRequest.Identifier, 0)),
2022-10-04 13:21:05 +08:00
}
if resp {
cefResponse := (*iCefResponse)(getPtr(4))
instance, ptr = GetInstancePtr(cefResponse.Instance)
response = &ICefResponse{
instance: instance,
ptr: ptr,
Status: int32(cefResponse.Status),
2022-12-03 21:56:51 +08:00
StatusText: api.GoStr(cefResponse.StatusText),
MimeType: api.GoStr(cefResponse.MimeType),
Charset: api.GoStr(cefResponse.Charset),
2022-10-04 13:21:05 +08:00
Error: int32(cefResponse.Error),
2022-12-03 21:56:51 +08:00
URL: api.GoStr(cefResponse.URL),
2022-10-04 13:21:05 +08:00
}
}
return lcl.AsObject(senderPtr), browser, frame, request, response
}
lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
defer func() {
if err := recover(); err != nil {
2022-10-05 20:43:25 +08:00
logger.Error("CEF Events Error:", err)
2022-10-04 13:21:05 +08:00
}
}()
var (
instance uintptr
ptr unsafe.Pointer
)
// 指针
getPtr := func(i int) unsafe.Pointer {
return unsafe.Pointer(getVal(i))
}
switch fn.(type) {
case ChromiumEventOnFindResult:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
cefRectPtr := (*tCefRect)(getPtr(4))
cefRect := &TCefRect{
X: int32(cefRectPtr.X),
Y: int32(cefRectPtr.Y),
Width: int32(cefRectPtr.Width),
Height: int32(cefRectPtr.Height),
}
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnFindResult)(lcl.AsObject(sender), browser, int32(getVal(2)), int32(getVal(3)), cefRect, int32(getVal(5)), api.GoBool(getVal(6)))
2022-10-04 13:21:05 +08:00
case BrowseProcessMessageReceived:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
2022-10-04 22:34:57 +08:00
cefProcMsg := (*ipc.CefProcessMessagePtr)(getPtr(4))
args := ipc.NewArgumentList()
2022-10-04 13:21:05 +08:00
args.UnPackageBytePtr(cefProcMsg.Data, int32(cefProcMsg.DataLen))
2022-10-04 22:34:57 +08:00
processMessage := &ipc.ICefProcessMessage{
2022-12-03 21:56:51 +08:00
Name: api.GoStr(cefProcMsg.Name),
2022-10-04 13:21:05 +08:00
ArgumentList: args,
}
var result = (*bool)(getPtr(5))
*result = fn.(BrowseProcessMessageReceived)(lcl.AsObject(sender), browser, frame, CefProcessId(getVal(3)), processMessage)
args.Clear()
cefProcMsg.Data = 0
cefProcMsg.DataLen = 0
cefProcMsg.Name = 0
cefProcMsg = nil
args = nil
case ChromiumEventOnResourceLoadComplete:
sender, browse, frame, request, response := resourceEventGet(fn, getVal, true)
fn.(ChromiumEventOnResourceLoadComplete)(sender, browse, frame, request, response, *(*TCefUrlRequestStatus)(getPtr(5)), *(*int64)(getPtr(6)))
case ChromiumEventOnResourceRedirect:
sender, browse, frame, request, response := resourceEventGet(fn, getVal, true)
var newStr = &String{}
var newStrPtr = (*uintptr)(getPtr(5))
fn.(ChromiumEventOnResourceRedirect)(sender, browse, frame, request, response, newStr)
2022-12-03 21:56:51 +08:00
*newStrPtr = api.PascalStr(newStr.GetValue())
2022-10-04 13:21:05 +08:00
case ChromiumEventOnResourceResponse:
sender, browse, frame, request, response := resourceEventGet(fn, getVal, true)
fn.(ChromiumEventOnResourceResponse)(sender, browse, frame, request, response, (*bool)(getPtr(5)))
case ChromiumEventOnBeforeResourceLoad:
sender, browse, frame, request, _ := resourceEventGet(fn, getVal, false)
_, ptr = getInstance(getVal(4))
callback := &ICefCallback{instance: ptr}
2022-10-04 13:21:05 +08:00
fn.(ChromiumEventOnBeforeResourceLoad)(sender, browse, frame, request, callback, (*TCefReturnValue)(getPtr(5)))
//menu begin
case ChromiumEventOnBeforeContextMenu:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
instance, ptr = getInstance(getVal(1))
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
cefParams := (*iCefContextMenuParams)(getPtr(3))
params := &ICefContextMenuParams{
XCoord: int32(cefParams.XCoord),
YCoord: int32(cefParams.YCoord),
TypeFlags: TCefContextMenuTypeFlags(cefParams.TypeFlags),
2022-12-03 21:56:51 +08:00
LinkUrl: api.GoStr(cefParams.LinkUrl),
UnfilteredLinkUrl: api.GoStr(cefParams.UnfilteredLinkUrl),
SourceUrl: api.GoStr(cefParams.SourceUrl),
TitleText: api.GoStr(cefParams.TitleText),
PageUrl: api.GoStr(cefParams.PageUrl),
FrameUrl: api.GoStr(cefParams.FrameUrl),
FrameCharset: api.GoStr(cefParams.FrameCharset),
2022-10-04 13:21:05 +08:00
MediaType: TCefContextMenuMediaType(cefParams.MediaType),
MediaStateFlags: TCefContextMenuMediaStateFlags(cefParams.MediaStateFlags),
2022-12-03 21:56:51 +08:00
SelectionText: api.GoStr(cefParams.SelectionText),
2022-10-04 13:21:05 +08:00
EditStateFlags: TCefContextMenuEditStateFlags(cefParams.EditStateFlags),
}
instance, ptr = getInstance(getVal(4))
KeyAccelerator.clear()
model := &ICefMenuModel{instance: instance, ptr: ptr, CefMis: KeyAccelerator}
fn.(ChromiumEventOnBeforeContextMenu)(lcl.AsObject(sender), browser, frame, params, model)
case ChromiumEventOnContextMenuCommand:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
cefParams := (*iCefContextMenuParams)(getPtr(3))
params := &ICefContextMenuParams{
XCoord: int32(cefParams.XCoord),
YCoord: int32(cefParams.YCoord),
TypeFlags: TCefContextMenuTypeFlags(cefParams.TypeFlags),
2022-12-03 21:56:51 +08:00
LinkUrl: api.GoStr(cefParams.LinkUrl),
UnfilteredLinkUrl: api.GoStr(cefParams.UnfilteredLinkUrl),
SourceUrl: api.GoStr(cefParams.SourceUrl),
TitleText: api.GoStr(cefParams.TitleText),
PageUrl: api.GoStr(cefParams.PageUrl),
FrameUrl: api.GoStr(cefParams.FrameUrl),
FrameCharset: api.GoStr(cefParams.FrameCharset),
2022-10-04 13:21:05 +08:00
MediaType: TCefContextMenuMediaType(cefParams.MediaType),
MediaStateFlags: TCefContextMenuMediaStateFlags(cefParams.MediaStateFlags),
2022-12-03 21:56:51 +08:00
SelectionText: api.GoStr(cefParams.SelectionText),
2022-10-04 13:21:05 +08:00
EditStateFlags: TCefContextMenuEditStateFlags(cefParams.EditStateFlags),
}
commandId := int32(getVal(4))
eventFlags := uint32(getVal(5))
if !KeyAccelerator.commandIdEventCallback(browser, commandId, params, eventFlags, (*bool)(getPtr(5))) {
fn.(ChromiumEventOnContextMenuCommand)(lcl.AsObject(sender), browser, frame, params, commandId, eventFlags, (*bool)(getPtr(6)))
}
case ChromiumEventOnContextMenuDismissed:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
fn.(ChromiumEventOnContextMenuDismissed)(lcl.AsObject(sender), browser, frame)
//menu end
//---
//cookie begin
case ChromiumEventOnCookieSet:
2022-12-03 21:56:51 +08:00
success := api.GoBool(getVal(1))
2022-10-04 13:21:05 +08:00
ID := int32(getVal(2))
fn.(ChromiumEventOnCookieSet)(lcl.AsObject(getVal(0)), success, ID)
case ChromiumEventOnCookiesDeleted:
numDeleted := int32(getVal(1))
fn.(ChromiumEventOnCookiesDeleted)(lcl.AsObject(getVal(0)), numDeleted)
case ChromiumEventOnCookiesFlushed:
fn.(ChromiumEventOnCookiesFlushed)(lcl.AsObject(getVal(0)))
case ChromiumEventOnCookiesVisited:
cookie := *(*cefCookie)(getPtr(1))
2022-10-04 22:34:57 +08:00
creation := *(*float64)(GetParamPtr(cookie.creation, 0))
lastAccess := *(*float64)(GetParamPtr(cookie.lastAccess, 0))
expires := *(*float64)(GetParamPtr(cookie.expires, 0))
2022-10-04 13:21:05 +08:00
iCookie := &ICefCookie{
2022-12-03 21:56:51 +08:00
Url: api.GoStr(cookie.url),
Name: api.GoStr(cookie.name),
Value: api.GoStr(cookie.value),
Domain: api.GoStr(cookie.domain),
Path: api.GoStr(cookie.path),
2022-10-04 22:34:57 +08:00
Secure: *(*bool)(GetParamPtr(cookie.secure, 0)),
Httponly: *(*bool)(GetParamPtr(cookie.httponly, 0)),
HasExpires: *(*bool)(GetParamPtr(cookie.hasExpires, 0)),
2022-10-04 13:21:05 +08:00
Creation: DDateTimeToGoDateTime(creation),
LastAccess: DDateTimeToGoDateTime(lastAccess),
Expires: DDateTimeToGoDateTime(expires),
Count: int32(cookie.count),
Total: int32(cookie.total),
ID: int32(cookie.aID),
SameSite: TCefCookieSameSite(cookie.sameSite),
Priority: TCefCookiePriority(cookie.priority),
2022-10-04 22:34:57 +08:00
SetImmediately: *(*bool)(GetParamPtr(cookie.aSetImmediately, 0)),
DeleteCookie: *(*bool)(GetParamPtr(cookie.aDeleteCookie, 0)),
Result: *(*bool)(GetParamPtr(cookie.aResult, 0)),
2022-10-04 13:21:05 +08:00
}
fn.(ChromiumEventOnCookiesVisited)(lcl.AsObject(getVal(0)), iCookie)
case ChromiumEventOnCookieVisitorDestroyed:
id := int32(getVal(1))
fn.(ChromiumEventOnCookieVisitorDestroyed)(lcl.AsObject(getVal(0)), id)
//cookie end
//--- other
case ChromiumEventOnScrollOffsetChanged:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
fn.(ChromiumEventOnScrollOffsetChanged)(lcl.AsObject(sender), browser, float64(getVal(2)), float64(getVal(2)))
case ChromiumEventOnRenderProcessTerminated:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
fn.(ChromiumEventOnRenderProcessTerminated)(lcl.AsObject(sender), browser, TCefTerminationStatus(getVal(2)))
case ChromiumEventOnRenderCompMsg:
message := *(*types.TMessage)(getPtr(1))
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnRenderCompMsg)(lcl.AsObject(getVal(0)), message, api.GoBool(getVal(2)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnCefBrowser:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
fn.(ChromiumEventOnCefBrowser)(lcl.AsObject(sender), browser)
case ChromiumEventOnTitleChange:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnTitleChange)(lcl.AsObject(sender), browser, api.GoStr(getVal(2)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnKeyEvent:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
keyEvent := (*TCefKeyEvent)(getPtr(2))
fn.(ChromiumEventOnKeyEvent)(lcl.AsObject(sender), browser, keyEvent, (*bool)(getPtr(3)))
case ChromiumEventOnFullScreenModeChange:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnFullScreenModeChange)(lcl.AsObject(sender), browser, api.GoBool(getVal(2)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnBeforeBrowser: //创建浏览器之前
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
chromiumOnBeforeBrowser(browser, frame)
var result = (*bool)(getPtr(3))
*result = fn.(ChromiumEventOnBeforeBrowser)(lcl.AsObject(sender), browser, frame)
2022-10-25 12:38:06 +08:00
case ChromiumEventOnAddressChange: //创建浏览器之前
sender := getPtr(0)
2022-10-25 12:38:06 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-25 12:38:06 +08:00
}
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnAddressChange)(lcl.AsObject(sender), browser, frame, api.GoStr(getVal(3)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnAfterCreated: //创建浏览器之后
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
//事件处理函数返回true将不继续执行
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
if chromiumOnAfterCreate(browser) {
return true
}
fn.(ChromiumEventOnAfterCreated)(lcl.AsObject(sender), browser)
case ChromiumEventOnBeforeClose: //关闭浏览器之前
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
chromiumOnBeforeClose(browser)
fn.(ChromiumEventOnBeforeClose)(lcl.AsObject(sender), browser)
case ChromiumEventOnClose:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
chromiumOnClose(browser)
fn.(ChromiumEventOnClose)(lcl.AsObject(sender), browser, (*TCefCloseBrowsesAction)(getPtr(2)))
case ChromiumEventOnResult: //通用Result bool事件
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnResult)(lcl.AsObject(getVal(0)), api.GoBool(getVal(1)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnResultFloat: //通用Result float事件
fn.(ChromiumEventOnResultFloat)(lcl.AsObject(getVal(0)), *(*float64)(getPtr(1)))
case ChromiumEventOnLoadStart:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
BrowserWindow.putBrowserFrame(browser, frame)
fn.(ChromiumEventOnLoadStart)(lcl.AsObject(sender), browser, frame)
case ChromiumEventOnLoadingStateChange:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
BrowserWindow.putBrowserFrame(browser, nil)
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnLoadingStateChange)(lcl.AsObject(sender), browser, api.GoBool(getVal(2)),
api.GoBool(getVal(3)), api.GoBool(getVal(4)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnLoadingProgressChange:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
fn.(ChromiumEventOnLoadingProgressChange)(lcl.AsObject(sender), browser, *(*float64)(getPtr(2)))
case ChromiumEventOnLoadError:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnLoadError)(lcl.AsObject(sender), browser, frame, CEF_NET_ERROR(getVal(3)), api.GoStr(getVal(4)), api.GoStr(getVal(5)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnLoadEnd:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
fn.(ChromiumEventOnLoadEnd)(lcl.AsObject(sender), browser, frame, int32(getVal(3)))
case ChromiumEventOnBeforeDownload: //下载之前
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
item := (*downloadItem)(getPtr(2))
downItem := &DownloadItem{
Id: int32(item.Id),
CurrentSpeed: int64(item.CurrentSpeed),
PercentComplete: int32(item.PercentComplete),
TotalBytes: int64(item.TotalBytes),
ReceivedBytes: int64(item.ReceivedBytes),
2022-10-04 22:34:57 +08:00
StartTime: DDateTimeToGoDateTime(*(*float64)(GetParamPtr(item.StartTime, 0))),
EndTime: DDateTimeToGoDateTime(*(*float64)(GetParamPtr(item.EndTime, 0))),
2022-12-03 21:56:51 +08:00
FullPath: api.GoStr(item.FullPath),
Url: api.GoStr(item.Url),
OriginalUrl: api.GoStr(item.OriginalUrl),
SuggestedFileName: api.GoStr(item.SuggestedFileName),
ContentDisposition: api.GoStr(item.ContentDisposition),
MimeType: api.GoStr(item.MimeType),
2022-10-04 13:21:05 +08:00
IsValid: *(*bool)(unsafe.Pointer(item.IsValid)),
State: int32(item.State),
}
2022-12-03 21:56:51 +08:00
suggestedName := api.GoStr(getVal(3))
2022-10-04 13:21:05 +08:00
instance, ptr = getInstance(getVal(4))
callback := &ICefBeforeDownloadCallback{
instance: instance, ptr: ptr,
browseId: browser.Identifier(),
downId: downItem.Id,
}
fn.(ChromiumEventOnBeforeDownload)(lcl.AsObject(sender), browser, downItem, suggestedName, callback)
case ChromiumEventOnDownloadUpdated: //下载更新
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
item := *(*downloadItem)(getPtr(2))
downItem := &DownloadItem{
Id: int32(item.Id),
CurrentSpeed: int64(item.CurrentSpeed),
PercentComplete: int32(item.PercentComplete),
TotalBytes: int64(item.TotalBytes),
ReceivedBytes: int64(item.ReceivedBytes),
2022-10-04 22:34:57 +08:00
StartTime: DDateTimeToGoDateTime(*(*float64)(GetParamPtr(item.StartTime, 0))),
EndTime: DDateTimeToGoDateTime(*(*float64)(GetParamPtr(item.EndTime, 0))),
2022-12-03 21:56:51 +08:00
FullPath: api.GoStr(item.FullPath),
Url: api.GoStr(item.Url),
OriginalUrl: api.GoStr(item.OriginalUrl),
SuggestedFileName: api.GoStr(item.SuggestedFileName),
ContentDisposition: api.GoStr(item.ContentDisposition),
MimeType: api.GoStr(item.MimeType),
2022-10-04 13:21:05 +08:00
IsValid: *(*bool)(unsafe.Pointer(item.IsValid)),
State: int32(item.State),
}
instance, ptr = getInstance(getVal(3))
callback := &ICefDownloadItemCallback{
instance: instance, ptr: ptr,
browseId: browser.Identifier(),
downId: downItem.Id,
}
fn.(ChromiumEventOnDownloadUpdated)(lcl.AsObject(sender), browser, downItem, callback)
//frame
case ChromiumEventOnFrameAttached:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
2022-12-03 21:56:51 +08:00
fn.(ChromiumEventOnFrameAttached)(lcl.AsObject(sender), browser, frame, api.GoBool(getVal(3)))
2022-10-04 13:21:05 +08:00
case ChromiumEventOnFrameCreated:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
2022-10-04 13:21:05 +08:00
}
fn.(ChromiumEventOnFrameCreated)(lcl.AsObject(sender), browser, frame)
case ChromiumEventOnFrameDetached:
sender := getVal(0)
browser := &ICefBrowser{browseId: int32(getVal(1))}
tempFrame := (*cefFrame)(getPtr(2))
frame := &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempFrame.Name),
Url: api.GoStr(tempFrame.Url),
Id: StrToInt64(api.GoStr(tempFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
chromiumOnFrameDetached(browser, frame)
fn.(ChromiumEventOnFrameDetached)(lcl.AsObject(sender), browser, frame)
case ChromiumEventOnMainFrameChanged:
sender := getPtr(0)
2022-10-04 13:21:05 +08:00
browser := &ICefBrowser{browseId: int32(getVal(1)), chromium: sender}
var (
oldFrame *ICefFrame = nil
newFrame *ICefFrame = nil
)
tempOldFrame := (*cefFrame)(getPtr(2))
if tempOldFrame != nil {
oldFrame = &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempOldFrame.Name),
Url: api.GoStr(tempOldFrame.Url),
Id: StrToInt64(api.GoStr(tempOldFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
}
tempNewFrame := (*cefFrame)(getPtr(3))
if tempNewFrame != nil {
newFrame = &ICefFrame{
Browser: browser,
2022-12-03 21:56:51 +08:00
Name: api.GoStr(tempNewFrame.Name),
Url: api.GoStr(tempNewFrame.Url),
Id: StrToInt64(api.GoStr(tempNewFrame.Identifier)),
2022-10-04 13:21:05 +08:00
}
}
chromiumOnMainFrameChanged(browser, oldFrame, newFrame)
fn.(ChromiumEventOnMainFrameChanged)(lcl.AsObject(sender), browser, oldFrame, newFrame)
//windowParent popup
case ChromiumEventOnBeforePopup:
chromiumOnBeforePopup(fn.(ChromiumEventOnBeforePopup), getVal)
//windowParent open url from tab
case ChromiumEventOnOpenUrlFromTab:
default:
return false
}
return true
})
}
func getInstance(value interface{}) (uintptr, unsafe.Pointer) {
var ptr uintptr
switch value.(type) {
case uintptr:
ptr = value.(uintptr)
case unsafe.Pointer:
ptr = uintptr(value.(unsafe.Pointer))
case lcl.IObject:
ptr = lcl.CheckPtr(value)
default:
ptr = getUIntPtr(value)
}
return ptr, unsafe.Pointer(ptr)
}
func getUIntPtr(v interface{}) uintptr {
switch v.(type) {
case int:
return uintptr(v.(int))
case uint:
return uintptr(v.(uint))
case int8:
return uintptr(v.(int8))
case uint8:
return uintptr(v.(uint8))
case int16:
return uintptr(v.(int16))
case uint16:
return uintptr(v.(uint16))
case int32:
return uintptr(v.(int32))
case uint32:
return uintptr(v.(uint32))
case int64:
return uintptr(v.(int64))
case uint64:
return uintptr(v.(uint64))
}
return 0
}