提交 75ea6773 编写于 作者: yanghye's avatar yanghye

upgrade-dev v2.2.10

上级 3e91eed7
......@@ -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) SetOnLoadStart(fn GlobalCEFAppEventOnRenderLoadStart) {
imports.Proc(internale_CEFGlobalApp_SetOnLoadStart).Call(api.MakeEventDataPtr(fn))
func (m *TCEFApplication) SetOnGetLocalizedString(fn GlobalCEFAppEventOnGetLocalizedString) {
imports.Proc(internale_CEFGlobalApp_SetOnGetLocalizedString).Call(api.MakeEventDataPtr(fn))
}
func (m *TCEFApplication) SetOnLoadEnd(fn GlobalCEFAppEventOnRenderLoadEnd) {
imports.Proc(internale_CEFGlobalApp_SetOnLoadEnd).Call(api.MakeEventDataPtr(fn))
func (m *TCEFApplication) SetOnBrowserDestroyed(fn GlobalCEFAppEventOnBrowserDestroyed) {
imports.Proc(internale_CEFGlobalApp_SetOnBrowserDestroyed).Call(api.MakeEventDataPtr(fn))
}
func (m *TCEFApplication) SetOnLoadError(fn GlobalCEFAppEventOnRenderLoadError) {
imports.Proc(internale_CEFGlobalApp_SetOnLoadError).Call(api.MakeEventDataPtr(fn))
func (m *TCEFApplication) SetOnRenderLoadStart(fn GlobalCEFAppEventOnRenderLoadStart) {
imports.Proc(internale_CEFGlobalApp_SetOnRenderLoadStart).Call(api.MakeEventDataPtr(fn))
}
func (m *TCEFApplication) SetOnLoadingStateChange(fn GlobalCEFAppEventOnRenderLoadingStateChange) {
imports.Proc(internale_CEFGlobalApp_SetOnLoadingStateChange).Call(api.MakeEventDataPtr(fn))
func (m *TCEFApplication) SetOnRenderLoadEnd(fn GlobalCEFAppEventOnRenderLoadEnd) {
imports.Proc(internale_CEFGlobalApp_SetOnRenderLoadEnd).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)))
......
......@@ -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
......
......@@ -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
}
......
......@@ -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()
......
......@@ -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
......
......@@ -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
)
......@@ -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.
先完成此消息的编辑!
想要评论请 注册