Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2017-01-24 17:23:26 +0000
committerAlexander Kurtakov2017-02-07 07:18:01 +0000
commit9b9501b0fef312da72586299e22d329f00ac5e20 (patch)
tree2a399c24a5820a37dc1aa420dfe1db0f1ba62146 /bundles/org.eclipse.swt/Eclipse SWT Browser
parenta647bf412269ed1dee039baacd08a7c5472595bb (diff)
downloadeclipse.platform.swt-9b9501b0fef312da72586299e22d329f00ac5e20.tar.gz
eclipse.platform.swt-9b9501b0fef312da72586299e22d329f00ac5e20.tar.xz
eclipse.platform.swt-9b9501b0fef312da72586299e22d329f00ac5e20.zip
Bug 508217 Implement webkit2 support for browser function
(Part 1: JavaScript to call Java) This implements Browser.function() on webkit2. Current implementation allows javascript to reach java, but java doesn't provide a return vaulue in the callback. For detailed architecture changes, see: Webkit2JavaCallback() inside WebKit.java. In short, in webkit1 an 'external' object was registered and callJava was a property of this object. In webkit2, 'external' object is no longer used and instead a callback/signal is registered/connected. With this patch, the following jUnits pass: test_BrowserFunction_callback test_BrowserFunction_callback_with_integer test_BrowserFunction_callback_with_boolean test_BrowserFunction_callback_with_String test_BrowserFunction_callback_with_multipleValues testBrowser4. The following does not: test_BrowserFunction_callback_with_javaReturningInt Patch set 4: - I noticed that after a page re-load, webkit2 custom functions did not work. This is because the page-reload mechanism has changed (Bg:510972) but in the ported webkit2 mechanism functions were not re-registered). - Added code to re-register custom functions after page reload. Patch set 7: - Removed 'protected' modifier. - Moved comments around. Change-Id: I94549ed306e0095c735d18389b55a36923c5ec08 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Browser')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/WebBrowser.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/WebBrowser.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/WebBrowser.java
index 5f79e68379..df7f31745e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/WebBrowser.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/common/org/eclipse/swt/browser/WebBrowser.java
@@ -346,8 +346,10 @@ public void createFunction (BrowserFunction function) {
functionBuffer.append (ERROR_ID.length ());
functionBuffer.append (")); throw error;} return result;};"); //$NON-NLS-1$
- StringBuffer buffer = new StringBuffer ("if (!window.callJava) {window.callJava = function callJava(index, token, args) {"); //$NON-NLS-1$
- buffer.append ("return external.callJava(index,token,args);}};"); //$NON-NLS-1$
+ String javaCallDeclaration = getJavaCallDeclaration();
+
+ StringBuffer buffer = new StringBuffer (); //$NON-NLS-1$
+ buffer.append (javaCallDeclaration); //$NON-NLS-1$
if (function.top) {
buffer.append (functionBuffer.toString ());
}
@@ -375,6 +377,18 @@ public void createFunction (BrowserFunction function) {
execute (function.functionString);
}
+/**
+ * Designed to be overriden.
+ * @return javaScrit code that defines the 'callJava' syntax for javascript.
+ */
+String getJavaCallDeclaration() {
+ return "if (!window.callJava) {\n"
+ + " window.callJava = function callJava(index, token, args) {\n"
+ + " return external.callJava(index,token,args);\n"
+ + " }\n"
+ + "};\n";
+}
+
void deregisterFunction (BrowserFunction function) {
functions.remove (function.index);
}
@@ -396,6 +410,9 @@ public Object evaluate (String script, boolean trusted) throws SWTException {
}
public Object evaluate (String script) throws SWTException {
+ // Developer note:
+ // Webkit1 & Mozilla use this mechanism.
+ // Webkit2 uses a different mechanism. See WebKit:evaluate();
BrowserFunction function = new EvaluateFunction (browser, ""); // $NON-NLS-1$
int index = getNextFunctionIndex ();
function.index = index;

Back to the top