返回 DeepSeek-Reasonix
ICoreWebView2CookieManager.go
根目录 / desktop / third_party / go-webview2 / pkg / edge / ICoreWebView2CookieManager.go
1 package edge
2
3 import (
4 "syscall"
5 "unsafe"
6
7 "golang.org/x/sys/windows"
8 )
9
10 // ICoreWebView2CookieManager vtable
11 type iCoreWebView2CookieManagerVtbl struct {
12 _IUnknownVtbl
13 CreateCookie ComProc
14 CopyCookie ComProc
15 GetCookies ComProc
16 AddOrUpdateCookie ComProc
17 DeleteCookie ComProc
18 DeleteCookies ComProc
19 DeleteCookiesWithDomainAndPath ComProc
20 DeleteAllCookies ComProc
21 }
22
23 // ICoreWebView2CookieManager represents the cookie manager interface
24 type ICoreWebView2CookieManager struct {
25 vtbl *iCoreWebView2CookieManagerVtbl
26 }
27
28 // AddRef increments the reference count of ICoreWebView2CookieManager interface
29 func (i *ICoreWebView2CookieManager) AddRef() uint32 {
30 ret, _, _ := i.vtbl.AddRef.Call(uintptr(unsafe.Pointer(i)))
31
32 return uint32(ret)
33 }
34
35 // Release decrements the reference count of ICoreWebView2CookieManager interface
36 func (i *ICoreWebView2CookieManager) Release() uint32 {
37 ret, _, _ := i.vtbl.Release.Call(uintptr(unsafe.Pointer(i)))
38
39 return uint32(ret)
40 }
41
42 // CreateCookie creates a new cookie with the given parameters
43 func (i *ICoreWebView2CookieManager) CreateCookie(name, value, domain, path string) (*ICoreWebView2Cookie, error) {
44 var cookie *ICoreWebView2Cookie
45
46 nameutf16, err := windows.UTF16PtrFromString(name)
47 if err != nil {
48 return nil, err
49 }
50 valueutf16, err := windows.UTF16PtrFromString(value)
51 if err != nil {
52 return nil, err
53 }
54 domainutf16, err := windows.UTF16PtrFromString(domain)
55 if err != nil {
56 return nil, err
57 }
58 pathutf16, err := windows.UTF16PtrFromString(path)
59 if err != nil {
60 return nil, err
61 }
62
63 hr, _, _ := i.vtbl.CreateCookie.Call(
64 uintptr(unsafe.Pointer(i)),
65 uintptr(unsafe.Pointer(nameutf16)),
66 uintptr(unsafe.Pointer(valueutf16)),
67 uintptr(unsafe.Pointer(domainutf16)),
68 uintptr(unsafe.Pointer(pathutf16)),
69 uintptr(unsafe.Pointer(&cookie)),
70 )
71 if hr != 0 {
72 return nil, syscall.Errno(hr)
73 }
74 return cookie, nil
75 }
76
77 // CopyCookie creates a copy of the given cookie
78 func (i *ICoreWebView2CookieManager) CopyCookie(cookie *ICoreWebView2Cookie) (*ICoreWebView2Cookie, error) {
79 var newCookie *ICoreWebView2Cookie
80 hr, _, _ := i.vtbl.CopyCookie.Call(
81 uintptr(unsafe.Pointer(i)),
82 uintptr(unsafe.Pointer(cookie)),
83 uintptr(unsafe.Pointer(&newCookie)),
84 )
85 if hr != 0 {
86 return nil, syscall.Errno(hr)
87 }
88 return newCookie, nil
89 }
90
91 // GetCookies gets all cookies matching the URI
92 func (i *ICoreWebView2CookieManager) GetCookies(uri string) (*ICoreWebView2CookieList, error) {
93 var list *ICoreWebView2CookieList
94 uriutf16, err := windows.UTF16PtrFromString(uri)
95 if err != nil {
96 return nil, err
97 }
98
99 hr, _, _ := i.vtbl.GetCookies.Call(
100 uintptr(unsafe.Pointer(i)),
101 uintptr(unsafe.Pointer(uriutf16)),
102 uintptr(unsafe.Pointer(&list)),
103 )
104 if hr != 0 {
105 return nil, syscall.Errno(hr)
106 }
107 return list, nil
108 }
109
110 // DeleteCookies deletes all cookies with matching name and uri
111 func (i *ICoreWebView2CookieManager) DeleteCookies(name, uri string) error {
112 nameutf16, err := windows.UTF16PtrFromString(name)
113 if err != nil {
114 return err
115 }
116 uriutf16, err := windows.UTF16PtrFromString(uri)
117 if err != nil {
118 return err
119 }
120
121 hr, _, _ := i.vtbl.DeleteCookies.Call(
122 uintptr(unsafe.Pointer(i)),
123 uintptr(unsafe.Pointer(nameutf16)),
124 uintptr(unsafe.Pointer(uriutf16)),
125 )
126 if hr != 0 {
127 return syscall.Errno(hr)
128 }
129 return nil
130 }
131
132 // DeleteCookiesWithDomainAndPath deletes all cookies matching the domain and path
133 func (i *ICoreWebView2CookieManager) DeleteCookiesWithDomainAndPath(domain, path string) error {
134 domainutf16, err := windows.UTF16PtrFromString(domain)
135 if err != nil {
136 return err
137 }
138 pathutf16, err := windows.UTF16PtrFromString(path)
139 if err != nil {
140 return err
141 }
142
143 hr, _, _ := i.vtbl.DeleteCookiesWithDomainAndPath.Call(
144 uintptr(unsafe.Pointer(i)),
145 uintptr(unsafe.Pointer(domainutf16)),
146 uintptr(unsafe.Pointer(pathutf16)),
147 )
148 if hr != 0 {
149 return syscall.Errno(hr)
150 }
151 return nil
152 }
153
154 // AddOrUpdateCookie adds or updates a cookie
155 func (i *ICoreWebView2CookieManager) AddOrUpdateCookie(cookie *ICoreWebView2Cookie) error {
156 hr, _, _ := i.vtbl.AddOrUpdateCookie.Call(
157 uintptr(unsafe.Pointer(i)),
158 uintptr(unsafe.Pointer(cookie)),
159 )
160 if hr != 0 {
161 return syscall.Errno(hr)
162 }
163 return nil
164 }
165
166 // DeleteCookie deletes a specific cookie
167 func (i *ICoreWebView2CookieManager) DeleteCookie(cookie *ICoreWebView2Cookie) error {
168 hr, _, _ := i.vtbl.DeleteCookie.Call(
169 uintptr(unsafe.Pointer(i)),
170 uintptr(unsafe.Pointer(cookie)),
171 )
172 if hr != 0 {
173 return syscall.Errno(hr)
174 }
175 return nil
176 }
177
178 // DeleteAllCookies deletes all cookies
179 func (i *ICoreWebView2CookieManager) DeleteAllCookies() error {
180 hr, _, _ := i.vtbl.DeleteAllCookies.Call(
181 uintptr(unsafe.Pointer(i)),
182 )
183 if hr != 0 {
184 return syscall.Errno(hr)
185 }
186 return nil
187 }
188
188 lines GO