summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorBenoit Hiller2013-03-29 22:06:57 (EDT)
committer Grant Gayed2013-04-05 11:50:13 (EDT)
commitb55452a689c4cca1526ed17fe12f1de2a1f0b028 (patch)
tree8cd9f5a7db81dda948eaafe2b80cb7deb75ff54f
parentbe6263654648217ed08af5e990a4fb80844c2be5 (diff)
downloadeclipse.platform.swt-b55452a689c4cca1526ed17fe12f1de2a1f0b028.zip
eclipse.platform.swt-b55452a689c4cca1526ed17fe12f1de2a1f0b028.tar.gz
eclipse.platform.swt-b55452a689c4cca1526ed17fe12f1de2a1f0b028.tar.bz2
Adding JS dialog events
Implemented the JS Dialog handler. This means that there are now methods for the 4 kinds of dialogs: confirm, alert, prompt and navigation. All of which are styled after the windows Webkit dialogs of the same kind. The methods take a JS Dialog Callback object that they execute after the dialog is closed. Caveats: * The style of the before navigation dialog is different from the others. This is something I duplicated from the webkit implementation but it strikes me as odd.
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.c62
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.c11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.h11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.c34
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.h12
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEF.java211
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFClient.java9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFJSDialogHandler.java120
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEF3.java9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEFJSDialogCallback.java31
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/cef_jsdialog_callback_t.java20
12 files changed, 529 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.c b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.c
index e3752b2..a782134 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.c
@@ -157,6 +157,31 @@ JNIEXPORT void JNICALL CEF3_NATIVE(callFuncVoid__JJJJI)(JNIEnv *env, jclass that
}
#endif
+#if (!defined(NO_callFuncVoid__IIILorg_eclipse_swt_internal_cef3_cef_1string_1t_2) && !defined(JNI64)) || (!defined(NO_callFuncVoid__JJILorg_eclipse_swt_internal_cef3_cef_1string_1t_2) && defined(JNI64))
+#ifndef JNI64
+JNIEXPORT void JNICALL CEF3_NATIVE(callFuncVoid__IIILorg_eclipse_swt_internal_cef3_cef_1string_1t_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2, jobject arg3)
+#else
+JNIEXPORT void JNICALL CEF3_NATIVE(callFuncVoid__JJILorg_eclipse_swt_internal_cef3_cef_1string_1t_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2, jobject arg3)
+#endif
+{
+ cef_string_t _arg3, *lparg3=NULL;
+#ifndef JNI64
+ CEF3_NATIVE_ENTER(env, that, callFuncVoid__IIILorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC);
+#else
+ CEF3_NATIVE_ENTER(env, that, callFuncVoid__JJILorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC);
+#endif
+ if (arg3) if ((lparg3 = getcef_string_tFields(env, arg3, &_arg3)) == NULL) goto fail;
+ ((void (CEF_CALLBACK*)())arg0)(arg1, arg2, lparg3);
+fail:
+ if (arg3 && lparg3) setcef_string_tFields(env, arg3, lparg3);
+#ifndef JNI64
+ CEF3_NATIVE_EXIT(env, that, callFuncVoid__IIILorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC);
+#else
+ CEF3_NATIVE_EXIT(env, that, callFuncVoid__JJILorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC);
+#endif
+}
+#endif
+
#if (!defined(NO_callFuncVoid__IILorg_eclipse_swt_internal_cef3_cef_1string_1t_2) && !defined(JNI64)) || (!defined(NO_callFuncVoid__JJLorg_eclipse_swt_internal_cef3_cef_1string_1t_2) && defined(JNI64))
#ifndef JNI64
JNIEXPORT void JNICALL CEF3_NATIVE(callFuncVoid__IILorg_eclipse_swt_internal_cef3_cef_1string_1t_2)(JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jobject arg2)
@@ -367,6 +392,18 @@ fail:
}
#endif
+#ifndef NO_cef_1jsdialog_1callback_1t_1sizeof
+JNIEXPORT jint JNICALL CEF3_NATIVE(cef_1jsdialog_1callback_1t_1sizeof)
+ (JNIEnv *env, jclass that)
+{
+ jint rc = 0;
+ CEF3_NATIVE_ENTER(env, that, cef_1jsdialog_1callback_1t_1sizeof_FUNC);
+ rc = (jint)cef_jsdialog_callback_t_sizeof();
+ CEF3_NATIVE_EXIT(env, that, cef_1jsdialog_1callback_1t_1sizeof_FUNC);
+ return rc;
+}
+#endif
+
#ifndef NO_cef_1list_1value_1t_1sizeof
JNIEXPORT jint JNICALL CEF3_NATIVE(cef_1list_1value_1t_1sizeof)
(JNIEnv *env, jclass that)
@@ -560,6 +597,31 @@ fail:
}
#endif
+#if (!defined(NO_memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2II) && !defined(JNI64)) || (!defined(NO_memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2JJ) && defined(JNI64))
+#ifndef JNI64
+JNIEXPORT void JNICALL CEF3_NATIVE(memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2II)(JNIEnv *env, jclass that, jobject arg0, jintLong arg1, jintLong arg2)
+#else
+JNIEXPORT void JNICALL CEF3_NATIVE(memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2JJ)(JNIEnv *env, jclass that, jobject arg0, jintLong arg1, jintLong arg2)
+#endif
+{
+ cef_jsdialog_callback_t _arg0, *lparg0=NULL;
+#ifndef JNI64
+ CEF3_NATIVE_ENTER(env, that, memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2II_FUNC);
+#else
+ CEF3_NATIVE_ENTER(env, that, memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2JJ_FUNC);
+#endif
+ if (arg0) if ((lparg0 = &_arg0) == NULL) goto fail;
+ memmove((void *)lparg0, (const void *)arg1, (size_t)arg2);
+fail:
+ if (arg0 && lparg0) setcef_jsdialog_callback_tFields(env, arg0, lparg0);
+#ifndef JNI64
+ CEF3_NATIVE_EXIT(env, that, memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2II_FUNC);
+#else
+ CEF3_NATIVE_EXIT(env, that, memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2JJ_FUNC);
+#endif
+}
+#endif
+
#if (!defined(NO_memmove__Lorg_eclipse_swt_internal_cef3_cef_1list_1value_1t_2II) && !defined(JNI64)) || (!defined(NO_memmove__Lorg_eclipse_swt_internal_cef3_cef_1list_1value_1t_2JJ) && defined(JNI64))
#ifndef JNI64
JNIEXPORT void JNICALL CEF3_NATIVE(memmove__Lorg_eclipse_swt_internal_cef3_cef_1list_1value_1t_2II)(JNIEnv *env, jclass that, jobject arg0, jintLong arg1, jintLong arg2)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.h b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.h
index 1b513fc..05f52ec 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3.h
@@ -21,6 +21,7 @@ typedef enum cef_state_t cef_state_t;
#include <cef_app_capi.h>
#include <cef_browser_capi.h>
#include <cef_frame_capi.h>
+#include <cef_jsdialog_handler_capi.h>
#include <cef_version.h>
#include <cef_process_message_capi.h>
#include <cef_values_capi.h>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.c b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.c
index 260f24e..b1d2c56 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.c
@@ -46,6 +46,11 @@ char * CEF3_nativeFunctionNames[] = {
"callFuncVoid__JJJJI",
#endif
#ifndef JNI64
+ "callFuncVoid__IIILorg_eclipse_swt_internal_cef3_cef_1string_1t_2",
+#else
+ "callFuncVoid__JJILorg_eclipse_swt_internal_cef3_cef_1string_1t_2",
+#endif
+#ifndef JNI64
"callFuncVoid__IILorg_eclipse_swt_internal_cef3_cef_1string_1t_2",
#else
"callFuncVoid__JJLorg_eclipse_swt_internal_cef3_cef_1string_1t_2",
@@ -69,6 +74,7 @@ char * CEF3_nativeFunctionNames[] = {
"cef_1execute_1process",
"cef_1frame_1t_1sizeof",
"cef_1initialize",
+ "cef_1jsdialog_1callback_1t_1sizeof",
"cef_1list_1value_1t_1sizeof",
"cef_1process_1message_1create",
"cef_1process_1message_1t_1sizeof",
@@ -97,6 +103,11 @@ char * CEF3_nativeFunctionNames[] = {
"memmove__Lorg_eclipse_swt_internal_cef3_cef_1frame_1t_2JJ",
#endif
#ifndef JNI64
+ "memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2II",
+#else
+ "memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2JJ",
+#endif
+#ifndef JNI64
"memmove__Lorg_eclipse_swt_internal_cef3_cef_1list_1value_1t_2II",
#else
"memmove__Lorg_eclipse_swt_internal_cef3_cef_1list_1value_1t_2JJ",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.h b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.h
index cf54b09..75cd868 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_stats.h
@@ -56,6 +56,11 @@ typedef enum {
callFuncVoid__JJJJI_FUNC,
#endif
#ifndef JNI64
+ callFuncVoid__IIILorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC,
+#else
+ callFuncVoid__JJILorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC,
+#endif
+#ifndef JNI64
callFuncVoid__IILorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC,
#else
callFuncVoid__JJLorg_eclipse_swt_internal_cef3_cef_1string_1t_2_FUNC,
@@ -79,6 +84,7 @@ typedef enum {
cef_1execute_1process_FUNC,
cef_1frame_1t_1sizeof_FUNC,
cef_1initialize_FUNC,
+ cef_1jsdialog_1callback_1t_1sizeof_FUNC,
cef_1list_1value_1t_1sizeof_FUNC,
cef_1process_1message_1create_FUNC,
cef_1process_1message_1t_1sizeof_FUNC,
@@ -107,6 +113,11 @@ typedef enum {
memmove__Lorg_eclipse_swt_internal_cef3_cef_1frame_1t_2JJ_FUNC,
#endif
#ifndef JNI64
+ memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2II_FUNC,
+#else
+ memmove__Lorg_eclipse_swt_internal_cef3_cef_1jsdialog_1callback_1t_2JJ_FUNC,
+#endif
+#ifndef JNI64
memmove__Lorg_eclipse_swt_internal_cef3_cef_1list_1value_1t_2II_FUNC,
#else
memmove__Lorg_eclipse_swt_internal_cef3_cef_1list_1value_1t_2JJ_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.c b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.c
index 9c366e2..50704d3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.c
@@ -500,6 +500,40 @@ void setcef_frame_tFields(JNIEnv *env, jobject lpObject, cef_frame_t *lpStruct)
}
#endif
+#ifndef NO_cef_jsdialog_callback_t
+typedef struct cef_jsdialog_callback_t_FID_CACHE {
+ int cached;
+ jclass clazz;
+ jfieldID cont;
+} cef_jsdialog_callback_t_FID_CACHE;
+
+cef_jsdialog_callback_t_FID_CACHE cef_jsdialog_callback_tFc;
+
+void cachecef_jsdialog_callback_tFields(JNIEnv *env, jobject lpObject)
+{
+ if (cef_jsdialog_callback_tFc.cached) return;
+ cachecef_base_tFields(env, lpObject);
+ cef_jsdialog_callback_tFc.clazz = (*env)->GetObjectClass(env, lpObject);
+ cef_jsdialog_callback_tFc.cont = (*env)->GetFieldID(env, cef_jsdialog_callback_tFc.clazz, "cont", I_J);
+ cef_jsdialog_callback_tFc.cached = 1;
+}
+
+cef_jsdialog_callback_t *getcef_jsdialog_callback_tFields(JNIEnv *env, jobject lpObject, cef_jsdialog_callback_t *lpStruct)
+{
+ if (!cef_jsdialog_callback_tFc.cached) cachecef_jsdialog_callback_tFields(env, lpObject);
+ getcef_base_tFields(env, lpObject, (cef_base_t *)lpStruct);
+ lpStruct->cont = (void (CEF_CALLBACK *)(struct _cef_jsdialog_callback_t* self, int success, const cef_string_t* user_input))(*env)->GetIntLongField(env, lpObject, cef_jsdialog_callback_tFc.cont);
+ return lpStruct;
+}
+
+void setcef_jsdialog_callback_tFields(JNIEnv *env, jobject lpObject, cef_jsdialog_callback_t *lpStruct)
+{
+ if (!cef_jsdialog_callback_tFc.cached) cachecef_jsdialog_callback_tFields(env, lpObject);
+ setcef_base_tFields(env, lpObject, (cef_base_t *)lpStruct);
+ (*env)->SetIntLongField(env, lpObject, cef_jsdialog_callback_tFc.cont, (jintLong)lpStruct->cont);
+}
+#endif
+
#ifndef NO_cef_list_value_t
typedef struct cef_list_value_t_FID_CACHE {
int cached;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.h b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.h
index cee33c4..bbb96d7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/library/cef3_structs.h
@@ -71,6 +71,18 @@ void setcef_frame_tFields(JNIEnv *env, jobject lpObject, cef_frame_t *lpStruct);
#define cef_frame_t_sizeof() 0
#endif
+#ifndef NO_cef_jsdialog_callback_t
+void cachecef_jsdialog_callback_tFields(JNIEnv *env, jobject lpObject);
+cef_jsdialog_callback_t *getcef_jsdialog_callback_tFields(JNIEnv *env, jobject lpObject, cef_jsdialog_callback_t *lpStruct);
+void setcef_jsdialog_callback_tFields(JNIEnv *env, jobject lpObject, cef_jsdialog_callback_t *lpStruct);
+#define cef_jsdialog_callback_t_sizeof() sizeof(cef_jsdialog_callback_t)
+#else
+#define cachecef_jsdialog_callback_tFields(a,b)
+#define getcef_jsdialog_callback_tFields(a,b,c) NULL
+#define setcef_jsdialog_callback_tFields(a,b,c)
+#define cef_jsdialog_callback_t_sizeof() 0
+#endif
+
#ifndef NO_cef_list_value_t
void cachecef_list_value_tFields(JNIEnv *env, jobject lpObject);
cef_list_value_t *getcef_list_value_tFields(JNIEnv *env, jobject lpObject, cef_list_value_t *lpStruct);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEF.java b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEF.java
index d5080cc..65d408d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEF.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEF.java
@@ -14,10 +14,14 @@ package org.eclipse.swt.browser;
import java.io.*;
import java.util.*;
import org.eclipse.swt.*;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.cef3.*;
import org.eclipse.swt.internal.win32.*;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;
public class CEF extends WebBrowser {
@@ -656,6 +660,213 @@ public boolean setUrl(String url, String postData, String[] headers) {
return true;
}
+void showAlertMessage (String title, String message, final CEFJSDialogCallback callback) {
+ Shell parent = browser.getShell();
+ final Shell dialog = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
+ GridLayout layout = new GridLayout(2, false);
+ layout.horizontalSpacing = 10;
+ layout.verticalSpacing = 20;
+ layout.marginWidth = layout.marginHeight = 10;
+ dialog.setLayout(layout);
+ dialog.setText(title);
+
+ Label label = new Label(dialog, SWT.NONE);
+ Image image = dialog.getDisplay().getSystemImage(SWT.ICON_WARNING);
+ label.setImage(image);
+
+ label = new Label(dialog, SWT.WRAP);
+ label.setText(message);
+ Monitor monitor = parent.getMonitor();
+ int maxWidth = monitor.getBounds().width * 2 / 3;
+ int width = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ data.widthHint = Math.min(width, maxWidth);
+ label.setLayoutData(data);
+
+ Button ok = new Button(dialog, SWT.PUSH);
+ ok.setText(SWT.getMessage("SWT_OK")); //$NON-NLS-1$
+ width = ok.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ GridData layoutData = new GridData();
+ layoutData.horizontalAlignment = SWT.CENTER;
+ layoutData.verticalAlignment = SWT.CENTER;
+ layoutData.horizontalSpan = 2;
+ layoutData.widthHint = Math.max(width, 75);
+ ok.setLayoutData(layoutData);
+
+ final int[] result = new int[1];
+ result[0] = 0;
+ ok.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ result[0] = 1;
+ dialog.dispose();
+ }
+ });
+
+ dialog.setDefaultButton(ok);
+ dialog.pack();
+ Rectangle parentSize = parent.getBounds();
+ Rectangle dialogSize = dialog.getBounds();
+ int x = parent.getLocation().x + (parentSize.width - dialogSize.width) / 2;
+ int y = parent.getLocation().y + (parentSize.height - dialogSize.height) / 2;
+ dialog.setLocation(x, y);
+ dialog.open();
+ Display display = browser.getDisplay();
+ while (!dialog.isDisposed()) {
+ if (!display.readAndDispatch()) display.sleep();
+ }
+ callback.cont(result[0], CEFSTRING_EMPTY);
+ callback.release();
+}
+
+void showBeforeUnloadConfirmPanel(String message, final CEFJSDialogCallback callback) {
+ Shell parent = browser.getShell();
+ StringBuffer text = new StringBuffer (Compatibility.getMessage ("SWT_OnBeforeUnload_Message1")); //$NON-NLS-1$
+ text.append ("\n\n"); //$NON-NLS-1$
+ text.append (message);
+ text.append ("\n\n"); //$NON-NLS-1$
+ text.append (Compatibility.getMessage ("SWT_OnBeforeUnload_Message2")); //$NON-NLS-1$
+ MessageBox box = new MessageBox (parent, SWT.OK | SWT.CANCEL | SWT.ICON_QUESTION);
+ box.setMessage (text.toString ());
+ int response = box.open () == SWT.OK ? 1 : 0;
+ callback.cont(response, CEFSTRING_EMPTY);
+ callback.release();
+}
+
+void showConfirmPanel(String title, String message, final CEFJSDialogCallback callback) {
+ Shell parent = browser.getShell();
+ final Shell dialog = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
+ GridLayout layout = new GridLayout(2, false);
+ layout.horizontalSpacing = 10;
+ layout.verticalSpacing = 20;
+ layout.marginWidth = layout.marginHeight = 10;
+ dialog.setLayout(layout);
+ dialog.setText(title);
+
+ Label label = new Label(dialog, SWT.NONE);
+ Image image = dialog.getDisplay().getSystemImage(SWT.ICON_QUESTION);
+ label.setImage(image);
+ label.setLayoutData(new GridData());
+
+ label = new Label(dialog, SWT.WRAP);
+ label.setText(message);
+ Monitor monitor = parent.getMonitor();
+ int maxWidth = monitor.getBounds().width * 2 / 3;
+ int width = label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
+ data.widthHint = Math.min(width, maxWidth);
+ label.setLayoutData(data);
+
+ Composite buttons = new Composite(dialog, SWT.NONE);
+ data = new GridData(SWT.CENTER, SWT.CENTER, true, true, 2, 1);
+ buttons.setLayoutData(data);
+ buttons.setLayout(new GridLayout(2, true));
+
+ Button ok = new Button(buttons, SWT.PUSH);
+ ok.setText(SWT.getMessage("SWT_OK")); //$NON-NLS-1$
+ GridData layoutData = new GridData();
+ layoutData.horizontalAlignment = SWT.CENTER;
+ layoutData.verticalAlignment = SWT.CENTER;
+ ok.setLayoutData(layoutData);
+
+ Button cancel = new Button(buttons, SWT.PUSH);
+ cancel.setText(SWT.getMessage("SWT_Cancel")); //$NON-NLS-1$
+ cancel.setLayoutData(layoutData);
+ width = cancel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
+ layoutData.widthHint = Math.max(width, 75);
+
+ final int[] result = new int[1];
+ result[0] = 0;
+ ok.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ result[0] = 1;
+ dialog.dispose();
+
+ }
+ });
+ cancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ dialog.dispose();
+ }
+ });
+
+ dialog.setDefaultButton(ok);
+ dialog.pack();
+ Rectangle parentSize = parent.getBounds();
+ Rectangle dialogSize = dialog.getBounds();
+ int x = parent.getLocation().x + (parentSize.width - dialogSize.width) / 2;
+ int y = parent.getLocation().y + (parentSize.height - dialogSize.height) / 2;
+ dialog.setLocation(x, y);
+ dialog.open();
+ Display display = browser.getDisplay();
+ while (!dialog.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ callback.cont(result[0], CEFSTRING_EMPTY);
+ callback.release();
+}
+void showTextPrompter(String title, String message, String defaultText, final CEFJSDialogCallback callback) {
+ Shell parent = browser.getShell();
+ final Shell dialog = new Shell(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
+ dialog.setLayout(new GridLayout());
+ dialog.setText(title);
+
+ Label label = new Label(dialog, SWT.NONE);
+ label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ label.setText(message);
+
+ final Text textBox = new Text(dialog, SWT.SINGLE | SWT.BORDER);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.widthHint = 300;
+ textBox.setLayoutData(data);
+ textBox.setText(defaultText);
+
+ Composite buttons = new Composite(dialog, SWT.NONE);
+ buttons.setLayout(new GridLayout(2, true));
+ buttons.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
+ Button ok = new Button(buttons, SWT.PUSH);
+ ok.setText(SWT.getMessage("SWT_OK")); //$NON-NLS-1$
+ ok.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ final int[] result = new int[1];
+ final cef_string_t [] text = new cef_string_t[1];
+ result[0] = 0;
+ text[0] = CEFSTRING_EMPTY;
+ ok.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ result[0] = 1;
+ text[0] = CreateCEFString(textBox.getText());
+ dialog.dispose();
+ }
+ });
+ Button cancel = new Button(buttons, SWT.PUSH);
+ cancel.setText(SWT.getMessage("SWT_Cancel")); //$NON-NLS-1$
+ cancel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ cancel.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ dialog.dispose();
+ }
+ });
+
+ dialog.setDefaultButton(ok);
+ dialog.pack();
+ Rectangle parentSize = parent.getBounds();
+ Rectangle dialogSize = dialog.getBounds();
+ int x = parent.getLocation().x + (parentSize.width - dialogSize.width) / 2;
+ int y = parent.getLocation().y + (parentSize.height - dialogSize.height) / 2;
+ dialog.setLocation(x, y);
+ dialog.open();
+ Display display = browser.getDisplay();
+ while (!dialog.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ callback.cont(result[0],text[0]);
+ callback.release();
+}
+
public void stop() {
htmlText = null;
if (cefBrowser == null) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFClient.java b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFClient.java
index 3a1cc84..8bba0d1 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFClient.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFClient.java
@@ -19,6 +19,7 @@ public class CEFClient {
CEFContextMenuHandler contextMenuHandler;
CEFDisplayHandler displayHandler;
CEFFocusHandler focusHandler;
+ CEFJSDialogHandler jsDialogHandler;
CEFLifeSpanHandler lifeSpanHandler;
CEFLoadHandler loadHandler;
CEFRequestHandler requestHandler;
@@ -143,8 +144,12 @@ long /*int*/ get_geolocation_handler() {
}
long /*int*/ get_jsdialog_handler() {
- if (Device.DEBUG) System.out.println("get_jsdialog_handler (TODO)");
- return 0;
+ if (Device.DEBUG) System.out.println("get_jsdialog_handler (impl)");
+ if (jsDialogHandler == null) {
+ jsDialogHandler = new CEFJSDialogHandler(host);
+ }
+ jsDialogHandler.add_ref();
+ return jsDialogHandler.getAddress();
}
long /*int*/ get_keyboard_handler() {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFJSDialogHandler.java b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFJSDialogHandler.java
new file mode 100644
index 0000000..8616154
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/browser/CEFJSDialogHandler.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.browser;
+
+import org.eclipse.swt.graphics.Device;
+import org.eclipse.swt.internal.cef3.*;
+
+public class CEFJSDialogHandler {
+ private static final int JSDIALOGTYPE_ALERT = 0;
+ private static final int JSDIALOGTYPE_CONFIRM = 1;
+ private static final int JSDIALOGTYPE_PROMPT = 2;
+ CEF3Object object;
+ CEF host;
+ int refCount = 1;
+
+public CEFJSDialogHandler(CEF host) {
+ this.host = host;
+ object = new CEF3Object (new int[] {0, 0, 0, 8, 4, 1}) {
+ public long /*int*/ method0(long /*int*/[] args) {return add_ref();}
+ public long /*int*/ method1(long /*int*/[] args) {return CEFJSDialogHandler.this.release();}
+ public long /*int*/ method2(long /*int*/[] args) {return get_refct();}
+ public long /*int*/ method3(long /*int*/[] args) {return on_jsdialog(args[0], args[1], args[2], (int)/*64*/ args[3], args[4], args[5], args[6],(int)/*64*/args[7]);}
+ public long /*int*/ method4(long /*int*/[] args) {return on_before_unload_dialog(args[0], args[1],(int)/*64*/args[2], args[3]);}
+ public long /*int*/ method5(long /*int*/[] args) {return on_reset_dialog_state(args[0]);}
+ };
+}
+
+long /*int*/ getAddress () {
+ return object.getAddress ();
+}
+
+/* cef_base_t */
+
+synchronized int add_ref() {
+ refCount++;
+ return refCount;
+}
+
+synchronized int get_refct() {
+ return refCount;
+}
+
+synchronized int release() {
+ if (--refCount == 0) {
+ if (Device.DEBUG) System.out.println("release: CEFJSDialogHandler");
+ if (object != null) {
+ object.dispose ();
+ }
+ object = null;
+ }
+ return refCount;
+}
+
+long /*int*/ on_jsdialog(long /*int*/ browser, long /*int*/ originUrl, long /*int*/ acceptLang, int dialogType, long /*int*/ strMessageText, long /*int*/ strDefaultPromptText, long /*int*/ pCallback, int suppressMessage) {
+ if (Device.DEBUG) System.out.println("on_jsdialog (impl)");
+ final String message = CEF.ExtractCEFString(strMessageText);
+ final CEFJSDialogCallback callback = new CEFJSDialogCallback(pCallback);
+ if (dialogType == JSDIALOGTYPE_ALERT) {
+ host.browser.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (host.browser.isDisposed()) return;
+ host.showAlertMessage("Javascript", message, callback); //$NON-NLS-1$
+ }
+ });
+ }
+ else if (dialogType == JSDIALOGTYPE_CONFIRM) {
+ host.browser.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (host.browser.isDisposed()) return;
+ host.showConfirmPanel("Javascript", message, callback); //$NON-NLS-1$
+ }
+ });
+ }
+ else if (dialogType == JSDIALOGTYPE_PROMPT) {
+ final String defaultPromptText = CEF.ExtractCEFString(strDefaultPromptText);
+ host.browser.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (host.browser.isDisposed()) return;
+ host.showTextPrompter("Javascript",message, defaultPromptText, callback); //$NON-NLS-1$
+ }
+ });
+ }
+ else {
+ new CEFBase(browser).release();
+ return 0;
+ }
+ new CEFBase(browser).release();
+ return 1;
+}
+
+
+long /*int*/ on_before_unload_dialog(long /*int*/ browser, long /*int*/ strMessageText, int isReload, long /*int*/ pCallback) {
+ if (Device.DEBUG) System.out.println("on_before_unload_dialog (impl)");
+ final String message = CEF.ExtractCEFString(strMessageText);
+ final CEFJSDialogCallback callback = new CEFJSDialogCallback(pCallback);
+ host.browser.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ if (host.browser.isDisposed()) return;
+ host.showBeforeUnloadConfirmPanel(message, callback);
+ }
+ });
+ new CEFBase(browser).release();
+ return 1;
+}
+
+long /*int*/ on_reset_dialog_state(long /*int*/ browser) {
+ if (Device.DEBUG) System.out.println("on_reset_dialog_state (TODO)");
+ new CEFBase(browser).release();
+ return 0;
+}
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEF3.java b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEF3.java
index 654e902..ad75688 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEF3.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEF3.java
@@ -91,6 +91,12 @@ public static final native void memmove(cef_process_message_t dest, long /*int*/
* @param size cast=(size_t)
*/
public static final native void memmove(cef_string_t dest, long /*int*/ src, long /*int*/ size);
+/**
+ * @param dest cast=(void *),flags=no_in critical
+ * @param src cast=(const void *)
+ * @param size cast=(size_t)
+ */
+public static final native void memmove(cef_jsdialog_callback_t dest, long /*int*/ src, long /*int*/ size);
/* function ptr invocations */
@@ -110,6 +116,8 @@ public static final native void callFuncVoid(long /*int*/ address, long /*int*/
/** @method convention=CEF_CALLBACK */
public static final native void callFuncVoid(long /*int*/ address, long /*int*/ arg0, cef_string_t arg1, cef_string_t arg2);
/** @method convention=CEF_CALLBACK */
+public static final native void callFuncVoid(long /*int*/ address, long /*int*/ arg0, int arg1, cef_string_t arg2);
+/** @method convention=CEF_CALLBACK */
public static final native void callFuncVoid(long /*int*/ address, long /*int*/ arg0, long /*int*/ arg1, long /*int*/ arg2, int arg3);
/** @method convention=CEF_CALLBACK */
public static final native void callFuncVoid(long /*int*/ address, long /*int*/ arg0, cef_string_t arg1, cef_string_t arg2, int arg3);
@@ -126,5 +134,6 @@ public static final native int cef_list_value_t_sizeof();
public static final native int cef_process_message_t_sizeof();
public static final native int cef_settings_t_sizeof();
public static final native int cef_string_t_sizeof();
+public static final native int cef_jsdialog_callback_t_sizeof();
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEFJSDialogCallback.java b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEFJSDialogCallback.java
new file mode 100644
index 0000000..0544817
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/CEFJSDialogCallback.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.internal.cef3;
+
+import org.eclipse.swt.internal.cef3.CEF3;
+import org.eclipse.swt.internal.cef3.CEFBase;
+import org.eclipse.swt.internal.cef3.cef_jsdialog_callback_t;
+import org.eclipse.swt.internal.cef3.cef_string_t;
+
+public class CEFJSDialogCallback extends CEFBase {
+ cef_jsdialog_callback_t struct;
+
+ public CEFJSDialogCallback(long /*int*/ address) {
+ super(address);
+ struct = new cef_jsdialog_callback_t();
+ CEF3.memmove(struct, address, cef_jsdialog_callback_t.sizeof);
+ }
+
+ public void cont(int success, cef_string_t userInput) {
+ CEF3.callFuncVoid(struct.cont, address, success, userInput);
+ }
+
+}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/cef_jsdialog_callback_t.java b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/cef_jsdialog_callback_t.java
new file mode 100644
index 0000000..b186090
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT CEF/win32/org/eclipse/swt/internal/cef3/cef_jsdialog_callback_t.java
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.internal.cef3;
+
+
+public class cef_jsdialog_callback_t extends cef_base_t {
+
+ /** @field cast="(void (CEF_CALLBACK *)(struct _cef_jsdialog_callback_t* self, int success, const cef_string_t* user_input))" */
+ public long /*int*/ cont;
+
+ public static final int sizeof = CEF3.cef_jsdialog_callback_t_sizeof();
+}