Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2017-11-06 16:52:38 +0000
committerLeo Ufimtsev2017-12-01 18:45:15 +0000
commit8009c3b86dee4f50191b785f9c121ef5cdd24746 (patch)
tree5f6294dc2ffef1f164dda77b88c91b00de2fe096 /bundles/org.eclipse.swt/Eclipse SWT PI/gtk
parent382c1d03f132e44887b0dcb83fdb7f7578ef9db2 (diff)
downloadeclipse.platform.swt-8009c3b86dee4f50191b785f9c121ef5cdd24746.tar.gz
eclipse.platform.swt-8009c3b86dee4f50191b785f9c121ef5cdd24746.tar.xz
eclipse.platform.swt-8009c3b86dee4f50191b785f9c121ef5cdd24746.zip
Bug 510905 [Webkit2] BrowserFunction with return value back to
Javascript (PRIOR TO MERGING, SWT BINARY REPO NEEDS TO BE PATCHED) Webkit2 moved it's webprocess into a separate process. For javascript to call a function, it needs to do so via the separate process. To interact with the separate process, we need to implement a webextension, which is a separate '.so' file loaded at run time. The extension needs to reside in it's own folder otherwise webkit will try to load the other .so files as extensions. (See Library.java changes). Communication between the extension and the main process is done via a gdbus channel. Javascript/Java types are packaged into GVariants and transmitted via gdbus. Compilation of the webextension requires webkit2gtk package to be present on build servers. Tests: - All jUnits pass - SWT Snippet (307) that use BrowserFunction work. - Attached local snippet can be used to test sending various paramaters over gdbus and receiving them back prints to main webview. - Child eclipse works fine with the patch. - Afaik, no known error/warnings are produced. (If there are, let me know). This might break 32bit build of SWT though, not tested on 32 bit. Patch set log: -------------- Patchset 6: - Passing webview as string in javascript function. Patchset 8: - Implemented dynamic gdbus bindigs on SWT/Java side. Works. (fairly large patch) Patchset 9: - Implemented gdbus bindings on client side, such that it can reach server. (working) Patchset 10: - Added GVariant conversion functions on SWT side. Works. - Moved code out of OS.java to reside only in WebKitGTK Patchset 11: - Figured out how to provide return value as an object array. Added snippet to show how to provide a string return value. (working) Patchset 12: - Passed webview pointer, index and token to Java. - Fixed typo in type definition. > (Working) Patchset 13: - Now passing javascript arguments along through gdbus to java. > (Working) Patchset 14: (Week 46) - Implemented support for 'null'. (use byte as magic number). - Found that there is a bug in how I deal with return value in gdbus, gdbus returns an array (always). Need to return first item in array. Patchset 15: (Week 46) - Implemented proper return value of java to javascript. - Found that js calls with no paramaters call() fail, need to fix. Patchset 16: (Week 46) - Implemented support for empty arrays (including calls without args). - Code tidy. - Found that I need to implement input argument verification from JS call and from java code ran by user, otherwise gdbus can crash. Patchset 17: (Week 46) - Implement checking of user-input arguments, to ensure it won't break gdbus connection. Patchset 18: (Week 46) - Implemented checking of return value from userfunction, so bad return value doesn't break gdbus. - Code tidy/polish. - Need to implement lazy loading of gdbus, only init gdbus for the first function that we instantiate. - Also still getting warning when loading webkit library. Patchset 19: [Week 47] - Implemented lazy loading of gdbus, to only load when needed. - wrapped getPID() into lock, otherwise had strange debug/execution behaviour. Patchset 20: [Week 47] - Two BrowserInstances with Two BrowserFunctions seem to hang (snippet), (need to investigate) Patchset 21: [W47] - Removed redundant print statements. Cleaned up code. Patchset 22: [W47] - Moved Webkit extension initialization logic into a callback, so that it's guaranteed to be loaded at the most optimal time. (All jUnits pass). Patchset 23: [W47] - Removed redundant println. Patchset 24: [W47] - Implemented mechanism by which webextension is compiled and loaded from a folder. (This needs a patch to binary project's build.properties) Patchset 25: [W47] - Code tidy. Patch complete (ish). Patchset 26: [W47] - forgot to add files to patchset 25. Patchset 27: [W47] - Verified that Browser widget will continue to work if webextension fails to load. - Added relevant warnings. Patchset 28: - Minor update on SWT_LIB_VERSIONS. Change-Id: Iccfc48bc78774ac4120aafd976186381f247c562 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT PI/gtk')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak36
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c12
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java14
5 files changed, 62 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak
index b9ec052d0d..3c83804a99 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/make_linux.mak
@@ -13,8 +13,9 @@
# SWT debug flags for various SWT components.
#SWT_WEBKIT_DEBUG = -DWEBKIT_DEBUG
-#SWT_LIB_DEBUG=1 # to debug glue code in /bundles/org.eclipse.swt/bin/library. E.g os_custom.c:swt_fixed_forall(..)
+#SWT_LIB_DEBUG=1 # to debug glue code in /bundles/org.eclipse.swt/bin/library. E.g os_custom.c:swt_fixed_forall(..)
+# Can be set via environment like: export SWT_LIB_DEBUG=1
ifdef SWT_LIB_DEBUG
SWT_DEBUG = -O0 -g3 -ggdb3
NO_STRIP=1
@@ -37,6 +38,7 @@ endif
CAIRO_PREFIX = swt-cairo
ATK_PREFIX = swt-atk
WEBKIT_PREFIX = swt-webkit
+WEBKIT_EXTENSION_PREFIX=swt-webkit2extension
GLX_PREFIX = swt-glx
SWT_LIB = lib$(SWT_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
@@ -44,8 +46,13 @@ AWT_LIB = lib$(AWT_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
SWTPI_LIB = lib$(SWTPI_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
CAIRO_LIB = lib$(CAIRO_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
ATK_LIB = lib$(ATK_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
-WEBKIT_LIB = lib$(WEBKIT_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
GLX_LIB = lib$(GLX_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
+WEBKIT_LIB = lib$(WEBKIT_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
+ALL_SWT_LIBS = $(SWT_LIB) $(AWT_LIB) $(SWTPI_LIB) $(CAIRO_LIB) $(ATK_LIB) $(GLX_LIB) $(WEBKIT_LIB)
+
+# Webkit extension lib has to be put into a separate folder and is treated differently from the other libraries.
+WEBKIT_EXTENSION_LIB = lib$(WEBKIT_EXTENSION_PREFIX)-$(WS_PREFIX)-$(SWT_VERSION).so
+WEBEXTENSION_DIR = webkitextensions$(maj_ver)$(min_ver)
CAIROCFLAGS = `pkg-config --cflags cairo`
CAIROLIBS = `pkg-config --libs-only-L cairo` -lcairo
@@ -71,6 +78,10 @@ GLXLIBS = -lGL -lGLU -lm
WEBKITLIBS = `pkg-config --libs-only-l gio-2.0`
WEBKITCFLAGS = `pkg-config --cflags gio-2.0`
+
+WEBKIT_EXTENSION_CFLAGS=`pkg-config --cflags gtk+-3.0 webkit2gtk-web-extension-4.0`
+WEBKIT_EXTENSION_LFLAGS=`pkg-config --libs gtk+-3.0 webkit2gtk-web-extension-4.0`
+
ifdef SWT_WEBKIT_DEBUG
# don't use 'webkit2gtk-4.0' in production, as some systems might not have those libs and we get crashes.
WEBKITLIBS += `pkg-config --libs-only-l webkit2gtk-4.0`
@@ -177,7 +188,11 @@ atk_stats.o: atk_stats.c atk_structs.h atk_stats.h atk.h
#
# WebKit lib
#
+ifeq ($(GTK_VERSION), 3.0)
+make_webkit: $(WEBKIT_LIB) make_webkit2extension #Webkit2 only used by gtk3.
+else
make_webkit: $(WEBKIT_LIB)
+endif
$(WEBKIT_LIB): $(WEBKIT_OBJECTS)
$(CC) $(LFLAGS) -o $(WEBKIT_LIB) $(WEBKIT_OBJECTS) $(WEBKITLIBS)
@@ -194,6 +209,16 @@ webkitgtk_stats.o: webkitgtk_stats.c webkitgtk_stats.h
webkitgtk_custom.o: webkitgtk_custom.c
$(CC) $(CFLAGS) $(WEBKITCFLAGS) -c webkitgtk_custom.c
+
+# Webkit2 extension is a seperate .so lib.
+make_webkit2extension: $(WEBKIT_EXTENSION_LIB)
+
+$(WEBKIT_EXTENSION_LIB) : webkitgtk_extension.o
+ $(CC) $(LFLAGS) -o $@ $^ $(WEBKIT_EXTENSION_LFLAGS)
+
+webkitgtk_extension.o : webkitgtk_extension.c
+ $(CC) $(CFLAGS) $(WEBKIT_EXTENSION_CFLAGS) ${SWT_PTR_CFLAGS} -fPIC -c $^
+
#
# GLX lib
#
@@ -217,6 +242,13 @@ glx_stats.o: glx_stats.c glx_stats.h
install: all
cp *.so $(OUTPUT_DIR)
+
+install: all
+ cp $(ALL_SWT_LIBS) $(OUTPUT_DIR)
+ifeq ($(GTK_VERSION), 3.0) # Copy webextension into it's own folder, but create folder first.
+ [ -d $(OUTPUT_DIR)/$(WEBEXTENSION_DIR) ] || mkdir $(OUTPUT_DIR)/$(WEBEXTENSION_DIR) # If folder not exist, make it.
+ cp $(WEBKIT_EXTENSION_LIB) $(OUTPUT_DIR)/$(WEBEXTENSION_DIR)/
+endif
#
# Clean
#
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
index db9b835c4e..3fe853f20c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -6927,6 +6927,18 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gdk_1x11_1window_1lookup_1for_1display)
}
#endif
+#ifndef NO__1getpid
+JNIEXPORT jint JNICALL OS_NATIVE(_1getpid)
+ (JNIEnv *env, jclass that)
+{
+ jint rc = 0;
+ OS_NATIVE_ENTER(env, that, _1getpid_FUNC);
+ rc = (jint)getpid();
+ OS_NATIVE_EXIT(env, that, _1getpid_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO__1glib_1major_1version
JNIEXPORT jint JNICALL OS_NATIVE(_1glib_1major_1version)
(JNIEnv *env, jclass that)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index dbb697a0b0..abba27976f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -574,6 +574,7 @@ char * OS_nativeFunctionNames[] = {
"_1gdk_1x11_1visual_1get_1xvisual",
"_1gdk_1x11_1window_1get_1xid",
"_1gdk_1x11_1window_1lookup_1for_1display",
+ "_1getpid",
"_1glib_1major_1version",
"_1glib_1micro_1version",
"_1glib_1minor_1version",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index 18464f35ef..609ba771a8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -584,6 +584,7 @@ typedef enum {
_1gdk_1x11_1visual_1get_1xvisual_FUNC,
_1gdk_1x11_1window_1get_1xid_FUNC,
_1gdk_1x11_1window_1lookup_1for_1display_FUNC,
+ _1getpid_FUNC,
_1glib_1major_1version_FUNC,
_1glib_1micro_1version_FUNC,
_1glib_1minor_1version_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 1ca20754b5..79cc73579d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -14989,6 +14989,20 @@ public static final void gtk_window_unmaximize(long /*int*/ handle) {
lock.unlock();
}
}
+
+// Technically works on OSX also, but currently only used on Linux.
+// Once SWT is moved to Java 9, consider using 'ProcessHandle.current().getPid();' instead,
+// but for now getpid() should do.
+// https://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id
+public static final native int _getpid ();
+public static final int getpid() {
+ lock.lock();
+ try {
+ return _getpid();
+ } finally {
+ lock.unlock();
+ }
+}
/**
* @param dest cast=(void *)
* @param src cast=(const void *),flags=no_out

Back to the top