2022-10-04 13:21:05 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2022-10-04 13:21:05 +08:00
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
package cef
|
|
|
|
|
2023-02-24 10:12:55 +08:00
|
|
|
import (
|
2023-06-11 00:10:55 +08:00
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports"
|
2023-02-24 10:12:55 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2023-02-25 22:23:57 +08:00
|
|
|
// V8ContextRef -> ICefV8Context
|
|
|
|
var V8ContextRef *cefV8ContextRef
|
|
|
|
|
|
|
|
// cefV8ContextRef
|
|
|
|
type cefV8ContextRef uintptr
|
|
|
|
|
2023-02-23 14:34:23 +08:00
|
|
|
// Instance 实例
|
|
|
|
func (m *ICefV8Context) Instance() uintptr {
|
|
|
|
return uintptr(m.instance)
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
2023-02-24 10:12:55 +08:00
|
|
|
|
|
|
|
func (m *ICefV8Context) Eval(code, scriptUrl string, startLine int32) (value *ICefV8Value, exception *ICefV8Exception, ok bool) {
|
2023-03-21 13:18:44 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-02-24 10:12:55 +08:00
|
|
|
var returnValuePtr uintptr
|
|
|
|
var returnExceptionPtr uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefV8Context_Eval).Call(m.Instance(), api.PascalStr(code), api.PascalStr(scriptUrl), uintptr(startLine), uintptr(unsafe.Pointer(&returnValuePtr)), uintptr(unsafe.Pointer(&returnExceptionPtr)))
|
2023-02-24 10:12:55 +08:00
|
|
|
ok = api.GoBool(r1)
|
|
|
|
if ok {
|
|
|
|
value = &ICefV8Value{instance: unsafe.Pointer(returnValuePtr)}
|
|
|
|
} else {
|
|
|
|
exception = &ICefV8Exception{instance: unsafe.Pointer(returnExceptionPtr)}
|
|
|
|
}
|
|
|
|
return value, exception, api.GoBool(r1)
|
|
|
|
}
|
|
|
|
|
2023-02-25 19:13:07 +08:00
|
|
|
// Enter 进入上下文
|
2023-02-24 10:12:55 +08:00
|
|
|
func (m *ICefV8Context) Enter() bool {
|
2023-03-21 13:18:44 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefV8Context_Enter).Call(m.Instance())
|
2023-02-24 10:12:55 +08:00
|
|
|
return api.GoBool(r1)
|
|
|
|
}
|
|
|
|
|
2023-02-25 19:13:07 +08:00
|
|
|
// Exit 退出上下文
|
2023-02-24 10:12:55 +08:00
|
|
|
func (m *ICefV8Context) Exit() bool {
|
2023-03-21 13:18:44 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefV8Context_Exit).Call(m.Instance())
|
2023-02-24 10:12:55 +08:00
|
|
|
return api.GoBool(r1)
|
|
|
|
}
|
|
|
|
|
2023-03-21 13:18:44 +08:00
|
|
|
func (m *ICefV8Context) IsValid() bool {
|
|
|
|
if m == nil || m.instance == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-02-24 10:12:55 +08:00
|
|
|
func (m *ICefV8Context) IsSame(that *ICefV8Context) bool {
|
2023-03-21 13:18:44 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return false
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
r1, _, _ := imports.Proc(def.CefV8Context_IsSame).Call(m.Instance(), that.Instance())
|
2023-02-24 10:12:55 +08:00
|
|
|
return api.GoBool(r1)
|
|
|
|
}
|
2023-02-25 22:23:57 +08:00
|
|
|
|
|
|
|
func (m *ICefV8Context) Browser() *ICefBrowser {
|
2023-03-21 13:18:44 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return nil
|
|
|
|
}
|
2023-03-02 18:47:39 +08:00
|
|
|
if m.browser == nil {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Context_Browser).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-03-02 18:47:39 +08:00
|
|
|
m.browser = &ICefBrowser{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
2023-02-25 22:23:57 +08:00
|
|
|
}
|
2023-03-02 18:47:39 +08:00
|
|
|
return m.browser
|
2023-02-25 22:23:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefV8Context) Frame() *ICefFrame {
|
2023-03-21 13:18:44 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return nil
|
|
|
|
}
|
2023-03-02 18:47:39 +08:00
|
|
|
if m.frame == nil {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Context_Frame).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-03-02 18:47:39 +08:00
|
|
|
m.frame = &ICefFrame{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
2023-02-25 22:23:57 +08:00
|
|
|
}
|
2023-03-02 18:47:39 +08:00
|
|
|
return m.frame
|
2023-02-25 22:23:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefV8Context) Global() *ICefV8Value {
|
2023-03-21 13:18:44 +08:00
|
|
|
if !m.IsValid() {
|
|
|
|
return nil
|
|
|
|
}
|
2023-03-02 18:47:39 +08:00
|
|
|
if m.global == nil {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8Context_Global).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-03-02 18:47:39 +08:00
|
|
|
m.global = &ICefV8Value{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
2023-02-25 22:23:57 +08:00
|
|
|
}
|
2023-03-02 18:47:39 +08:00
|
|
|
return m.global
|
2023-02-25 22:23:57 +08:00
|
|
|
}
|
|
|
|
|
2023-03-09 16:35:38 +08:00
|
|
|
func (m *ICefV8Context) Free() {
|
2023-03-12 21:02:35 +08:00
|
|
|
if m.instance != nil {
|
2023-03-21 13:18:44 +08:00
|
|
|
if m.frame != nil {
|
|
|
|
m.frame.Free()
|
|
|
|
m.frame = nil
|
|
|
|
}
|
|
|
|
if m.browser != nil {
|
|
|
|
m.browser.Free()
|
|
|
|
m.browser = nil
|
|
|
|
}
|
|
|
|
if m.global != nil {
|
|
|
|
m.global.Free()
|
|
|
|
m.global = nil
|
|
|
|
}
|
2023-03-12 21:02:35 +08:00
|
|
|
m.base.Free(m.Instance())
|
|
|
|
m.instance = nil
|
|
|
|
}
|
2023-03-09 16:35:38 +08:00
|
|
|
}
|
|
|
|
|
2023-02-25 22:23:57 +08:00
|
|
|
func (m *cefV8ContextRef) Current() *ICefV8Context {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8ContextRef_Current).Call(uintptr(unsafe.Pointer(&result)))
|
2023-02-25 22:23:57 +08:00
|
|
|
return &ICefV8Context{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *cefV8ContextRef) Entered() *ICefV8Context {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8ContextRef_Entered).Call(uintptr(unsafe.Pointer(&result)))
|
2023-02-25 22:23:57 +08:00
|
|
|
return &ICefV8Context{
|
|
|
|
instance: unsafe.Pointer(result),
|
|
|
|
}
|
|
|
|
}
|
2023-03-04 11:19:45 +08:00
|
|
|
|
|
|
|
func (m *cefV8ContextRef) UnWrap(data *ICefV8Context) *ICefV8Context {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefV8ContextRef_UnWrap).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-03-04 11:58:35 +08:00
|
|
|
data.instance = unsafe.Pointer(result)
|
|
|
|
return data
|
2023-03-04 11:19:45 +08:00
|
|
|
}
|