| 1 | //go:build windows |
| 2 | |
| 3 | package edge |
| 4 | |
| 5 | import ( |
| 6 | "unsafe" |
| 7 | |
| 8 | "golang.org/x/sys/windows" |
| 9 | ) |
| 10 | |
| 11 | type _ICoreWebView2WebResourceRequestVtbl struct { |
| 12 | _IUnknownVtbl |
| 13 | GetUri ComProc |
| 14 | PutUri ComProc |
| 15 | GetMethod ComProc |
| 16 | PutMethod ComProc |
| 17 | GetContent ComProc |
| 18 | PutContent ComProc |
| 19 | GetHeaders ComProc |
| 20 | } |
| 21 | |
| 22 | type ICoreWebView2WebResourceRequest struct { |
| 23 | vtbl *_ICoreWebView2WebResourceRequestVtbl |
| 24 | } |
| 25 | |
| 26 | func (i *ICoreWebView2WebResourceRequest) AddRef() uintptr { |
| 27 | ret, _, _ := i.vtbl.AddRef.Call(uintptr(unsafe.Pointer(i))) |
| 28 | |
| 29 | return ret |
| 30 | } |
| 31 | |
| 32 | func (i *ICoreWebView2WebResourceRequest) Release() uintptr { |
| 33 | ret, _, _ := i.vtbl.Release.Call(uintptr(unsafe.Pointer(i))) |
| 34 | |
| 35 | return ret |
| 36 | } |
| 37 | |
| 38 | func (i *ICoreWebView2WebResourceRequest) GetMethod() (string, error) { |
| 39 | // Create *uint16 to hold result |
| 40 | var _method *uint16 |
| 41 | hr, _, _ := i.vtbl.GetMethod.Call( |
| 42 | uintptr(unsafe.Pointer(i)), |
| 43 | uintptr(unsafe.Pointer(&_method)), |
| 44 | ) |
| 45 | if windows.Handle(hr) != windows.S_OK { |
| 46 | return "", windows.Errno(hr) |
| 47 | } |
| 48 | // Get result and cleanup |
| 49 | uri := windows.UTF16PtrToString(_method) |
| 50 | windows.CoTaskMemFree(unsafe.Pointer(_method)) |
| 51 | return uri, nil |
| 52 | } |
| 53 | |
| 54 | func (i *ICoreWebView2WebResourceRequest) GetUri() (string, error) { |
| 55 | |
| 56 | // Create *uint16 to hold result |
| 57 | var _uri *uint16 |
| 58 | hr, _, _ := i.vtbl.GetUri.Call( |
| 59 | uintptr(unsafe.Pointer(i)), |
| 60 | uintptr(unsafe.Pointer(&_uri)), |
| 61 | ) |
| 62 | if windows.Handle(hr) != windows.S_OK { |
| 63 | return "", windows.Errno(hr) |
| 64 | } // Get result and cleanup |
| 65 | uri := windows.UTF16PtrToString(_uri) |
| 66 | windows.CoTaskMemFree(unsafe.Pointer(_uri)) |
| 67 | return uri, nil |
| 68 | } |
| 69 | |
| 70 | // GetContent returns the body of the request. Returns nil if there's no body. Make sure to call |
| 71 | // Release on the returned IStream after finished using it. |
| 72 | func (i *ICoreWebView2WebResourceRequest) GetContent() (*IStream, error) { |
| 73 | var stream *IStream |
| 74 | hr, _, _ := i.vtbl.GetContent.Call( |
| 75 | uintptr(unsafe.Pointer(i)), |
| 76 | uintptr(unsafe.Pointer(&stream)), |
| 77 | ) |
| 78 | if windows.Handle(hr) != windows.S_OK { |
| 79 | return nil, windows.Errno(hr) |
| 80 | } |
| 81 | return stream, nil |
| 82 | } |
| 83 | |
| 84 | // GetHeaders returns the mutable HTTP request headers. Make sure to call |
| 85 | // Release on the returned Object after finished using it. |
| 86 | func (i *ICoreWebView2WebResourceRequest) GetHeaders() (*ICoreWebView2HttpRequestHeaders, error) { |
| 87 | var headers *ICoreWebView2HttpRequestHeaders |
| 88 | hr, _, _ := i.vtbl.GetHeaders.Call( |
| 89 | uintptr(unsafe.Pointer(i)), |
| 90 | uintptr(unsafe.Pointer(&headers)), |
| 91 | ) |
| 92 | if windows.Handle(hr) != windows.S_OK { |
| 93 | return nil, windows.Errno(hr) |
| 94 | } |
| 95 | return headers, nil |
| 96 | } |
| 97 |