diff --git a/README.md b/README.md index 2d6c962..4d68201 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,8 @@ func Example() { webView.Connect("load-failed", func() { fmt.Println("Load failed.") }) - webView.Connect("load-changed", func(ctx *glib.CallbackContext) { - loadEvent := webkit2.LoadEvent(ctx.Arg(0).Int()) + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := webkit2.LoadEvent(event) switch loadEvent { case webkit2.LoadFinished: fmt.Println("Load finished.") diff --git a/cmd/webkit-eval-js/evaljs.go b/cmd/webkit-eval-js/evaljs.go index ffbb145..86cbcc7 100644 --- a/cmd/webkit-eval-js/evaljs.go +++ b/cmd/webkit-eval-js/evaljs.go @@ -67,7 +67,8 @@ func main() { webView.Connect("load-failed", func() { fmt.Println("Load failed.") }) - webView.Connect("load-changed", func(_ *glib.Object, loadEvent webkit2.LoadEvent) { + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := webkit2.LoadEvent(event) switch loadEvent { case webkit2.LoadFinished: webView.RunJavaScript(string(script), func(val *gojs.Value, err error) { diff --git a/webkit2/cairo_endianes.c b/webkit2/cairo_endianes.c new file mode 100644 index 0000000..dbf6382 --- /dev/null +++ b/webkit2/cairo_endianes.c @@ -0,0 +1,144 @@ +#include +//#include + +#include "cairo_endianes.h" + +const uint32_t gowk2_endian_test = 0x00010203; + +// Endianes constants +#define GOWK2_BIG_ENDIAN 0x00010203 +#define GOWK2_LITTLE_ENDIAN_8 0x03020100 +#define GOWK2_LITTLE_ENDIAN_16 0x02030001 +#define GOWK2_MIDLE_ENDIAN 0x01000302 + +uint8_t* gowk2_detect_endianes_byte() { + return (uint8_t*)&gowk2_endian_test; +} + +uint32_t gowk2_detect_endianes_word() { + uint8_t *b_ptr; + b_ptr = (uint8_t*)&gowk2_endian_test; + return ((uint32_t)b_ptr[0] << 24) | ((uint32_t)b_ptr[1] << 16) | ((uint32_t)b_ptr[2] << 8) | ((uint32_t)b_ptr[3]); +} + +void gowk2_cairo_endian_depended_ARGB32_to_RGBA(unsigned char *data, unsigned char *out, unsigned int len) { + // s1 and s2 are swap variables for the case, when data==out + register char sw; + register unsigned int i; + uint32_t order; + //printf("webkit endian 0\n"); + + + order = gowk2_detect_endianes_word(); + + //printf("webkit endian 1\n"); + switch(order) { + case GOWK2_BIG_ENDIAN: + // A R G B -> R G B A + // 0 1 2 3 -> 1 2 3 0 + for(i=0; i R G B A + // 3 2 1 0 -> 2 1 0 3 + if(data == out) { + // just swap + // if we are swapping bytes inside same array, then we do not need to copy all data. + // this saves time + for(i=0; i R G B A + // 2 3 0 1 -> 3 0 1 2 + for(i=0; i R G B A + // 1 0 3 2 -> 0 3 2 1 + if(data == out) { + // just swap + // if we are swapping bytes inside same array, then we do not need to copy all data. + // this saves time + for(i=0; i +// #include +import "C" +import ( + "github.com/gotk3/gotk3/glib" + "unsafe" +) + +// CookieManager — Defines how to handle cookies in a WebContext +// +// See also: WebKitCookieManager at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitCookieManager.html. +type CookieManager struct { + *glib.Object + cookieManager *C.WebKitCookieManager +} + +func newCookieManager(cookieManager *C.WebKitCookieManager) *CookieManager { + obj := &glib.Object{glib.ToGObject(unsafe.Pointer(cookieManager))} + return &CookieManager{obj, cookieManager} +} + +// CookiePersistentStorage values used to denote the cookie persistent storage types +// are described at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitCookieManager.html#WebKitCookiePersistentStorage +type CookiePersistentStorage int + +const ( + CookiePersistentStorageText CookiePersistentStorage = iota + CookiePersistentStorageSqlite +) + +// SetPersistentStorage sets the filename where non-session cookies are stored +// persistently using storage as the format to read/write the cookies. +// +// See also: webkit_cookie_manager_set_persistent_storage +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitCookieManager.html#webkit-cookie-manager-set-persistent-storage +func (cm *CookieManager) SetPersistentStorage(filename string, storage CookiePersistentStorage) { + cstr := C.CString(filename) + defer C.free(unsafe.Pointer(cstr)) + C.webkit_cookie_manager_set_persistent_storage(cm.cookieManager, + (*C.gchar)(cstr), + C.WebKitCookiePersistentStorage(storage)) +} + +// CookiePersistentStorage values used to denote the cookie acceptance policies. +// are described at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitCookieManager.html#WebKitCookieAcceptPolicy +type CookieAcceptPolicy int + +const ( + CookiePolicyAcceptAlways CookieAcceptPolicy = iota + CookiePolicyAcceptNever + CookiePolicyAcceptNoThirdParty +) + +// SetAcceptPolicy set the cookie acceptance policy of CookieManager as policy . +// +// See also: webkit_cookie_manager_set_accept_policy +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitCookieManager.html#webkit-cookie-manager-set-accept-policy +func (cm *CookieManager) SetAcceptPolicy(policy CookieAcceptPolicy) { + C.webkit_cookie_manager_set_accept_policy(cm.cookieManager, + C.WebKitCookieAcceptPolicy(policy)) +} + +// DeleteCookiesForDomain Remove all cookies of CookieManager for the given domain. +// +// See also: webkit_cookie_manager_delete_cookies_for_domain +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitCookieManager.html#webkit-cookie-manager-delete-cookies-for-domain +func (cm *CookieManager) DeleteCookiesForDomain(domain string) { + cstr := C.CString(domain) + defer C.free(unsafe.Pointer(cstr)) + C.webkit_cookie_manager_delete_cookies_for_domain(cm.cookieManager, + (*C.gchar)(cstr)) +} + +// DeleteAllCookies delete all cookies of CookieManager. +// +// See also: webkit_cookie_manager_delete_all_cookies +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitCookieManager.html#webkit-cookie-manager-delete-all-cookies +func (cm *CookieManager) DeleteAllCookies(domain string) { + C.webkit_cookie_manager_delete_all_cookies(cm.cookieManager) +} diff --git a/webkit2/gasyncreadycallback.go b/webkit2/gasyncreadycallback.go index 3f79cc0..01cb9e8 100644 --- a/webkit2/gasyncreadycallback.go +++ b/webkit2/gasyncreadycallback.go @@ -6,6 +6,7 @@ import "C" import ( "errors" "reflect" + "sync" "unsafe" ) @@ -13,11 +14,25 @@ type garCallback struct { f reflect.Value } +var ( + //Map stores callbacks pointers, to protect them from GC. + callbackProtectMap map[C.gpointer]*garCallback + protectMapLock sync.RWMutex +) + +func init() { + callbackProtectMap = make(map[C.gpointer]*garCallback) +} + //export _go_gasyncreadycallback_call func _go_gasyncreadycallback_call(cbinfoRaw C.gpointer, cresult unsafe.Pointer) { result := (*C.GAsyncResult)(cresult) cbinfo := (*garCallback)(unsafe.Pointer(cbinfoRaw)) cbinfo.f.Call([]reflect.Value{reflect.ValueOf(result)}) + // protect callback from Garbage collection + protectMapLock.Lock() + delete(callbackProtectMap, cbinfoRaw) + protectMapLock.Unlock() } func newGAsyncReadyCallback(f interface{}) (cCallback C.GAsyncReadyCallback, userData C.gpointer, err error) { @@ -26,5 +41,10 @@ func newGAsyncReadyCallback(f interface{}) (cCallback C.GAsyncReadyCallback, use return nil, nil, errors.New("f is not a function") } cbinfo := &garCallback{rf} - return C.GAsyncReadyCallback(C._gasyncreadycallback_call), C.gpointer(unsafe.Pointer(cbinfo)), nil + cbinfoRaw := C.gpointer(unsafe.Pointer(cbinfo)) + // protect callback from Garbage collection + protectMapLock.Lock() + callbackProtectMap[cbinfoRaw] = cbinfo + protectMapLock.Unlock() + return C.GAsyncReadyCallback(C._gasyncreadycallback_call), cbinfoRaw, nil } diff --git a/webkit2/settings.go b/webkit2/settings.go index 59229d3..3ab0c23 100644 --- a/webkit2/settings.go +++ b/webkit2/settings.go @@ -1,5 +1,6 @@ package webkit2 +// #include // #include import "C" import "unsafe" @@ -34,11 +35,31 @@ func (s *Settings) SetAutoLoadImages(autoLoad bool) { C.webkit_settings_set_auto_load_images(s.settings, gboolean(autoLoad)) } +// GetEnableDeveloperExtras returns the "enable-developer-extras" property. +// +// See also: webkit_settings_set_enable_developer_extras at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-get-enable-developer-extras +func (s *Settings) GetEnableDeveloperExtras() bool { + return gobool(C.webkit_settings_get_enable_developer_extras(s.settings)) +} + +// SetEnableDeveloperExtras sets the "enable-developer-extras" property. +// +// See also: webkit_settings_set_enable_developer_extras at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html#webkit-settings-set-enable-developer-extras +func (s *Settings) SetEnableDeveloperExtras(autoLoad bool) { + C.webkit_settings_set_enable_developer_extras(s.settings, gboolean(autoLoad)) +} + // SetUserAgentWithApplicationDetails sets the "user-agent" property by // appending the application details to the default user agent. // // See also: webkit_settings_set_user_agent_with_application_details at // http://webkitgtk.org/reference/webkit2gtk/unstable/WebKitSettings.html#webkit-settings-set-user-agent-with-application-details func (s *Settings) SetUserAgentWithApplicationDetails(appName, appVersion string) { - C.webkit_settings_set_user_agent_with_application_details(s.settings, (*C.gchar)(C.CString(appName)), (*C.gchar)(C.CString(appVersion))) + cName := C.CString(appName) + defer C.free(unsafe.Pointer(cName)) + cVersion := C.CString(appVersion) + defer C.free(unsafe.Pointer(cVersion)) + C.webkit_settings_set_user_agent_with_application_details(s.settings, (*C.gchar)(cName), (*C.gchar)(cVersion)) } diff --git a/webkit2/webcontext.go b/webkit2/webcontext.go index 4a55074..f2c1749 100644 --- a/webkit2/webcontext.go +++ b/webkit2/webcontext.go @@ -1,22 +1,33 @@ package webkit2 +// #include // #include import "C" +import ( + "github.com/gotk3/gotk3/glib" + "unsafe" +) // WebContext manages all aspects common to all WebViews. // // See also: WebKitWebContext at // http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html. type WebContext struct { + *glib.Object webContext *C.WebKitWebContext } +func newWebContext(webContext *C.WebKitWebContext) *WebContext { + obj := &glib.Object{glib.ToGObject(unsafe.Pointer(webContext))} + return &WebContext{obj, webContext} +} + // DefaultWebContext returns the default WebContext. // // See also: webkit_web_context_get_default at // http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-get-default. func DefaultWebContext() *WebContext { - return &WebContext{C.webkit_web_context_get_default()} + return newWebContext(C.webkit_web_context_get_default()) } // CacheModel describes the caching behavior. @@ -56,3 +67,37 @@ func (wc *WebContext) SetCacheModel(model CacheModel) { func (wc *WebContext) ClearCache() { C.webkit_web_context_clear_cache(wc.webContext) } + +// SetDiskCacheDirectory sets the directory where disk cache files will be stored . +// +// See also: webkit_web_context_set_disk_cache_directory +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-set-disk-cache-directory +func (wc *WebContext) SetDiskCacheDirectory(directory string) { + cstr := C.CString(directory) + defer C.free(unsafe.Pointer(cstr)) + C.webkit_web_context_set_disk_cache_directory(wc.webContext, (*C.gchar)(cstr)) +} + +// SetFaviconDatabaseDirectory sets the directory path to be used to store the favicons database for context on disk. +// +// See also: webkit_web_context_set_favicon_database_directory +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-set-favicon-database-directory +func (wc *WebContext) SetFaviconDatabaseDirectory(directory string) { + cstr := C.CString(directory) + defer C.free(unsafe.Pointer(cstr)) + C.webkit_web_context_set_favicon_database_directory(wc.webContext, (*C.gchar)(cstr)) +} + +func (wc *WebContext) GetCookieManager() *CookieManager { + return newCookieManager(C.webkit_web_context_get_cookie_manager(wc.webContext)) +} + +// SetWebExtensionsDirectory sets the directory where WebKit will look for Web Extensions. +// +// See also: webkit_web_context_set_web_extensions_directory +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#webkit-web-context-set-web-extensions-directory +func (wc *WebContext) SetWebExtensionsDirectory(directory string) { + cstr := C.CString(directory) + defer C.free(unsafe.Pointer(cstr)) + C.webkit_web_context_set_web_extensions_directory(wc.webContext, (*C.gchar)(cstr)) +} diff --git a/webkit2/webview.go b/webkit2/webview.go index 8249757..e7e3fa2 100644 --- a/webkit2/webview.go +++ b/webkit2/webview.go @@ -4,14 +4,14 @@ package webkit2 // #include // #include // +//#include "cairo_endianes.h" +// // static WebKitWebView* to_WebKitWebView(GtkWidget* w) { return WEBKIT_WEB_VIEW(w); } // // #cgo pkg-config: webkit2gtk-3.0 import "C" import ( - "bytes" - "encoding/binary" "errors" "image" "unsafe" @@ -58,7 +58,7 @@ func newWebView(webViewWidget *C.GtkWidget) *WebView { // See also: webkit_web_view_get_context at // http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-context. func (v *WebView) Context() *WebContext { - return &WebContext{C.webkit_web_view_get_context(v.webView)} + return newWebContext(C.webkit_web_view_get_context(v.webView)) } // LoadURI requests loading of the specified URI string. @@ -66,7 +66,9 @@ func (v *WebView) Context() *WebContext { // See also: webkit_web_view_load_uri at // http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-load-uri func (v *WebView) LoadURI(uri string) { - C.webkit_web_view_load_uri(v.webView, (*C.gchar)(C.CString(uri))) + cUri := C.CString(uri) + defer C.free(unsafe.Pointer(cUri)) + C.webkit_web_view_load_uri(v.webView, (*C.gchar)(cUri)) } // LoadHTML loads the given content string with the specified baseURI. The MIME @@ -75,7 +77,34 @@ func (v *WebView) LoadURI(uri string) { // See also: webkit_web_view_load_html at // http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-load-html func (v *WebView) LoadHTML(content, baseURI string) { - C.webkit_web_view_load_html(v.webView, (*C.gchar)(C.CString(content)), (*C.gchar)(C.CString(baseURI))) + cContent := C.CString(content) + defer C.free(unsafe.Pointer(cContent)) + cBaseURI := C.CString(baseURI) + defer C.free(unsafe.Pointer(cBaseURI)) + C.webkit_web_view_load_html(v.webView, (*C.gchar)(cContent), (*C.gchar)(cBaseURI)) +} + +// LoadAlternateHTML loads the given content string for the URI content_uri . +// This allows clients to display page-loading errors in the WebKitWebView itself +// +// See also: webkit_web_view_load_alternate_html at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-load-alternate-html +func (v *WebView) LoadAlternateHTML(content, contentURI, baseURI string) { + cContent := C.CString(content) + defer C.free(unsafe.Pointer(cContent)) + cContentURI := C.CString(contentURI) + defer C.free(unsafe.Pointer(cContentURI)) + cBaseURI := C.CString(baseURI) + defer C.free(unsafe.Pointer(cBaseURI)) + C.webkit_web_view_load_alternate_html(v.webView, (*C.gchar)(cContent), (*C.gchar)(cContentURI), (*C.gchar)(cBaseURI)) +} + +// Reloads the current contents of web_view . See also webkit_web_view_reload_bypass_cache(). +// +// See also: webkit_web_view_reload_html at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-reload +func (v *WebView) Reload() { + C.webkit_web_view_reload(v.webView) } // Settings returns the current active settings of this WebView's WebViewGroup. @@ -144,7 +173,9 @@ func (v *WebView) RunJavaScript(script string, resultCallback func(result *gojs. panic(err) } } - C.webkit_web_view_run_javascript(v.webView, (*C.gchar)(C.CString(script)), nil, cCallback, userData) + cScript := C.CString(script) + defer C.free(unsafe.Pointer(cScript)) + C.webkit_web_view_run_javascript(v.webView, (*C.gchar)(cScript), nil, cCallback, userData) } // Destroy destroys the WebView's corresponding GtkWidget and marks its internal @@ -170,20 +201,64 @@ const ( LoadFinished ) +func (le LoadEvent) String() string { + switch le { + case LoadStarted: + return "load-started" + case LoadRedirected: + return "load-redirected" + case LoadCommitted: + return "load-commited" + case LoadFinished: + return "load-finished" + } + + return "unknown" +} + // http://cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-type-t const cairoSurfaceTypeImage = 0 // http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t const cairoImageSurfaceFormatARGB32 = 0 +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitSnapshotRegion +type SnapshotRegion int + +const ( + SnapshotRegionVisible SnapshotRegion = C.WEBKIT_SNAPSHOT_REGION_VISIBLE + SnapshotRegionFullDocument SnapshotRegion = C.WEBKIT_SNAPSHOT_REGION_FULL_DOCUMENT +) + +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#WebKitSnapshotOptions +type SnapshotOptions int + +const ( + SnapshotOptionsNone = C.WEBKIT_SNAPSHOT_OPTIONS_NONE + SnapshotOptionsIncludeRegionHighlighting = C.WEBKIT_SNAPSHOT_OPTIONS_INCLUDE_SELECTION_HIGHLIGHTING +) + // GetSnapshot runs asynchronously, taking a snapshot of the WebView. // Upon completion, resultCallback will be called with a copy of the underlying // bitmap backing store for the frame, or with an error encountered during // execution. +// The same as GetSnapshotCustom, but with difference difference that +// region and options are pre set to SnapshotRegionFullDocument and SnapshotOptionsNone in advance. // // See also: webkit_web_view_get_snapshot at // http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-snapshot func (v *WebView) GetSnapshot(resultCallback func(result *image.RGBA, err error)) { + v.GetSnapshotCustom(SnapshotRegionFullDocument, SnapshotOptionsNone, resultCallback) +} + +// GetSnapshotCustom runs asynchronously, taking a snapshot of the WebView. +// Upon completion, resultCallback will be called with a copy of the underlying +// bitmap backing store for the frame, or with an error encountered during +// execution. +// +// See also: webkit_web_view_get_snapshot at +// http://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebView.html#webkit-web-view-get-snapshot +func (v *WebView) GetSnapshotCustom(region SnapshotRegion, options SnapshotOptions, resultCallback func(result *image.RGBA, err error)) { var cCallback C.GAsyncReadyCallback var userData C.gpointer var err error @@ -207,32 +282,18 @@ func (v *WebView) GetSnapshot(resultCallback func(result *image.RGBA, err error) w := int(C.cairo_image_surface_get_width(snapResult)) h := int(C.cairo_image_surface_get_height(snapResult)) stride := int(C.cairo_image_surface_get_stride(snapResult)) + C.cairo_surface_flush(snapResult) data := unsafe.Pointer(C.cairo_image_surface_get_data(snapResult)) - surfaceBytes := C.GoBytes(data, C.int(stride*h)) - // convert from b,g,r,a or a,r,g,b(local endianness) to r,g,b,a - testint, _ := binary.ReadUvarint(bytes.NewBuffer([]byte{0x1, 0})) - if testint == 0x1 { - // Little: b,g,r,a -> r,g,b,a - for i := 0; i < w*h; i++ { - b := surfaceBytes[4*i+0] - r := surfaceBytes[4*i+2] - surfaceBytes[4*i+0] = r - surfaceBytes[4*i+2] = b - } - } else { - // Big: a,r,g,b -> r,g,b,a - for i := 0; i < w*h; i++ { - a := surfaceBytes[4*i+0] - r := surfaceBytes[4*i+1] - g := surfaceBytes[4*i+2] - b := surfaceBytes[4*i+3] - surfaceBytes[4*i+0] = r - surfaceBytes[4*i+1] = g - surfaceBytes[4*i+2] = b - surfaceBytes[4*i+3] = a - } - } - rgba := &image.RGBA{surfaceBytes, stride, image.Rect(0, 0, w, h)} + + //(miha) fix endianes depended byte order, and copy to go slice at the same time. + data_fixed := make([]byte, stride*h) + C.gowk2_cairo_endian_depended_ARGB32_to_RGBA((*C.uchar)(data), (*C.uchar)(&data_fixed[0]), C.uint(stride*h)) + rgba := &image.RGBA{data_fixed, stride, image.Rect(0, 0, w, h)} + + // slower but doesn't use Go pointers inside C. See https://github.com/golang/go/issues/8310 !!!!!!! + //C.gowk2_cairo_endian_depended_ARGB32_to_RGBA((*C.uchar)(data), C.uint(stride*h)) + //rgba := &image.RGBA{C.GoBytes(data, C.int(stride*h)), stride, image.Rect(0, 0, w, h)} + resultCallback(rgba, nil) } cCallback, userData, err = newGAsyncReadyCallback(callback) @@ -242,8 +303,8 @@ func (v *WebView) GetSnapshot(resultCallback func(result *image.RGBA, err error) } C.webkit_web_view_get_snapshot(v.webView, - (C.WebKitSnapshotRegion)(1), // FullDocument is the only working region at this point - (C.WebKitSnapshotOptions)(0), + (C.WebKitSnapshotRegion)(region), + (C.WebKitSnapshotOptions)(options), nil, cCallback, userData) diff --git a/webkit2/webview_test.go b/webkit2/webview_test.go index 6fb6590..141af9e 100644 --- a/webkit2/webview_test.go +++ b/webkit2/webview_test.go @@ -43,7 +43,8 @@ func TestWebView_LoadURI(t *testing.T) { webView.Connect("load-failed", func() { t.Errorf("load failed") }) - webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) { + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := LoadEvent(event) switch loadEvent { case LoadFinished: loadFinished = true @@ -75,7 +76,8 @@ func TestWebView_LoadURI_load_failed(t *testing.T) { webView.Connect("load-failed", func() { loadFailed = true }) - webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) { + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := LoadEvent(event) switch loadEvent { case LoadFinished: loadFinished = true @@ -107,7 +109,8 @@ func TestWebView_LoadHTML(t *testing.T) { webView.Connect("load-failed", func() { t.Errorf("load failed") }) - webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) { + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := LoadEvent(event) switch loadEvent { case LoadFinished: loadOk = true @@ -204,7 +207,8 @@ func TestWebView_RunJavaScript(t *testing.T) { defer webView.Destroy() wantResultString := "abc" - webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) { + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := LoadEvent(event) switch loadEvent { case LoadFinished: webView.RunJavaScript(`document.getElementById("foo").innerHTML`, func(result *gojs.Value, err error) { @@ -233,7 +237,8 @@ func TestWebView_RunJavaScript_exception(t *testing.T) { defer webView.Destroy() wantErr := errors.New("An exception was raised in JavaScript") - webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) { + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := LoadEvent(event) switch loadEvent { case LoadFinished: webView.RunJavaScript(`throw new Error("foo")`, func(result *gojs.Value, err error) { @@ -261,7 +266,8 @@ func TestWebView_GetSnapshot(t *testing.T) { webView := NewWebView() defer webView.Destroy() - webView.Connect("load-changed", func(_ *glib.Object, loadEvent LoadEvent) { + webView.Connect("load-changed", func(_ *glib.Object, event int) { + loadEvent := LoadEvent(event) switch loadEvent { case LoadFinished: webView.GetSnapshot(func(img *image.RGBA, err error) {