forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
clientHandler.go
226 lines (197 loc) · 6.54 KB
/
clientHandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
// Copyright (c) 2014 The cef2go authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/fromkeith/cef2go
// Website: https://github.com/CzarekTomczak/cef2go
package cef2go
/*
#include <stdlib.h>
#include "include/capi/cef_client_capi.h"
extern void initialize_client_handler(struct _cef_client_t* client);
*/
import "C"
import (
// "fmt"
"unsafe"
)
var (
clientHandlerMap = make(map[unsafe.Pointer]ClientHandler)
)
type ClientHandlerT struct {
CStruct *C.struct__cef_client_t
}
func (c ClientHandlerT) AddRef() {
AddRef(unsafe.Pointer(c.CStruct))
}
func (c ClientHandlerT) Release() {
Release(unsafe.Pointer(c.CStruct))
}
type ClientHandler interface {
GetContextMenuHandler() ContextMenuHandlerT
GetDialogHandler() DialogHandlerT
GetDisplayHandler() DisplayHandler
GetDownloadHandler() DownloadHandler
GetDragHandler() DragHandlerT
GetFocusHandler() FocusHandlerT
GetGeoLocationHandler() GeolocationHandlerT
GetJsDialogHandler() JsdialogHandlerT
GetKeyboardHandler() KeyboardHandlerT
GetLifeSpanHandler() LifeSpanHandler
GetLoadHandler() LoadHandlerT
GetRenderHandler() RenderHandlerT
GetRequestHandler() RequestHandler
GetClientHandlerT() ClientHandlerT
}
// these structs haven't been defined yet
type ContextMenuHandlerT struct {
CStruct *C.struct__cef_context_menu_handler_t
}
type DialogHandlerT struct {
CStruct *C.struct__cef_dialog_handler_t
}
type DragHandlerT struct {
CStruct *C.struct__cef_drag_handler_t
}
type FocusHandlerT struct {
CStruct *C.struct__cef_focus_handler_t
}
type GeolocationHandlerT struct {
CStruct *C.struct__cef_geolocation_handler_t
}
type JsdialogHandlerT struct {
CStruct *C.struct__cef_jsdialog_handler_t
}
type KeyboardHandlerT struct {
CStruct *C.struct__cef_keyboard_handler_t
}
type LoadHandlerT struct {
CStruct *C.struct__cef_load_handler_t
}
type RenderHandlerT struct {
CStruct *C.struct__cef_render_handler_t
}
//export go_GetContextMenuHandler
func go_GetContextMenuHandler(self *C.struct__cef_client_t) *C.struct__cef_context_menu_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetContextMenuHandler()
return res.CStruct
}
return nil
}
//export go_GetDialogHandler
func go_GetDialogHandler(self *C.struct__cef_client_t) *C.struct__cef_dialog_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetDialogHandler()
return res.CStruct
}
return nil
}
//export go_GetDisplayHandler
func go_GetDisplayHandler(self *C.struct__cef_client_t) *C.struct__cef_display_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetDisplayHandler()
if res != nil {
res.GetDisplayHandlerT().AddRef()
return res.GetDisplayHandlerT().CStruct
}
}
return nil
}
//export go_GetDownloadHandler
func go_GetDownloadHandler(self *C.struct__cef_client_t) *C.struct__cef_download_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetDownloadHandler()
if res != nil {
res.GetDownloadHandlerT().AddRef()
return res.GetDownloadHandlerT().CStruct
}
}
return nil
}
//export go_GetDragHandler
func go_GetDragHandler(self *C.struct__cef_client_t) *C.struct__cef_drag_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetDragHandler()
return res.CStruct
}
return nil
}
//export go_GetFocusHandler
func go_GetFocusHandler(self *C.struct__cef_client_t) *C.struct__cef_focus_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetFocusHandler()
return res.CStruct
}
return nil
}
//export go_GetGeoLocationHandler
func go_GetGeoLocationHandler(self *C.struct__cef_client_t) *C.struct__cef_geolocation_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetGeoLocationHandler()
return res.CStruct
}
return nil
}
//export go_GetJsDialogHandler
func go_GetJsDialogHandler(self *C.struct__cef_client_t) *C.struct__cef_jsdialog_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetJsDialogHandler()
return res.CStruct
}
return nil
}
//export go_GetKeyboardHandler
func go_GetKeyboardHandler(self *C.struct__cef_client_t) *C.struct__cef_keyboard_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetKeyboardHandler()
return res.CStruct
}
return nil
}
//export go_GetLifespanHandler
func go_GetLifespanHandler(self *C.struct__cef_client_t) *C.struct__cef_life_span_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetLifeSpanHandler()
if res != nil {
res.GetLifeSpanHandlerT().AddRef()
return res.GetLifeSpanHandlerT().CStruct
}
}
return nil
}
//export go_GetLoadHandler
func go_GetLoadHandler(self *C.struct__cef_client_t) *C.struct__cef_load_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetLoadHandler()
return res.CStruct
}
return nil
}
//export go_GetRenderHandler
func go_GetRenderHandler(self *C.struct__cef_client_t) *C.struct__cef_render_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetRenderHandler()
return res.CStruct
}
return nil
}
//export go_GetRequestHandler
func go_GetRequestHandler(self *C.struct__cef_client_t) *C.struct__cef_request_handler_t {
if handler, ok := clientHandlerMap[unsafe.Pointer(self)]; ok {
res := handler.GetRequestHandler()
if res != nil {
res.GetRequestHandlerT().AddRef()
return res.GetRequestHandlerT().CStruct
}
}
return nil
}
func NewClientHandlerT(handler ClientHandler) ClientHandlerT {
var c ClientHandlerT
c.CStruct = (*C.struct__cef_client_t)(
C.calloc(1, C.sizeof_struct__cef_client_t))
C.initialize_client_handler(c.CStruct)
go_AddRef(unsafe.Pointer(c.CStruct))
Logger.Infof("_ClientHandler: %x", unsafe.Pointer(c.CStruct))
clientHandlerMap[unsafe.Pointer(c.CStruct)] = handler
return c
}