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
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// cef -> energy 结构类型定义
|
2022-10-04 13:21:05 +08:00
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
2022-10-04 22:34:57 +08:00
|
|
|
. "github.com/energye/energy/consts"
|
2022-12-14 11:11:33 +08:00
|
|
|
. "github.com/energye/energy/types"
|
2023-03-03 10:00:29 +08:00
|
|
|
"github.com/energye/golcl/lcl"
|
2022-10-04 13:21:05 +08:00
|
|
|
"time"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefCloseBrowsesAction 浏览器关闭控制
|
2022-12-13 22:43:31 +08:00
|
|
|
type TCefCloseBrowsesAction = CBS
|
2022-10-04 13:21:05 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ICefCookie CEF Cookie
|
2022-10-04 13:21:05 +08:00
|
|
|
type ICefCookie struct {
|
|
|
|
Url, Name, Value, Domain, Path string
|
|
|
|
Secure, Httponly, HasExpires bool
|
|
|
|
Creation, LastAccess, Expires time.Time
|
|
|
|
Count, Total, ID int32
|
|
|
|
SameSite TCefCookieSameSite
|
|
|
|
Priority TCefCookiePriority
|
|
|
|
SetImmediately bool
|
|
|
|
DeleteCookie bool
|
|
|
|
Result bool
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefKeyEvent CEF 键盘事件
|
2022-10-04 13:21:05 +08:00
|
|
|
type TCefKeyEvent struct {
|
|
|
|
Kind TCefKeyEventType // called 'type' in the original CEF source code
|
|
|
|
Modifiers TCefEventFlags
|
2022-12-14 11:11:33 +08:00
|
|
|
WindowsKeyCode Int32
|
|
|
|
NativeKeyCode Int32
|
|
|
|
IsSystemKey Int32
|
|
|
|
Character UInt16
|
|
|
|
UnmodifiedCharacter UInt16
|
|
|
|
FocusOnEditableField Int32
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefRequestContextSettings CEF 请求上下文配置
|
2022-12-13 22:43:31 +08:00
|
|
|
type TCefRequestContextSettings struct {
|
2022-12-14 11:11:33 +08:00
|
|
|
Size UInt32
|
2022-12-13 22:43:31 +08:00
|
|
|
CachePath TCefString
|
2022-12-14 11:11:33 +08:00
|
|
|
PersistSessionCookies Int32
|
|
|
|
PersistUserPreferences Int32
|
2022-12-13 22:43:31 +08:00
|
|
|
AcceptLanguageList TCefString
|
|
|
|
CookieableSchemesList TCefString
|
2022-12-14 11:11:33 +08:00
|
|
|
CookieableSchemesExcludeDefaults Int32
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefRequestContextSettings) ToPtr() *tCefRequestContextSettingsPtr {
|
|
|
|
return &tCefRequestContextSettingsPtr{
|
|
|
|
Size: m.Size.ToPtr(),
|
|
|
|
CachePath: m.CachePath.ToPtr(),
|
|
|
|
PersistSessionCookies: m.PersistSessionCookies.ToPtr(),
|
|
|
|
PersistUserPreferences: m.PersistUserPreferences.ToPtr(),
|
|
|
|
AcceptLanguageList: m.AcceptLanguageList.ToPtr(),
|
|
|
|
CookieableSchemesList: m.CookieableSchemesList.ToPtr(),
|
|
|
|
CookieableSchemesExcludeDefaults: m.CookieableSchemesExcludeDefaults.ToPtr(),
|
|
|
|
}
|
2022-12-13 22:43:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefBrowserSettings CEF Browser配置
|
2022-12-13 22:43:31 +08:00
|
|
|
type TCefBrowserSettings struct {
|
|
|
|
Size NativeUInt
|
|
|
|
WindowlessFrameRate Integer
|
|
|
|
StandardFontFamily TCefString
|
|
|
|
FixedFontFamily TCefString
|
|
|
|
SerifFontFamily TCefString
|
|
|
|
SansSerifFontFamily TCefString
|
|
|
|
CursiveFontFamily TCefString
|
|
|
|
FantasyFontFamily TCefString
|
|
|
|
DefaultFontSize Integer
|
|
|
|
DefaultFixedFontSize Integer
|
|
|
|
MinimumFontSize Integer
|
|
|
|
MinimumLogicalFontSize Integer
|
|
|
|
DefaultEncoding TCefString
|
|
|
|
RemoteFonts TCefState
|
|
|
|
Javascript TCefState
|
|
|
|
JavascriptCloseWindows TCefState
|
|
|
|
JavascriptAccessClipboard TCefState
|
|
|
|
JavascriptDomPaste TCefState
|
|
|
|
ImageLoading TCefState
|
|
|
|
ImageShrinkStandaLonetoFit TCefState
|
|
|
|
TextAreaResize TCefState
|
|
|
|
TabToLinks TCefState
|
|
|
|
LocalStorage TCefState
|
|
|
|
Databases TCefState
|
|
|
|
Webgl TCefState
|
|
|
|
BackgroundColor TCefColor
|
|
|
|
AcceptLanguageList TCefString
|
|
|
|
ChromeStatusBubble TCefState
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefCommandLine 进程启动命令行参数设置
|
2022-12-13 22:43:31 +08:00
|
|
|
type TCefCommandLine struct {
|
|
|
|
commandLines map[string]string
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefProxy 代理配置
|
2022-10-04 13:21:05 +08:00
|
|
|
type TCefProxy struct {
|
|
|
|
ProxyType TCefProxyType
|
|
|
|
ProxyScheme TCefProxyScheme
|
|
|
|
ProxyServer string
|
|
|
|
ProxyPort int32
|
|
|
|
ProxyUsername string
|
|
|
|
ProxyPassword string
|
|
|
|
ProxyScriptURL string
|
|
|
|
ProxyByPassList string
|
|
|
|
MaxConnectionsPerProxy int32
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefTouchEvent 触摸事件
|
2022-10-04 13:21:05 +08:00
|
|
|
type TCefTouchEvent struct {
|
|
|
|
Id int32
|
|
|
|
X float32
|
|
|
|
Y float32
|
|
|
|
RadiusX float32
|
|
|
|
RadiusY float32
|
|
|
|
RotationAngle float32
|
|
|
|
Pressure float32
|
|
|
|
Type TCefTouchEeventType
|
|
|
|
Modifiers TCefEventFlags
|
|
|
|
PointerType TCefPointerType
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCustomHeader 自定义请求头
|
2023-02-04 23:52:15 +08:00
|
|
|
type TCustomHeader struct {
|
|
|
|
CustomHeaderName string
|
|
|
|
CustomHeaderValue string
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefMouseEvent 鼠标事件
|
2022-10-04 13:21:05 +08:00
|
|
|
type TCefMouseEvent struct {
|
|
|
|
X int32
|
|
|
|
Y int32
|
|
|
|
Modifiers TCefEventFlags
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// BeforePopupInfo 弹出子窗口信息
|
2022-10-04 13:21:05 +08:00
|
|
|
type BeforePopupInfo struct {
|
|
|
|
TargetUrl string
|
|
|
|
TargetFrameName string
|
|
|
|
TargetDisposition TCefWindowOpenDisposition
|
|
|
|
UserGesture bool
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefRect 矩形
|
2022-10-04 13:21:05 +08:00
|
|
|
type TCefRect struct {
|
|
|
|
X int32
|
|
|
|
Y int32
|
|
|
|
Width int32
|
|
|
|
Height int32
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefSize 大小
|
2023-01-07 11:48:19 +08:00
|
|
|
type TCefSize struct {
|
|
|
|
Width int32
|
|
|
|
Height int32
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefPoint 位置
|
2022-12-12 17:34:57 +08:00
|
|
|
type TCefPoint struct {
|
|
|
|
X int32
|
|
|
|
Y int32
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
// ICefImage
|
|
|
|
type ICefImage struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefDraggableRegions 拖拽区域集合
|
2023-01-07 23:39:34 +08:00
|
|
|
type TCefDraggableRegions struct {
|
2023-01-08 18:05:03 +08:00
|
|
|
regions []TCefDraggableRegion
|
2023-01-08 21:38:39 +08:00
|
|
|
regionsCount int
|
2023-01-07 23:39:34 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCefDraggableRegion 拖拽区域集
|
2022-12-12 18:09:31 +08:00
|
|
|
type TCefDraggableRegion struct {
|
|
|
|
Bounds TCefRect
|
2023-01-07 23:39:34 +08:00
|
|
|
Draggable bool
|
2022-12-12 18:09:31 +08:00
|
|
|
}
|
|
|
|
|
2023-02-24 19:28:56 +08:00
|
|
|
// ICefProcessMessage
|
|
|
|
type ICefProcessMessage struct {
|
2023-03-01 14:18:39 +08:00
|
|
|
instance unsafe.Pointer
|
|
|
|
argumentList *ICefListValue
|
2023-02-24 19:28:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ICefValue -> ArgumentList
|
|
|
|
type ICefValue struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
// ICefListValue -> ArgumentList
|
|
|
|
type ICefListValue struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
// ICefBinaryValue -> ArgumentList
|
|
|
|
type ICefBinaryValue struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
// ICefDictionaryValue -> ArgumentList
|
|
|
|
type ICefDictionaryValue struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ICefDisplay
|
2022-12-13 09:14:59 +08:00
|
|
|
type ICefDisplay struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ICefWindow
|
2022-12-13 11:49:32 +08:00
|
|
|
type ICefWindow struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-26 22:29:03 +08:00
|
|
|
// ICefRequest
|
|
|
|
type ICefRequest struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
Url string
|
|
|
|
Method string
|
|
|
|
ReferrerUrl string
|
|
|
|
ReferrerPolicy TCefReferrerPolicy
|
|
|
|
Flags TCefUrlRequestFlags
|
|
|
|
FirstPartyForCookies string
|
|
|
|
ResourceType TCefResourceType
|
|
|
|
TransitionType TCefTransitionType
|
|
|
|
Identifier uint64
|
|
|
|
}
|
|
|
|
|
|
|
|
// ICefResponse 实例
|
|
|
|
type ICefResponse struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
Status int32
|
|
|
|
StatusText string
|
|
|
|
MimeType string
|
|
|
|
Charset string
|
|
|
|
Error TCefErrorCode
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
|
2023-02-27 09:15:37 +08:00
|
|
|
// ICefStringMultiMap 实例
|
|
|
|
type ICefStringMultiMap struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-26 23:21:44 +08:00
|
|
|
// ICefPostData
|
|
|
|
type ICefPostData struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-27 11:33:00 +08:00
|
|
|
// ICefPostDataElement
|
|
|
|
type ICefPostDataElement struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
// TCefPostDataElementArray
|
|
|
|
type TCefPostDataElementArray struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
postDataElement uintptr
|
|
|
|
postDataElementLength uint32
|
|
|
|
}
|
|
|
|
|
2023-02-28 21:52:13 +08:00
|
|
|
// ICefBrowserView
|
|
|
|
type ICefBrowserView struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ICefView
|
2022-12-31 13:16:30 +08:00
|
|
|
type ICefView struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ICefClient
|
2022-10-04 13:21:05 +08:00
|
|
|
type ICefClient struct {
|
2022-12-12 17:34:57 +08:00
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ICefDragData
|
2023-01-08 17:04:39 +08:00
|
|
|
type ICefDragData struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-24 10:12:55 +08:00
|
|
|
// ICefV8Exception
|
|
|
|
type ICefV8Exception struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-23 14:34:23 +08:00
|
|
|
// ICefV8Context
|
2023-03-01 23:15:39 +08:00
|
|
|
//
|
|
|
|
// v8上下文对象
|
|
|
|
//
|
|
|
|
// 生命周期
|
|
|
|
// 1. 在回调函数中有效
|
|
|
|
// 2. 回调函数外使用 cef.V8ContextRef.Current() 获取上下文对象
|
2023-02-23 14:34:23 +08:00
|
|
|
type ICefV8Context struct {
|
|
|
|
instance unsafe.Pointer
|
2023-03-02 18:47:39 +08:00
|
|
|
browser *ICefBrowser
|
|
|
|
frame *ICefFrame
|
|
|
|
global *ICefV8Value
|
2023-02-23 14:34:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ICefV8Value
|
|
|
|
type ICefV8Value struct {
|
2023-03-02 23:47:20 +08:00
|
|
|
instance unsafe.Pointer
|
|
|
|
valueType V8ValueType
|
|
|
|
valueArrays []*ICefV8Value
|
|
|
|
valueMaps map[int]*ICefV8Value
|
2023-02-23 14:34:23 +08:00
|
|
|
}
|
|
|
|
|
2023-03-03 10:00:29 +08:00
|
|
|
// ICefV8ValueKeys
|
|
|
|
type ICefV8ValueKeys struct {
|
|
|
|
keys *lcl.TStrings
|
|
|
|
count int
|
|
|
|
}
|
|
|
|
|
2023-02-27 11:33:00 +08:00
|
|
|
// TCefV8ValueArray ICefV8Value 数组的替代结构
|
|
|
|
type TCefV8ValueArray struct {
|
2023-03-02 22:20:42 +08:00
|
|
|
instance unsafe.Pointer
|
|
|
|
arguments uintptr
|
|
|
|
argumentsLength int
|
|
|
|
argumentsCollect []*ICefV8Value
|
2023-02-27 11:33:00 +08:00
|
|
|
}
|
|
|
|
|
2023-02-23 14:34:23 +08:00
|
|
|
// ICefV8Handler
|
|
|
|
type ICefV8Handler struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
//ICefV8Interceptor
|
|
|
|
type ICefV8Interceptor struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
//ICefV8Accessor
|
|
|
|
type ICefV8Accessor struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
//ICefV8ArrayBufferReleaseCallback
|
|
|
|
type ICefV8ArrayBufferReleaseCallback struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-28 09:55:20 +08:00
|
|
|
// ICefDownloadItem 下载项
|
|
|
|
type ICefDownloadItem struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
// ICefDownloadItemCallback
|
|
|
|
//
|
|
|
|
// 下载中回调
|
|
|
|
type ICefDownloadItemCallback struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
|
|
|
// ICefBeforeDownloadCallback
|
|
|
|
//
|
|
|
|
// 下载之前回调
|
|
|
|
type ICefBeforeDownloadCallback struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-03-01 23:02:14 +08:00
|
|
|
// ICefPdfPrintCallback
|
|
|
|
type ICefPdfPrintCallback struct {
|
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-03-01 20:25:21 +08:00
|
|
|
type CefPdfPrintSettings struct {
|
2023-03-01 23:02:14 +08:00
|
|
|
Landscape int32 // Integer
|
|
|
|
PrintBackground int32 // Integer
|
|
|
|
Scale float64 // double
|
|
|
|
PaperWidth float64 // double
|
|
|
|
PaperHeight float64 // double
|
|
|
|
PreferCssPageSize int32 // Integer
|
|
|
|
MarginType TCefPdfPrintMarginType // TCefPdfPrintMarginType
|
|
|
|
MarginTop float64 // double
|
|
|
|
MarginRight float64 // double
|
|
|
|
MarginBottom float64 // double
|
|
|
|
MarginLeft float64 // double
|
|
|
|
PageRanges string // TCefString
|
|
|
|
DisplayHeaderFooter int32 // Integer
|
|
|
|
HeaderTemplate string // TCefString
|
|
|
|
FooterTemplate string // TCefString
|
2023-03-01 20:25:21 +08:00
|
|
|
}
|
|
|
|
|
2023-02-26 23:21:44 +08:00
|
|
|
// Exception 异常返回信息
|
2023-02-23 22:19:04 +08:00
|
|
|
type Exception struct {
|
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Exception) SetMessage(message string) {
|
|
|
|
m.message = message
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Exception) Message() string {
|
|
|
|
return m.message
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// NewCefRect
|
2023-01-07 11:48:19 +08:00
|
|
|
func NewCefRect(x, y, width, height int32) *TCefRect {
|
|
|
|
return &TCefRect{
|
|
|
|
X: x,
|
|
|
|
Y: y,
|
|
|
|
Width: width,
|
|
|
|
Height: height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// NewCefSize
|
2022-12-27 21:38:01 +08:00
|
|
|
func NewCefSize(width, height int32) *TCefSize {
|
|
|
|
return &TCefSize{
|
|
|
|
Width: width,
|
|
|
|
Height: height,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// NewCefPoint
|
2023-01-07 11:48:19 +08:00
|
|
|
func NewCefPoint(x, y int32) *TCefPoint {
|
|
|
|
return &TCefPoint{
|
|
|
|
X: x,
|
|
|
|
Y: y,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *ICefClient) SetClient(client *ICefClient) {
|
|
|
|
m.instance = client.instance
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefKeyEvent) KeyDown() bool {
|
|
|
|
return m.Kind == KEYEVENT_RAW_KEYDOWN || m.Kind == KEYEVENT_KEYDOWN
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCefKeyEvent) KeyUp() bool {
|
|
|
|
return m.Kind == KEYEVENT_KEYUP
|
|
|
|
}
|