Check-in [47ae24e3e7]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:in twv use runtime linking for webkit2gtk
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 47ae24e3e7010788ff86e469ca4840a6524dc497
User & Date: chw 2019-06-17 14:06:00
Context
2019-06-17
16:22
when building linux vanillawish use prebuilt twv if no webkit2gtk available check-in: 4d8dd37323 user: chw tags: trunk
14:06
in twv use runtime linking for webkit2gtk check-in: 47ae24e3e7 user: chw tags: trunk
2019-06-16
08:19
some fixes in undroidwish/vanilla build scripts check-in: ff246e49df user: chw tags: trunk
Changes

Changes to undroid/twv/Makefile.

15
16
17
18
19
20
21




22
23
24
25
26
27
28
29
30
31
32
	WEBVIEW_CFLAGS := -DWEBVIEW_WINAPI=1
	WEBVIEW_LDFLAGS := -lole32 -lcomctl32 -loleaut32 -luuid -mwindows
else ifeq ($(shell uname -s),Darwin)
	TARGET := libtwv.dylib
	WEBVIEW_CFLAGS := -DWEBVIEW_COCOA=1
	WEBVIEW_LDFLAGS := -framework WebKit
else




	TARGET := libtwv.so
	WEBVIEW_CFLAGS := -DWEBVIEW_GTK=1 \
	    $(shell pkg-config --cflags gtk+-3.0 webkit2gtk-4.0)
	WEBVIEW_LDFLAGS := $(shell pkg-config --libs webkit2gtk-4.0)
endif

all:	$(TARGET)

$(TARGET): twv.c
	$(CC) -fPIC -shared $(CFLAGS) $(TCL_CFLAGS) $(WEBVIEW_CFLAGS) twv.c \
	    $(LDFLAGS) $(TCL_LDFLAGS) $(WEBVIEW_LDFLAGS) -o $@







>
>
>
>

|

|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
	WEBVIEW_CFLAGS := -DWEBVIEW_WINAPI=1
	WEBVIEW_LDFLAGS := -lole32 -lcomctl32 -loleaut32 -luuid -mwindows
else ifeq ($(shell uname -s),Darwin)
	TARGET := libtwv.dylib
	WEBVIEW_CFLAGS := -DWEBVIEW_COCOA=1
	WEBVIEW_LDFLAGS := -framework WebKit
else

# to omit runtime linking, remove WEBVIEW_GTK_DL and use
# WEBVIEW_LDFLAGS := $(shell pkg-config --libs webkit2gtk-4.0)

	TARGET := libtwv.so
	WEBVIEW_CFLAGS := -DWEBVIEW_GTK=1 -DWEBVIEW_GTK_DL=1 \
	    $(shell pkg-config --cflags gtk+-3.0 webkit2gtk-4.0)
	WEBVIEW_LDFLAGS := -lgtk-3 -lgdk-3 -lglib-2.0
endif

all:	$(TARGET)

$(TARGET): twv.c
	$(CC) -fPIC -shared $(CFLAGS) $(TCL_CFLAGS) $(WEBVIEW_CFLAGS) twv.c \
	    $(LDFLAGS) $(TCL_LDFLAGS) $(WEBVIEW_LDFLAGS) -o $@

Added undroid/twv/prebuilt/i386/libtwv.so.

cannot compute difference between binary files

Added undroid/twv/prebuilt/x86_64/libtwv.so.

cannot compute difference between binary files

Changes to undroid/twv/twv.c.

1
2
3
4



5
6
7
8
9
10
11
...
566
567
568
569
570
571
572






573
574
575
576
577
578
579
#include <tcl.h>

#define WEBVIEW_IMPLEMENTATION
#define WEBVIEW_STATIC



#include "webview.h"

/*
 * set w [::twv::new options ...]
 *
 * options:
 *   -width int
................................................................................
    if (Tcl_InitStubs(interp, "8.4", 0) == NULL) {
        return TCL_ERROR;
    }
#else
    if (Tcl_PkgRequire(interp, "Tcl", "8.4", 0) == NULL) {
        return TCL_ERROR;
    }






#endif
    if (Tcl_PkgProvide(interp, "twv", "0.1") != TCL_OK) {
        return TCL_ERROR;
    }
    tctrl = ckalloc(sizeof (tctrl));
    tctrl->counter = 0;
    Tcl_CreateNamespace(interp, "::twv", NULL, NULL);




>
>
>







 







>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
...
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
#include <tcl.h>

#define WEBVIEW_IMPLEMENTATION
#define WEBVIEW_STATIC
#ifdef WEBVIEW_GTK_DL
#include "webview_dl.h"
#endif
#include "webview.h"

/*
 * set w [::twv::new options ...]
 *
 * options:
 *   -width int
................................................................................
    if (Tcl_InitStubs(interp, "8.4", 0) == NULL) {
        return TCL_ERROR;
    }
#else
    if (Tcl_PkgRequire(interp, "Tcl", "8.4", 0) == NULL) {
        return TCL_ERROR;
    }
#endif
#ifdef WEBVIEW_GTK_DL
    if (webview_dl_init() < 0) {
	Tcl_SetResult(interp, "runtime linking webview failed", TCL_STATIC);
	return TCL_ERROR;
    }
#endif
    if (Tcl_PkgProvide(interp, "twv", "0.1") != TCL_OK) {
        return TCL_ERROR;
    }
    tctrl = ckalloc(sizeof (tctrl));
    tctrl->counter = 0;
    Tcl_CreateNamespace(interp, "::twv", NULL, NULL);

Added undroid/twv/webview_dl.h.





































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef WEBVIEW_DL_H
#define WEBVIEW_DL_H

#ifdef WEBVIEW_GTK
#include <dlfcn.h>
#include <pthread.h>
#include <JavaScriptCore/JavaScript.h>
#include <webkit2/webkit2.h>

typedef size_t (*fn_JSStringGetMaximumUTF8CStringSize)(JSStringRef);
typedef size_t (*fn_JSStringGetUTF8CString)(JSStringRef string, char *, size_t);
typedef void (*fn_JSStringRelease)(JSStringRef);
typedef JSStringRef (*fn_JSValueToStringCopy)(JSContextRef, JSValueRef, JSValueRef *);
typedef JSGlobalContextRef (*fn_webkit_javascript_result_get_global_context)(WebKitJavascriptResult *);
typedef JSValueRef (*fn_webkit_javascript_result_get_value)(WebKitJavascriptResult *);
typedef void (*fn_webkit_settings_set_enable_developer_extras)(WebKitSettings *, gboolean);
typedef void (*fn_webkit_settings_set_enable_write_console_messages_to_stdout)(WebKitSettings *, gboolean);
typedef WebKitUserContentManager *(*fn_webkit_user_content_manager_new)(void);
typedef gboolean (*fn_webkit_user_content_manager_register_script_message_handler)(WebKitUserContentManager *, const gchar *);
typedef WebKitSettings *(*fn_webkit_web_view_get_settings)(WebKitWebView *);
typedef GType (*fn_webkit_web_view_get_type)(void);
typedef void (*fn_webkit_web_view_load_uri)(WebKitWebView *, const gchar *);
typedef GtkWidget *(*fn_webkit_web_view_new_with_user_content_manager)(WebKitUserContentManager *);
typedef void (*fn_webkit_web_view_run_javascript)(WebKitWebView *, const gchar *, GCancellable *, GAsyncReadyCallback, gpointer);
typedef void (*fn_webkit_web_view_set_background_color)(WebKitWebView *, const GdkRGBA *);

struct wk_dl {
  fn_JSStringGetMaximumUTF8CStringSize JSStringGetMaximumUTF8CStringSize;
  fn_JSStringGetUTF8CString JSStringGetUTF8CString;
  fn_JSStringRelease JSStringRelease;
  fn_JSValueToStringCopy JSValueToStringCopy;
  fn_webkit_javascript_result_get_global_context webkit_javascript_result_get_global_context;
  fn_webkit_javascript_result_get_value webkit_javascript_result_get_value;
  fn_webkit_settings_set_enable_developer_extras webkit_settings_set_enable_developer_extras;
  fn_webkit_settings_set_enable_write_console_messages_to_stdout webkit_settings_set_enable_write_console_messages_to_stdout;
  fn_webkit_user_content_manager_new webkit_user_content_manager_new;
  fn_webkit_user_content_manager_register_script_message_handler webkit_user_content_manager_register_script_message_handler;
  fn_webkit_web_view_get_settings webkit_web_view_get_settings;
  fn_webkit_web_view_get_type webkit_web_view_get_type;
  fn_webkit_web_view_load_uri webkit_web_view_load_uri;
  fn_webkit_web_view_new_with_user_content_manager webkit_web_view_new_with_user_content_manager;
  fn_webkit_web_view_run_javascript webkit_web_view_run_javascript;
  fn_webkit_web_view_set_background_color webkit_web_view_set_background_color;
};

#ifdef WEBVIEW_STATIC
#define WEBVIEW_API static
static struct wk_dl wk_dl = { 0 };
#else
#define WEBVIEW_API extern
extern struct wk_dl wk_dl = { 0 };
#endif

WEBVIEW_API int webview_dl_init(void) {
  static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
  static int initialized = 0;
  int i, result;
  static const char *libnames[2] = {
    "libwebkit2gtk-4.0.so.37",
    "libjavascriptcoregtk-4.0.so.18",
  };
  static void *libs[2] = { NULL, NULL };

  if (!initialized) {
    pthread_mutex_lock(&init_mutex);
    if (initialized) {
      goto done;
    }
    for (i = 0; i < 2; i++) {
      libs[i] = dlopen(libnames[i], RTLD_NOW);
      if (libs[i] == NULL) {
	initialized = -1;
	while (i > 0) {
	  --i;
	  dlclose(libs[i]);
	  libs[i] = NULL;
	}
	goto done;
      }
    }

#define DOSYM(name)				      \
    wk_dl.name = (fn_ ## name) dlsym(libs[0], #name); \
    if (wk_dl.name == NULL) goto dlerr;

    DOSYM(webkit_javascript_result_get_global_context);
    DOSYM(webkit_javascript_result_get_value);
    DOSYM(webkit_settings_set_enable_developer_extras);
    DOSYM(webkit_settings_set_enable_write_console_messages_to_stdout);
    DOSYM(webkit_user_content_manager_new);
    DOSYM(webkit_user_content_manager_register_script_message_handler);
    DOSYM(webkit_web_view_get_settings);
    DOSYM(webkit_web_view_get_type);
    DOSYM(webkit_web_view_load_uri);
    DOSYM(webkit_web_view_new_with_user_content_manager);
    DOSYM(webkit_web_view_run_javascript);
    DOSYM(webkit_web_view_set_background_color);

#undef DOSYM

#define DOSYM(name)				      \
    wk_dl.name = (fn_ ## name) dlsym(libs[1], #name); \
    if (wk_dl.name == NULL) goto dlerr;

    DOSYM(JSStringGetMaximumUTF8CStringSize);
    DOSYM(JSStringGetUTF8CString);
    DOSYM(JSStringRelease);
    DOSYM(JSValueToStringCopy);

#undef DOSYM

    initialized = 1;
    goto done;

dlerr:
    initialized = -1;
    for (i = 0; i < 2; i++) {
      dlclose(libs[i]);
      libs[i] = NULL;
    }

done:
    pthread_mutex_unlock(&init_mutex);
  }

  return (initialized > 0) ? 0 : -1;
}

#define JSStringGetMaximumUTF8CStringSize \
  wk_dl.JSStringGetMaximumUTF8CStringSize

#define JSStringGetUTF8CString \
  wk_dl.JSStringGetUTF8CString

#define JSStringRelease \
  wk_dl.JSStringRelease

#define JSValueToStringCopy \
  wk_dl.JSValueToStringCopy

#define webkit_javascript_result_get_global_context \
  wk_dl.webkit_javascript_result_get_global_context

#define webkit_javascript_result_get_value \
  wk_dl.webkit_javascript_result_get_value

#define webkit_settings_set_enable_developer_extras \
  wk_dl.webkit_settings_set_enable_developer_extras

#define webkit_settings_set_enable_write_console_messages_to_stdout \
  wk_dl.webkit_settings_set_enable_write_console_messages_to_stdout

#define webkit_user_content_manager_new \
  wk_dl.webkit_user_content_manager_new

#define webkit_user_content_manager_register_script_message_handler \
  wk_dl.webkit_user_content_manager_register_script_message_handler

#define webkit_web_view_get_settings \
  wk_dl.webkit_web_view_get_settings

#define webkit_web_view_get_type \
  wk_dl.webkit_web_view_get_type

#define webkit_web_view_load_uri \
  wk_dl.webkit_web_view_load_uri

#define webkit_web_view_new_with_user_content_manager \
  wk_dl.webkit_web_view_new_with_user_content_manager

#define webkit_web_view_run_javascript \
  wk_dl.webkit_web_view_run_javascript

#define webkit_web_view_set_background_color \
  wk_dl.webkit_web_view_set_background_color

#endif /* WEBVIEW_GTK */
#endif /* WEBVIEW_DL_H */