types-v8-interceptor.go 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
//----------------------------------------
//
// 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
14 15
//
// TODO 未使用
16

yanghye's avatar
yanghye 已提交
17 18
package cef

yanghye's avatar
yanghye 已提交
19
import (
yanghye's avatar
yanghye 已提交
20
	"github.com/energye/energy/v2/common/imports"
yanghye's avatar
yanghye 已提交
21 22 23 24
	"github.com/energye/golcl/lcl/api"
	"unsafe"
)

25
// V8InterceptorGetByName 拦截函数 根据name获取一个值
yanghye's avatar
yanghye 已提交
26
type V8InterceptorGetByName func(name string, object, retVal *ICefV8Value, exception *ResultString)
27 28

// V8InterceptorGetByIndex 拦截函数 根据index获取一个值
yanghye's avatar
yanghye 已提交
29
type V8InterceptorGetByIndex func(index int32, object, retVal *ICefV8Value, exception *ResultString)
30 31

// V8InterceptorSetByName 拦截函数 根据name设置一个值
yanghye's avatar
yanghye 已提交
32
type V8InterceptorSetByName func(name string, object, value *ICefV8Value, exception *ResultString)
33 34

// V8InterceptorSetByIndex 拦截函数 根据index设置一个值
yanghye's avatar
yanghye 已提交
35
type V8InterceptorSetByIndex func(index int32, object, value *ICefV8Value, exception *ResultString)
yanghye's avatar
yanghye 已提交
36

37 38 39 40 41 42 43
//V8InterceptorRef -> ICefV8Interceptor
var V8InterceptorRef cefV8Interceptor

//cefV8Interceptor
type cefV8Interceptor uintptr

func (*cefV8Interceptor) New() *ICefV8Interceptor {
yanghye's avatar
yanghye 已提交
44 45 46 47 48 49 50
	var result uintptr
	imports.Proc(internale_CefV8InterceptorRef_Create).Call(uintptr(unsafe.Pointer(&result)))
	return &ICefV8Interceptor{
		instance: unsafe.Pointer(result),
	}
}

yanghye's avatar
yanghye 已提交
51 52 53 54 55 56 57
// Instance 实例
func (m *ICefV8Interceptor) Instance() uintptr {
	if m == nil {
		return 0
	}
	return uintptr(m.instance)
}
yanghye's avatar
yanghye 已提交
58

59
// GetByName 拦截函数 根据name获取一个值
yanghye's avatar
yanghye 已提交
60
func (m *ICefV8Interceptor) GetByName(fn V8InterceptorGetByName) {
61
	imports.Proc(internale_CefV8Interceptor_GetByName).Call(m.Instance(), api.MakeEventDataPtr(fn))
yanghye's avatar
yanghye 已提交
62
}
63 64

// GetByIndex 拦截函数 根据index获取一个值
yanghye's avatar
yanghye 已提交
65
func (m *ICefV8Interceptor) GetByIndex(fn V8InterceptorGetByIndex) {
66
	imports.Proc(internale_CefV8Interceptor_GetByIndex).Call(m.Instance(), api.MakeEventDataPtr(fn))
yanghye's avatar
yanghye 已提交
67
}
68 69

// SetByName 拦截函数 根据name设置一个值
yanghye's avatar
yanghye 已提交
70
func (m *ICefV8Interceptor) SetByName(fn V8InterceptorSetByName) {
71
	imports.Proc(internale_CefV8Interceptor_SetByName).Call(m.Instance(), api.MakeEventDataPtr(fn))
yanghye's avatar
yanghye 已提交
72
}
73 74

// SetByIndex 拦截函数 根据index设置一个值
yanghye's avatar
yanghye 已提交
75
func (m *ICefV8Interceptor) SetByIndex(fn V8InterceptorSetByIndex) {
76
	imports.Proc(internale_CefV8Interceptor_SetByIndex).Call(m.Instance(), api.MakeEventDataPtr(fn))
yanghye's avatar
yanghye 已提交
77
}
78 79

// Destroy 销毁这个拦截器
yanghye's avatar
yanghye 已提交
80
func (m *ICefV8Interceptor) Destroy() {
81
	imports.Proc(internale_CefV8Interceptor_Destroy).Call(m.Instance())
yanghye's avatar
yanghye 已提交
82 83
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
//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
//	})
//}