-
Notifications
You must be signed in to change notification settings - Fork 23
/
chromium.go
75 lines (67 loc) · 1.76 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
//----------------------------------------
//
// 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/cef/internal/def"
"github.com/energye/energy/v2/common/imports"
. "github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl"
"github.com/energye/golcl/lcl/types"
"unsafe"
)
// IChromium 组件接口
type IChromium interface {
lcl.IObject
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
isClosing bool
}
// NewChromium 创建一个新的 TCEFChromium
func NewChromium(owner lcl.IComponent, config *TCefChromiumConfig) IChromium {
m := new(TCEFChromium)
if config != nil {
m.config = config
} else {
m.config = NewChromiumConfig()
}
r1, _, _ := imports.Proc(def.CEFChromium_Create).Call(lcl.CheckPtr(owner))
m.instance = unsafe.Pointer(r1)
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)
}