upgrade-dev v2.1.12

This commit is contained in:
杨红岩 2023-03-02 21:08:51 +08:00
parent d66f576577
commit d95f742b16
2 changed files with 62 additions and 26 deletions

View File

@ -30,7 +30,8 @@ var (
)
type contextCreate struct {
make bool
ipc *ICefV8Value
bind *ICefV8Value
}
type mainRun struct {
@ -58,8 +59,7 @@ func appOnContextCreated(browser *ICefBrowser, frame *ICefFrame, context *ICefV8
for name, value := range binds {
fmt.Println("\t", name, value.ValueType())
}
ctx.makeIPC(context)
ctx.makeBind(context)
ctx.makeCtx(context)
}
// appMainRunCallback 应用运行 - 默认实现
@ -70,37 +70,62 @@ func appMainRunCallback() {
//indGoToJS(nil, nil)
}
func (m *contextCreate) makeCtx(context *ICefV8Context) {
ctx.makeIPC(context)
ctx.makeBind(context)
}
// makeIPC ipc
func (m *contextCreate) makeIPC(context *ICefV8Context) {
//ipc emit
// ipc emit
emitHandler := V8HandlerRef.New()
emitHandler.Execute(func(name string, object *ICefV8Value, arguments *TCefV8ValueArray, retVal *ResultV8Value, exception *Exception) bool {
return false
})
emitHandler.Execute(m.ipcEmitExecute)
// ipc on
onHandler := V8HandlerRef.New()
onHandler.Execute(func(name string, object *ICefV8Value, arguments *TCefV8ValueArray, retVal *ResultV8Value, exception *Exception) bool {
return false
})
//ipc object
ipc := V8ValueRef.NewObject(nil)
ipc.setValueByKey(internalEmit, V8ValueRef.newFunction(internalEmit, emitHandler), consts.V8_PROPERTY_ATTRIBUTE_READONLY)
ipc.setValueByKey(internalOn, V8ValueRef.newFunction(internalOn, onHandler), consts.V8_PROPERTY_ATTRIBUTE_READONLY)
context.Global().setValueByKey(internalIPCKey, ipc, consts.V8_PROPERTY_ATTRIBUTE_READONLY)
onHandler.Execute(m.ipcOnExecute)
// ipc object
m.ipc = V8ValueRef.NewObject(nil)
m.ipc.setValueByKey(internalEmit, V8ValueRef.newFunction(internalEmit, emitHandler), consts.V8_PROPERTY_ATTRIBUTE_READONLY)
m.ipc.setValueByKey(internalOn, V8ValueRef.newFunction(internalOn, onHandler), consts.V8_PROPERTY_ATTRIBUTE_READONLY)
// global to v8 ipc key
context.Global().setValueByKey(internalIPCKey, m.ipc, consts.V8_PROPERTY_ATTRIBUTE_READONLY)
}
func (m *contextCreate) ipcEmitExecute(name string, object *ICefV8Value, arguments *TCefV8ValueArray, retVal *ResultV8Value, exception *Exception) bool {
fmt.Println("emit handler name:", name)
return false
}
func (m *contextCreate) ipcOnExecute(name string, object *ICefV8Value, arguments *TCefV8ValueArray, retVal *ResultV8Value, exception *Exception) bool {
fmt.Println("on handler name:", name, "object", object.IsObject())
fmt.Println("on handler arguments:", arguments.Size())
frame := V8ContextRef.Current().Frame()
fmt.Println("frame", frame.Identifier())
sendBrowserProcessMsg := ProcessMessageRef.New("ipcOnExecute")
sendBrowserProcessMsg.ArgumentList().SetString(0, "ipcOnExecute测试值")
frame.SendProcessMessage(consts.PID_BROWSER, sendBrowserProcessMsg)
sendBrowserProcessMsg.Free()
return false
}
// makeBind bind object accessor
func (m *contextCreate) makeBind(context *ICefV8Context) {
// bind accessor
objectAccessor := V8AccessorRef.New()
objectAccessor.Get(func(name string, object *ICefV8Value, retVal *ResultV8Value, exception *Exception) bool {
return false
})
objectAccessor.Set(func(name string, object *ICefV8Value, value *ICefV8Value, exception *Exception) bool {
return false
})
//bind object
object := V8ValueRef.NewObject(objectAccessor)
context.Global().setValueByKey(internalObjectRootName, object, consts.V8_PROPERTY_ATTRIBUTE_NONE)
objectAccessor.Get(m.bindGet)
objectAccessor.Set(m.bindSet)
// bind object
m.bind = V8ValueRef.NewObject(objectAccessor)
// global to v8 bind objectRootName
context.Global().setValueByKey(internalObjectRootName, m.bind, consts.V8_PROPERTY_ATTRIBUTE_NONE)
}
func (m *contextCreate) bindGet(name string, object *ICefV8Value, retVal *ResultV8Value, exception *Exception) bool {
fmt.Println("get accessor name:", name)
return false
}
func (m *contextCreate) bindSet(name string, object *ICefV8Value, value *ICefV8Value, exception *Exception) bool {
fmt.Println("set accessor name:", name)
return false
}

View File

@ -17,12 +17,23 @@
msg("ipc-event: 页面加载完成...");
}
function ipcEmit() {
ipc.emit("emitName");
}
function ipcOn() {
ipc.on('onName');
}
</script>
</head>
<body style="overflow: hidden;margin: 0px;padding: 0px;">
<p>
<h3>process-message</h3></p>
<p><a target="_blank" href="ipc-event.html">open</a></p>
<p>
<button onclick="ipcEmit()">ipcEmit</button>
<button onclick="ipcOn()">ipcOn</button>
</p>
<p id="msgHtml"></p>
</body>
</html>