forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcef_app.go
More file actions
77 lines (68 loc) · 2.19 KB
/
cef_app.go
File metadata and controls
77 lines (68 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) 2014 The cef2go authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/CzarekTomczak/cef2go
// Website: https://github.com/fromkeith/cef2go
package chrome
/*
#cgo CFLAGS: -I./
#include <stdlib.h>
#include "include/capi/cef_app_capi.h"
extern void initialize_app_handler(cef_app_t* app);
*/
import "C"
import (
log "github.com/cihub/seelog"
"unsafe"
)
var knownAppHandlers = make(map[unsafe.Pointer]AppHandler)
// create the underlying C structure for an App Handler.
func NewAppHandlerT(handler AppHandler) AppHandlerT {
var a AppHandlerT
a.CStruct = (*C.cef_app_t)(C.calloc(1, C.sizeof_cef_app_t))
log.Info("Initialize App Handler")
C.initialize_app_handler(a.CStruct)
knownAppHandlers[unsafe.Pointer(a.CStruct)] = handler
return a
}
//export go_GetBrowserProcessHandler
func go_GetBrowserProcessHandler(self *C.cef_app_t) *C.struct__cef_browser_process_handler_t {
if handler, ok := knownAppHandlers[unsafe.Pointer(self)]; ok {
bph := handler.GetBrowserProcessHandler()
if bph != nil {
return bph.GetBrowserProcessHandlerT().CStruct
}
}
return nil
}
type AppHandler interface {
// TODO implement these thing
OnBeforeCommandLineProcessing(processType string, commandLine CommandLineT)
OnRegisterCustomSchemes()
GetResourceBundleHandler()
GetRenderProcessHandler()
// called to get the underlying c struct.
GetAppHandlerT() AppHandlerT
GetBrowserProcessHandler() BrowserProcessHandler
}
type AppHandlerT struct {
CStruct *C.cef_app_t
}
//base Handler
type BaseAppHandler struct {
handler AppHandlerT
browserProcessHandler BrowserProcessHandler
}
func (app *BaseAppHandler) haveBase() bool { return true }
func (app *BaseAppHandler) OnBeforeCommandLineProcessing(processType string,
commandLine CommandLineT) {
}
func (app *BaseAppHandler) OnRegisterCustomSchemes() {}
func (app *BaseAppHandler) GetResourceBundleHandler() {}
func (app *BaseAppHandler) GetBrowserProcessHandler() BrowserProcessHandler {
app.browserProcessHandler.GetBrowserProcessHandlerT().AddRef()
return app.browserProcessHandler
}
func (app *BaseAppHandler) GetRenderProcessHandler() {}
func (app *BaseAppHandler) GetAppHandlerT() AppHandlerT {
return app.handler
}