-
Notifications
You must be signed in to change notification settings - Fork 2
/
MiniblinkBrowser.go
171 lines (144 loc) · 4.45 KB
/
MiniblinkBrowser.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
package GoMiniblink
import (
"image"
url2 "net/url"
"reflect"
"strings"
cs "github.com/hujun528/GoMiniblink/forms/controls"
)
type MiniblinkBrowser struct {
cs.Control
core Miniblink
fnlist map[string]reflect.Value
EvRequestBefore map[string]func(sender *MiniblinkBrowser, e RequestBeforeEvArgs)
OnRequestBefore func(e RequestBeforeEvArgs)
EvJsReady map[string]func(sender *MiniblinkBrowser, e JsReadyEvArgs)
OnJsReady func(e JsReadyEvArgs)
EvConsole map[string]func(sender *MiniblinkBrowser, e ConsoleEvArgs)
OnConsole func(e ConsoleEvArgs)
EvDocumentReady map[string]func(sender *MiniblinkBrowser, e DocumentReadyEvArgs)
OnDocumentReady func(e DocumentReadyEvArgs)
EvPaintUpdated map[string]func(sender *MiniblinkBrowser, e PaintUpdatedEvArgs)
OnPaintUpdated func(e PaintUpdatedEvArgs)
ResourceLoader []LoadResource
}
func (_this *MiniblinkBrowser) Init() *MiniblinkBrowser {
_this.Control.Init()
_this.EvRequestBefore = make(map[string]func(*MiniblinkBrowser, RequestBeforeEvArgs))
_this.EvJsReady = make(map[string]func(*MiniblinkBrowser, JsReadyEvArgs))
_this.EvConsole = make(map[string]func(*MiniblinkBrowser, ConsoleEvArgs))
_this.EvDocumentReady = make(map[string]func(*MiniblinkBrowser, DocumentReadyEvArgs))
_this.OnRequestBefore = _this.defOnRequestBefore
_this.OnJsReady = _this.defOnJsReady
_this.OnConsole = _this.defOnConsole
_this.OnDocumentReady = _this.defOnDocumentReady
_this.OnPaintUpdated = _this.defOnPaintUpdated
_this.EvRequestBefore["__goMiniblink"] = _this.loadRes
_this.EvDestroy["__goMiniblink"] = _this.onClosed
_this.core = new(freeMiniblink).init(&_this.Control)
_this.mbInit()
return _this
}
func (_this *MiniblinkBrowser) onClosed(_ cs.GUI) {
destroyWebView(_this.core.GetHandle())
}
func (_this *MiniblinkBrowser) loadRes(_ *MiniblinkBrowser, e RequestBeforeEvArgs) {
if len(_this.ResourceLoader) == 0 {
return
}
url, err := url2.Parse(e.Url())
if err != nil {
return
}
host := strings.ToLower(url.Host)
for i := range _this.ResourceLoader {
loader := _this.ResourceLoader[i]
if strings.HasPrefix(strings.ToLower(loader.Domain()), host) == false {
continue
}
data := loader.ByUri(url)
if data != nil {
e.SetData(data)
break
}
}
}
func (_this *MiniblinkBrowser) mbInit() {
_this.core.SetOnRequestBefore(func(args RequestBeforeEvArgs) {
if _this.OnRequestBefore != nil {
_this.OnRequestBefore(args)
}
})
_this.core.SetOnJsReady(func(args JsReadyEvArgs) {
if _this.OnJsReady != nil {
_this.OnJsReady(args)
}
})
_this.core.SetOnConsole(func(args ConsoleEvArgs) {
if _this.OnConsole != nil {
_this.OnConsole(args)
}
})
_this.core.SetOnDocumentReady(func(args DocumentReadyEvArgs) {
if _this.OnDocumentReady != nil {
_this.OnDocumentReady(args)
}
})
_this.core.SetOnPaintUpdated(func(args PaintUpdatedEvArgs) {
if _this.OnPaintUpdated != nil {
_this.OnPaintUpdated(args)
}
})
}
func (_this *MiniblinkBrowser) SetProxy(info ProxyInfo) {
_this.core.SetProxy(info)
}
func (_this *MiniblinkBrowser) LoadUri(uri string) {
_this.core.LoadUri(uri)
}
func (_this *MiniblinkBrowser) WkeRunMessageLoop() {
_this.core.WkeRunMessageLoop()
}
func (_this *MiniblinkBrowser) SetDebugConfig(debugString string, param string) {
_this.core.SetDebugConfig(debugString, param)
}
func (_this *MiniblinkBrowser) JsFunc(name string, fn GoFn, state interface{}) {
_this.core.JsFunc(name, fn, state)
}
func (_this *MiniblinkBrowser) JsFuncEx(name string, fn interface{}) {
p := reflect.TypeOf(fn)
if p.Kind() != reflect.Func {
return
}
_this.JsFunc(name, func(ctx GoFnContext) interface{} {
rt := reflect.TypeOf(ctx.State)
rv := reflect.ValueOf(ctx.State)
var args []reflect.Value
for i := 0; i < rt.NumIn() && i < len(ctx.Param); i++ {
args = append(args, reflect.ValueOf(ctx.Param[i]))
}
rs := rv.Call(args)
if rt.NumOut() > 0 {
return rs[0].Interface()
}
return nil
}, fn)
}
func (_this *MiniblinkBrowser) CallJsFunc(name string, param ...interface{}) interface{} {
return _this.core.CallJsFunc(name, param)
}
func (_this *MiniblinkBrowser) ToBitmap() *image.RGBA {
return _this.core.ToBitmap()
}
func (_this *MiniblinkBrowser) GetMiniblinkHandle() uintptr {
return uintptr(_this.core.GetHandle())
}
func (_this *MiniblinkBrowser) MouseIsEnable() bool {
return _this.core.MouseIsEnable()
}
func (_this *MiniblinkBrowser) MouseEnable(b bool) {
_this.core.MouseEnable(b)
}
func (_this *MiniblinkBrowser) SetBmpPaintMode(b bool) {
_this.core.SetBmpPaintMode(b)
}