提交 26a1f388 编写于 作者: R Richard Wilkes

Update to CEF v3.3626.1891.g52be333 (2/15/2019)

上级 240376d9
...@@ -83,8 +83,12 @@ func gocef_resource_handler_process_request(self *C.cef_resource_handler_t, requ ...@@ -83,8 +83,12 @@ func gocef_resource_handler_process_request(self *C.cef_resource_handler_t, requ
// (0) or the specified number of bytes have been read. Use the |response| // (0) or the specified number of bytes have been read. Use the |response|
// object to set the mime type, http status code and other optional header // object to set the mime type, http status code and other optional header
// values. To redirect the request to a new URL set |redirectUrl| to the new // values. To redirect the request to a new URL set |redirectUrl| to the new
// URL. If an error occured while setting up the request you can call // URL. |redirectUrl| can be either a relative or fully qualified URL. It is
// set_error() on |response| to indicate the error condition. // also possible to set |response| to a redirect http status code and pass the
// new URL via a Location header. Likewise with |redirectUrl| it is valid to
// set a relative or fully qualified URL as the Location header value. If an
// error occured while setting up the request you can call set_error() on
// |response| to indicate the error condition.
func (d *ResourceHandler) GetResponseHeaders(response *Response, response_length *int64, redirectUrl *string) { func (d *ResourceHandler) GetResponseHeaders(response *Response, response_length *int64, redirectUrl *string) {
lookupResourceHandlerProxy(d.Base()).GetResponseHeaders(d, response, response_length, redirectUrl) lookupResourceHandlerProxy(d.Base()).GetResponseHeaders(d, response, response_length, redirectUrl)
} }
......
...@@ -127,9 +127,10 @@ type Settings struct { ...@@ -127,9 +127,10 @@ type Settings struct {
LogFile string LogFile string
// LogSeverity (log_severity) // LogSeverity (log_severity)
// The log severity. Only messages of this severity level or higher will be // The log severity. Only messages of this severity level or higher will be
// logged. Also configurable using the "log-severity" command-line switch with // logged. When set to DISABLE no messages will be written to the log file,
// a value of "verbose", "info", "warning", "error", "error-report" or // but FATAL messages will still be output to stderr. Also configurable using
// "disable". // the "log-severity" command-line switch with a value of "verbose", "info",
// "warning", "error", "fatal" or "disable".
LogSeverity LogSeverity LogSeverity LogSeverity
// JavascriptFlags (javascript_flags) // JavascriptFlags (javascript_flags)
// Custom flags that will be used when initializing the V8 JavaScript engine. // Custom flags that will be used when initializing the V8 JavaScript engine.
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
// WindowInfo (cef_window_info_t) - Mac-specific variant // WindowInfo (cef_window_info_t) - Mac-specific variant
// Class representing window information. // Class representing window information.
type WindowInfo struct { type WindowInfo struct { //nolint:maligned
// WindowName (window_name) // WindowName (window_name)
WindowName string WindowName string
// X (x) // X (x)
......
...@@ -644,7 +644,10 @@ const ( ...@@ -644,7 +644,10 @@ const (
LogseverityWarning LogSeverity = ((LogseverityVerbose) + 1) + 1 // LOGSEVERITY_WARNING LogseverityWarning LogSeverity = ((LogseverityVerbose) + 1) + 1 // LOGSEVERITY_WARNING
// DEBUG logging. // DEBUG logging.
LogseverityError LogSeverity = (((LogseverityVerbose) + 1) + 1) + 1 // LOGSEVERITY_ERROR LogseverityError LogSeverity = (((LogseverityVerbose) + 1) + 1) + 1 // LOGSEVERITY_ERROR
// Completely disable logging. // DEBUG logging.
LogseverityFatal LogSeverity = ((((LogseverityVerbose) + 1) + 1) + 1) + 1 // LOGSEVERITY_FATAL
// Disable logging to file for all messages, and to stderr for messages with
// severity less than FATAL.
LogseverityDisable LogSeverity = 99 // LOGSEVERITY_DISABLE LogseverityDisable LogSeverity = 99 // LOGSEVERITY_DISABLE
) )
......
...@@ -367,9 +367,8 @@ func ListValueCreate() *ListValue { ...@@ -367,9 +367,8 @@ func ListValueCreate() *ListValue {
// have a visible frame at all times, center alignment, additional padding and a // have a visible frame at all times, center alignment, additional padding and a
// default minimum size of 70x33 DIP. If |with_frame| is false (0) the button // default minimum size of 70x33 DIP. If |with_frame| is false (0) the button
// will only have a visible frame on hover/press, left alignment, less padding // will only have a visible frame on hover/press, left alignment, less padding
// and no default minimum size. If |with_menu_marker| is true (1) a menu marker // and no default minimum size.
// will be added to the button. func MenuButtonCreate(delegate *MenuButtonDelegate, text string, with_frame int32) *MenuButton {
func MenuButtonCreate(delegate *MenuButtonDelegate, text string, with_frame, with_menu_marker int32) *MenuButton {
var delegate_ *C.cef_menu_button_delegate_t var delegate_ *C.cef_menu_button_delegate_t
if delegate != nil { if delegate != nil {
delegate_ = delegate.toNative() delegate_ = delegate.toNative()
...@@ -379,7 +378,7 @@ func MenuButtonCreate(delegate *MenuButtonDelegate, text string, with_frame, wit ...@@ -379,7 +378,7 @@ func MenuButtonCreate(delegate *MenuButtonDelegate, text string, with_frame, wit
defer func() { defer func() {
C.cef_string_userfree_free(text_) C.cef_string_userfree_free(text_)
}() }()
return (*MenuButton)(C.cef_menu_button_create(delegate_, (*C.cef_string_t)(text_), C.int(with_frame), C.int(with_menu_marker))) return (*MenuButton)(C.cef_menu_button_create(delegate_, (*C.cef_string_t)(text_), C.int(with_frame)))
} }
// MenuModelCreate (cef_menu_model_create from include/capi/cef_menu_model_capi.h) // MenuModelCreate (cef_menu_model_create from include/capi/cef_menu_model_capi.h)
......
module github.com/richardwilkes/cef module github.com/richardwilkes/cef
require ( require github.com/richardwilkes/toolbox v1.1.6
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 // indirect
github.com/richardwilkes/toolbox v1.1.3
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/sys v0.0.0-20190114130336-2be517255631 // indirect
)
...@@ -8,23 +8,18 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN ...@@ -8,23 +8,18 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/term v0.0.0-20181116001808-27bbf2edb814 h1:qWlKm6sU/AyVAgBC1Pg1uuY/X/p4lNYG7t4v8/f4FJE=
github.com/pkg/term v0.0.0-20181116001808-27bbf2edb814/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 h1:A7GG7zcGjl3jqAqGPmcNjd/D9hzL95SuoOQAaFNdLU0= github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942 h1:A7GG7zcGjl3jqAqGPmcNjd/D9hzL95SuoOQAaFNdLU0=
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ= github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/richardwilkes/toolbox v1.1.3 h1:alQu+xxpfWKpzlxAkYevRY40IiD8U2aegJ6USDELpGw= github.com/richardwilkes/toolbox v1.1.6 h1:PB6UljMWRB4bxM5bCbblOX+ybnpcjnV6qY5zcAheRUQ=
github.com/richardwilkes/toolbox v1.1.3/go.mod h1:e/y5ODoUj7gDs7Rrovgn7g4btCm/eA7IALsVGwAW9hg= github.com/richardwilkes/toolbox v1.1.6/go.mod h1:edL6Olij9w158Mdr9kkoRGGAokwDrlMPjIJ+jkRmdG4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/sys v0.0.0-20181212120007-b05ddf57801d h1:G59MrP9Qg6bymPjN3yGmqnmuCEH1h0eFP8zpRpl1RiU= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181212120007-b05ddf57801d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 h1:3Nsfe5Xa1wTt01QxlAFIY5j9ycDtS+d7mhvI8ZY5bn0=
golang.org/x/sys v0.0.0-20190114130336-2be517255631 h1:g/5trXm6f9Tm+ochb21RlFNnF63lt+elB9hVBqtPu5Y= golang.org/x/sys v0.0.0-20190220154126-629670e5acc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190114130336-2be517255631/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
......
...@@ -8,6 +8,8 @@ import ( ...@@ -8,6 +8,8 @@ import (
"github.com/richardwilkes/toolbox/log/jot" "github.com/richardwilkes/toolbox/log/jot"
) )
const baseFieldName = "base"
type field struct { type field struct {
Owner *structDef Owner *structDef
Var *variable Var *variable
...@@ -89,7 +91,7 @@ func (f *field) CallFunctionPointer() string { ...@@ -89,7 +91,7 @@ func (f *field) CallFunctionPointer() string {
func (f *field) ReturnField() string { func (f *field) ReturnField() string {
var buffer strings.Builder var buffer strings.Builder
buffer.WriteString("return ") buffer.WriteString("return ")
if f.Var.Name == "base" { if f.Var.Name == baseFieldName {
if sdef, exists := sdefsMap[f.Var.BaseType]; exists && !sdef.isClassEquivalent() { if sdef, exists := sdefsMap[f.Var.BaseType]; exists && !sdef.isClassEquivalent() {
buffer.WriteString("(&d.base).toGo()") buffer.WriteString("(&d.base).toGo()")
return buffer.String() return buffer.String()
...@@ -101,7 +103,7 @@ func (f *field) ReturnField() string { ...@@ -101,7 +103,7 @@ func (f *field) ReturnField() string {
buffer.WriteString(f.Var.GoType) buffer.WriteString(f.Var.GoType)
} }
buffer.WriteString("(") buffer.WriteString("(")
if f.Var.Name == "base" { if f.Var.Name == baseFieldName {
buffer.WriteString("&") buffer.WriteString("&")
} }
fmt.Fprintf(&buffer, "d.%s)", f.Var.Name) fmt.Fprintf(&buffer, "d.%s)", f.Var.Name)
...@@ -114,16 +116,16 @@ func (f *field) ToNative() string { ...@@ -114,16 +116,16 @@ func (f *field) ToNative() string {
fmt.Fprintf(&buffer, "d.%s.toNative(&native.%s)", f.Var.GoName, f.Var.Name) fmt.Fprintf(&buffer, "d.%s.toNative(&native.%s)", f.Var.GoName, f.Var.Name)
} else { } else {
switch f.Var.CType { switch f.Var.CType {
case "void *": case voidPtrType:
fmt.Fprintf(&buffer, "native.%s = d.%s", f.Var.Name, f.Var.GoName) fmt.Fprintf(&buffer, "native.%s = d.%s", f.Var.Name, f.Var.GoName)
case "cef_string_t": case cefStringType:
fmt.Fprintf(&buffer, `setCEFStr(d.%s, &native.%s)`, f.Var.GoName, f.Var.Name) fmt.Fprintf(&buffer, `setCEFStr(d.%s, &native.%s)`, f.Var.GoName, f.Var.Name)
case "cef_string_t *": case cefStringPtrType:
fmt.Fprintf(&buffer, `setCEFStr(d.%s, native.%s)`, f.Var.GoName, f.Var.Name) fmt.Fprintf(&buffer, `setCEFStr(d.%s, native.%s)`, f.Var.GoName, f.Var.Name)
default: default:
fmt.Fprintf(&buffer, "native.%s = ", f.Var.Name) fmt.Fprintf(&buffer, "native.%s = ", f.Var.Name)
if i := strings.Index(f.Var.CType, " "); i != -1 { if i := strings.Index(f.Var.CType, " "); i != -1 {
if f.Var.Name == "base" { if f.Var.Name == baseFieldName {
fmt.Fprintf(&buffer, "*(%sC.%s)(unsafe.Pointer(d.Base))", f.Var.CType[i+1:], f.Var.CType[:i]) fmt.Fprintf(&buffer, "*(%sC.%s)(unsafe.Pointer(d.Base))", f.Var.CType[i+1:], f.Var.CType[:i])
} else { } else {
fmt.Fprintf(&buffer, "(%sC.%s)(d.%s)", f.Var.CType[i+1:], f.Var.CType[:i], f.Var.GoName) fmt.Fprintf(&buffer, "(%sC.%s)(d.%s)", f.Var.CType[i+1:], f.Var.CType[:i], f.Var.GoName)
...@@ -143,14 +145,14 @@ func (f *field) IntoGo() string { ...@@ -143,14 +145,14 @@ func (f *field) IntoGo() string {
} else { } else {
fmt.Fprintf(&buffer, "d.%s = ", f.Var.GoName) fmt.Fprintf(&buffer, "d.%s = ", f.Var.GoName)
switch f.Var.CType { switch f.Var.CType {
case "void *": case voidPtrType:
fmt.Fprintf(&buffer, "n.%s", f.Var.Name) fmt.Fprintf(&buffer, "n.%s", f.Var.Name)
case "cef_string_t": case cefStringType:
fmt.Fprintf(&buffer, "cefstrToString(&n.%s)", f.Var.Name) fmt.Fprintf(&buffer, "cefstrToString(&n.%s)", f.Var.Name)
case "cef_string_t *": case cefStringPtrType:
fmt.Fprintf(&buffer, "cefstrToString(n.%s)", f.Var.Name) fmt.Fprintf(&buffer, "cefstrToString(n.%s)", f.Var.Name)
default: default:
if f.Var.Name == "base" { if f.Var.Name == baseFieldName {
fmt.Fprintf(&buffer, "(%s)(&n.base)", f.Var.GoType) fmt.Fprintf(&buffer, "(%s)(&n.base)", f.Var.GoType)
} else { } else {
if strings.HasPrefix(f.Var.GoType, "*") { if strings.HasPrefix(f.Var.GoType, "*") {
...@@ -247,7 +249,7 @@ func (f *field) CallbackParams() string { ...@@ -247,7 +249,7 @@ func (f *field) CallbackParams() string {
buffer.WriteString(", ") buffer.WriteString(", ")
} }
buffer.WriteString(p.Name) buffer.WriteString(p.Name)
if p.BaseType == "void" { if p.BaseType == voidType {
switch p.Ptrs { switch p.Ptrs {
case "": case "":
case "*": case "*":
......
...@@ -54,27 +54,28 @@ func (f *funcDef) Body() string { ...@@ -54,27 +54,28 @@ func (f *funcDef) Body() string {
return buffer.String() return buffer.String()
} }
func prepGoVarsForC(vars []*variable) (string, []string) { func prepGoVarsForC(vars []*variable) (prep string, names []string) {
var buffer strings.Builder var buffer strings.Builder
names := make([]string, len(vars)) names = make([]string, len(vars))
for i, p := range vars { for i, p := range vars {
names[i] = p.Name names[i] = p.Name
if p.BaseType == "cef_string_t" { switch {
case p.BaseType == cefStringType:
names[i] = p.Name + "_" names[i] = p.Name + "_"
fmt.Fprintf(&buffer, "%s_ := C.cef_string_userfree_alloc()\n", p.Name) fmt.Fprintf(&buffer, "%s_ := C.cef_string_userfree_alloc()\n", p.Name)
ptrs := p.Ptrs ptrs := p.Ptrs
if !p.HadConst && p.paramGoType() == "*string" { if !p.HadConst && p.paramGoType() == stringPtrGoType {
ptrs = "*" ptrs = "*"
} else if len(ptrs) > 0 { } else if len(ptrs) > 0 {
ptrs = ptrs[1:] ptrs = ptrs[1:]
} }
fmt.Fprintf(&buffer, "setCEFStr(%[1]s%[2]s, %[2]s_)\n", ptrs, p.Name) fmt.Fprintf(&buffer, "setCEFStr(%[1]s%[2]s, %[2]s_)\n", ptrs, p.Name)
buffer.WriteString("defer func() {\n") buffer.WriteString("defer func() {\n")
if !p.HadConst && p.paramGoType() == "*string" { if !p.HadConst && p.paramGoType() == stringPtrGoType {
fmt.Fprintf(&buffer, "*%[1]s = cefstrToString(%[1]s_)\n", p.Name) fmt.Fprintf(&buffer, "*%[1]s = cefstrToString(%[1]s_)\n", p.Name)
} }
fmt.Fprintf(&buffer, "C.cef_string_userfree_free(%s_)\n}()\n", p.Name) fmt.Fprintf(&buffer, "C.cef_string_userfree_free(%s_)\n}()\n", p.Name)
} else if p.Ptrs == "**" { case p.Ptrs == "**":
if sdef, exists := sdefsMap[p.BaseType]; exists { if sdef, exists := sdefsMap[p.BaseType]; exists {
names[i] = p.Name + "_" names[i] = p.Name + "_"
fmt.Fprintf(&buffer, "%[1]s_ := (*%[1]s).toNative(", p.Name) fmt.Fprintf(&buffer, "%[1]s_ := (*%[1]s).toNative(", p.Name)
...@@ -82,7 +83,7 @@ func prepGoVarsForC(vars []*variable) (string, []string) { ...@@ -82,7 +83,7 @@ func prepGoVarsForC(vars []*variable) (string, []string) {
fmt.Fprintf(&buffer, "&C.%s{}", p.BaseType) fmt.Fprintf(&buffer, "&C.%s{}", p.BaseType)
} }
buffer.WriteString(")\n") buffer.WriteString(")\n")
} else if p.BaseType == "char" { } else if p.BaseType == charType {
names[i] = p.Name + "_" names[i] = p.Name + "_"
fmt.Fprintf(&buffer, `%[1]s_ := C.calloc(C.size_t(len(%[1]s)), C.size_t(unsafe.Sizeof(uintptr(0)))) fmt.Fprintf(&buffer, `%[1]s_ := C.calloc(C.size_t(len(%[1]s)), C.size_t(unsafe.Sizeof(uintptr(0))))
%[1]s_p := (*[1<<30 - 1]*C.char)(%[1]s_) %[1]s_p := (*[1<<30 - 1]*C.char)(%[1]s_)
...@@ -91,7 +92,7 @@ for i, one := range %[1]s { ...@@ -91,7 +92,7 @@ for i, one := range %[1]s {
} }
`, p.Name) `, p.Name)
} }
} else if p.Ptrs == "*" { case p.Ptrs == "*":
if _, exists := edefsMap[p.BaseType]; exists { if _, exists := edefsMap[p.BaseType]; exists {
names[i] = p.Name + "_" names[i] = p.Name + "_"
fmt.Fprintf(&buffer, "%[1]s_ := C.%[2]s(*%[1]s)\n", p.Name, p.BaseType) fmt.Fprintf(&buffer, "%[1]s_ := C.%[2]s(*%[1]s)\n", p.Name, p.BaseType)
...@@ -106,6 +107,7 @@ for i, one := range %[1]s { ...@@ -106,6 +107,7 @@ for i, one := range %[1]s {
buffer.WriteString(")\n") buffer.WriteString(")\n")
buffer.WriteString("}\n") buffer.WriteString("}\n")
} }
default:
} }
} }
return buffer.String(), names return buffer.String(), names
...@@ -125,12 +127,12 @@ return result__`, expression, retVar.GoType) ...@@ -125,12 +127,12 @@ return result__`, expression, retVar.GoType)
} }
} else { } else {
switch retVar.CType { switch retVar.CType {
case "void *": case voidPtrType:
fmt.Fprintf(buffer, "return %s", expression) fmt.Fprintf(buffer, "return %s", expression)
case "cef_string_t": case cefStringType:
fmt.Fprintf(buffer, `native__ := %s fmt.Fprintf(buffer, `native__ := %s
return cefstrToString(&native__)`, expression) return cefstrToString(&native__)`, expression)
case "cef_string_t *": case cefStringPtrType:
fmt.Fprintf(buffer, "return cefstrToString(%s)", expression) fmt.Fprintf(buffer, "return cefstrToString(%s)", expression)
case "cef_string_userfree_t": case "cef_string_userfree_t":
fmt.Fprintf(buffer, "return cefuserfreestrToString(%s)", expression) fmt.Fprintf(buffer, "return cefuserfreestrToString(%s)", expression)
...@@ -151,18 +153,21 @@ func emitParamsForCCall(buffer *strings.Builder, vars []*variable, names []strin ...@@ -151,18 +153,21 @@ func emitParamsForCCall(buffer *strings.Builder, vars []*variable, names []strin
if !omitFirstComma || i != 0 { if !omitFirstComma || i != 0 {
buffer.WriteString(", ") buffer.WriteString(", ")
} }
if p.BaseType == "void" { switch {
case p.BaseType == voidType:
buffer.WriteString(names[i]) buffer.WriteString(names[i])
} else if p.BaseType == "char" && p.Ptrs == "**" { case p.BaseType == charType && p.Ptrs == "**":
fmt.Fprintf(buffer, "(**C.char)(%s)", names[i]) fmt.Fprintf(buffer, "(**C.char)(%s)", names[i])
} else { default:
if p.Ptrs == "*" { if p.Ptrs == "*" {
if _, exists := edefsMap[p.BaseType]; exists { if _, exists := edefsMap[p.BaseType]; exists {
fmt.Fprintf(buffer, "&%s", names[i]) fmt.Fprintf(buffer, "&%s", names[i])
continue continue
} }
} }
if sdef, exists := sdefsMap[p.BaseType]; exists { sdef, exists := sdefsMap[p.BaseType]
switch {
case exists:
if len(p.Ptrs) > 1 { if len(p.Ptrs) > 1 {
fmt.Fprintf(buffer, "&%s", names[i]) fmt.Fprintf(buffer, "&%s", names[i])
} else { } else {
...@@ -176,9 +181,9 @@ func emitParamsForCCall(buffer *strings.Builder, vars []*variable, names []strin ...@@ -176,9 +181,9 @@ func emitParamsForCCall(buffer *strings.Builder, vars []*variable, names []strin
buffer.WriteString(")") buffer.WriteString(")")
} }
} }
} else if len(p.Ptrs) > 0 { case len(p.Ptrs) > 0:
fmt.Fprintf(buffer, "(%sC.%s)(%s)", p.Ptrs, p.BaseType, names[i]) fmt.Fprintf(buffer, "(%sC.%s)(%s)", p.Ptrs, p.BaseType, names[i])
} else { default:
fmt.Fprintf(buffer, "C.%s(%s)", p.BaseType, names[i]) fmt.Fprintf(buffer, "C.%s(%s)", p.BaseType, names[i])
} }
} }
......
...@@ -179,13 +179,14 @@ func headerList(dir string) []os.FileInfo { ...@@ -179,13 +179,14 @@ func headerList(dir string) []os.FileInfo {
func clangArgs(headers []string) []string { func clangArgs(headers []string) []string {
args := make([]string, 0, len(headers)+7) args := make([]string, 0, len(headers)+7)
args = append(args, "-I") args = append(args,
args = append(args, ".") "-I",
args = append(args, "-Xclang") ".",
args = append(args, "-ast-dump") "-Xclang",
args = append(args, "-fsyntax-only") "-ast-dump",
args = append(args, "-fno-color-diagnostics") "-fsyntax-only",
args = append(args, "-Wno-visibility") "-fno-color-diagnostics",
"-Wno-visibility")
args = append(args, headers...) args = append(args, headers...)
return args return args
} }
...@@ -193,7 +194,7 @@ func clangArgs(headers []string) []string { ...@@ -193,7 +194,7 @@ func clangArgs(headers []string) []string {
func createCommonHeader(headers []string) { func createCommonHeader(headers []string) {
f, err := os.Create(filepath.Join(outputBaseDir, "capi_gen.h")) f, err := os.Create(filepath.Join(outputBaseDir, "capi_gen.h"))
jot.FatalIfErr(err) jot.FatalIfErr(err)
f.WriteString(`// Code generated - DO NOT EDIT. _, err = f.WriteString(`// Code generated - DO NOT EDIT.
#ifndef GOCEF_CAPI_H_ #ifndef GOCEF_CAPI_H_
#define GOCEF_CAPI_H_ #define GOCEF_CAPI_H_
...@@ -201,12 +202,14 @@ func createCommonHeader(headers []string) { ...@@ -201,12 +202,14 @@ func createCommonHeader(headers []string) {
#include <stdlib.h> #include <stdlib.h>
`) `)
jot.FatalIfErr(err)
for _, header := range headers { for _, header := range headers {
fmt.Fprintf(f, `#include "%s" fmt.Fprintf(f, `#include "%s"
`, header) `, header)
} }
f.WriteString(` _, err = f.WriteString(`
#endif // GOCEF_CAPI_H_ #endif // GOCEF_CAPI_H_
`) `)
jot.FatalIfErr(err)
jot.FatalIfErr(f.Close()) jot.FatalIfErr(f.Close())
} }
...@@ -129,7 +129,7 @@ func (p position) Text(line, startCol, endCol int) string { ...@@ -129,7 +129,7 @@ func (p position) Text(line, startCol, endCol int) string {
return "" return ""
} }
text := lines[line-1] text := lines[line-1]
if len(text) == 0 { if text == "" {
return "" return ""
} }
if startCol < 1 { if startCol < 1 {
......
...@@ -51,7 +51,7 @@ func (s *structDef) NeedsUnsafeImport() bool { ...@@ -51,7 +51,7 @@ func (s *structDef) NeedsUnsafeImport() bool {
} }
func (s *structDef) hasInheritance() bool { func (s *structDef) hasInheritance() bool {
return !s.isClassEquivalent() && len(s.Fields) > 0 && s.Fields[0].Var.Name == "base" return !s.isClassEquivalent() && len(s.Fields) > 0 && s.Fields[0].Var.Name == baseFieldName
} }
func (s *structDef) isClassEquivalent() bool { func (s *structDef) isClassEquivalent() bool {
......
...@@ -30,7 +30,7 @@ func newTypeDef(name, refersTo string, pos position) *typeDef { ...@@ -30,7 +30,7 @@ func newTypeDef(name, refersTo string, pos position) *typeDef {
} }
var excludeMap = map[string]bool{ var excludeMap = map[string]bool{
"cef_string_t": true, cefStringType: true,
"cef_string_userfree_t": true, "cef_string_userfree_t": true,
"cef_string_userfree_utf8_t": true, "cef_string_userfree_utf8_t": true,
"cef_string_userfree_utf16_t": true, "cef_string_userfree_utf16_t": true,
...@@ -83,7 +83,7 @@ func dumpTypedefs() { ...@@ -83,7 +83,7 @@ func dumpTypedefs() {
func translateRefersToType(in string) string { func translateRefersToType(in string) string {
switch in { switch in {
case "void *": case voidPtrType:
return "unsafe.Pointer" return "unsafe.Pointer"
case "uint32": case "uint32":
return in return in
......
...@@ -10,6 +10,15 @@ import ( ...@@ -10,6 +10,15 @@ import (
"github.com/richardwilkes/toolbox/txt" "github.com/richardwilkes/toolbox/txt"
) )
const (
voidType = "void"
voidPtrType = "void *"
charType = "char"
cefStringType = "cef_string_t"
cefStringPtrType = "cef_string_t *"
stringPtrGoType = "*string"
)
var ( var (
cNamesToPrefixForAccess = []string{"range", "type"} cNamesToPrefixForAccess = []string{"range", "type"}
paramRenames = []string{"chan", "defer", "error", "fallthrough", "func", "go", "import", "interface", "map", "package", "range", "select", "string", "type", "var"} paramRenames = []string{"chan", "defer", "error", "fallthrough", "func", "go", "import", "interface", "map", "package", "range", "select", "string", "type", "var"}
...@@ -70,7 +79,7 @@ func newCVar(name, typeInfo string, pos position) *variable { ...@@ -70,7 +79,7 @@ func newCVar(name, typeInfo string, pos position) *variable {
typeInfo = strings.TrimSpace(typeInfo) typeInfo = strings.TrimSpace(typeInfo)
typeInfo = strings.TrimPrefix(typeInfo, "struct _") typeInfo = strings.TrimPrefix(typeInfo, "struct _")
typeInfo = strings.Replace(typeInfo, "long long", "longlong", -1) typeInfo = strings.Replace(typeInfo, "long long", "longlong", -1)
if v.Name == "base" { if v.Name == baseFieldName {
typeInfo += " *" typeInfo += " *"
} }
v.CType = typeInfo v.CType = typeInfo
...@@ -81,7 +90,7 @@ func newCVar(name, typeInfo string, pos position) *variable { ...@@ -81,7 +90,7 @@ func newCVar(name, typeInfo string, pos position) *variable {
v.BaseType = typeInfo v.BaseType = typeInfo
} }
switch v.BaseType { switch v.BaseType {
case "void": case voidType:
switch v.Ptrs { switch v.Ptrs {
case "": case "":
case "*": case "*":
...@@ -93,7 +102,7 @@ func newCVar(name, typeInfo string, pos position) *variable { ...@@ -93,7 +102,7 @@ func newCVar(name, typeInfo string, pos position) *variable {
default: default:
jot.Fatal(1, errs.Newf("Unhandled void case: %s", v.Ptrs)) jot.Fatal(1, errs.Newf("Unhandled void case: %s", v.Ptrs))
} }
case "char": case charType:
if v.Ptrs == "**" { if v.Ptrs == "**" {
v.NeedUnsafe = true v.NeedUnsafe = true
v.GoType = "[]string" v.GoType = "[]string"
...@@ -112,14 +121,14 @@ func newCVar(name, typeInfo string, pos position) *variable { ...@@ -112,14 +121,14 @@ func newCVar(name, typeInfo string, pos position) *variable {
v.GoType = v.Ptrs + "float64" v.GoType = v.Ptrs + "float64"
case "size_t": case "size_t":
v.GoType = v.Ptrs + "uint64" v.GoType = v.Ptrs + "uint64"
case "cef_string_t", "cef_string_userfree_t", "cef_string_userfree_utf8_t", case cefStringType, "cef_string_userfree_t", "cef_string_userfree_utf8_t",
"cef_string_userfree_utf16_t", "cef_string_userfree_wide_t", "cef_string_userfree_utf16_t", "cef_string_userfree_wide_t",
"cef_string_utf8_t", "cef_string_utf16_t", "cef_string_wide_t": "cef_string_utf8_t", "cef_string_utf16_t", "cef_string_wide_t":
switch v.Ptrs { switch v.Ptrs {
case "", "*": case "", "*":
v.GoType = "string" v.GoType = "string"
case "**": case "**":
v.GoType = "*string" v.GoType = stringPtrGoType
default: default:
jot.Fatal(1, errs.Newf("Unhandled string case: %s", v.Ptrs)) jot.Fatal(1, errs.Newf("Unhandled string case: %s", v.Ptrs))
} }
...@@ -172,7 +181,7 @@ func adjustedParamName(name string) string { ...@@ -172,7 +181,7 @@ func adjustedParamName(name string) string {
func (v *variable) paramGoType() string { func (v *variable) paramGoType() string {
if !v.HadConst && v.GoType == "string" { if !v.HadConst && v.GoType == "string" {
return "*string" return stringPtrGoType
} }
return v.GoType return v.GoType
} }
...@@ -188,29 +197,31 @@ func (v *variable) transformCToGo(w io.Writer) string { ...@@ -188,29 +197,31 @@ func (v *variable) transformCToGo(w io.Writer) string {
fmt.Fprintf(w, "%[1]s__p := &%[1]s_\n", v.Name) fmt.Fprintf(w, "%[1]s__p := &%[1]s_\n", v.Name)
return fmt.Sprintf("%s__p", v.Name) return fmt.Sprintf("%s__p", v.Name)
} }
} else { } else if v.Ptrs == "*" {
if v.Ptrs == "*" { fmt.Fprintf(w, "%[1]s_ := %[1]s.toGo()\n", v.Name)
fmt.Fprintf(w, "%[1]s_ := %[1]s.toGo()\n", v.Name) return fmt.Sprintf("%s_", v.Name)
return fmt.Sprintf("%s_", v.Name)
}
} }
} else if _, exists := edefsMap[v.BaseType]; exists { } else {
switch v.Ptrs { _, exists := edefsMap[v.BaseType]
case "": switch {
case exists:
switch v.Ptrs {
case "":
return v.GoCast(v.Name)
case "*":
fmt.Fprintf(w, "%[1]s_ := %[2]s(*%[1]s)\n", v.Name, v.GoType[1:])
return fmt.Sprintf("&%s_", v.Name)
}
case v.BaseType == cefStringType:
addressOf := ""
if !v.HadConst {
addressOf = "&"
}
fmt.Fprintf(w, "%[1]s_ := cefstrToString(%[1]s)\n", v.Name)
return fmt.Sprintf("%s%s_", addressOf, v.Name)
default:
return v.GoCast(v.Name) return v.GoCast(v.Name)
case "*":
fmt.Fprintf(w, "%[1]s_ := %[2]s(*%[1]s)\n", v.Name, v.GoType[1:])
return fmt.Sprintf("&%s_", v.Name)
}
} else if v.BaseType == "cef_string_t" {
addressOf := ""
if !v.HadConst {
addressOf = "&"
} }
fmt.Fprintf(w, "%[1]s_ := cefstrToString(%[1]s)\n", v.Name)
return fmt.Sprintf("%s%s_", addressOf, v.Name)
} else {
return v.GoCast(v.Name)
} }
jot.Fatal(1, errs.Newf("Unhandled param conversion: %s", v.Name)) jot.Fatal(1, errs.Newf("Unhandled param conversion: %s", v.Name))
return "" return ""
...@@ -230,7 +241,7 @@ func (v *variable) CGoCast(expression string) string { ...@@ -230,7 +241,7 @@ func (v *variable) CGoCast(expression string) string {
} }
func (v *variable) GoCast(expression string) string { func (v *variable) GoCast(expression string) string {
if v.BaseType == "void" { if v.BaseType == voidType {
return expression return expression
} }
if strings.HasPrefix(v.GoType, "*") { if strings.HasPrefix(v.GoType, "*") {
......
...@@ -40,7 +40,7 @@ func NewDist() cmdline.Cmd { ...@@ -40,7 +40,7 @@ func NewDist() cmdline.Cmd {
copyrightOwner: "Unknown", copyrightOwner: "Unknown",
} }
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": case MacOS:
d.root = path.Join(d.root, "macos") d.root = path.Join(d.root, "macos")
d.icon = "AppIcon.icns" d.icon = "AppIcon.icns"
default: default:
...@@ -76,9 +76,9 @@ func (d *dist) Run(cl *cmdline.CmdLine, args []string) error { ...@@ -76,9 +76,9 @@ func (d *dist) Run(cl *cmdline.CmdLine, args []string) error {
} }
createDir(d.root, 0755) createDir(d.root, 0755)
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": case MacOS:
d.distMacOS() d.distMacOS()
case "linux", "windows": case LinuxOS, WindowsOS:
d.distNotMacOS() d.distNotMacOS()
default: default:
return fmt.Errorf("Unhandled OS: %s", runtime.GOOS) return fmt.Errorf("Unhandled OS: %s", runtime.GOOS)
......
...@@ -83,7 +83,7 @@ int main(int argc, char **argv) { ...@@ -83,7 +83,7 @@ int main(int argc, char **argv) {
} }
`), 0644), "write", name) `), 0644), "write", name)
c.untar(bytes.NewBuffer(c.downloadAndUncompressArchive())) c.untar(bytes.NewBuffer(c.downloadAndUncompressArchive()))
if runtime.GOOS == "windows" { if runtime.GOOS == WindowsOS {
dir := path.Join(path.Dir(os.Getenv("MINGW_PREFIX")), "lib/pkgconfig") dir := path.Join(path.Dir(os.Getenv("MINGW_PREFIX")), "lib/pkgconfig")
createDir(dir, 0755) createDir(dir, 0755)
name = path.Join(dir, "cef.pc") name = path.Join(dir, "cef.pc")
......
...@@ -9,6 +9,13 @@ import ( ...@@ -9,6 +9,13 @@ import (
"github.com/richardwilkes/toolbox/atexit" "github.com/richardwilkes/toolbox/atexit"
) )
// Constants for comparison to runtime.GOOS
const (
MacOS = "darwin"
WindowsOS = "windows"
LinuxOS = "linux"
)
var ( var (
installPrefix = "/usr/local/cef" installPrefix = "/usr/local/cef"
cefPlatform string cefPlatform string
...@@ -16,11 +23,11 @@ var ( ...@@ -16,11 +23,11 @@ var (
func checkPlatform() { func checkPlatform() {
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": case MacOS:
cefPlatform = "macosx64" cefPlatform = "macosx64"
case "linux": case LinuxOS:
cefPlatform = "linux64" cefPlatform = "linux64"
case "windows": case WindowsOS:
if os.Getenv("MSYSTEM") != "MINGW64" { if os.Getenv("MSYSTEM") != "MINGW64" {
fmt.Println("Windows is only supported through the use of MINGW64") fmt.Println("Windows is only supported through the use of MINGW64")
atexit.Exit(1) atexit.Exit(1)
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"github.com/richardwilkes/toolbox/cmdline" "github.com/richardwilkes/toolbox/cmdline"
) )
const desiredCEFVersion = "3.3578.1863.gbf8cff2" const desiredCEFVersion = "3.3626.1891.g52be333"
func main() { func main() {
cmdline.CopyrightYears = "2018-2019" cmdline.CopyrightYears = "2018-2019"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册