forked from Aquietorange/GoMiniblink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiniblinkBrowser_Events.go
More file actions
393 lines (332 loc) · 8.84 KB
/
MiniblinkBrowser_Events.go
File metadata and controls
393 lines (332 loc) · 8.84 KB
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
package GoMiniblink
import (
"image"
"strconv"
"github.com/hujun528/GoMiniblink/forms"
)
type PaintUpdatedEvArgs interface {
Bitmap() *image.RGBA
Bound() forms.Bound
Cancel()
IsCancel() bool
}
type freePaintUpdatedEvArgs struct {
bitmap *image.RGBA
bound forms.Bound
cancel bool
}
func (_this *freePaintUpdatedEvArgs) init(bitmap *image.RGBA, bound forms.Bound) *freePaintUpdatedEvArgs {
_this.bitmap = bitmap
_this.bound = bound
return _this
}
func (_this *freePaintUpdatedEvArgs) Bitmap() *image.RGBA {
return _this.bitmap
}
func (_this *freePaintUpdatedEvArgs) Bound() forms.Bound {
return _this.bound
}
func (_this *freePaintUpdatedEvArgs) IsCancel() bool {
return _this.cancel
}
func (_this *freePaintUpdatedEvArgs) Cancel() {
_this.cancel = true
}
type DocumentReadyEvArgs interface {
FrameContext
}
type freeDocumentReadyEvArgs struct {
*freeFrameContext
}
func (_this *freeDocumentReadyEvArgs) init(mb Miniblink, frame wkeFrame) *freeDocumentReadyEvArgs {
_this.freeFrameContext = new(freeFrameContext).init(mb, frame)
return _this
}
type FrameContext interface {
FrameId() uintptr
IsMain() bool
Url() string
IsRemote() bool
RunJs(script string) interface{}
}
type freeFrameContext struct {
id uintptr
isMain bool
url string
isRemote bool
core Miniblink
}
func (_this *freeFrameContext) init(mb Miniblink, frame wkeFrame) *freeFrameContext {
_this.core = mb
_this.id = uintptr(frame)
_this.isMain = mbApi.wkeIsMainFrame(_this.core.GetHandle(), frame)
_this.isRemote = mbApi.wkeIsWebRemoteFrame(_this.core.GetHandle(), frame)
_this.url = mbApi.wkeGetFrameUrl(_this.core.GetHandle(), frame)
return _this
}
func (_this *freeFrameContext) RunJs(script string) interface{} {
if len(script) > 0 {
es := mbApi.wkeGetGlobalExecByFrame(_this.core.GetHandle(), wkeFrame(_this.id))
rs := mbApi.jsEval(es, script)
return toGoValue(_this.core, es, rs)
}
return nil
}
func (_this *freeFrameContext) IsRemote() bool {
return _this.isRemote
}
func (_this *freeFrameContext) Url() string {
return _this.url
}
func (_this *freeFrameContext) IsMain() bool {
return _this.isMain
}
func (_this *freeFrameContext) FrameId() uintptr {
return _this.id
}
type ConsoleEvArgs interface {
Level() string
Message() string
SourceName() string
SourceLine() int
StackTrace() string
}
type freeConsoleMessageEvArgs struct {
level string
message string
name string
line int
stack string
}
func (_this *freeConsoleMessageEvArgs) init() *freeConsoleMessageEvArgs {
return _this
}
func (_this *freeConsoleMessageEvArgs) Level() string {
return _this.level
}
func (_this *freeConsoleMessageEvArgs) Message() string {
return _this.message
}
func (_this *freeConsoleMessageEvArgs) SourceName() string {
return _this.name
}
func (_this *freeConsoleMessageEvArgs) SourceLine() int {
return _this.line
}
func (_this *freeConsoleMessageEvArgs) StackTrace() string {
return _this.stack
}
type JsReadyEvArgs interface {
FrameContext
}
type wkeJsReadyEvArgs struct {
*freeFrameContext
}
func (_this *wkeJsReadyEvArgs) init(mb Miniblink, frame wkeFrame) *wkeJsReadyEvArgs {
_this.freeFrameContext = new(freeFrameContext).init(mb, frame)
return _this
}
type ResponseEvArgs interface {
RequestBefore() RequestBeforeEvArgs
ContentType() string
SetContentType(contentType string)
Data() []byte
SetData(data []byte)
Headers() map[string]string
}
type freeResponseEvArgs struct {
_req *freeRequestBeforeEvArgs
_data []byte
}
func (_this *freeResponseEvArgs) init(request *freeRequestBeforeEvArgs, data []byte) *freeResponseEvArgs {
_this._req = request
_this._data = data
return _this
}
func (_this *freeResponseEvArgs) Headers() map[string]string {
return mbApi.wkeNetGetRawResponseHead(_this._req._job)
}
func (_this *freeResponseEvArgs) SetData(data []byte) {
_this._data = data
mbApi.wkeNetSetData(_this._req._job, _this._data)
}
func (_this *freeResponseEvArgs) Data() []byte {
return _this._data
}
func (_this *freeResponseEvArgs) RequestBefore() RequestBeforeEvArgs {
return _this._req
}
func (_this *freeResponseEvArgs) ContentType() string {
return mbApi.wkeNetGetMIMEType(_this._req._job)
}
func (_this *freeResponseEvArgs) SetContentType(contentType string) {
mbApi.wkeNetSetMIMEType(_this._req._job, contentType)
}
type LoadFailEvArgs interface {
RequestBefore() RequestBeforeEvArgs
}
type freeLoadFailEvArgs struct {
_req *freeRequestBeforeEvArgs
}
func (_this *freeLoadFailEvArgs) init(request *freeRequestBeforeEvArgs) *freeLoadFailEvArgs {
_this._req = request
return _this
}
func (_this *freeLoadFailEvArgs) RequestBefore() RequestBeforeEvArgs {
return _this._req
}
type RequestBeforeEvArgs interface {
Url() string
Method() string
SetData([]byte)
Data() []byte
SetCancel(b bool)
ResetUrl(url string)
SetHeader(name, value string)
/**
内容最终呈现时触发
args:intf, ResponseEvArgs
*/
EvResponse() *EventDispatcher
/**
加载失败时触发
args:intf, LoadFailEvArgs
*/
EvLoadFail() *EventDispatcher
/**
请求流程全部完成时触发
args:intf, RequestBeforeEvArgs
*/
EvFinish() *EventDispatcher
}
type freeRequestBeforeEvArgs struct {
_wke Miniblink
_job wkeNetJob
_url string
_cancel bool
_data []byte
//1=发送之前,2=异步处理,3=已发送,4=收到真实数据,5=完成
_state int
_evResponseKey string
_evResponse *EventDispatcher
_evLoadFailKey string
_evLoadFail *EventDispatcher
_evFinishKey string
_evFinish *EventDispatcher
}
func (_this *freeRequestBeforeEvArgs) init(wke Miniblink, job wkeNetJob) *freeRequestBeforeEvArgs {
_this._wke = wke
_this._url = mbApi.wkeNetGetUrlByJob(job)
_this._job = job
_this._state = 1
_this._evResponseKey = "evResp" + strconv.FormatUint(uint64(job), 10)
_this._evResponse = new(EventDispatcher).Init(_this._evResponseKey)
_this._evLoadFailKey = "evFail" + strconv.FormatUint(uint64(job), 10)
_this._evLoadFail = new(EventDispatcher).Init(_this._evLoadFailKey)
_this._evFinishKey = "evFsh" + strconv.FormatUint(uint64(job), 10)
_this._evFinish = new(EventDispatcher).Init(_this._evFinishKey)
return _this
}
func (_this *freeRequestBeforeEvArgs) EvFinish() *EventDispatcher {
return _this._evFinish
}
func (_this *freeRequestBeforeEvArgs) EvLoadFail() *EventDispatcher {
return _this._evLoadFail
}
func (_this *freeRequestBeforeEvArgs) EvResponse() *EventDispatcher {
return _this._evResponse
}
func (_this *freeRequestBeforeEvArgs) ResetUrl(url string) {
mbApi.wkeNetChangeRequestUrl(_this._job, url)
_this._url = url
}
func (_this *freeRequestBeforeEvArgs) SetHeader(name, value string) {
mbApi.wkeNetSetHTTPHeaderField(_this._job, name, value)
}
func (_this *freeRequestBeforeEvArgs) SetData(data []byte) {
_this._data = data
}
func (_this *freeRequestBeforeEvArgs) Data() []byte {
return _this._data
}
func (_this *freeRequestBeforeEvArgs) Method() string {
t := mbApi.wkeNetGetRequestMethod(_this._job)
switch t {
case wkeRequestType_Get:
return "GET"
case wkeRequestType_Post:
return "POST"
case wkeRequestType_Put:
return "PUT"
default:
return "UNKNOW"
}
}
func (_this *freeRequestBeforeEvArgs) Url() string {
return _this._url
}
func (_this *freeRequestBeforeEvArgs) SetCancel(b bool) {
_this._cancel = b
}
func (_this *freeRequestBeforeEvArgs) onBegin() {
if _this._state == 2 {
return
}
if _this._state == 1 && _this._data != nil {
mbApi.wkeNetSetData(_this._job, _this._data)
_this._cancel = true
_this._state = 5
} else if _this._evResponse.IsEmtpy() == false {
mbApi.wkeNetHookRequest(_this._job)
_this._cancel = false
}
if _this._cancel {
mbApi.wkeNetCancelRequest(_this._job)
if _this._data != nil {
_this.onResponse(_this._data)
} else {
_this._evFinish.Fire(_this._evFinishKey, _this, _this)
}
} else {
_this._state = 3
}
}
func (_this *freeRequestBeforeEvArgs) onResponse(data []byte) {
_this._state = 5
args := new(freeResponseEvArgs).init(_this, data)
_this._evResponse.Fire(_this._evResponseKey, _this, args)
_this._evFinish.Fire(_this._evFinishKey, _this, _this)
}
func (_this *freeRequestBeforeEvArgs) onFail() {
_this._state = 4
args := new(freeLoadFailEvArgs).init(_this)
_this._evLoadFail.Fire(_this._evLoadFailKey, _this, args)
if _this._evResponse.IsEmtpy() {
_this._evFinish.Fire(_this._evFinishKey, _this, _this)
}
}
func (_this *MiniblinkBrowser) defOnRequestBefore(e RequestBeforeEvArgs) {
for _, v := range _this.EvRequestBefore {
v(_this, e)
}
}
func (_this *MiniblinkBrowser) defOnJsReady(e JsReadyEvArgs) {
for _, v := range _this.EvJsReady {
v(_this, e)
}
}
func (_this *MiniblinkBrowser) defOnConsole(e ConsoleEvArgs) {
for _, v := range _this.EvConsole {
v(_this, e)
}
}
func (_this *MiniblinkBrowser) defOnDocumentReady(e DocumentReadyEvArgs) {
for _, v := range _this.EvDocumentReady {
v(_this, e)
}
}
func (_this *MiniblinkBrowser) defOnPaintUpdated(e PaintUpdatedEvArgs) {
for _, v := range _this.EvPaintUpdated {
v(_this, e)
}
}