| 1 | //go:build windows |
| 2 | |
| 3 | package edge |
| 4 | |
| 5 | import ( |
| 6 | "golang.org/x/sys/windows" |
| 7 | "syscall" |
| 8 | "unsafe" |
| 9 | ) |
| 10 | |
| 11 | type ICoreWebView2Settings2Vtbl struct { |
| 12 | _IUnknownVtbl |
| 13 | GetIsScriptEnabled ComProc |
| 14 | PutIsScriptEnabled ComProc |
| 15 | GetIsWebMessageEnabled ComProc |
| 16 | PutIsWebMessageEnabled ComProc |
| 17 | GetAreDefaultScriptDialogsEnabled ComProc |
| 18 | PutAreDefaultScriptDialogsEnabled ComProc |
| 19 | GetIsStatusBarEnabled ComProc |
| 20 | PutIsStatusBarEnabled ComProc |
| 21 | GetAreDevToolsEnabled ComProc |
| 22 | PutAreDevToolsEnabled ComProc |
| 23 | GetAreDefaultContextMenusEnabled ComProc |
| 24 | PutAreDefaultContextMenusEnabled ComProc |
| 25 | GetAreHostObjectsAllowed ComProc |
| 26 | PutAreHostObjectsAllowed ComProc |
| 27 | GetIsZoomControlEnabled ComProc |
| 28 | PutIsZoomControlEnabled ComProc |
| 29 | GetIsBuiltInErrorPageEnabled ComProc |
| 30 | PutIsBuiltInErrorPageEnabled ComProc |
| 31 | GetUserAgent ComProc |
| 32 | PutUserAgent ComProc |
| 33 | } |
| 34 | |
| 35 | type ICoreWebView2Settings2 struct { |
| 36 | Vtbl *ICoreWebView2Settings2Vtbl |
| 37 | } |
| 38 | |
| 39 | func (i *ICoreWebView2Settings2) AddRef() uintptr { |
| 40 | refCounter, _, _ := i.Vtbl.AddRef.Call(uintptr(unsafe.Pointer(i))) |
| 41 | return refCounter |
| 42 | } |
| 43 | |
| 44 | func (i *ICoreWebViewSettings) GetICoreWebView2Settings2() *ICoreWebView2Settings2 { |
| 45 | var result *ICoreWebView2Settings2 |
| 46 | |
| 47 | iidICoreWebView2Settings2 := NewGUID("{ee9a0f68-f46c-4e32-ac23-ef8cac224d2a}") |
| 48 | _, _, _ = i.vtbl.QueryInterface.Call( |
| 49 | uintptr(unsafe.Pointer(i)), |
| 50 | uintptr(unsafe.Pointer(iidICoreWebView2Settings2)), |
| 51 | uintptr(unsafe.Pointer(&result))) |
| 52 | |
| 53 | return result |
| 54 | } |
| 55 | |
| 56 | func (i *ICoreWebView2Settings2) GetUserAgent() (string, error) { |
| 57 | // Create *uint16 to hold result |
| 58 | var _userAgent *uint16 |
| 59 | |
| 60 | hr, _, _ := i.Vtbl.GetUserAgent.Call( |
| 61 | uintptr(unsafe.Pointer(i)), |
| 62 | uintptr(unsafe.Pointer(_userAgent)), |
| 63 | ) |
| 64 | if windows.Handle(hr) != windows.S_OK { |
| 65 | return "", syscall.Errno(hr) |
| 66 | } |
| 67 | // Get result and cleanup |
| 68 | userAgent := UTF16PtrToString(_userAgent) |
| 69 | CoTaskMemFree(unsafe.Pointer(_userAgent)) |
| 70 | return userAgent, nil |
| 71 | } |
| 72 | |
| 73 | func (i *ICoreWebView2Settings2) PutUserAgent(userAgent string) error { |
| 74 | |
| 75 | // Convert string 'userAgent' to *uint16 |
| 76 | _userAgent, err := UTF16PtrFromString(userAgent) |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | |
| 81 | hr, _, _ := i.Vtbl.PutUserAgent.Call( |
| 82 | uintptr(unsafe.Pointer(i)), |
| 83 | uintptr(unsafe.Pointer(_userAgent)), |
| 84 | ) |
| 85 | if windows.Handle(hr) != windows.S_OK { |
| 86 | return syscall.Errno(hr) |
| 87 | } |
| 88 | return nil |
| 89 | } |
| 90 |