forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcefLifeSpanHandler.go
133 lines (108 loc) · 3.43 KB
/
cefLifeSpanHandler.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
// Copyright (c) 2014 The cefcapi authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/fromkeith/cefcapi
package cef2go
/*
#include <stdlib.h>
#include "cefBase.h"
#include "include/capi/cef_client_capi.h"
#include "include/capi/cef_life_span_handler_capi.h"
extern void initialize_life_span_handler(struct _cef_life_span_handler_t* lifeHandler);
*/
import "C"
import (
"unsafe"
)
var (
lifeSpanHandlerMap = make(map[unsafe.Pointer]LifeSpanHandler)
)
type LifeSpanHandler interface {
OnAfterCreated(browser CefBrowserT)
RunModal(browser CefBrowserT) int
DoClose(browser CefBrowserT) int
BeforeClose(browser CefBrowserT)
GetLifeSpanHandlerT() LifeSpanHandlerT
}
type LifeSpanHandlerT struct {
CStruct *C.struct__cef_life_span_handler_t
}
func (r LifeSpanHandlerT) AddRef() {
AddRef(unsafe.Pointer(r.CStruct))
}
func (r LifeSpanHandlerT) Release() {
Release(unsafe.Pointer(r.CStruct))
}
//export go_OnBeforePopup
func go_OnBeforePopup(
self * C.struct__cef_life_span_handler_t,
browser * C.struct__cef_browser_t,
frame * C.struct__cef_frame_t,
target_url *C.cef_string_t,
target_frame_name *C.cef_string_t,
popupFeatures * C.struct__cef_popup_features_t,
windowInfo * C.struct__cef_window_info_t,
client ** C.struct__cef_client_t,
settings * C.struct__cef_browser_settings_t,
no_javascript_access * C.int) int {
C.releaseVoid(unsafe.Pointer(browser))
C.releaseVoid(unsafe.Pointer(frame))
C.releaseVoid(unsafe.Pointer(popupFeatures))
C.releaseVoid(unsafe.Pointer(windowInfo))
//C.releaseVoid(unsafe.Pointer(client))
C.releaseVoid(unsafe.Pointer(settings))
return 1
}
//export go_OnAfterCreated
func go_OnAfterCreated(
self *C.struct__cef_life_span_handler_t,
browser *C.struct__cef_browser_t) {
b := CefBrowserT{browser}
if handler, ok := lifeSpanHandlerMap[unsafe.Pointer(self)]; ok {
handler.OnAfterCreated(b)
return
}
b.Release()
}
//export go_RunModal
func go_RunModal(
self *C.struct__cef_life_span_handler_t,
browser *C.struct__cef_browser_t) int {
b := CefBrowserT{browser}
if handler, ok := lifeSpanHandlerMap[unsafe.Pointer(self)]; ok {
return handler.RunModal(b)
}
b.Release()
return 0
}
//export go_DoClose
func go_DoClose(
self *C.struct__cef_life_span_handler_t,
browser *C.struct__cef_browser_t) int {
b := CefBrowserT{browser}
if handler, ok := lifeSpanHandlerMap[unsafe.Pointer(self)]; ok {
return handler.DoClose(b)
}
b.Release()
return 0
}
//export go_BeforeClose
func go_BeforeClose(
self *C.struct__cef_life_span_handler_t,
browser *C.struct__cef_browser_t) {
b := CefBrowserT{browser}
if handler, ok := lifeSpanHandlerMap[unsafe.Pointer(self)]; ok {
handler.BeforeClose(b)
return
}
b.Release()
}
func NewLifeSpanHandlerT(life LifeSpanHandler) LifeSpanHandlerT {
var handler LifeSpanHandlerT
handler.CStruct = (*C.struct__cef_life_span_handler_t)(
C.calloc(1, C.sizeof_struct__cef_life_span_handler_t))
C.initialize_life_span_handler(handler.CStruct)
go_AddRef(unsafe.Pointer(handler.CStruct))
Logger.Infof("_LifespanHandler: %x\n", unsafe.Pointer(handler.CStruct))
lifeSpanHandlerMap[unsafe.Pointer(handler.CStruct)] = life
return handler
}