forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcefBrowser.go
165 lines (133 loc) · 5.39 KB
/
cefBrowser.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Copyright (c) 2014 The cefcapi authors. All rights reserved.
// License: BSD 3-clause.
// Website: https://github.com/fromkeith/cefcapi
package cef2go
/*
#include <stdlib.h>
#include "cefBase.h"
#include "include/capi/cef_client_capi.h"
#include "include/capi/cef_browser_capi.h"
extern struct _cef_browser_host_t* cef_browser_t_get_host(struct _cef_browser_t* self);
extern int cef_browser_t_can_go_back(struct _cef_browser_t* self);
extern void cef_browser_t_go_back(struct _cef_browser_t* self);
extern int cef_browser_t_can_go_forward(struct _cef_browser_t* self);
extern void cef_browser_t_go_forward(struct _cef_browser_t* self);
extern int cef_browser_t_is_loading(struct _cef_browser_t* self);
extern void cef_browser_t_reload(struct _cef_browser_t* self);
extern void cef_browser_t_reload_ignore_cache(struct _cef_browser_t* self);
extern void cef_browser_t_stop_load(struct _cef_browser_t* self);
extern int cef_browser_t_get_identifier(struct _cef_browser_t* self);
extern int cef_browser_t_is_same(struct _cef_browser_t* self, struct _cef_browser_t* that);
extern int cef_browser_t_is_popup(struct _cef_browser_t* self);
extern int cef_browser_t_has_document(struct _cef_browser_t* self);
extern struct _cef_frame_t* cef_browser_t_get_main_frame(struct _cef_browser_t* self);
extern struct _cef_frame_t* cef_browser_t_get_focused_frame(struct _cef_browser_t* self);
extern struct _cef_frame_t* cef_browser_t_get_frame_byident(struct _cef_browser_t* self, int64 identifier);
extern struct _cef_frame_t* cef_browser_t_get_frame(struct _cef_browser_t* self, char * nameChar);
extern size_t cef_browser_t_get_frame_count(struct _cef_browser_t* self);
extern size_t cef_browser_t_get_frame_identifiers(struct _cef_browser_t* self, size_t count, int64 * ids);
extern void cef_browser_t_get_frame_names(struct _cef_browser_t* self, cef_string_list_t names);
extern int64 int64_array_get(int64* aa, size_t i);
*/
import "C"
import (
"unsafe"
)
type CefBrowserT struct {
CStruct *C.struct__cef_browser_t
}
func (b CefBrowserT) Release() {
C.releaseVoid(unsafe.Pointer(b.CStruct))
}
func (b CefBrowserT) AddRef() {
C.add_refVoid(unsafe.Pointer(b.CStruct))
}
func (b CefBrowserT) GetHost() CefBrowserHostT {
hostStruct := C.cef_browser_t_get_host(b.CStruct)
return CefBrowserHostT{hostStruct}
}
func (b CefBrowserT) CanGoBack() bool {
return C.cef_browser_t_can_go_back(b.CStruct) == 1
}
func (b CefBrowserT) GoBack() {
C.cef_browser_t_go_back(b.CStruct)
}
func (b CefBrowserT) CanGoForward() bool {
return C.cef_browser_t_can_go_forward(b.CStruct) == 1
}
func (b CefBrowserT) GoForward() {
C.cef_browser_t_go_forward(b.CStruct)
}
func (b CefBrowserT) IsLoading() bool {
return C.cef_browser_t_is_loading(b.CStruct) == 1
}
func (b CefBrowserT) Reload() {
C.cef_browser_t_reload(b.CStruct)
}
func (b CefBrowserT) ReloadIgnoreCache() {
C.cef_browser_t_reload_ignore_cache(b.CStruct)
}
func (b CefBrowserT) StopLoad() {
C.cef_browser_t_stop_load(b.CStruct)
}
func (b CefBrowserT) GetIdentifier() int {
return int(C.cef_browser_t_get_identifier(b.CStruct))
}
func (b CefBrowserT) IsSame(other CefBrowserT) bool {
return C.cef_browser_t_is_same(b.CStruct, other.CStruct) == 1
}
func (b CefBrowserT) IsPopup() bool {
return C.cef_browser_t_is_popup(b.CStruct) == 1
}
func (b CefBrowserT) HasDocument() bool {
return C.cef_browser_t_has_document(b.CStruct) == 1
}
func (b CefBrowserT) GetMainFrame() CefFrameT {
return CefFrameT{C.cef_browser_t_get_main_frame(b.CStruct)}
}
func (b CefBrowserT) GetFocusedFrame() CefFrameT {
return CefFrameT{C.cef_browser_t_get_focused_frame(b.CStruct)}
}
func (b CefBrowserT) GetFrameByIdent(identifier int64) CefFrameT {
return CefFrameT{C.cef_browser_t_get_frame_byident(b.CStruct, C.int64(identifier))}
}
func (b CefBrowserT) GetFrame(name string) CefFrameT {
cString := C.CString(name)
defer C.free(unsafe.Pointer(cString))
result := CefFrameT{C.cef_browser_t_get_frame(b.CStruct, cString)}
return result
}
func (b CefBrowserT) GetFrameCount() int64 {
return int64(C.cef_browser_t_get_frame_count(b.CStruct))
}
func (b CefBrowserT) GetFrameIdentifiers() []int64 {
var count C.size_t = C.size_t(b.GetFrameCount())
var ids *C.int64 = (*C.int64)(C.calloc(count, C.sizeof_int64))
count = C.cef_browser_t_get_frame_identifiers(b.CStruct, count, ids)
rCount := int64(count)
result := make([]int64, rCount)
var i int64
for i = 0; i < rCount; i++ {
result[i] = int64(C.int64_array_get(ids, C.size_t(i)))
}
C.free(unsafe.Pointer(ids))
return result
}
func (b CefBrowserT) GetFrameNames() []string {
nameList := C.cef_string_list_alloc()
C.cef_browser_t_get_frame_names(b.CStruct, nameList)
length := int(C.cef_string_list_size(nameList))
goList := make([]string, length)
for i := range goList {
var cefName *C.cef_string_utf16_t = C.cef_string_userfree_utf16_alloc()
didRet := C.cef_string_list_value(nameList, C.int(i), C.cefString16CastToCefString(cefName))
if didRet == C.int(1) {
nameUtf8 := C.cefStringToUtf8(C.cefString16CastToCefString(cefName))
goList[i] = C.GoString(nameUtf8.str)
C.cef_string_userfree_utf8_free(nameUtf8)
}
C.cef_string_userfree_utf16_free(cefName)
}
return goList
}
//func (b CefBrowserT) SendProcessMessage(targetProcess int, message *C.struct__cef_process_message_T) int