diff options
| author | Lev Ufimtsev | 2016-07-21 21:17:30 +0000 |
|---|---|---|
| committer | Alexander Kurtakov | 2016-07-27 19:43:42 +0000 |
| commit | 24607eb68067e6c91f3c5c7a3f9697729f23dc76 (patch) | |
| tree | 54496fb4bf062ab72deebf89094614f623e81124 | |
| parent | 6a5d3e119bdc4f831b7e68a8bfc59a68ab85ce25 (diff) | |
| download | eclipse.platform.swt-24607eb68067e6c91f3c5c7a3f9697729f23dc76.tar.gz eclipse.platform.swt-24607eb68067e6c91f3c5c7a3f9697729f23dc76.tar.xz eclipse.platform.swt-24607eb68067e6c91f3c5c7a3f9697729f23dc76.zip | |
Bug 430538 - [GTK3][webkit] Support Custom JavaScript execution in
WebKit2 mode of SWT Browser
Fixes to JNI bindings. Now 'execution' of Javascript works.
However, currently return value is not supported on Webkit2. To be worked
on in future commit. (exec() returns false although it does run JS)
Snippet for testing:
https://github.com/LeoUfimtsev/swt.snippets/blob/master/swt.crossplatform.snippets/generic/browser/Snip_Browser_Javascript_execute.java
Change-Id: Icd4c100da4d7be445f4bcf12be2969d95b7ad8fb
Signed-off-by: Lev Ufimtsev <lufimtse@redhat.com>
3 files changed, 26 insertions, 17 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/library/webkitgtk.c b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/library/webkitgtk.c index 15b7761ab4..f1031ecfdb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/library/webkitgtk.c +++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/library/webkitgtk.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2014 IBM Corporation and others. All rights reserved. + * Copyright (c) 2009, 2016 IBM Corporation and others. All rights reserved. * The contents of this file are made available under the terms * of the GNU Lesser General Public License (LGPL) Version 2.1 that * accompanies this distribution (lgpl-v21.txt). The LGPL is also @@ -2793,18 +2793,22 @@ JNIEXPORT void JNICALL WebKitGTK_NATIVE(_1webkit_1web_1view_1reload) #ifndef NO__1webkit_1web_1view_1run_1javascript JNIEXPORT void JNICALL WebKitGTK_NATIVE(_1webkit_1web_1view_1run_1javascript) - (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jintLong arg2, jintLong arg3, jintLong arg4) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jintLong arg2, jintLong arg3, jintLong arg4) { + jbyte *lparg1=NULL; WebKitGTK_NATIVE_ENTER(env, that, _1webkit_1web_1view_1run_1javascript_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; /* - webkit_web_view_run_javascript(arg0, arg1, arg2, arg3, arg4); + webkit_web_view_run_javascript(arg0, lparg1, arg2, arg3, arg4); */ { WebKitGTK_LOAD_FUNCTION(fp, webkit_web_view_run_javascript) if (fp) { - ((void (CALLING_CONVENTION*)(jintLong, jintLong, jintLong, jintLong, jintLong))fp)(arg0, arg1, arg2, arg3, arg4); + ((void (CALLING_CONVENTION*)(jintLong, jbyte *, jintLong, jintLong, jintLong))fp)(arg0, lparg1, arg2, arg3, arg4); } } +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); WebKitGTK_NATIVE_EXIT(env, that, _1webkit_1web_1view_1run_1javascript_FUNC); } #endif diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java index 779c7baf9d..42c7450bed 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java +++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java @@ -899,25 +899,28 @@ boolean close (boolean showPrompters) { @Override public boolean execute (String script) { - byte[] bytes = (script + '\0').getBytes (StandardCharsets.UTF_8); //$NON-NLS-1$ - long /*int*/ scriptString = WebKitGTK.JSStringCreateWithUTF8CString (bytes); + byte[] scriptBytes = (script + '\0').getBytes (StandardCharsets.UTF_8); //$NON-NLS-1$ - bytes = (getUrl () + '\0').getBytes (StandardCharsets.UTF_8); //$NON-NLS-1$ - long /*int*/ result = 0; + long /*int*/ result = 0; if (WEBKIT2){ - WebKitGTK.webkit_web_view_run_javascript (webView, scriptString, 0, 0, 0); + WebKitGTK.webkit_web_view_run_javascript (webView, scriptBytes, 0, 0, 0); + // TODO - this call is asynchronous, so no return vaulue. As result this call executes but + // returns false. Handling of return value to be implemented... } else { - long /*int*/ urlString = WebKitGTK.JSStringCreateWithUTF8CString (bytes); + long /*int*/ jsScriptString = WebKitGTK.JSStringCreateWithUTF8CString (scriptBytes); + // Currently loaded website will be used as 'source file' of the javascript to be exucuted. + byte[] sourceUrlbytes = (getUrl () + '\0').getBytes (StandardCharsets.UTF_8); //$NON-NLS-1$ + + long /*int*/ jsSourceUrlString = WebKitGTK.JSStringCreateWithUTF8CString (sourceUrlbytes); long /*int*/ frame = WebKitGTK.webkit_web_view_get_main_frame (webView); long /*int*/ context = WebKitGTK.webkit_web_frame_get_global_context (frame); - result = WebKitGTK.JSEvaluateScript (context, scriptString, 0, urlString, 0, null); + result = WebKitGTK.JSEvaluateScript (context, jsScriptString, 0, jsSourceUrlString, 0, null); - WebKitGTK.JSStringRelease (urlString); + WebKitGTK.JSStringRelease (jsSourceUrlString); + WebKitGTK.JSStringRelease (jsScriptString); } - - WebKitGTK.JSStringRelease (scriptString); return result != 0; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java index f7505bad91..98fe4e30d0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java +++ b/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java @@ -15,7 +15,7 @@ package org.eclipse.swt.internal.webkit; -import org.eclipse.swt.internal.C; +import org.eclipse.swt.internal.*; public class WebKitGTK extends C { @@ -1517,9 +1517,11 @@ public static final void webkit_web_view_reload (long /*int*/ web_view) { } } + +//fyi: void webkit_web_view_run_javascript (WebKitWebView *web_view, const gchar *script, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data); /** @method flags=dynamic */ -public static final native void _webkit_web_view_run_javascript (long /*int*/ web_view, long /*int*/ script, long /*int*/ cancellable, long /*int*/ callback, long /*int*/ user_data); -public static final void webkit_web_view_run_javascript (long /*int*/ web_view, long /*int*/ script, long /*int*/ cancellable, long /*int*/ callback, long /*int*/ user_data) { +public static final native void _webkit_web_view_run_javascript (long /*int*/ web_view, byte [] script, long /*int*/ cancellable, long /*int*/ callback, long /*int*/ user_data); +public static final void webkit_web_view_run_javascript (long /*int*/ web_view, byte[] script, long /*int*/ cancellable, long /*int*/ callback, long /*int*/ user_data) { lock.lock(); try { _webkit_web_view_run_javascript (web_view, script, cancellable, callback, user_data); |
