chore(deps): bump purego-cef to v0.14.1
v0.14.0 pinned the CEF API 15000 contract and fixed the struct ABI corruption that made BrowserSettings.BackgroundColor land on chrome_status_bubble (transparent windowless canvas). v0.14.1 restores the global function bindings dropped by that regeneration (DictionaryValueCreate, V8ContextGetCurrentContext, all *Create factories) and fixes global factory ownership so created objects are adopted without a leaked reference. This makes the white-canvas fix in this branch effective: the opaque white BrowserSettings.BackgroundColor now actually reaches libcef.
- commit
- 902c404508da47722a324d2f14b2a4cfc04a2812
- author
- brice · · 2026-07-21 19:07 UTC
- parent
- 1dc7dd4
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
75 files · +1836 -1983
M go.mod +1 -1
| @@ -6,7 +6,7 @@ require ( | |||
| 6 | 6 | github.com/a-h/templ v0.3.1020 | |
| 7 | 7 | github.com/andybalholm/brotli v1.2.2 | |
| 8 | 8 | github.com/bnema/purego v0.11.0-bnema.4 | |
| 9 | - | github.com/bnema/purego-cef v0.13.4 | |
| 9 | + | github.com/bnema/purego-cef v0.14.1 | |
| 10 | 10 | github.com/bnema/purego-cef2gtk v0.8.5 | |
| 11 | 11 | github.com/bnema/purego-pipewire v0.1.5 | |
| 12 | 12 | github.com/bnema/purego-sqlite v0.1.4 | |
| @@ -6,7 +6,7 @@ require ( | |||||
| 6 | github.com/a-h/templ v0.3.1020 | 6 | github.com/a-h/templ v0.3.1020 | ||
| 7 | github.com/andybalholm/brotli v1.2.2 | 7 | github.com/andybalholm/brotli v1.2.2 | ||
| 8 | github.com/bnema/purego v0.11.0-bnema.4 | 8 | github.com/bnema/purego v0.11.0-bnema.4 | ||
| 9 | - | github.com/bnema/purego-cef v0.13.4 | 9 | + | github.com/bnema/purego-cef v0.14.1 |
| 10 | github.com/bnema/purego-cef2gtk v0.8.5 | 10 | github.com/bnema/purego-cef2gtk v0.8.5 | ||
| 11 | github.com/bnema/purego-pipewire v0.1.5 | 11 | github.com/bnema/purego-pipewire v0.1.5 | ||
| 12 | github.com/bnema/purego-sqlite v0.1.4 | 12 | github.com/bnema/purego-sqlite v0.1.4 | ||
M go.sum +2 -2 generated file: collapsed
M vendor/github.com/bnema/purego-cef/cef/cef_browser_gen.go +15 -2 generated file: collapsed
M vendor/github.com/bnema/purego-cef/cef/cef_command_line_gen.go +15 -2 generated file: collapsed
A vendor/github.com/bnema/purego-cef/cef/cef_component_updater_gen.go +323 -0
| @@ -0,0 +1,323 @@ | |||
| 1 | + | // Code generated by cefgen. DO NOT EDIT. | |
| 2 | + | ||
| 3 | + | package cef | |
| 4 | + | ||
| 5 | + | import ( | |
| 6 | + | "runtime" | |
| 7 | + | "sync" | |
| 8 | + | "unsafe" | |
| 9 | + | ||
| 10 | + | "github.com/bnema/purego-cef/internal/capi" | |
| 11 | + | ||
| 12 | + | portin "github.com/bnema/purego-cef/internal/ports/in" | |
| 13 | + | ) | |
| 14 | + | ||
| 15 | + | // ComponentUpdateCallback Callback structure for component update results. | |
| 16 | + | type ComponentUpdateCallback = portin.ComponentUpdateCallback | |
| 17 | + | ||
| 18 | + | // componentUpdateCallbackWrapper wraps a user-provided ComponentUpdateCallback implementation together | |
| 19 | + | // with the raw CEF struct pointer allocated by NewComponentUpdateCallback. It satisfies the | |
| 20 | + | // ComponentUpdateCallback interface (by embedding the user impl) and core.RawPointerHolder | |
| 21 | + | // (so extractRawPointer can recover the raw pointer). | |
| 22 | + | type componentUpdateCallbackWrapper struct { | |
| 23 | + | ComponentUpdateCallback // embed user impl for interface delegation | |
| 24 | + | rawPtr *capi.CEFComponentUpdateCallbackT | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | func (w *componentUpdateCallbackWrapper) RawPointer() unsafe.Pointer { | |
| 28 | + | return unsafe.Pointer(w.rawPtr) | |
| 29 | + | } | |
| 30 | + | ||
| 31 | + | var componentUpdateCallbackOnCompleteSharedOnce sync.Once | |
| 32 | + | var componentUpdateCallbackOnCompleteSharedCallback uintptr | |
| 33 | + | ||
| 34 | + | func componentUpdateCallbackOnCompleteCEFCallback() uintptr { | |
| 35 | + | return sharedCEFCallback(&componentUpdateCallbackOnCompleteSharedOnce, &componentUpdateCallbackOnCompleteSharedCallback, func(self uintptr, arg0 uintptr, arg1 uintptr) { | |
| 36 | + | impl, ownerOK := cefCallbackOwnerAs[ComponentUpdateCallback](self) | |
| 37 | + | if !ownerOK { | |
| 38 | + | return | |
| 39 | + | } | |
| 40 | + | componentID := goString(unsafe.Pointer(arg0)) | |
| 41 | + | error := ComponentUpdateError(arg1) | |
| 42 | + | impl.OnComplete(componentID, error) | |
| 43 | + | }) | |
| 44 | + | } | |
| 45 | + | ||
| 46 | + | // NewComponentUpdateCallback creates a CEF handler backed by the given implementation. | |
| 47 | + | func NewComponentUpdateCallback(impl ComponentUpdateCallback) ComponentUpdateCallback { | |
| 48 | + | if isNilImpl(impl) { | |
| 49 | + | return nil | |
| 50 | + | } | |
| 51 | + | r := new(capi.CEFComponentUpdateCallbackT) | |
| 52 | + | w := &componentUpdateCallbackWrapper{rawPtr: r} | |
| 53 | + | w.ComponentUpdateCallback = impl | |
| 54 | + | initRefCount(unsafe.Pointer(r), unsafe.Sizeof(*r), w) | |
| 55 | + | ||
| 56 | + | r.OverrideOnComplete(componentUpdateCallbackOnCompleteCEFCallback()) | |
| 57 | + | ||
| 58 | + | return w | |
| 59 | + | } | |
| 60 | + | ||
| 61 | + | // componentUpdateCallbackImpl is a reverse wrapper for a CEF-owned ComponentUpdateCallback pointer. | |
| 62 | + | // Release is idempotent, but callers must externally synchronize Release with | |
| 63 | + | // concurrent method calls and must not use the wrapper after Release returns. | |
| 64 | + | type componentUpdateCallbackImpl struct { | |
| 65 | + | rawPtr *capi.CEFComponentUpdateCallbackT | |
| 66 | + | releaseOnce sync.Once | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | func (obj *componentUpdateCallbackImpl) OnComplete(componentID string, error ComponentUpdateError) { | |
| 70 | + | if obj == nil || obj.rawPtr == nil { | |
| 71 | + | return | |
| 72 | + | } | |
| 73 | + | rawPtr := obj.rawPtr | |
| 74 | + | componentIDStr := cefString(componentID) | |
| 75 | + | defer freeCefString(&componentIDStr) | |
| 76 | + | rawPtr.CallOnComplete(uintptr(unsafe.Pointer(&componentIDStr)), uintptr(error)) | |
| 77 | + | } | |
| 78 | + | ||
| 79 | + | func (obj *componentUpdateCallbackImpl) RawPointer() unsafe.Pointer { | |
| 80 | + | if obj == nil || obj.rawPtr == nil { | |
| 81 | + | return nil | |
| 82 | + | } | |
| 83 | + | return unsafe.Pointer(obj.rawPtr) | |
| 84 | + | } | |
| 85 | + | ||
| 86 | + | // Release releases the underlying CEF object. | |
| 87 | + | func (obj *componentUpdateCallbackImpl) Release() { | |
| 88 | + | if obj == nil { | |
| 89 | + | return | |
| 90 | + | } | |
| 91 | + | obj.releaseOnce.Do(func() { | |
| 92 | + | if obj.rawPtr == nil { | |
| 93 | + | return | |
| 94 | + | } | |
| 95 | + | rawPtr := obj.rawPtr | |
| 96 | + | obj.rawPtr = nil | |
| 97 | + | runtime.SetFinalizer(obj, nil) | |
| 98 | + | base := (*capi.CEFBaseRefCountedT)(unsafe.Pointer(rawPtr)) | |
| 99 | + | base.CallRelease() | |
| 100 | + | }) | |
| 101 | + | } | |
| 102 | + | ||
| 103 | + | // wrapComponentUpdateCallback wraps a CEF handler pointer received from CEF into a thin Go façade. | |
| 104 | + | func wrapComponentUpdateCallback(ptr unsafe.Pointer) ComponentUpdateCallback { | |
| 105 | + | if ptr == nil { | |
| 106 | + | return nil | |
| 107 | + | } | |
| 108 | + | r := (*capi.CEFComponentUpdateCallbackT)(ptr) | |
| 109 | + | base := (*capi.CEFBaseRefCountedT)(ptr) | |
| 110 | + | base.CallAddRef() | |
| 111 | + | impl := &componentUpdateCallbackImpl{rawPtr: r} | |
| 112 | + | runtime.SetFinalizer(impl, (*componentUpdateCallbackImpl).Release) | |
| 113 | + | return impl | |
| 114 | + | } | |
| 115 | + | ||
| 116 | + | // Component Structure representing a snapshot of a component's state at the time of retrieval. To get updated information, retrieve a new cef_component_t object via cef_component_updater_t::GetComponentByID or GetComponents. The functions of this structure may be called on any thread. | |
| 117 | + | type Component = portin.Component | |
| 118 | + | ||
| 119 | + | // componentImpl is a reverse wrapper for a CEF-owned Component pointer. | |
| 120 | + | // Release is idempotent, but callers must externally synchronize Release with | |
| 121 | + | // concurrent method calls and must not use the wrapper after Release returns. | |
| 122 | + | type componentImpl struct { | |
| 123 | + | rawPtr *capi.CEFComponentT | |
| 124 | + | releaseOnce sync.Once | |
| 125 | + | } | |
| 126 | + | ||
| 127 | + | func (obj *componentImpl) GetID() string { | |
| 128 | + | if obj == nil || obj.rawPtr == nil { | |
| 129 | + | return "" | |
| 130 | + | } | |
| 131 | + | rawPtr := obj.rawPtr | |
| 132 | + | ret := rawPtr.CallGetID() | |
| 133 | + | return goStringUserfree(unsafe.Pointer(ret)) | |
| 134 | + | } | |
| 135 | + | ||
| 136 | + | func (obj *componentImpl) GetName() string { | |
| 137 | + | if obj == nil || obj.rawPtr == nil { | |
| 138 | + | return "" | |
| 139 | + | } | |
| 140 | + | rawPtr := obj.rawPtr | |
| 141 | + | ret := rawPtr.CallGetName() | |
| 142 | + | return goStringUserfree(unsafe.Pointer(ret)) | |
| 143 | + | } | |
| 144 | + | ||
| 145 | + | func (obj *componentImpl) GetVersion() string { | |
| 146 | + | if obj == nil || obj.rawPtr == nil { | |
| 147 | + | return "" | |
| 148 | + | } | |
| 149 | + | rawPtr := obj.rawPtr | |
| 150 | + | ret := rawPtr.CallGetVersion() | |
| 151 | + | return goStringUserfree(unsafe.Pointer(ret)) | |
| 152 | + | } | |
| 153 | + | ||
| 154 | + | func (obj *componentImpl) GetState() ComponentState { | |
| 155 | + | if obj == nil || obj.rawPtr == nil { | |
| 156 | + | return 0 | |
| 157 | + | } | |
| 158 | + | rawPtr := obj.rawPtr | |
| 159 | + | ret := rawPtr.CallGetState() | |
| 160 | + | return ComponentState(ret) | |
| 161 | + | } | |
| 162 | + | ||
| 163 | + | func (obj *componentImpl) RawPointer() unsafe.Pointer { | |
| 164 | + | if obj == nil || obj.rawPtr == nil { | |
| 165 | + | return nil | |
| 166 | + | } | |
| 167 | + | return unsafe.Pointer(obj.rawPtr) | |
| 168 | + | } | |
| 169 | + | ||
| 170 | + | // Release releases the underlying CEF object. | |
| 171 | + | func (obj *componentImpl) Release() { | |
| 172 | + | if obj == nil { | |
| 173 | + | return | |
| 174 | + | } | |
| 175 | + | obj.releaseOnce.Do(func() { | |
| 176 | + | if obj.rawPtr == nil { | |
| 177 | + | return | |
| 178 | + | } | |
| 179 | + | rawPtr := obj.rawPtr | |
| 180 | + | obj.rawPtr = nil | |
| 181 | + | runtime.SetFinalizer(obj, nil) | |
| 182 | + | base := (*capi.CEFBaseRefCountedT)(unsafe.Pointer(rawPtr)) | |
| 183 | + | base.CallRelease() | |
| 184 | + | }) | |
| 185 | + | } | |
| 186 | + | ||
| 187 | + | func wrapComponent(ptr unsafe.Pointer) Component { | |
| 188 | + | if ptr == nil { | |
| 189 | + | return nil | |
| 190 | + | } | |
| 191 | + | r := (*capi.CEFComponentT)(ptr) | |
| 192 | + | base := (*capi.CEFBaseRefCountedT)(ptr) | |
| 193 | + | base.CallAddRef() | |
| 194 | + | impl := &componentImpl{rawPtr: r} | |
| 195 | + | runtime.SetFinalizer(impl, (*componentImpl).Release) | |
| 196 | + | return impl | |
| 197 | + | } | |
| 198 | + | ||
| 199 | + | // ComponentUpdater This structure provides access to Chromium's component updater service, allowing clients to discover registered components and trigger on-demand updates. The functions of this structure may only be called on the browser process UI thread. If the CEF context is not initialized or the component updater service is not available, functions will return safe defaults (0, nullptr, or NULL). | |
| 200 | + | type ComponentUpdater = portin.ComponentUpdater | |
| 201 | + | ||
| 202 | + | // componentUpdaterImpl is a reverse wrapper for a CEF-owned ComponentUpdater pointer. | |
| 203 | + | // Release is idempotent, but callers must externally synchronize Release with | |
| 204 | + | // concurrent method calls and must not use the wrapper after Release returns. | |
| 205 | + | type componentUpdaterImpl struct { | |
| 206 | + | rawPtr *capi.CEFComponentUpdaterT | |
| 207 | + | releaseOnce sync.Once | |
| 208 | + | } | |
| 209 | + | ||
| 210 | + | func (obj *componentUpdaterImpl) GetComponentCount() int { | |
| 211 | + | if obj == nil || obj.rawPtr == nil { | |
| 212 | + | return 0 | |
| 213 | + | } | |
| 214 | + | rawPtr := obj.rawPtr | |
| 215 | + | ret := rawPtr.CallGetComponentCount() | |
| 216 | + | return int(ret) | |
| 217 | + | } | |
| 218 | + | ||
| 219 | + | func (obj *componentUpdaterImpl) GetComponents(componentscount *int, components []Component) { | |
| 220 | + | if obj == nil || obj.rawPtr == nil { | |
| 221 | + | return | |
| 222 | + | } | |
| 223 | + | rawPtr := obj.rawPtr | |
| 224 | + | var componentsRaw []uintptr | |
| 225 | + | var componentsPtr unsafe.Pointer | |
| 226 | + | componentsCountPtr := componentscount | |
| 227 | + | if componentsCountPtr == nil { | |
| 228 | + | componentsCountScratch := len(components) | |
| 229 | + | componentsCountPtr = &componentsCountScratch | |
| 230 | + | } else { | |
| 231 | + | *componentsCountPtr = len(components) | |
| 232 | + | } | |
| 233 | + | if len(components) > 0 { | |
| 234 | + | componentsRaw = make([]uintptr, len(components)) | |
| 235 | + | componentsPtr = unsafe.Pointer(&componentsRaw[0]) | |
| 236 | + | } | |
| 237 | + | rawPtr.CallGetComponents(uintptr(unsafe.Pointer(componentsCountPtr)), uintptr(componentsPtr)) | |
| 238 | + | if len(components) > 0 { | |
| 239 | + | n := len(components) | |
| 240 | + | if *componentsCountPtr < n { | |
| 241 | + | n = *componentsCountPtr | |
| 242 | + | } | |
| 243 | + | for i := 0; i < n; i++ { | |
| 244 | + | components[i] = wrapComponent(unsafe.Pointer(componentsRaw[i])) | |
| 245 | + | } | |
| 246 | + | } | |
| 247 | + | } | |
| 248 | + | ||
| 249 | + | func (obj *componentUpdaterImpl) GetComponentByID(componentID string) Component { | |
| 250 | + | if obj == nil || obj.rawPtr == nil { | |
| 251 | + | return nil | |
| 252 | + | } | |
| 253 | + | rawPtr := obj.rawPtr | |
| 254 | + | componentIDStr := cefString(componentID) | |
| 255 | + | defer freeCefString(&componentIDStr) | |
| 256 | + | ret := rawPtr.CallGetComponentByID(uintptr(unsafe.Pointer(&componentIDStr))) | |
| 257 | + | return wrapComponent(unsafe.Pointer(ret)) | |
| 258 | + | } | |
| 259 | + | ||
| 260 | + | func (obj *componentUpdaterImpl) Update(componentID string, priority ComponentUpdatePriority, callback ComponentUpdateCallback) { | |
| 261 | + | if obj == nil || obj.rawPtr == nil { | |
| 262 | + | return | |
| 263 | + | } | |
| 264 | + | rawPtr := obj.rawPtr | |
| 265 | + | componentIDStr := cefString(componentID) | |
| 266 | + | defer freeCefString(&componentIDStr) | |
| 267 | + | rawPtr.CallUpdate(uintptr(unsafe.Pointer(&componentIDStr)), uintptr(priority), uintptr(extractOrWrapRawPointer(callback, func() any { return NewComponentUpdateCallback(callback) }))) | |
| 268 | + | } | |
| 269 | + | ||
| 270 | + | func (obj *componentUpdaterImpl) RawPointer() unsafe.Pointer { | |
| 271 | + | if obj == nil || obj.rawPtr == nil { | |
| 272 | + | return nil | |
| 273 | + | } | |
| 274 | + | return unsafe.Pointer(obj.rawPtr) | |
| 275 | + | } | |
| 276 | + | ||
| 277 | + | // Release releases the underlying CEF object. | |
| 278 | + | func (obj *componentUpdaterImpl) Release() { | |
| 279 | + | if obj == nil { | |
| 280 | + | return | |
| 281 | + | } | |
| 282 | + | obj.releaseOnce.Do(func() { | |
| 283 | + | if obj.rawPtr == nil { | |
| 284 | + | return | |
| 285 | + | } | |
| 286 | + | rawPtr := obj.rawPtr | |
| 287 | + | obj.rawPtr = nil | |
| 288 | + | runtime.SetFinalizer(obj, nil) | |
| 289 | + | base := (*capi.CEFBaseRefCountedT)(unsafe.Pointer(rawPtr)) | |
| 290 | + | base.CallRelease() | |
| 291 | + | }) | |
| 292 | + | } | |
| 293 | + | ||
| 294 | + | func wrapComponentUpdater(ptr unsafe.Pointer) ComponentUpdater { | |
| 295 | + | if ptr == nil { | |
| 296 | + | return nil | |
| 297 | + | } | |
| 298 | + | r := (*capi.CEFComponentUpdaterT)(ptr) | |
| 299 | + | base := (*capi.CEFBaseRefCountedT)(ptr) | |
| 300 | + | base.CallAddRef() | |
| 301 | + | impl := &componentUpdaterImpl{rawPtr: r} | |
| 302 | + | runtime.SetFinalizer(impl, (*componentUpdaterImpl).Release) | |
| 303 | + | return impl | |
| 304 | + | } | |
| 305 | + | ||
| 306 | + | // takeComponentUpdater adopts a CEF ComponentUpdater pointer whose reference is already owned by | |
| 307 | + | // the caller (as returned by a global factory function). Unlike wrapComponentUpdater it | |
| 308 | + | // does NOT call AddRef, because the C API already transferred one reference to us. | |
| 309 | + | func takeComponentUpdater(ptr unsafe.Pointer) ComponentUpdater { | |
| 310 | + | if ptr == nil { | |
| 311 | + | return nil | |
| 312 | + | } | |
| 313 | + | r := (*capi.CEFComponentUpdaterT)(ptr) | |
| 314 | + | impl := &componentUpdaterImpl{rawPtr: r} | |
| 315 | + | runtime.SetFinalizer(impl, (*componentUpdaterImpl).Release) | |
| 316 | + | return impl | |
| 317 | + | } | |
| 318 | + | ||
| 319 | + | // ComponentUpdaterGet Returns the global cef_component_updater_t singleton. Returns nullptr if called from the incorrect thread. | |
| 320 | + | func ComponentUpdaterGet() ComponentUpdater { | |
| 321 | + | ret := capi.CEFComponentUpdaterGet() | |
| 322 | + | return takeComponentUpdater(ret) | |
| 323 | + | } | |
| @@ -0,0 +1,323 @@ | |||||
| 1 | + | // Code generated by cefgen. DO NOT EDIT. | |||
| 2 | + | ||||
| 3 | + | package cef | |||
| 4 | + | ||||
| 5 | + | import ( | |||
| 6 | + | "runtime" | |||
| 7 | + | "sync" | |||
| 8 | + | "unsafe" | |||
| 9 | + | ||||
| 10 | + | "github.com/bnema/purego-cef/internal/capi" | |||
| 11 | + | ||||
| 12 | + | portin "github.com/bnema/purego-cef/internal/ports/in" | |||
| 13 | + | ) | |||
| 14 | + | ||||
| 15 | + | // ComponentUpdateCallback Callback structure for component update results. | |||
| 16 | + | type ComponentUpdateCallback = portin.ComponentUpdateCallback | |||
| 17 | + | ||||
| 18 | + | // componentUpdateCallbackWrapper wraps a user-provided ComponentUpdateCallback implementation together | |||
| 19 | + | // with the raw CEF struct pointer allocated by NewComponentUpdateCallback. It satisfies the | |||
| 20 | + | // ComponentUpdateCallback interface (by embedding the user impl) and core.RawPointerHolder | |||
| 21 | + | // (so extractRawPointer can recover the raw pointer). | |||
| 22 | + | type componentUpdateCallbackWrapper struct { | |||
| 23 | + | ComponentUpdateCallback // embed user impl for interface delegation | |||
| 24 | + | rawPtr *capi.CEFComponentUpdateCallbackT | |||
| 25 | + | } | |||
| 26 | + | ||||
| 27 | + | func (w *componentUpdateCallbackWrapper) RawPointer() unsafe.Pointer { | |||
| 28 | + | return unsafe.Pointer(w.rawPtr) | |||
| 29 | + | } | |||
| 30 | + | ||||
| 31 | + | var componentUpdateCallbackOnCompleteSharedOnce sync.Once | |||
| 32 | + | var componentUpdateCallbackOnCompleteSharedCallback uintptr | |||
| 33 | + | ||||
| 34 | + | func componentUpdateCallbackOnCompleteCEFCallback() uintptr { | |||
| 35 | + | return sharedCEFCallback(&componentUpdateCallbackOnCompleteSharedOnce, &componentUpdateCallbackOnCompleteSharedCallback, func(self uintptr, arg0 uintptr, arg1 uintptr) { | |||
| 36 | + | impl, ownerOK := cefCallbackOwnerAs[ComponentUpdateCallback](self) | |||
| 37 | + | if !ownerOK { | |||
| 38 | + | return | |||
| 39 | + | } | |||
| 40 | + | componentID := goString(unsafe.Pointer(arg0)) | |||
| 41 | + | error := ComponentUpdateError(arg1) | |||
| 42 | + | impl.OnComplete(componentID, error) | |||
| 43 | + | }) | |||
| 44 | + | } | |||
| 45 | + | ||||
| 46 | + | // NewComponentUpdateCallback creates a CEF handler backed by the given implementation. | |||
| 47 | + | func NewComponentUpdateCallback(impl ComponentUpdateCallback) ComponentUpdateCallback { | |||
| 48 | + | if isNilImpl(impl) { | |||
| 49 | + | return nil | |||
| 50 | + | } | |||
| 51 | + | r := new(capi.CEFComponentUpdateCallbackT) | |||
| 52 | + | w := &componentUpdateCallbackWrapper{rawPtr: r} | |||
| 53 | + | w.ComponentUpdateCallback = impl | |||
| 54 | + | initRefCount(unsafe.Pointer(r), unsafe.Sizeof(*r), w) | |||
| 55 | + | ||||
| 56 | + | r.OverrideOnComplete(componentUpdateCallbackOnCompleteCEFCallback()) | |||
| 57 | + | ||||
| 58 | + | return w | |||
| 59 | + | } | |||
| 60 | + | ||||
| 61 | + | // componentUpdateCallbackImpl is a reverse wrapper for a CEF-owned ComponentUpdateCallback pointer. | |||
| 62 | + | // Release is idempotent, but callers must externally synchronize Release with | |||
| 63 | + | // concurrent method calls and must not use the wrapper after Release returns. | |||
| 64 | + | type componentUpdateCallbackImpl struct { | |||
| 65 | + | rawPtr *capi.CEFComponentUpdateCallbackT | |||
| 66 | + | releaseOnce sync.Once | |||
| 67 | + | } | |||
| 68 | + | ||||
| 69 | + | func (obj *componentUpdateCallbackImpl) OnComplete(componentID string, error ComponentUpdateError) { | |||
| 70 | + | if obj == nil || obj.rawPtr == nil { | |||
| 71 | + | return | |||
| 72 | + | } | |||
| 73 | + | rawPtr := obj.rawPtr | |||
| 74 | + | componentIDStr := cefString(componentID) | |||
| 75 | + | defer freeCefString(&componentIDStr) | |||
| 76 | + | rawPtr.CallOnComplete(uintptr(unsafe.Pointer(&componentIDStr)), uintptr(error)) | |||
| 77 | + | } | |||
| 78 | + | ||||
| 79 | + | func (obj *componentUpdateCallbackImpl) RawPointer() unsafe.Pointer { | |||
| 80 | + | if obj == nil || obj.rawPtr == nil { | |||
| 81 | + | return nil | |||
| 82 | + | } | |||
| 83 | + | return unsafe.Pointer(obj.rawPtr) | |||
| 84 | + | } | |||
| 85 | + | ||||
| 86 | + | // Release releases the underlying CEF object. | |||
| 87 | + | func (obj *componentUpdateCallbackImpl) Release() { | |||
| 88 | + | if obj == nil { | |||
| 89 | + | return | |||
| 90 | + | } | |||
| 91 | + | obj.releaseOnce.Do(func() { | |||
| 92 | + | if obj.rawPtr == nil { | |||
| 93 | + | return | |||
| 94 | + | } | |||
| 95 | + | rawPtr := obj.rawPtr | |||
| 96 | + | obj.rawPtr = nil | |||
| 97 | + | runtime.SetFinalizer(obj, nil) | |||
| 98 | + | base := (*capi.CEFBaseRefCountedT)(unsafe.Pointer(rawPtr)) | |||
| 99 | + | base.CallRelease() | |||
| 100 | + | }) | |||
| 101 | + | } | |||
| 102 | + | ||||
| 103 | + | // wrapComponentUpdateCallback wraps a CEF handler pointer received from CEF into a thin Go façade. | |||
| 104 | + | func wrapComponentUpdateCallback(ptr unsafe.Pointer) ComponentUpdateCallback { | |||
| 105 | + | if ptr == nil { | |||
| 106 | + | return nil | |||
| 107 | + | } | |||
| 108 | + | r := (*capi.CEFComponentUpdateCallbackT)(ptr) | |||
| 109 | + | base := (*capi.CEFBaseRefCountedT)(ptr) | |||
| 110 | + | base.CallAddRef() | |||
| 111 | + | impl := &componentUpdateCallbackImpl{rawPtr: r} | |||
| 112 | + | runtime.SetFinalizer(impl, (*componentUpdateCallbackImpl).Release) | |||
| 113 | + | return impl | |||
| 114 | + | } | |||
| 115 | + | ||||
| 116 | + | // Component Structure representing a snapshot of a component's state at the time of retrieval. To get updated information, retrieve a new cef_component_t object via cef_component_updater_t::GetComponentByID or GetComponents. The functions of this structure may be called on any thread. | |||
| 117 | + | type Component = portin.Component | |||
| 118 | + | ||||
| 119 | + | // componentImpl is a reverse wrapper for a CEF-owned Component pointer. | |||
| 120 | + | // Release is idempotent, but callers must externally synchronize Release with | |||
| 121 | + | // concurrent method calls and must not use the wrapper after Release returns. | |||
| 122 | + | type componentImpl struct { | |||
| 123 | + | rawPtr *capi.CEFComponentT | |||
| 124 | + | releaseOnce sync.Once | |||
| 125 | + | } | |||
| 126 | + | ||||
| 127 | + | func (obj *componentImpl) GetID() string { | |||
| 128 | + | if obj == nil || obj.rawPtr == nil { | |||
| 129 | + | return "" | |||
| 130 | + | } | |||
| 131 | + | rawPtr := obj.rawPtr | |||
| 132 | + | ret := rawPtr.CallGetID() | |||
| 133 | + | return goStringUserfree(unsafe.Pointer(ret)) | |||
| 134 | + | } | |||
| 135 | + | ||||
| 136 | + | func (obj *componentImpl) GetName() string { | |||
| 137 | + | if obj == nil || obj.rawPtr == nil { | |||
| 138 | + | return "" | |||
| 139 | + | } | |||
| 140 | + | rawPtr := obj.rawPtr | |||
| 141 | + | ret := rawPtr.CallGetName() | |||
| 142 | + | return goStringUserfree(unsafe.Pointer(ret)) | |||
| 143 | + | } | |||
| 144 | + | ||||
| 145 | + | func (obj *componentImpl) GetVersion() string { | |||
| 146 | + | if obj == nil || obj.rawPtr == nil { | |||
| 147 | + | return "" | |||
| 148 | + | } | |||
| 149 | + | rawPtr := obj.rawPtr | |||
| 150 | + | ret := rawPtr.CallGetVersion() | |||
| 151 | + | return goStringUserfree(unsafe.Pointer(ret)) | |||
| 152 | + | } | |||
| 153 | + | ||||
| 154 | + | func (obj *componentImpl) GetState() ComponentState { | |||
| 155 | + | if obj == nil || obj.rawPtr == nil { | |||
| 156 | + | return 0 | |||
| 157 | + | } | |||
| 158 | + | rawPtr := obj.rawPtr | |||
| 159 | + | ret := rawPtr.CallGetState() | |||
| 160 | + | return ComponentState(ret) | |||
| 161 | + | } | |||
| 162 | + | ||||
| 163 | + | func (obj *componentImpl) RawPointer() unsafe.Pointer { | |||
| 164 | + | if obj == nil || obj.rawPtr == nil { | |||
| 165 | + | return nil | |||
| 166 | + | } | |||
| 167 | + | return unsafe.Pointer(obj.rawPtr) | |||
| 168 | + | } | |||
| 169 | + | ||||
| 170 | + | // Release releases the underlying CEF object. | |||
| 171 | + | func (obj *componentImpl) Release() { | |||
| 172 | + | if obj == nil { | |||
| 173 | + | return | |||
| 174 | + | } | |||
| 175 | + | obj.releaseOnce.Do(func() { | |||
| 176 | + | if obj.rawPtr == nil { | |||
| 177 | + | return | |||
| 178 | + | } | |||
| 179 | + | rawPtr := obj.rawPtr | |||
| 180 | + | obj.rawPtr = nil | |||
| 181 | + | runtime.SetFinalizer(obj, nil) | |||
| 182 | + | base := (*capi.CEFBaseRefCountedT)(unsafe.Pointer(rawPtr)) | |||
| 183 | + | base.CallRelease() | |||
| 184 | + | }) | |||
| 185 | + | } | |||
| 186 | + | ||||
| 187 | + | func wrapComponent(ptr unsafe.Pointer) Component { | |||
| 188 | + | if ptr == nil { | |||
| 189 | + | return nil | |||
| 190 | + | } | |||
| 191 | + | r := (*capi.CEFComponentT)(ptr) | |||
| 192 | + | base := (*capi.CEFBaseRefCountedT)(ptr) | |||
| 193 | + | base.CallAddRef() | |||
| 194 | + | impl := &componentImpl{rawPtr: r} | |||
| 195 | + | runtime.SetFinalizer(impl, (*componentImpl).Release) | |||
| 196 | + | return impl | |||
| 197 | + | } | |||
| 198 | + | ||||
| 199 | + | // ComponentUpdater This structure provides access to Chromium's component updater service, allowing clients to discover registered components and trigger on-demand updates. The functions of this structure may only be called on the browser process UI thread. If the CEF context is not initialized or the component updater service is not available, functions will return safe defaults (0, nullptr, or NULL). | |||
| 200 | + | type ComponentUpdater = portin.ComponentUpdater | |||
| 201 | + | ||||
| 202 | + | // componentUpdaterImpl is a reverse wrapper for a CEF-owned ComponentUpdater pointer. | |||
| 203 | + | // Release is idempotent, but callers must externally synchronize Release with | |||
| 204 | + | // concurrent method calls and must not use the wrapper after Release returns. | |||
| 205 | + | type componentUpdaterImpl struct { | |||
| 206 | + | rawPtr *capi.CEFComponentUpdaterT | |||
| 207 | + | releaseOnce sync.Once | |||
| 208 | + | } | |||
| 209 | + | ||||
| 210 | + | func (obj *componentUpdaterImpl) GetComponentCount() int { | |||
| 211 | + | if obj == nil || obj.rawPtr == nil { | |||
| 212 | + | return 0 | |||
| 213 | + | } | |||
| 214 | + | rawPtr := obj.rawPtr | |||
| 215 | + | ret := rawPtr.CallGetComponentCount() | |||
| 216 | + | return int(ret) | |||
| 217 | + | } | |||
| 218 | + | ||||
| 219 | + | func (obj *componentUpdaterImpl) GetComponents(componentscount *int, components []Component) { | |||
| 220 | + | if obj == nil || obj.rawPtr == nil { | |||
| 221 | + | return | |||
| 222 | + | } | |||
| 223 | + | rawPtr := obj.rawPtr | |||
| 224 | + | var componentsRaw []uintptr | |||
| 225 | + | var componentsPtr unsafe.Pointer | |||
| 226 | + | componentsCountPtr := componentscount | |||
| 227 | + | if componentsCountPtr == nil { | |||
| 228 | + | componentsCountScratch := len(components) | |||
| 229 | + | componentsCountPtr = &componentsCountScratch | |||
| 230 | + | } else { | |||
| 231 | + | *componentsCountPtr = len(components) | |||
| 232 | + | } | |||
| 233 | + | if len(components) > 0 { | |||
| 234 | + | componentsRaw = make([]uintptr, len(components)) | |||
| 235 | + | componentsPtr = unsafe.Pointer(&componentsRaw[0]) | |||
| 236 | + | } | |||
| 237 | + | rawPtr.CallGetComponents(uintptr(unsafe.Pointer(componentsCountPtr)), uintptr(componentsPtr)) | |||
| 238 | + | if len(components) > 0 { | |||
| 239 | + | n := len(components) | |||
| 240 | + | if *componentsCountPtr < n { | |||
| 241 | + | n = *componentsCountPtr | |||
| 242 | + | } | |||
| 243 | + | for i := 0; i < n; i++ { | |||
| 244 | + | components[i] = wrapComponent(unsafe.Pointer(componentsRaw[i])) | |||
| 245 | + | } | |||
| 246 | + | } | |||
| 247 | + | } | |||
| 248 | + | ||||
| 249 | + | func (obj *componentUpdaterImpl) GetComponentByID(componentID string) Component { | |||
| 250 | + | if obj == nil || obj.rawPtr == nil { | |||
| 251 | + | return nil | |||
| 252 | + | } | |||
| 253 | + | rawPtr := obj.rawPtr | |||
| 254 | + | componentIDStr := cefString(componentID) | |||
| 255 | + | defer freeCefString(&componentIDStr) | |||
| 256 | + | ret := rawPtr.CallGetComponentByID(uintptr(unsafe.Pointer(&componentIDStr))) | |||
| 257 | + | return wrapComponent(unsafe.Pointer(ret)) | |||
| 258 | + | } | |||
| 259 | + | ||||
| 260 | + | func (obj *componentUpdaterImpl) Update(componentID string, priority ComponentUpdatePriority, callback ComponentUpdateCallback) { | |||
| 261 | + | if obj == nil || obj.rawPtr == nil { | |||
| 262 | + | return | |||
| 263 | + | } | |||
| 264 | + | rawPtr := obj.rawPtr | |||
| 265 | + | componentIDStr := cefString(componentID) | |||
| 266 | + | defer freeCefString(&componentIDStr) | |||
| 267 | + | rawPtr.CallUpdate(uintptr(unsafe.Pointer(&componentIDStr)), uintptr(priority), uintptr(extractOrWrapRawPointer(callback, func() any { return NewComponentUpdateCallback(callback) }))) | |||
| 268 | + | } | |||
| 269 | + | ||||
| 270 | + | func (obj *componentUpdaterImpl) RawPointer() unsafe.Pointer { | |||
| 271 | + | if obj == nil || obj.rawPtr == nil { | |||
| 272 | + | return nil | |||
| 273 | + | } | |||
| 274 | + | return unsafe.Pointer(obj.rawPtr) | |||
| 275 | + | } | |||
| 276 | + | ||||
| 277 | + | // Release releases the underlying CEF object. | |||
| 278 | + | func (obj *componentUpdaterImpl) Release() { | |||
| 279 | + | if obj == nil { | |||
| 280 | + | return | |||
| 281 | + | } | |||
| 282 | + | obj.releaseOnce.Do(func() { | |||
| 283 | + | if obj.rawPtr == nil { | |||
| 284 | + | return | |||
| 285 | + | } | |||
| 286 | + | rawPtr := obj.rawPtr | |||
| 287 | + | obj.rawPtr = nil | |||
| 288 | + | runtime.SetFinalizer(obj, nil) | |||
| 289 | + | base := (*capi.CEFBaseRefCountedT)(unsafe.Pointer(rawPtr)) | |||
| 290 | + | base.CallRelease() | |||
| 291 | + | }) | |||
| 292 | + | } | |||
| 293 | + | ||||
| 294 | + | func wrapComponentUpdater(ptr unsafe.Pointer) ComponentUpdater { | |||
| 295 | + | if ptr == nil { | |||
| 296 | + | return nil | |||
| 297 | + | } | |||
| 298 | + | r := (*capi.CEFComponentUpdaterT)(ptr) | |||
| 299 | + | base := (*capi.CEFBaseRefCountedT)(ptr) | |||
| 300 | + | base.CallAddRef() | |||
| 301 | + | impl := &componentUpdaterImpl{rawPtr: r} | |||
| 302 | + | runtime.SetFinalizer(impl, (*componentUpdaterImpl).Release) | |||
| 303 | + | return impl | |||
| 304 | + | } | |||
| 305 | + | ||||
| 306 | + | // takeComponentUpdater adopts a CEF ComponentUpdater pointer whose reference is already owned by | |||
| 307 | + | // the caller (as returned by a global factory function). Unlike wrapComponentUpdater it | |||
| 308 | + | // does NOT call AddRef, because the C API already transferred one reference to us. | |||
| 309 | + | func takeComponentUpdater(ptr unsafe.Pointer) ComponentUpdater { | |||
| 310 | + | if ptr == nil { | |||
| 311 | + | return nil | |||
| 312 | + | } | |||
| 313 | + | r := (*capi.CEFComponentUpdaterT)(ptr) | |||
| 314 | + | impl := &componentUpdaterImpl{rawPtr: r} | |||
| 315 | + | runtime.SetFinalizer(impl, (*componentUpdaterImpl).Release) | |||
| 316 | + | return impl | |||
| 317 | + | } | |||
| 318 | + | ||||
| 319 | + | // ComponentUpdaterGet Returns the global cef_component_updater_t singleton. Returns nullptr if called from the incorrect thread. | |||
| 320 | + | func ComponentUpdaterGet() ComponentUpdater { | |||
| 321 | + | ret := capi.CEFComponentUpdaterGet() | |||
| 322 | + | return takeComponentUpdater(ret) | |||
| 323 | + | } | |||