mirror of
https://gitee.com/energye/energy.git
synced 2024-11-30 10:47:57 +08:00
升级和优化,绑定和进程通信 v10
This commit is contained in:
parent
12784a93d2
commit
e94a855ffd
@ -38,12 +38,12 @@ type FrameNames struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
// 获取浏览器ID 每一个窗口独占唯一ID
|
||||
// GetBrowserId 获取浏览器ID 每一个窗口独占唯一ID
|
||||
func (m *ICefBrowser) GetBrowserId() int32 {
|
||||
return m.browseId
|
||||
}
|
||||
|
||||
// 获取FrameID 一个窗口中可以有多Frame
|
||||
// GetFrameId 获取FrameID 一个窗口中可以有多Frame
|
||||
func (m *ICefBrowser) GetFrameId() int64 {
|
||||
if mainFrame := m.MainFrame(); mainFrame != nil {
|
||||
return mainFrame.Id
|
||||
@ -51,7 +51,7 @@ func (m *ICefBrowser) GetFrameId() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// 浏览器ID号
|
||||
// Identifier 浏览器ID号
|
||||
func (m *ICefBrowser) Identifier() int32 {
|
||||
return m.browseId
|
||||
}
|
||||
|
@ -381,7 +381,7 @@ func (m *TCEFChromium) SendProcessMessage(targetProcess CefProcessId, processMes
|
||||
var browser = BrowserWindow.GetBrowser(1)
|
||||
data := processMessage.ArgumentList.Package()
|
||||
|
||||
r1 := _CEFFrame_SendProcessMessage(1, browser.MainFrame().Id, processMessage.Name, targetProcess, int32(processMessage.ArgumentList.Size()), uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)))
|
||||
r1 := _CEFFrame_SendProcessMessageByIPC(1, browser.MainFrame().Id, processMessage.Name, targetProcess, int32(processMessage.ArgumentList.Size()), uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)))
|
||||
return int(r1)
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ func (m *TCEFChromium) GetBrowserById(browserId int32) *ICefBrowser {
|
||||
|
||||
func (m *TCEFChromium) browseEmitJsOnEvent(browseId int32, frameId int64, name string, argumentList ipc.IArgumentList) ProcessMessageError {
|
||||
data := argumentList.Package()
|
||||
r1 := _CEFFrame_SendProcessMessage(browseId, frameId, name, PID_RENDER, int32(argumentList.Size()), uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)))
|
||||
r1 := _CEFFrame_SendProcessMessageByIPC(browseId, frameId, name, PID_RENDER, int32(argumentList.Size()), uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)))
|
||||
return ProcessMessageError(r1)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
// ICefFrame
|
||||
// Html <frame>...</frame>
|
||||
// Html <iframe></iframe>
|
||||
type ICefFrame struct {
|
||||
instance unsafe.Pointer
|
||||
Browser *ICefBrowser
|
||||
@ -47,6 +47,13 @@ func (m TCEFFrame) GetByFrameId(frameId int64) *ICefFrame {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Instance 实例
|
||||
func (m *ICefFrame) Instance() uintptr {
|
||||
return uintptr(m.instance)
|
||||
}
|
||||
|
||||
// ---- CEF Frame for frameId ----
|
||||
|
||||
// Undo 撤销操作
|
||||
func (m *ICefFrame) Undo() {
|
||||
var frameId = m.Id
|
||||
@ -128,19 +135,53 @@ func (m *ICefFrame) IsFocused() bool {
|
||||
return api.GoBool(r1)
|
||||
}
|
||||
|
||||
// SendProcessMessage 发送进程消息
|
||||
func (m *ICefFrame) SendProcessMessage(targetProcess CefProcessId, processMessage *ipc.ICefProcessMessage) ProcessMessageError {
|
||||
// SendProcessMessageByIPC 发送进程消息
|
||||
func (m *ICefFrame) SendProcessMessageByIPC(targetProcess CefProcessId, processMessage *ipc.ICefProcessMessage) ProcessMessageError {
|
||||
if processMessage == nil || processMessage.Name == "" || processMessage.ArgumentList == nil {
|
||||
return PMErr_REQUIRED_PARAMS_IS_NULL
|
||||
} else if ipc.InternalIPCNameCheck(processMessage.Name) {
|
||||
return PMErr_NAME_CANNOT_USED
|
||||
}
|
||||
data := processMessage.ArgumentList.Package()
|
||||
r1 := _CEFFrame_SendProcessMessage(m.Browser.Identifier(), m.Id, processMessage.Name, targetProcess, int32(processMessage.ArgumentList.Size()), uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)))
|
||||
r1 := _CEFFrame_SendProcessMessageByIPC(m.Browser.Identifier(), m.Id, processMessage.Name, targetProcess, int32(processMessage.ArgumentList.Size()), uintptr(unsafe.Pointer(&data[0])), uintptr(len(data)))
|
||||
return ProcessMessageError(r1)
|
||||
}
|
||||
|
||||
func _CEFFrame_SendProcessMessage(browseId int32, frameId int64, name string, targetProcess CefProcessId, itemLength int32, data, dataLen uintptr) uintptr {
|
||||
r1, _, _ := imports.Proc(internale_CEFFrame_SendProcessMessage).Call(uintptr(browseId), uintptr(unsafe.Pointer(&frameId)), api.PascalStr(name), uintptr(targetProcess), uintptr(itemLength), data, dataLen)
|
||||
func _CEFFrame_SendProcessMessageByIPC(browseId int32, frameId int64, name string, targetProcess CefProcessId, itemLength int32, data, dataLen uintptr) uintptr {
|
||||
r1, _, _ := imports.Proc(internale_CEFFrame_SendProcessMessageByIPC).Call(uintptr(browseId), uintptr(unsafe.Pointer(&frameId)), api.PascalStr(name), uintptr(targetProcess), uintptr(itemLength), data, dataLen)
|
||||
return r1
|
||||
}
|
||||
|
||||
// ---- CEF Frame for ptr ----
|
||||
|
||||
//func (m *ICefFrame) IsValid: Boolean;
|
||||
//func (m *ICefFrame) Undo;
|
||||
//func (m *ICefFrame) Redo;
|
||||
//func (m *ICefFrame) Cut;
|
||||
//func (m *ICefFrame) Copy;
|
||||
//func (m *ICefFrame) Paste;
|
||||
//func (m *ICefFrame) Del;
|
||||
//func (m *ICefFrame) SelectAll;
|
||||
//func (m *ICefFrame) ViewSource;
|
||||
//func (m *ICefFrame) GetSource(const visitor: ICefStringVisitor);
|
||||
//func (m *ICefFrame) GetSourceProc(const proc: TCefStringVisitorProc);
|
||||
//func (m *ICefFrame) GetText(const visitor: ICefStringVisitor);
|
||||
//func (m *ICefFrame) GetTextProc(const proc: TCefStringVisitorProc);
|
||||
//func (m *ICefFrame) LoadRequest(const request: ICefRequest);
|
||||
//func (m *ICefFrame) LoadUrl(const url: ustring);
|
||||
//func (m *ICefFrame) ExecuteJavaScript(const code, scriptUrl: ustring; startLine: Integer);
|
||||
//func (m *ICefFrame) IsMain: Boolean;
|
||||
//func (m *ICefFrame) IsFocused: Boolean;
|
||||
//func (m *ICefFrame) GetName: ustring;
|
||||
//func (m *ICefFrame) GetIdentifier: Int64;
|
||||
//func (m *ICefFrame) GetParent: ICefFrame;
|
||||
//func (m *ICefFrame) GetUrl: ustring;
|
||||
//func (m *ICefFrame) GetBrowser: ICefBrowser;
|
||||
//func (m *ICefFrame) GetV8Context: ICefv8Context;
|
||||
//func (m *ICefFrame) VisitDom(const visitor: ICefDomVisitor);
|
||||
//func (m *ICefFrame) VisitDomProc(const proc: TCefDomVisitorProc);
|
||||
//func (m *ICefFrame) CreateUrlRequest(const request: ICefRequest; const client: ICefUrlrequestClient): ICefUrlRequest;
|
||||
|
||||
func (m *ICefFrame) SendProcessMessage(targetProcess CefProcessId, message *ICefProcessMessage) {
|
||||
imports.Proc(internale_CEFFrame_SendProcessMessage).Call(m.Instance(), targetProcess.ToPtr(), message.Instance())
|
||||
}
|
||||
|
@ -375,6 +375,7 @@ func init() {
|
||||
dllimports.NewEnergyImport("CEFFrame_IsValid", 0),
|
||||
dllimports.NewEnergyImport("CEFFrame_IsMain", 0),
|
||||
dllimports.NewEnergyImport("CEFFrame_IsFocused", 0),
|
||||
dllimports.NewEnergyImport("CEFFrame_SendProcessMessageByIPC", 0),
|
||||
dllimports.NewEnergyImport("CEFFrame_SendProcessMessage", 0),
|
||||
//ICefMenuModel
|
||||
dllimports.NewEnergyImport("cefMenuModel_AddSeparator", 0),
|
||||
@ -1122,6 +1123,7 @@ const (
|
||||
internale_CEFFrame_IsValid
|
||||
internale_CEFFrame_IsMain
|
||||
internale_CEFFrame_IsFocused
|
||||
internale_CEFFrame_SendProcessMessageByIPC
|
||||
internale_CEFFrame_SendProcessMessage
|
||||
//ICefMenuModel
|
||||
internale_cefMenuModel_AddSeparator
|
||||
|
@ -116,6 +116,8 @@ func main() {
|
||||
val, ex, ok = context.Eval("errtest();", "", 0)
|
||||
fmt.Println("Execute errtest:", val, ex, ok)
|
||||
fmt.Println("Execute errtest-error:", ex.Message(), ex.LineNumber())
|
||||
fmt.Println("V8ContextRef.Current()", cef.V8ContextRef.Current().Global().GetValueByKey("arrBuf").IsArrayBuffer())
|
||||
fmt.Println("V8ContextRef.Entered()", cef.V8ContextRef.Entered().Global().GetValueByKey("arrBuf").IsArrayBuffer())
|
||||
return true
|
||||
})
|
||||
object := cef.V8ValueRef.NewObject(accessor)
|
||||
@ -148,8 +150,6 @@ func main() {
|
||||
buffer := cef.V8ValueRef.NewArrayBuffer(buf, callback)
|
||||
fmt.Println("ArrayBuffer IsValid", buffer.IsValid())
|
||||
context.Global().SetValueByKey("arrBuf", buffer, consts.V8_PROPERTY_ATTRIBUTE_NONE)
|
||||
fmt.Println("V8ContextRef.Current()", cef.V8ContextRef.Current().Global().GetValueByKey("arrBuf").IsArrayBuffer())
|
||||
fmt.Println("V8ContextRef.Entered()", cef.V8ContextRef.Entered().Global().GetValueByKey("arrBuf").IsArrayBuffer())
|
||||
return false
|
||||
})
|
||||
|
||||
|
@ -54,5 +54,6 @@
|
||||
<p>
|
||||
<h3>bind</h3></p>
|
||||
<p id="test"></p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -73,7 +73,7 @@ func AppRenderInit() *cef.TCEFApplication {
|
||||
fmt.Println("\t|--Args:", common.Args.ProcessType(), "message:", message.ArgumentList.GetString(0))
|
||||
message = ipc.NewProcessMessage("test")
|
||||
message.ArgumentList.SetString(0, "渲染进程发送数据")
|
||||
frame.SendProcessMessage(consts.PID_BROWSER, message)
|
||||
frame.SendProcessMessageByIPC(consts.PID_BROWSER, message)
|
||||
message.ArgumentList.Clear()
|
||||
return false
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user