forked from cztomczak/cef2go
-
Notifications
You must be signed in to change notification settings - Fork 7
/
cefRequestT.go
244 lines (197 loc) · 8.2 KB
/
cefRequestT.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// 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_request_handler_capi.h"
extern cef_string_utf8_t * cef_request_t_get_url(struct _cef_request_t * self);
extern int cef_request_t_is_read_only(struct _cef_request_t * self);
extern void cef_request_t_set_url(struct _cef_request_t * self, char * url);
extern cef_string_utf8_t * cef_request_t_get_method(struct _cef_request_t * self);
extern void cef_request_t_set_method(struct _cef_request_t * self, char * meth);
extern struct _cef_post_data_t * cef_request_t_get_post_data(struct _cef_request_t * self);
extern cef_string_multimap_t cef_request_t_get_header_map(struct _cef_request_t * self);
extern int cef_request_t_get_flags(struct _cef_request_t * self);
extern void cef_request_t_set_flags(struct _cef_request_t * self, int f);
extern cef_string_utf8_t * cef_request_t_get_first_party_for_cookies(struct _cef_request_t * self);
extern int cef_request_t_get_resource_type(struct _cef_request_t * self);
extern int cef_request_t_get_transition_type(struct _cef_request_t * self);
// post data
extern int cef_post_data_is_read_only(struct _cef_post_data_t* self);
extern size_t cef_post_data_get_element_count(struct _cef_post_data_t* self);
extern void cef_post_data_get_elements(struct _cef_post_data_t* self, size_t* elementsCount, struct _cef_post_data_element_t** elements);
extern int cef_post_data_remove_element(struct _cef_post_data_t* self, struct _cef_post_data_element_t* element);
extern int cef_post_data_add_element(struct _cef_post_data_t* self, struct _cef_post_data_element_t* element);
extern void cef_post_data_remove_elements(struct _cef_post_data_t* self);
extern struct _cef_post_data_element_t* get_element_pointer(int i, struct _cef_post_data_element_t** elements);
// post data element
extern int cef_post_data_element_is_read_only(struct _cef_post_data_element_t* self);
extern void cef_post_data_element_set_to_empty(struct _cef_post_data_element_t* self);
extern void cef_post_data_element_set_to_file(struct _cef_post_data_element_t* self, const cef_string_t* fileName);
extern void cef_post_data_element_set_to_bytes(struct _cef_post_data_element_t* self, size_t size, const void* bytes);
extern cef_postdataelement_type_t cef_post_data_element_get_type(struct _cef_post_data_element_t* self);
extern cef_string_utf8_t* cef_post_data_element_get_file(struct _cef_post_data_element_t* self);
extern size_t cef_post_data_element_get_bytes_count(struct _cef_post_data_element_t* self);
extern size_t cef_post_data_element_get_bytes(struct _cef_post_data_element_t* self, size_t size, void* bytes);
*/
import "C"
import (
"unsafe"
//"fmt"
)
type CefRequestT struct {
CStruct *C.struct__cef_request_t
}
type CefPostDataT struct {
CStruct *C.struct__cef_post_data_t
}
type CefPostDataElementT struct {
CStruct *C.struct__cef_post_data_element_t
}
func (b CefPostDataElementT) Release() {
C.releaseVoid(unsafe.Pointer(b.CStruct))
}
func (b CefPostDataElementT) AddRef() {
C.add_refVoid(unsafe.Pointer(b.CStruct))
}
func (b CefPostDataT) Release() {
C.releaseVoid(unsafe.Pointer(b.CStruct))
}
func (b CefPostDataT) AddRef() {
C.add_refVoid(unsafe.Pointer(b.CStruct))
}
func (b CefRequestT) Release() {
C.releaseVoid(unsafe.Pointer(b.CStruct))
}
func (b CefRequestT) AddRef() {
C.add_refVoid(unsafe.Pointer(b.CStruct))
}
func (r CefRequestT) GetUrl() string {
stringStruct := C.cef_request_t_get_url(r.CStruct)
defer C.cef_string_userfree_utf8_free(stringStruct)
str := C.GoString(stringStruct.str)
return str
}
func (r CefRequestT) IsReadOnly() bool {
result := C.cef_request_t_is_read_only(r.CStruct)
return result == 1
}
func (r CefRequestT) SetUrl(newUrl string) {
var newUrlCString *C.char = C.CString(newUrl)
defer C.free(unsafe.Pointer(newUrlCString))
C.cef_request_t_set_url(r.CStruct, newUrlCString)
}
func (r CefRequestT) GetMethod() string {
stringStruct := C.cef_request_t_get_method(r.CStruct)
defer C.cef_string_userfree_utf8_free(stringStruct)
str := C.GoString(stringStruct.str)
return str
}
func (r CefRequestT) SetMethod(method string) {
var methodCString *C.char = C.CString(method)
defer C.free(unsafe.Pointer(methodCString))
C.cef_request_t_set_url(r.CStruct, methodCString)
}
func (r CefRequestT) GetPostData() CefPostDataT {
postDataCStruct := C.cef_request_t_get_post_data(r.CStruct)
return CefPostDataT{postDataCStruct}
}
func (r CefRequestT) SetPostData(data CefPostDataT) {
// do nothing for now
}
func (r CefRequestT) GetHeaderMap() map[string][]string {
cefMapPointer := C.cef_request_t_get_header_map(r.CStruct)
if cefMapPointer == nil {
return nil
}
defer C.cef_string_multimap_free(cefMapPointer)
return extractCefMultiMap(cefMapPointer)
}
func (r CefRequestT) SetHeaderMap(headerMap map[string]string) {
// do nothing for now
}
func (r CefRequestT) Set(url, method string, postData CefPostDataT, headerMap map[string]string) {
// do nothing for now
}
func (r CefRequestT) GetFlags() int {
return int(C.cef_request_t_get_flags(r.CStruct))
}
func (r CefRequestT) SetFlags(flags int) {
C.cef_request_t_set_flags(r.CStruct, C.int(flags))
}
func (r CefRequestT) GetFirstPartyForCookies() string {
stringStruct := C.cef_request_t_get_first_party_for_cookies(r.CStruct)
defer C.cef_string_userfree_utf8_free(stringStruct)
str := C.GoString(stringStruct.str)
return str
}
func (r CefRequestT) SetFirstPartyForCookies(url string) {
// do nothing cause i'm lazy right now
}
func (r CefRequestT) GetResourceType() int {
return int(C.cef_request_t_get_resource_type(r.CStruct))
}
func (r CefRequestT) GetTransitionType() int {
return int(C.cef_request_t_get_transition_type(r.CStruct))
}
func (p CefPostDataT) IsReadOnly() bool {
return C.cef_post_data_is_read_only(p.CStruct) == 1
}
func (p CefPostDataT) GetElementCount() int {
return int(C.cef_post_data_get_element_count(p.CStruct))
}
func (p CefPostDataT) GetElements(numToGet int) []CefPostDataElementT {
var numElements C.size_t = C.size_t(numToGet)
elements := (**C.struct__cef_post_data_element_t)(
C.calloc(numElements, 32)) /// i should really have the size of a pointer....
C.cef_post_data_get_elements(p.CStruct, &numElements, elements)
numEle := int(numElements)
out := make([]CefPostDataElementT, numEle)
for i := range out {
out[i].CStruct = C.get_element_pointer(C.int(i), elements)
}
C.free(unsafe.Pointer(elements))
return out
}
func (p CefPostDataT) RemoveElement(element CefPostDataElementT) bool {
element.AddRef()
return C.cef_post_data_remove_element(p.CStruct, element.CStruct) == 1
}
func (p CefPostDataT) AddElement(element CefPostDataElementT) bool {
element.AddRef()
return C.cef_post_data_add_element(p.CStruct, element.CStruct) == 1
}
func (p CefPostDataT) RemoveElements() {
C.cef_post_data_remove_elements(p.CStruct)
}
// post data element
func (e CefPostDataElementT) IsReadOnly() bool {
return C.cef_post_data_element_is_read_only(e.CStruct) == 1
}
func (e CefPostDataElementT) SetToEmpty() {
C.cef_post_data_element_set_to_empty(e.CStruct)
}
func (e CefPostDataElementT) SetToFile(fileName string) {
panic("Not implemented")
//C.cef_post_data_element_set_to_file(e.CStruct, const cef_string_t* fileName)
}
func (e CefPostDataElementT) SetToBytes(b []byte) {
C.cef_post_data_element_set_to_bytes(e.CStruct, C.size_t(len(b)), unsafe.Pointer(&b[0]))
}
func (e CefPostDataElementT) GetType() C.cef_postdataelement_type_t {
return C.cef_post_data_element_get_type(e.CStruct)
}
func (e CefPostDataElementT) GetFile() string {
cefString := C.cef_post_data_element_get_file(e.CStruct)
defer C.cef_string_userfree_utf8_free(cefString)
return C.GoString(cefString.str)
}
func (e CefPostDataElementT) GetBytesCount() int {
return int(C.cef_post_data_element_get_bytes_count(e.CStruct))
}
func (e CefPostDataElementT) GetBytes(b []byte) int {
return int(C.cef_post_data_element_get_bytes(e.CStruct, C.size_t(len(b)), unsafe.Pointer(&b[0])))
}