| 1 | package edge |
| 2 | |
| 3 | import ( |
| 4 | "math" |
| 5 | "unsafe" |
| 6 | |
| 7 | "golang.org/x/sys/windows" |
| 8 | ) |
| 9 | |
| 10 | // ICoreWebView2Cookie vtable |
| 11 | type iCoreWebView2CookieVtbl struct { |
| 12 | _IUnknownVtbl |
| 13 | GetName ComProc |
| 14 | GetValue ComProc |
| 15 | PutValue ComProc |
| 16 | GetDomain ComProc |
| 17 | GetPath ComProc |
| 18 | GetExpires ComProc |
| 19 | PutExpires ComProc |
| 20 | GetIsHttpOnly ComProc |
| 21 | PutIsHttpOnly ComProc |
| 22 | GetSameSite ComProc |
| 23 | PutSameSite ComProc |
| 24 | GetIsSecure ComProc |
| 25 | PutIsSecure ComProc |
| 26 | } |
| 27 | |
| 28 | // ICoreWebView2Cookie represents a cookie |
| 29 | type ICoreWebView2Cookie struct { |
| 30 | vtbl *iCoreWebView2CookieVtbl |
| 31 | } |
| 32 | |
| 33 | // Addref increments refernce count of the ICoreWebView2Cookie interface |
| 34 | func (i *ICoreWebView2Cookie) AddRef() uintptr { |
| 35 | ret, _, _ := i.vtbl.AddRef.Call(uintptr(unsafe.Pointer(i))) |
| 36 | |
| 37 | return ret |
| 38 | } |
| 39 | |
| 40 | // Release decrements reference count of the ICoreWebView2Cookie interface |
| 41 | func (i *ICoreWebView2Cookie) Release() uintptr { |
| 42 | ret, _, _ := i.vtbl.Release.Call(uintptr(unsafe.Pointer(i))) |
| 43 | |
| 44 | return ret |
| 45 | } |
| 46 | |
| 47 | // GetName gets the cookie name |
| 48 | func (i *ICoreWebView2Cookie) GetName() (string, error) { |
| 49 | var name *uint16 |
| 50 | hr, _, _ := i.vtbl.GetName.Call( |
| 51 | uintptr(unsafe.Pointer(i)), |
| 52 | uintptr(unsafe.Pointer(&name)), |
| 53 | ) |
| 54 | if hr != 0 { |
| 55 | return "", windows.Errno(hr) |
| 56 | } |
| 57 | return windows.UTF16PtrToString(name), nil |
| 58 | } |
| 59 | |
| 60 | // GetValue gets the cookie value |
| 61 | func (i *ICoreWebView2Cookie) GetValue() (string, error) { |
| 62 | var value *uint16 |
| 63 | hr, _, _ := i.vtbl.GetValue.Call( |
| 64 | uintptr(unsafe.Pointer(i)), |
| 65 | uintptr(unsafe.Pointer(&value)), |
| 66 | ) |
| 67 | if hr != 0 { |
| 68 | return "", windows.Errno(hr) |
| 69 | } |
| 70 | return windows.UTF16PtrToString(value), nil |
| 71 | } |
| 72 | |
| 73 | // PutValue sets the cookie value |
| 74 | func (i *ICoreWebView2Cookie) PutValue(value string) error { |
| 75 | ptr, err := windows.UTF16PtrFromString(value) |
| 76 | if err != nil { |
| 77 | return err |
| 78 | } |
| 79 | hr, _, _ := i.vtbl.PutValue.Call( |
| 80 | uintptr(unsafe.Pointer(i)), |
| 81 | uintptr(unsafe.Pointer(ptr)), |
| 82 | ) |
| 83 | if hr != 0 { |
| 84 | return windows.Errno(hr) |
| 85 | } |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | // GetDomain gets the cookie domain |
| 90 | func (i *ICoreWebView2Cookie) GetDomain() (string, error) { |
| 91 | var domain *uint16 |
| 92 | hr, _, _ := i.vtbl.GetDomain.Call( |
| 93 | uintptr(unsafe.Pointer(i)), |
| 94 | uintptr(unsafe.Pointer(&domain)), |
| 95 | ) |
| 96 | if hr != 0 { |
| 97 | return "", windows.Errno(hr) |
| 98 | } |
| 99 | return windows.UTF16PtrToString(domain), nil |
| 100 | } |
| 101 | |
| 102 | // GetPath gets the cookie path |
| 103 | func (i *ICoreWebView2Cookie) GetPath() (string, error) { |
| 104 | var path *uint16 |
| 105 | hr, _, _ := i.vtbl.GetPath.Call( |
| 106 | uintptr(unsafe.Pointer(i)), |
| 107 | uintptr(unsafe.Pointer(&path)), |
| 108 | ) |
| 109 | if hr != 0 { |
| 110 | return "", windows.Errno(hr) |
| 111 | } |
| 112 | return windows.UTF16PtrToString(path), nil |
| 113 | } |
| 114 | |
| 115 | // GetExpires gets the cookie expiration time |
| 116 | func (i *ICoreWebView2Cookie) GetExpires() (float64, error) { |
| 117 | var expiresUint64 uint64 |
| 118 | hr, _, _ := i.vtbl.GetExpires.Call( |
| 119 | uintptr(unsafe.Pointer(i)), |
| 120 | uintptr(unsafe.Pointer(&expiresUint64)), |
| 121 | ) |
| 122 | if hr != 0 { |
| 123 | return 0.0, windows.Errno(hr) |
| 124 | } |
| 125 | return math.Float64frombits(expiresUint64), nil |
| 126 | } |
| 127 | |
| 128 | // PutExpires sets the cookie expiration time |
| 129 | func (i *ICoreWebView2Cookie) PutExpires(expires float64) error { |
| 130 | hr, _, _ := i.vtbl.PutExpires.Call( |
| 131 | uintptr(unsafe.Pointer(i)), |
| 132 | uintptr(math.Float64bits(expires)), |
| 133 | ) |
| 134 | if hr != 0 { |
| 135 | return windows.Errno(hr) |
| 136 | } |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | // GetIsHttpOnly gets whether the cookie is HTTP-only |
| 141 | func (i *ICoreWebView2Cookie) GetIsHttpOnly() (bool, error) { |
| 142 | var isHttpOnly int32 |
| 143 | hr, _, _ := i.vtbl.GetIsHttpOnly.Call( |
| 144 | uintptr(unsafe.Pointer(i)), |
| 145 | uintptr(unsafe.Pointer(&isHttpOnly)), |
| 146 | ) |
| 147 | if hr != 0 { |
| 148 | return false, windows.Errno(hr) |
| 149 | } |
| 150 | return isHttpOnly != 0, nil |
| 151 | } |
| 152 | |
| 153 | // PutIsHttpOnly sets whether the cookie is HTTP-only |
| 154 | func (i *ICoreWebView2Cookie) PutIsHttpOnly(isHttpOnly bool) error { |
| 155 | value := int32(0) |
| 156 | if isHttpOnly { |
| 157 | value = 1 |
| 158 | } |
| 159 | hr, _, _ := i.vtbl.PutIsHttpOnly.Call( |
| 160 | uintptr(unsafe.Pointer(i)), |
| 161 | uintptr(value), |
| 162 | ) |
| 163 | if hr != 0 { |
| 164 | return windows.Errno(hr) |
| 165 | } |
| 166 | return nil |
| 167 | } |
| 168 | |
| 169 | // GetSameSite gets the cookie's SameSite attribute |
| 170 | func (i *ICoreWebView2Cookie) GetSameSite() (int32, error) { |
| 171 | var sameSite int32 |
| 172 | hr, _, _ := i.vtbl.GetSameSite.Call( |
| 173 | uintptr(unsafe.Pointer(i)), |
| 174 | uintptr(unsafe.Pointer(&sameSite)), |
| 175 | ) |
| 176 | if hr != 0 { |
| 177 | return 0, windows.Errno(hr) |
| 178 | } |
| 179 | return sameSite, nil |
| 180 | } |
| 181 | |
| 182 | // PutSameSite sets the cookie's SameSite attribute |
| 183 | func (i *ICoreWebView2Cookie) PutSameSite(sameSite int32) error { |
| 184 | hr, _, _ := i.vtbl.PutSameSite.Call( |
| 185 | uintptr(unsafe.Pointer(i)), |
| 186 | uintptr(sameSite), |
| 187 | ) |
| 188 | if hr != 0 { |
| 189 | return windows.Errno(hr) |
| 190 | } |
| 191 | return nil |
| 192 | } |
| 193 | |
| 194 | // GetIsSecure gets whether the cookie is secure |
| 195 | func (i *ICoreWebView2Cookie) GetIsSecure() (bool, error) { |
| 196 | var isSecure int32 |
| 197 | hr, _, _ := i.vtbl.GetIsSecure.Call( |
| 198 | uintptr(unsafe.Pointer(i)), |
| 199 | uintptr(unsafe.Pointer(&isSecure)), |
| 200 | ) |
| 201 | if hr != 0 { |
| 202 | return false, windows.Errno(hr) |
| 203 | } |
| 204 | return isSecure != 0, nil |
| 205 | } |
| 206 | |
| 207 | // PutIsSecure sets whether the cookie is secure |
| 208 | func (i *ICoreWebView2Cookie) PutIsSecure(isSecure bool) error { |
| 209 | value := int32(0) |
| 210 | if isSecure { |
| 211 | value = 1 |
| 212 | } |
| 213 | hr, _, _ := i.vtbl.PutIsSecure.Call( |
| 214 | uintptr(unsafe.Pointer(i)), |
| 215 | uintptr(value), |
| 216 | ) |
| 217 | if hr != 0 { |
| 218 | return windows.Errno(hr) |
| 219 | } |
| 220 | return nil |
| 221 | } |
| 222 | |
| 223 | // QueryInterface queries for a specific interface |
| 224 | func (i *ICoreWebView2Cookie) QueryInterface(riid *windows.GUID, ppvObject *unsafe.Pointer) error { |
| 225 | hr, _, _ := i.vtbl.QueryInterface.Call( |
| 226 | uintptr(unsafe.Pointer(i)), |
| 227 | uintptr(unsafe.Pointer(riid)), |
| 228 | uintptr(unsafe.Pointer(ppvObject)), |
| 229 | ) |
| 230 | if hr != 0 { |
| 231 | return windows.Errno(hr) |
| 232 | } |
| 233 | return nil |
| 234 | } |
| 235 |