Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
75ea6773
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
75ea6773
编写于
3月 13, 2023
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
upgrade-dev v2.2.10
上级
3e91eed7
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
118 addition
and
39 deletion
+118
-39
cef/cef-application.go
cef/cef-application.go
+29
-12
cef/cef-events-def.go
cef/cef-events-def.go
+2
-0
cef/cef-ipc-render.go
cef/cef-ipc-render.go
+29
-17
cef/cef-ipc.go
cef/cef-ipc.go
+20
-6
cef/cef-types.go
cef/cef-types.go
+11
-0
consts/consts.go
consts/consts.go
+23
-0
example/dev-test/ipc-event/ipc-event.go
example/dev-test/ipc-event/ipc-event.go
+4
-4
未找到文件。
cef/cef-application.go
浏览文件 @
75ea6773
...
...
@@ -12,6 +12,7 @@
package
cef
import
(
"fmt"
"github.com/energye/energy/common"
"github.com/energye/energy/common/imports"
.
"github.com/energye/energy/consts"
...
...
@@ -54,6 +55,9 @@ func (m *TCEFApplication) registerDefaultEvent() {
m
.
defaultSetOnContextCreated
()
m
.
defaultSetOnProcessMessageReceived
()
m
.
defaultSetOnBeforeChildProcessLaunch
()
m
.
SetOnRenderLoadStart
(
func
(
browser
*
ICefBrowser
,
frame
*
ICefFrame
,
transitionType
TCefTransitionType
)
{
fmt
.
Println
(
"SetOnLoadStart"
)
})
}
// Instance 实例
...
...
@@ -127,6 +131,10 @@ func (m *TCEFApplication) defaultSetOnContextCreated() {
})
}
func
(
m
*
TCEFApplication
)
SetOnRegCustomSchemes
(
fn
GlobalCEFAppEventOnRegCustomSchemes
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOnRegCustomSchemes
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
(
m
*
TCEFApplication
)
SetOnContextInitialized
(
fn
GlobalCEFAppEventOnContextInitialized
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOnContextInitialized
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
...
...
@@ -159,28 +167,36 @@ func (m *TCEFApplication) defaultSetOnBeforeChildProcessLaunch() {
m
.
SetOnBeforeChildProcessLaunch
(
func
(
commandLine
*
TCefCommandLine
)
{})
}
func
(
m
*
TCEFApplication
)
SetOnBrowserDestroyed
(
fn
GlobalCEFAppEventOnBrowserDestroyed
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOnBrowserDestroyed
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
//func (m *TCEFApplication) SetOnScheduleMessagePumpWork(fn ) {
// imports.Proc(internale_CEFGlobalApp_SetOnScheduleMessagePumpWork).Call(api.MakeEventDataPtr(fn))
//}
func
(
m
*
TCEFApplication
)
SetOnGetDefaultClient
(
fn
GlobalCEFAppEventOnGetDefaultClient
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOnGetDefaultClient
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
(
m
*
TCEFApplication
)
SetOn
LoadStart
(
fn
GlobalCEFAppEventOnRenderLoadStart
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
LoadStart
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
func
(
m
*
TCEFApplication
)
SetOn
GetLocalizedString
(
fn
GlobalCEFAppEventOnGetLocalizedString
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
GetLocalizedString
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
(
m
*
TCEFApplication
)
SetOn
LoadEnd
(
fn
GlobalCEFAppEventOnRenderLoadEn
d
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
LoadEn
d
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
func
(
m
*
TCEFApplication
)
SetOn
BrowserDestroyed
(
fn
GlobalCEFAppEventOnBrowserDestroye
d
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
BrowserDestroye
d
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
(
m
*
TCEFApplication
)
SetOn
LoadError
(
fn
GlobalCEFAppEventOnRenderLoadError
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
LoadError
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
func
(
m
*
TCEFApplication
)
SetOn
RenderLoadStart
(
fn
GlobalCEFAppEventOnRenderLoadStart
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
RenderLoadStart
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
(
m
*
TCEFApplication
)
SetOn
LoadingStateChange
(
fn
GlobalCEFAppEventOnRenderLoadingStateChange
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
LoadingStateChange
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
func
(
m
*
TCEFApplication
)
SetOn
RenderLoadEnd
(
fn
GlobalCEFAppEventOnRenderLoadEnd
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOn
RenderLoadEnd
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
(
m
*
TCEFApplication
)
SetOnGetDefaultClient
(
fn
GlobalCEFAppEventOnGetDefaultClient
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOnGetDefaultClient
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
func
(
m
*
TCEFApplication
)
SetOnRenderLoadError
(
fn
GlobalCEFAppEventOnRenderLoadError
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOnRenderLoadError
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
(
m
*
TCEFApplication
)
SetOnRenderLoadingStateChange
(
fn
GlobalCEFAppEventOnRenderLoadingStateChange
)
{
imports
.
Proc
(
internale_CEFGlobalApp_SetOnRenderLoadingStateChange
)
.
Call
(
api
.
MakeEventDataPtr
(
fn
))
}
func
init
()
{
...
...
@@ -192,6 +208,7 @@ func init() {
case
GlobalCEFAppEventOnBrowserDestroyed
:
fn
.
(
GlobalCEFAppEventOnBrowserDestroyed
)(
&
ICefBrowser
{
instance
:
getPtr
(
0
)})
case
GlobalCEFAppEventOnRenderLoadStart
:
ipcRender
.
clear
()
browse
:=
&
ICefBrowser
{
instance
:
getPtr
(
0
)}
frame
:=
&
ICefFrame
{
instance
:
getPtr
(
1
)}
fn
.
(
GlobalCEFAppEventOnRenderLoadStart
)(
browse
,
frame
,
TCefTransitionType
(
getVal
(
2
)))
...
...
cef/cef-events-def.go
浏览文件 @
75ea6773
...
...
@@ -87,6 +87,7 @@ type ChromiumEventOnResourceLoadComplete func(sender lcl.IObject, browser *ICefB
// GlobalCEFAppEvent
type
GlobalCEFAppEventOnContextCreated
func
(
browser
*
ICefBrowser
,
frame
*
ICefFrame
,
context
*
ICefV8Context
)
bool
type
GlobalCEFAppEventOnRegCustomSchemes
func
(
registrar
TCefSchemeRegistrarRef
)
type
GlobalCEFAppEventOnWebKitInitialized
func
()
type
GlobalCEFAppEventOnContextInitialized
func
()
type
GlobalCEFAppEventOnBeforeChildProcessLaunch
func
(
commandLine
*
TCefCommandLine
)
...
...
@@ -96,6 +97,7 @@ type GlobalCEFAppEventOnRenderLoadEnd func(browser *ICefBrowser, frame *ICefFram
type
GlobalCEFAppEventOnRenderLoadError
func
(
browser
*
ICefBrowser
,
frame
*
ICefFrame
,
errorCode
consts
.
TCefErrorCode
,
errorText
,
failedUrl
string
)
type
GlobalCEFAppEventOnRenderLoadingStateChange
func
(
browser
*
ICefBrowser
,
frame
*
ICefFrame
,
isLoading
,
canGoBack
,
canGoForward
bool
)
type
GlobalCEFAppEventOnGetDefaultClient
func
(
client
*
ICefClient
)
type
GlobalCEFAppEventOnGetLocalizedString
func
(
stringId
int32
,
stringVal
string
,
aResult
bool
)
// Browser & Rneder 进程消息接收
type
RenderProcessMessageReceived
func
(
browser
*
ICefBrowser
,
frame
*
ICefFrame
,
sourceProcess
consts
.
CefProcessId
,
message
*
ICefProcessMessage
)
bool
...
...
cef/cef-ipc-render.go
浏览文件 @
75ea6773
...
...
@@ -18,10 +18,24 @@ import (
// ipcRenderProcess 渲染进程
type
ipcRenderProcess
struct
{
ipc
*
ICefV8Value
// ipc object
ipcEmit
*
ipcEmitHandler
// ipc.emit handler
ipcOn
*
ipcOnHandler
// ipc.on handler
bind
*
ICefV8Value
// go bind
bind
*
ICefV8Value
// go bind
ipc
*
ICefV8Value
// ipc object
emitHandler
*
ipcEmitHandler
// ipc.emit handler
onHandler
*
ipcOnHandler
// ipc.on handler
}
func
(
m
*
ipcRenderProcess
)
clear
()
{
if
m
.
bind
!=
nil
{
m
.
bind
.
Free
()
m
.
bind
=
nil
}
if
m
.
ipc
!=
nil
{
m
.
ipc
.
Free
()
m
.
ipc
=
nil
}
if
m
.
onHandler
!=
nil
{
m
.
onHandler
.
clear
()
}
}
// makeCtx ipc 和 bind
...
...
@@ -33,15 +47,15 @@ func (m *ipcRenderProcess) makeCtx(context *ICefV8Context) {
// makeIPC ipc
func
(
m
*
ipcRenderProcess
)
makeIPC
(
context
*
ICefV8Context
)
{
// ipc emit
m
.
ipcEmit
.
handler
=
V8HandlerRef
.
New
()
m
.
ipcEmit
.
handler
.
Execute
(
m
.
ipcEmitExecute
)
m
.
emitHandler
.
handler
=
V8HandlerRef
.
New
()
m
.
emitHandler
.
handler
.
Execute
(
m
.
ipcEmitExecute
)
// ipc on
m
.
ipcOn
.
handler
=
V8HandlerRef
.
New
()
m
.
ipcOn
.
handler
.
Execute
(
m
.
ipcOnExecute
)
m
.
onHandler
.
handler
=
V8HandlerRef
.
New
()
m
.
onHandler
.
handler
.
Execute
(
m
.
ipcOnExecute
)
// ipc object
m
.
ipc
=
V8ValueRef
.
NewObject
(
nil
)
m
.
ipc
.
setValueByKey
(
internalEmit
,
V8ValueRef
.
newFunction
(
internalEmit
,
m
.
ipcEmit
.
handler
),
consts
.
V8_PROPERTY_ATTRIBUTE_READONLY
)
m
.
ipc
.
setValueByKey
(
internalOn
,
V8ValueRef
.
newFunction
(
internalOn
,
m
.
ipcOn
.
handler
),
consts
.
V8_PROPERTY_ATTRIBUTE_READONLY
)
m
.
ipc
.
setValueByKey
(
internalEmit
,
V8ValueRef
.
newFunction
(
internalEmit
,
m
.
emitHandler
.
handler
),
consts
.
V8_PROPERTY_ATTRIBUTE_READONLY
)
m
.
ipc
.
setValueByKey
(
internalOn
,
V8ValueRef
.
newFunction
(
internalOn
,
m
.
onHandler
.
handler
),
consts
.
V8_PROPERTY_ATTRIBUTE_READONLY
)
// global to v8 ipc key
context
.
Global
()
.
setValueByKey
(
internalIPCKey
,
m
.
ipc
,
consts
.
V8_PROPERTY_ATTRIBUTE_READONLY
)
}
...
...
@@ -78,11 +92,9 @@ func (m *ipcRenderProcess) ipcOnExecute(name string, object *ICefV8Value, argume
return
}
onNameValue
=
onName
.
GetStringValue
()
if
callback
:=
m
.
ipcOn
.
getCallback
(
onNameValue
);
callback
!=
nil
{
callback
.
free
()
}
//ipc on
m
.
ipcOn
.
addCallback
(
onNameValue
,
&
ipcCallback
{
arguments
:
arguments
,
context
:
V8ContextRef
.
Current
(),
function
:
V8ValueRef
.
UnWrap
(
onCallback
)})
m
.
onHandler
.
addCallback
(
onNameValue
,
&
ipcCallback
{
arguments
:
arguments
,
context
:
V8ContextRef
.
Current
(),
function
:
V8ValueRef
.
UnWrap
(
onCallback
)})
fmt
.
Println
(
"on handler name:"
,
name
,
"arguments-size:"
,
arguments
.
Size
())
frame
:=
V8ContextRef
.
Current
()
.
Frame
()
...
...
@@ -175,7 +187,7 @@ func (m *ipcRenderProcess) ipcEmitExecute(name string, object *ICefV8Value, argu
//回调函数
if
emitCallback
!=
nil
{
//回调函数临时存放到缓存中
messageId
=
ipcRender
.
ipcEmit
.
addCallback
(
&
ipcCallback
{
messageId
=
ipcRender
.
emitHandler
.
addCallback
(
&
ipcCallback
{
arguments
:
arguments
,
context
:
context
,
function
:
V8ValueRef
.
UnWrap
(
emitCallback
),
...
...
@@ -202,7 +214,7 @@ func (m *ipcRenderProcess) ipcEmitExecute(name string, object *ICefV8Value, argu
func
(
m
*
ipcRenderProcess
)
ipcEmitMessageReply
(
browser
*
ICefBrowser
,
frame
*
ICefFrame
,
sourceProcess
consts
.
CefProcessId
,
message
*
ICefProcessMessage
)
(
result
bool
)
{
result
=
true
messageId
:=
message
.
ArgumentList
()
.
GetInt
(
0
)
if
callback
:=
ipcRender
.
ipcEmit
.
getCallback
(
messageId
);
callback
!=
nil
{
if
callback
:=
ipcRender
.
emitHandler
.
getCallback
(
messageId
);
callback
!=
nil
{
//第二个参数 true 有返回参数
if
isReturn
:=
message
.
ArgumentList
()
.
GetBool
(
1
);
isReturn
{
//[]byte
...
...
@@ -234,7 +246,7 @@ func (m *ipcRenderProcess) ipcEmitMessageReply(browser *ICefBrowser, frame *ICef
}
//remove
callback
.
free
()
ipcRender
.
ipcEmit
.
removeCallback
(
messageId
)
ipcRender
.
emitHandler
.
removeCallback
(
messageId
)
}
return
}
...
...
cef/cef-ipc.go
浏览文件 @
75ea6773
...
...
@@ -21,9 +21,9 @@ const (
internalOn
=
"on"
// JavaScript -> ipc.on 在 JavaScript 监听事件, 提供给 GO 调用
)
const
(
internalProcessMessageIPCEmit
=
"
ipcEmit"
// 进程消息 ipcEmit
internalProcessMessageIPCEmit
=
"
emitHandler"
// 进程消息 emitHandler
internalProcessMessageIPCEmitReply
=
"ipcEmitReply"
// 进程消息 ipcEmitReply
internalProcessMessageIPCOn
=
"
ipcOn"
// 进程消息 ipcOn
internalProcessMessageIPCOn
=
"
onHandler"
// 进程消息 onHandler
)
var
(
...
...
@@ -61,16 +61,16 @@ func ipcInit() {
if
isSingleProcess
{
ipcBrowser
=
&
ipcBrowserProcess
{}
ipcRender
=
&
ipcRenderProcess
{
ipcEmit
:
&
ipcEmitHandler
{
callbackList
:
make
(
map
[
int32
]
*
ipcCallback
)},
ipcOn
:
&
ipcOnHandler
{
callbackList
:
make
(
map
[
string
]
*
ipcCallback
)},
emitHandler
:
&
ipcEmitHandler
{
callbackList
:
make
(
map
[
int32
]
*
ipcCallback
)},
onHandler
:
&
ipcOnHandler
{
callbackList
:
make
(
map
[
string
]
*
ipcCallback
)},
}
}
else
{
if
common
.
Args
.
IsMain
()
{
ipcBrowser
=
&
ipcBrowserProcess
{}
}
else
if
common
.
Args
.
IsRender
()
{
ipcRender
=
&
ipcRenderProcess
{
ipcEmit
:
&
ipcEmitHandler
{
callbackList
:
make
(
map
[
int32
]
*
ipcCallback
)},
ipcOn
:
&
ipcOnHandler
{
callbackList
:
make
(
map
[
string
]
*
ipcCallback
)},
emitHandler
:
&
ipcEmitHandler
{
callbackList
:
make
(
map
[
int32
]
*
ipcCallback
)},
onHandler
:
&
ipcOnHandler
{
callbackList
:
make
(
map
[
string
]
*
ipcCallback
)},
}
}
}
...
...
@@ -112,6 +112,13 @@ func (m *ipcEmitHandler) getCallback(messageId int32) *ipcCallback {
return
m
.
callbackList
[
messageId
]
}
func
(
m
*
ipcEmitHandler
)
clear
()
{
for
_
,
v
:=
range
m
.
callbackList
{
v
.
free
()
}
m
.
callbackList
=
make
(
map
[
int32
]
*
ipcCallback
)
}
// addCallback
func
(
m
*
ipcOnHandler
)
addCallback
(
eventName
string
,
callback
*
ipcCallback
)
int32
{
//return uintptr(unsafe.Pointer(m.callbackList.PushBack(callback)))
...
...
@@ -137,6 +144,13 @@ func (m *ipcOnHandler) getCallback(eventName string) *ipcCallback {
return
m
.
callbackList
[
eventName
]
}
func
(
m
*
ipcOnHandler
)
clear
()
{
for
_
,
v
:=
range
m
.
callbackList
{
v
.
free
()
}
m
.
callbackList
=
make
(
map
[
string
]
*
ipcCallback
)
}
func
(
m
*
ipcCallback
)
free
()
{
if
m
.
context
!=
nil
{
m
.
context
.
Free
()
...
...
cef/cef-types.go
浏览文件 @
75ea6773
...
...
@@ -178,6 +178,11 @@ type TCefPoint struct {
Y
int32
}
// TCefSchemeRegistrarRef
type
TCefSchemeRegistrarRef
struct
{
instance
unsafe
.
Pointer
}
// ICefCallback
type
ICefCallback
struct
{
instance
unsafe
.
Pointer
...
...
@@ -441,6 +446,12 @@ type ICefPdfPrintCallback struct {
instance
unsafe
.
Pointer
}
// ICefCommandLine
type
ICefCommandLine
struct
{
base
TCefBaseRefCounted
instance
unsafe
.
Pointer
}
type
CefPdfPrintSettings
struct
{
Landscape
int32
// Integer
PrintBackground
int32
// Integer
...
...
consts/consts.go
浏览文件 @
75ea6773
...
...
@@ -1079,3 +1079,26 @@ const (
V8vtFunction
V8vtPromise
)
type
TCefPreferencesType
=
types
.
Int32
const
(
CEF_PREFERENCES_TYPE_GLOBAL
TCefPreferencesType
=
iota
CEF_PREFERENCES_TYPE_REQUEST_CONTEXT
)
type
TCefScaleFactor
=
types
.
Int32
// /include/internal/cef_types.h (cef_scale_factor_t)
const
(
SCALE_FACTOR_NONE
TCefScaleFactor
=
iota
SCALE_FACTOR_100P
SCALE_FACTOR_125P
SCALE_FACTOR_133P
SCALE_FACTOR_140P
SCALE_FACTOR_150P
SCALE_FACTOR_180P
SCALE_FACTOR_200P
SCALE_FACTOR_250P
SCALE_FACTOR_300P
)
example/dev-test/ipc-event/ipc-event.go
浏览文件 @
75ea6773
...
...
@@ -94,11 +94,11 @@ func main() {
ipc
.
On
(
"testEmitName"
,
func
(
context
ipc
.
IContext
)
{
num
++
argument
:=
context
.
ArgumentList
()
fmt
.
Println
(
"testEmitName"
,
argument
.
Size
(),
context
.
BrowserId
(),
context
.
FrameId
(),
num
)
fmt
.
Println
(
"data:"
,
argument
.
GetByIndex
(
1
)
.
Data
())
//
fmt.Println("testEmitName", argument.Size(), context.BrowserId(), context.FrameId(), num)
//
fmt.Println("data:", argument.GetByIndex(1).Data())
for
i
:=
0
;
i
<
argument
.
Size
();
i
++
{
value
:=
argument
.
GetByIndex
(
i
)
fmt
.
Println
(
i
,
"type:"
,
value
.
Type
(),
"isInt:"
,
value
.
IsInt
())
argument
.
GetByIndex
(
i
)
//
fmt.Println(i, "type:", value.Type(), "isInt:", value.IsInt())
}
var
r0
=
"字符串{}{}{}字符串[][]字符串"
var
r1
=
1000011
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录