-
Notifications
You must be signed in to change notification settings - Fork 23
/
chromium.go
82 lines (73 loc) · 1.92 KB
/
chromium.go
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
78
79
80
81
82
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
// CEF Chromium 组件
package cef
import (
. "github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
"unsafe"
)
// IChromium 组件接口
type IChromium interface {
IChromiumProc
IChromiumEvent
}
// TCEFChromium 组件
type TCEFChromium struct {
*lcl.TComponent
instance unsafe.Pointer
options IChromiumOptions
config *TCefChromiumConfig
browser *ICefBrowser
idBrowsers map[int32]*ICefBrowser
browserHandle types.HWND
widgetHandle types.HWND
renderHandle types.HWND
initialized bool
}
// NewChromium 创建一个新的 TCEFChromium
func NewChromium(owner lcl.IComponent, config *TCefChromiumConfig) IChromium {
m := new(TCEFChromium)
if config != nil {
m.config = config
} else {
m.config = NewChromiumConfig()
}
m.instance = unsafe.Pointer(_CEFChromium_Create(lcl.CheckPtr(owner)))
m.initDefault()
m.options = NewChromiumOptions(m)
return m
}
// 默认的初始配置
func (m *TCEFChromium) initDefault() {
//通过设置这些首选项,可以降低/避免WebRTC的IP泄漏
m.SetWebRTCIPHandlingPolicy(HpDisableNonProxiedUDP)
m.SetWebRTCMultipleRoutes(STATE_DISABLED)
m.SetWebRTCNonproxiedUDP(STATE_DISABLED)
}
// Instance 组件实例指针
func (m *TCEFChromium) Instance() uintptr {
if m == nil || m.instance == nil {
return 0
}
return uintptr(m.instance)
}
// ExecuteJavaScript
// 执行JS代码
//
// code: js代码
//
// scriptURL: js脚本地址 默认about:blank
//
// startLine: js脚本启始执行行号
func (m *TCEFChromium) ExecuteJavaScript(code, scriptURL string, startLine int32) {
_CEFChromium_ExecuteJavaScript(uintptr(m.instance), code, scriptURL, startLine)
}