energy/cef/application_callback.go

76 lines
2.8 KiB
Go
Raw Normal View History

2023-03-01 18:01:34 +08:00
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
// application event 默认事件实现
2023-05-31 17:41:14 +08:00
2023-03-01 18:01:34 +08:00
package cef
import (
2023-05-31 18:00:34 +08:00
"github.com/energye/energy/v2/cef/internal/ipc"
"github.com/energye/energy/v2/cef/internal/process"
"github.com/energye/energy/v2/consts"
2023-08-28 13:18:23 +08:00
"strings"
2023-03-02 18:47:39 +08:00
)
// 创建应用上下文 - 默认实现
2023-03-02 18:47:39 +08:00
func appOnContextCreated(browser *ICefBrowser, frame *ICefFrame, context *ICefV8Context) {
2023-05-31 17:41:14 +08:00
process.Current.SetBrowserId(browser.Identifier()) // 当前进程 browserID
process.Current.SetFrameId(frame.Identifier()) // 当前进程 frameId
ipc.RenderChan().SetRealityChannel(browser.Identifier(), frame.Identifier()) // 设置并更新真实的通道ID
ipcRender.registerGoWaitReplayEvent() // render ipc
ipcRender.makeIPC(frame.Identifier(), context) // render ipc make
2023-06-02 14:49:23 +08:00
makeProcess(browser, frame, context) // process make
2023-03-03 12:52:00 +08:00
}
// 应用运行 - 默认实现
2023-03-03 17:08:06 +08:00
func appMainRunCallback() {
2023-05-31 17:41:14 +08:00
ipcBrowser.registerEvent() // browser ipc
2023-03-03 17:08:06 +08:00
}
// webkit - 默认实现
2023-03-23 21:34:56 +08:00
func appWebKitInitialized() {
dragExtensionHandler() // drag extension handler
2023-03-23 21:34:56 +08:00
}
// 渲染进程消息 - 默认实现
2023-03-13 17:30:13 +08:00
func renderProcessMessageReceived(browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) (result bool) {
2023-03-20 10:09:54 +08:00
if message.Name() == internalIPCJSExecuteGoEventReplay {
2023-03-14 17:41:30 +08:00
result = ipcRender.ipcJSExecuteGoEventMessageReply(browser, frame, sourceProcess, message)
2023-03-21 16:17:29 +08:00
} else if message.Name() == internalIPCGoExecuteJSEvent {
2023-03-14 17:41:30 +08:00
result = ipcRender.ipcGoExecuteJSEvent(browser, frame, sourceProcess, message)
2023-03-13 16:48:40 +08:00
}
return
}
// 注册自定义协议 - 默认实现
func regCustomSchemes(registrar *TCefSchemeRegistrarRef) {
if localLoadRes.enable() {
2023-08-28 13:18:23 +08:00
// 以下几种默认的协议不去注册
switch strings.ToUpper(localLoadRes.Scheme) {
case "HTTP", "HTTPS", "FILE", "FTP", "ABOUT", "DATA":
return
}
if application.IsSpecVer49() {
registrar.AddCustomScheme(localLoadRes.Scheme, consts.CEF_SCHEME_OPTION_STANDARD|consts.CEF_SCHEME_OPTION_LOCAL)
} else {
registrar.AddCustomScheme(localLoadRes.Scheme,
consts.CEF_SCHEME_OPTION_STANDARD|consts.CEF_SCHEME_OPTION_CORS_ENABLED|consts.CEF_SCHEME_OPTION_SECURE|consts.CEF_SCHEME_OPTION_FETCH_ENABLED)
}
}
}
// 主进程消息 - 默认实现
2023-03-21 13:18:44 +08:00
func browserProcessMessageReceived(browser *ICefBrowser, frame *ICefFrame, message *ICefProcessMessage) (result bool) {
2023-03-20 10:09:54 +08:00
if message.Name() == internalIPCJSExecuteGoEvent {
2023-03-21 13:18:44 +08:00
result = ipcBrowser.jsExecuteGoMethodMessage(browser, frame, message)
2023-03-02 22:08:10 +08:00
}
2023-03-04 17:12:22 +08:00
return
2023-03-02 21:08:51 +08:00
}