-
Notifications
You must be signed in to change notification settings - Fork 23
/
types_frame.go
292 lines (260 loc) · 6.92 KB
/
types_frame.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
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
// ----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// # Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// ----------------------------------------
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
"github.com/energye/energy/v2/cef/ipc/argument"
"github.com/energye/energy/v2/cef/ipc/target"
"github.com/energye/energy/v2/common/imports"
. "github.com/energye/energy/v2/consts"
"github.com/energye/energy/v2/pkgs/json"
"github.com/energye/golcl/lcl/api"
"unsafe"
)
// Instance 实例
func (m *ICefFrame) Instance() uintptr {
if m == nil {
return 0
}
return uintptr(m.instance)
}
// IsValid 该Frame是否有效
func (m *ICefFrame) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
r1, _, _ := imports.Proc(def.CEFFrame_IsValid).Call(m.Instance())
return api.GoBool(r1)
}
// Undo 撤销操作
func (m *ICefFrame) Undo() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_Undo).Call(m.Instance())
}
// Redo 恢复
func (m *ICefFrame) Redo() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_Redo).Call(m.Instance())
}
// Cut 剪切
func (m *ICefFrame) Cut() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_Cut).Call(m.Instance())
}
// Copy 复制
func (m *ICefFrame) Copy() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_Copy).Call(m.Instance())
}
// Paste 粘贴
func (m *ICefFrame) Paste() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_Paste).Call(m.Instance())
}
// Del 删除
func (m *ICefFrame) Del() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_Del).Call(m.Instance())
}
// SelectAll 选择所有
func (m *ICefFrame) SelectAll() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_SelectAll).Call(m.Instance())
}
// ViewSource 显示源码
func (m *ICefFrame) ViewSource() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_ViewSource).Call(m.Instance())
}
// LoadUrl 加载URL
func (m *ICefFrame) LoadUrl(url string) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_LoadUrl).Call(m.Instance(), api.PascalStr(url))
}
// ExecuteJavaScript 执行JS
func (m *ICefFrame) ExecuteJavaScript(code, scriptUrl string, startLine int32) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_ExecuteJavaScript).Call(m.Instance(), api.PascalStr(code), api.PascalStr(scriptUrl), uintptr(startLine))
}
// IsMain 是否为主Frame
func (m *ICefFrame) IsMain() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFFrame_IsMain).Call(m.Instance())
return api.GoBool(r1)
}
// IsFocused 是否已获取焦点
func (m *ICefFrame) IsFocused() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFFrame_IsFocused).Call(m.Instance())
return api.GoBool(r1)
}
// SendProcessMessage 发送进程消息
func (m *ICefFrame) SendProcessMessage(targetProcess CefProcessId, message *ICefProcessMessage) {
if !m.IsValid() || application.IsSpecVer49() {
return
}
imports.Proc(def.CEFFrame_SendProcessMessage).Call(m.Instance(), targetProcess.ToPtr(), message.Instance())
message.Free()
}
// SendProcessMessageForJSONBytes 发送进程消息
func (m *ICefFrame) SendProcessMessageForJSONBytes(messageName string, targetProcess CefProcessId, data []byte) {
if !m.IsValid() || application.IsSpecVer49() {
return
}
var (
dataPtr uintptr
count = uint32(len(data))
)
if count > 0 {
dataPtr = uintptr(unsafe.Pointer(&data[0]))
}
imports.Proc(def.CEFFrame_SendProcessMessageForJSONBytes).Call(m.Instance(), api.PascalStr(messageName), targetProcess.ToPtr(), dataPtr, uintptr(count))
}
// SendProcessMessageForV8Value 发送进程消息
func (m *ICefFrame) SendProcessMessageForV8Value(messageName string, targetProcess CefProcessId, arguments *ICefV8Value) {
if !m.IsValid() || application.IsSpecVer49() {
return
}
imports.Proc(def.CEFFrame_SendProcessMessageForV8Value).Call(m.Instance(), api.PascalStr(messageName), targetProcess.ToPtr(), arguments.Instance())
}
// EmitRender IPC 发送进程 消息
//
// messageId != 0 是带有回调函数消息
func (m *ICefFrame) EmitRender(messageId int32, eventName string, target target.ITarget, data ...interface{}) bool {
if !m.IsValid() || application.IsSpecVer49() {
return false
}
message := &argument.List{Id: messageId, EventName: eventName}
if len(data) > 0 {
argumentJSONArray := json.NewJSONArray(nil)
for _, result := range data {
switch result.(type) {
case error:
argumentJSONArray.Add(result.(error).Error())
default:
argumentJSONArray.Add(result)
}
}
message.Data = argumentJSONArray.Data()
}
m.SendProcessMessageForJSONBytes(internalIPCGoExecuteJSEvent, PID_RENDER, message.Bytes())
message.Reset()
return true
}
func (m *ICefFrame) LoadRequest(request *ICefRequest) {
if !m.IsValid() || request == nil {
return
}
imports.Proc(def.CEFFrame_LoadRequest).Call(m.Instance(), request.Instance())
}
func (m *ICefFrame) Browser() *ICefBrowser {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.CEFFrame_Browser).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefBrowser{instance: unsafe.Pointer(result)}
}
func (m *ICefFrame) V8Context() *ICefV8Context {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.CEFFrame_GetV8Context).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefV8Context{instance: unsafe.Pointer(result)}
}
func (m *ICefFrame) VisitDom(visitor *ICefDomVisitor) {
if !m.IsValid() || !visitor.IsValid() {
return
}
imports.Proc(def.CEFFrame_VisitDom).Call(m.Instance(), visitor.Instance())
}
func (m *ICefFrame) Identifier() (result int64) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFFrame_Identifier).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return result
}
func (m *ICefFrame) Name() (value string) {
if !m.IsValid() {
return ""
}
val := NewTString()
imports.Proc(def.CEFFrame_Name).Call(m.Instance(), val.Instance())
value = val.Value()
val.Free()
return
}
func (m *ICefFrame) Url() (value string) {
if !m.IsValid() {
return ""
}
val := NewTString()
imports.Proc(def.CEFFrame_Url).Call(m.Instance(), val.Instance())
value = val.Value()
val.Free()
return
}
func (m *ICefFrame) Parent() *ICefFrame {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.CEFFrame_Parent).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefFrame{instance: unsafe.Pointer(result)}
}
func (m *ICefFrame) Free() {
if !m.IsValid() {
return
}
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
// FrameRef -> *ICefFrame
var FrameRef frameRef
// frameRef
type frameRef uintptr
func (m *frameRef) UnWrap(data *ICefFrame) *ICefFrame {
var result uintptr
imports.Proc(def.CEFFrameRef_UnWrap).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
if result == 0 {
return nil
}
//data.base.Free(data.Instance())
data.instance = getInstance(result)
return data
}