Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
36583d9
changed inports
mdimec4 Jan 10, 2014
ff622b4
changed glib Connect api to new version of gotk3
mdimec4 Jan 24, 2014
cc3f23c
tests
mdimec4 Jan 24, 2014
629e336
Merge remote-tracking branch 'sourcegraph/master'
mdimec4 Feb 5, 2014
52e61c0
GetSnepshot(): Protect callback from GC
mdimec4 May 12, 2014
8d91135
go-webkit2: GetSnapshot: more optins with GetSnapshotCustum
mdimec4 May 12, 2014
6409aa5
small changes
mdimec4 May 12, 2014
61f07f3
go fmt
mdimec4 May 14, 2014
7d871d4
spelling error
mdimec4 May 16, 2014
f5fc9f6
spelling 2
mdimec4 May 16, 2014
f7244ff
Added remote webkit inspector.
matevzmihalic Jun 23, 2014
4306d0b
go fmt
mdimec4 Jun 23, 2014
f08b072
add SetExtensionsDir to go-webkit2
mdimec4 Aug 6, 2014
297d536
webkit2: fix WebKitWebContext
mdimec4 Aug 6, 2014
6134040
Merge pull request #1 from visionect/develop
mdimec4 Aug 11, 2014
985457e
cookie local storage gotk3/go-webkit2
mdimec4 Aug 25, 2014
110c3cd
Small fix for webview.go
Aug 27, 2014
cc771f4
compilable with go 1.3.1 compiler
mdimec4 Sep 8, 2014
f36d2de
better load fail handling
mdimec4 Nov 27, 2014
a9f0963
conflict CString() free
mdimec4 Dec 19, 2014
93220d2
mulltiple processes can't share the same cache location
mdimec4 Jan 16, 2015
1a1d546
conflicts
mdimec4 Feb 12, 2015
46c7954
go-webkit2 conflicts
mdimec4 Feb 12, 2015
57ee1eb
go-webkit2 conflicts2
mdimec4 Feb 12, 2015
19a3d75
color order fix
mdimec4 Jul 29, 2015
a49f24f
Issue #331 not finished yet. Timer works. JS api is prepared. Connect…
mdimec4 Aug 26, 2015
08efe86
webkit image debug messages!
mdimec4 Oct 8, 2015
84d7bc4
webkit: optimize cairo endian dependent to RGBA image pixels flip. #379
mdimec4 Oct 22, 2015
7ef683e
Remove debug messages.
mdimec4 Oct 26, 2015
6879289
Merge remote-tracking branch 'origin/develop'
mdimec4 Sep 7, 2016
980f938
Merge remote-tracking branch 'sourcegraph/master' into sg_pull_req_1
mdimec4 Sep 8, 2016
ccce6e6
fix paths back to sourcegraph
mdimec4 Sep 8, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down
3 changes: 2 additions & 1 deletion cmd/webkit-eval-js/evaljs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
144 changes: 144 additions & 0 deletions webkit2/cairo_endianes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#include <stdint.h>
//#include <stdio.h>

#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<len; i+=4) {
sw = data[i+0];
out[i+0] = data[i+1];
out[i+1] = data[i+2];
out[i+2] = data[i+3];
out[i+3] = sw;
}
break;
case GOWK2_LITTLE_ENDIAN_8:
// A R G B -> 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<len; i+=4) {
sw =data[i+0];
out[i+0] = data[i+2];
out[i+2] = sw;
}
} else {
// also copy
for(i=0; i<len; i+=4) {
sw =data[i+0];
out[i+0] = data[i+2];
out[i+1] = data[i+1];
out[i+2] = sw;
out[i+3] = data[i+3];
}
}
break;
case GOWK2_LITTLE_ENDIAN_16:
// A R G B -> R G B A
// 2 3 0 1 -> 3 0 1 2
for(i=0; i<len; i+=4) {
sw = data[i+0];
out[i+0] = data[i+3];
out[i+3] = data[i+2];
out[i+2] = data[i+1];
out[i+1] = sw;
}
break;
case GOWK2_MIDLE_ENDIAN:
// A R G B -> 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<len; i+=4) {
sw = data[i+1];
out[i+1] = data[i+3];
out[i+3] = sw;
}
} else {
// also copy
for(i=0; i<len; i+=4) {
sw = data[i+1];
out[i+0] = data[i+0];
out[i+1] = data[i+3];
out[i+2] = data[i+2];
out[i+3] = sw;
}
}
break;
default:
gowk2_cairo_endian_depended_ARGB32_to_RGBA_smart(data, out, len);
break;
}
}

void gowk2_cairo_endian_depended_ARGB32_to_RGBA_smart(unsigned char *data, unsigned char *out, unsigned int len) {
register char r, g, b, a;
register unsigned int i,j;
char* order;
//printf("webkit endian 0\n");


order = gowk2_detect_endianes_byte();

//printf("webkit endian 1\n");
for(i=0; i<len; i+=4) {
for(j=0;j<4;j++) {
switch(order[j]) {
case 0x00:
a = data[i+j];
break;
case 0x01:
r = data[i+j];
break;
case 0x02:
g = data[i+j];
break;
case 0x03:
b = data[i+j];
break;
}
}
out[i+0] = r;
out[i+1] = g;
out[i+2] = b;
out[i+3] = a;
}
//printf("webkit endian 2\n");
return;
}
15 changes: 15 additions & 0 deletions webkit2/cairo_endianes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package webkit2

// #include "cairo_endianes.h"
import "C"
import (
"unsafe"
)

func CairoEndianDependedARGB32ToRGBA(data []byte, out []byte) {
C.gowk2_cairo_endian_depended_ARGB32_to_RGBA((*C.uchar)(unsafe.Pointer(&data[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(len(data)))
}

func CairoEndianDependedARGB32ToRGBASmart(data []byte, out []byte) {
C.gowk2_cairo_endian_depended_ARGB32_to_RGBA_smart((*C.uchar)(unsafe.Pointer(&data[0])), (*C.uchar)(unsafe.Pointer(&out[0])), (C.uint)(len(data)))
}
5 changes: 5 additions & 0 deletions webkit2/cairo_endianes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef GOWK2_CAIRO_ENDIANES
#define GOWK2_CAIRO_ENDIANES
void gowk2_cairo_endian_depended_ARGB32_to_RGBA(unsigned char *data, unsigned char *out, unsigned int len);
void gowk2_cairo_endian_depended_ARGB32_to_RGBA_smart(unsigned char *data, unsigned char *out, unsigned int len);
#endif
48 changes: 48 additions & 0 deletions webkit2/cairo_endianes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package webkit2

import (
"math/rand"
"reflect"
"testing"
)

func generateImageARGB32(w, h int) []byte {
r := rand.New(rand.NewSource(666))
pix := make([]byte, 4*w*h)
for i, _ := range pix {
pix[i] = byte(r.Intn(255))
}
return pix
}

func TestEndianDependeARGB32ToRGBA(t *testing.T) {
pix := generateImageARGB32(1800, 1600)
pix2 := make([]byte, len(pix))
copy(pix2, pix)
t.Log(pix2[:12])
CairoEndianDependedARGB32ToRGBA(pix, pix)
CairoEndianDependedARGB32ToRGBASmart(pix2, pix2)
if !reflect.DeepEqual(pix, pix2) {
t.Fatal("Endianes correction function comparison mismatch!")
}
t.Log(pix[:12])
t.Log(pix2[:12])
}

func BenchmarkCairoEndianDependeARGB32ToRGBA(b *testing.B) {
pix := generateImageARGB32(1800, 1600)
rgba := make([]uint8, len(pix))
b.ResetTimer()
for i := 0; i < b.N; i++ {
CairoEndianDependedARGB32ToRGBA(pix, rgba)
}
}

func BenchmarkCairoEndianDependeARGB32ToRGBASamrt(b *testing.B) {
pix := generateImageARGB32(1800, 1600)
rgba := make([]uint8, len(pix))
b.ResetTimer()
for i := 0; i < b.N; i++ {
CairoEndianDependedARGB32ToRGBASmart(pix, rgba)
}
}
85 changes: 85 additions & 0 deletions webkit2/cookiemanager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package webkit2

// #include <stdlib.h>
// #include <webkit2/webkit2.h>
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)
}
22 changes: 21 additions & 1 deletion webkit2/gasyncreadycallback.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,33 @@ import "C"
import (
"errors"
"reflect"
"sync"
"unsafe"
)

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) {
Expand All @@ -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
}
Loading