2023-02-25 19:13:07 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
//CEF v8 对象拦截器 V8InterceptorRef.New
|
|
|
|
//
|
|
|
|
// ICefV8Value
|
2023-02-25 20:09:57 +08:00
|
|
|
//
|
|
|
|
// TODO 未使用
|
2023-06-01 10:15:20 +08:00
|
|
|
|
2023-02-23 14:34:23 +08:00
|
|
|
package cef
|
|
|
|
|
2023-02-23 19:23:17 +08:00
|
|
|
import (
|
2023-06-11 00:10:55 +08:00
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports"
|
2023-02-23 19:23:17 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2023-02-25 19:13:07 +08:00
|
|
|
// V8InterceptorGetByName 拦截函数 根据name获取一个值
|
2023-03-14 11:06:08 +08:00
|
|
|
type V8InterceptorGetByName func(name string, object, retVal *ICefV8Value, exception *ResultString)
|
2023-02-25 19:13:07 +08:00
|
|
|
|
|
|
|
// V8InterceptorGetByIndex 拦截函数 根据index获取一个值
|
2023-03-14 11:06:08 +08:00
|
|
|
type V8InterceptorGetByIndex func(index int32, object, retVal *ICefV8Value, exception *ResultString)
|
2023-02-25 19:13:07 +08:00
|
|
|
|
|
|
|
// V8InterceptorSetByName 拦截函数 根据name设置一个值
|
2023-03-14 11:06:08 +08:00
|
|
|
type V8InterceptorSetByName func(name string, object, value *ICefV8Value, exception *ResultString)
|
2023-02-25 19:13:07 +08:00
|
|
|
|
|
|
|
// V8InterceptorSetByIndex 拦截函数 根据index设置一个值
|
2023-03-14 11:06:08 +08:00
|
|
|
type V8InterceptorSetByIndex func(index int32, object, value *ICefV8Value, exception *ResultString)
|
2023-02-23 19:23:17 +08:00
|
|
|
|
2023-02-25 12:01:31 +08:00
|
|
|
//V8InterceptorRef -> ICefV8Interceptor
|
|
|
|
var V8InterceptorRef cefV8Interceptor
|
|
|
|
|
|
|
|
//cefV8Interceptor
|
|
|
|
type cefV8Interceptor uintptr
|
|
|
|
|
|
|
|
func (*cefV8Interceptor) New() *ICefV8Interceptor {
|
2023-02-23 19:23:17 +08:00
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8InterceptorRef_Create).Call(uintptr(unsafe.Pointer(&result)))
|
2023-02-23 19:23:17 +08:00
|
|
|
return &ICefV8Interceptor{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-23 14:34:23 +08:00
|
|
|
// Instance 实例
|
|
|
|
func (m *ICefV8Interceptor) Instance() uintptr {
|
|
|
|
if m == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return uintptr(m.instance)
|
|
|
|
}
|
2023-02-23 19:23:17 +08:00
|
|
|
|
2023-02-25 19:13:07 +08:00
|
|
|
// GetByName 拦截函数 根据name获取一个值
|
2023-02-23 19:23:17 +08:00
|
|
|
func (m *ICefV8Interceptor) GetByName(fn V8InterceptorGetByName) {
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Interceptor_GetByName).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-02-23 19:23:17 +08:00
|
|
|
}
|
2023-02-25 19:13:07 +08:00
|
|
|
|
|
|
|
// GetByIndex 拦截函数 根据index获取一个值
|
2023-02-23 19:23:17 +08:00
|
|
|
func (m *ICefV8Interceptor) GetByIndex(fn V8InterceptorGetByIndex) {
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Interceptor_GetByIndex).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-02-23 19:23:17 +08:00
|
|
|
}
|
2023-02-25 19:13:07 +08:00
|
|
|
|
|
|
|
// SetByName 拦截函数 根据name设置一个值
|
2023-02-23 19:23:17 +08:00
|
|
|
func (m *ICefV8Interceptor) SetByName(fn V8InterceptorSetByName) {
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Interceptor_SetByName).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-02-23 19:23:17 +08:00
|
|
|
}
|
2023-02-25 19:13:07 +08:00
|
|
|
|
|
|
|
// SetByIndex 拦截函数 根据index设置一个值
|
2023-02-23 19:23:17 +08:00
|
|
|
func (m *ICefV8Interceptor) SetByIndex(fn V8InterceptorSetByIndex) {
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Interceptor_SetByIndex).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-02-23 19:23:17 +08:00
|
|
|
}
|
2023-02-25 19:13:07 +08:00
|
|
|
|
|
|
|
// Destroy 销毁这个拦截器
|
2023-02-24 10:12:55 +08:00
|
|
|
func (m *ICefV8Interceptor) Destroy() {
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Interceptor_Destroy).Call(m.Instance())
|
2023-02-23 19:23:17 +08:00
|
|
|
}
|
|
|
|
|
2023-02-25 20:09:57 +08:00
|
|
|
//func init() {
|
|
|
|
// lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
|
|
|
|
// //getPtr := func(i int) unsafe.Pointer {
|
|
|
|
// // return unsafe.Pointer(getVal(i))
|
|
|
|
// //}
|
|
|
|
// switch fn.(type) {
|
|
|
|
// case V8InterceptorGetByName:
|
|
|
|
// case V8InterceptorGetByIndex:
|
|
|
|
// case V8InterceptorSetByName:
|
|
|
|
// case V8InterceptorSetByIndex:
|
|
|
|
// default:
|
|
|
|
// return false
|
|
|
|
// }
|
|
|
|
// return true
|
|
|
|
// })
|
|
|
|
//}
|