Closed WarWithinMe closed 6 years ago
You should implement CEFRenderProcessHandler
in the helper app.
@lvsti Should I also call CEFProcessUtils.initializeMain
in the helper app? Not sure how to tell CEF that I would provide the CEFRednerProcessHandler
right, the demo app's helper is just a dummy... I might add a more useful helper app in the future, until then take a look at this example:
class App: CEFApp, CEFRenderProcessHandler {
var renderProcessHandler: CEFRenderProcessHandler? {
return self
}
func onContextCreated(browser: CEFBrowser, frame: CEFFrame, context: CEFV8Context) {
context.enter()
let v8Str = CEFV8Value.createString("Hello World!")
NSLog("\(v8Str?.stringValue)")
context.exit()
}
}
let mainArgs = CEFMainArgs(arguments: CommandLine.arguments)
let commandLine = CEFCommandLine()!
commandLine.initFromArguments(CommandLine.arguments)
let retval: Int
if commandLine.switchValue(for: "type") == "renderer" {
retval = CEFProcessUtils.executeProcess(with: mainArgs, app: App())
}
else {
retval = CEFProcessUtils.executeProcess(with: mainArgs)
}
exit(Int32(retval))
Pro tip: debugging the helper app is not trivial since it runs in a separate process. In order to attach Xcode to the running render process, place the following line somewhere in the helper:
raise(SIGSTOP)
This will make the process hang and wait at that point until the debugger is attached. After that, you can use breakpoints as usual.
Thank you for the information
To use multi-process mode, if I want to implement logics (for example, js bindings) in main process, then I will need to use IPC to communicate with the render process. Or maybe I just move all the logics to render process, and only leave window management logics in the main process?
It seems that it will take a lot of effort to use multi-process mode.
It is indeed a lot of effort but so far neither I have found another way. Moving the logic over to the render process probably won't solve all your problems because that process is sandboxed, meaning it cannot access the filesystem, network etc.
Checked CefSharp, it sends message from the RenderProcess to MainProcess, to allow handling JS binding on the MainProcess. I'll try porting CefSharp's Subprocess logics to CEF.swift when I have time.
In my app, I wrote something like this:
ContextCreated
will be printed. However, if I setuseSingleProcess
to false,ContextCreated
will not be printed.I guess I might need to implement some logic in the helper app, but I'm not sure how. Please shed some light on how to use multi-process mode. Many thanks~