@@ -233,15 +233,24 @@ static void error(int code, int hr) {
233233 SWT .error (code , null , String .format (" [0x%08x]" , hr ));
234234}
235235
236- static IUnknown newCallback (ICoreWebView2SwtCallback handler ) {
237- long punk = COM .CreateSwtWebView2Callback ((arg0 , arg1 ) -> {
236+ static class HandleCoreWebView2SwtCallback implements ICoreWebView2SwtCallback {
237+ private final ICoreWebView2SwtCallback handler ;
238+ public HandleCoreWebView2SwtCallback (ICoreWebView2SwtCallback handler ) {
239+ this .handler = handler ;
240+ }
241+ @ Override
242+ public int Invoke (long arg0 , long arg1 ) {
238243 inCallback ++;
239244 try {
240245 return handler .Invoke (arg0 , arg1 );
241246 } finally {
242247 inCallback --;
243248 }
244- });
249+ }
250+ }
251+
252+ static IUnknown newCallback (ICoreWebView2SwtCallback handler ) {
253+ long punk = COM .CreateSwtWebView2Callback (new HandleCoreWebView2SwtCallback (handler ));
245254 if (punk == 0 ) error (SWT .ERROR_NO_HANDLES , COM .E_OUTOFMEMORY );
246255 return new IUnknown (punk );
247256}
@@ -789,7 +798,7 @@ void setupBrowser(int hr, long pv) {
789798 handler .Release ();
790799 }
791800
792- IUnknown hostDisp = newHostObject (this :: handleCallJava );
801+ IUnknown hostDisp = newHostObject (new HandleCoreWebView2SwtHost ( this . functions ) );
793802 long [] hostObj = { COM .VT_DISPATCH , hostDisp .getAddress (), 0 }; // VARIANT
794803 webView .AddHostObjectToScript ("swt\0 " .toCharArray (), hostObj );
795804 hostDisp .Release ();
@@ -1020,24 +1029,31 @@ int handleDocumentTitleChanged(long pView, long pArgs) {
10201029 return COM .S_OK ;
10211030}
10221031
1023- long handleCallJava (int index , long bstrToken , long bstrArgsJson ) {
1024- Object result = null ;
1025- String token = bstrToString (bstrToken );
1026- BrowserFunction function = functions .get (index );
1027- if (function != null && token .equals (function .token )) {
1028- inCallback ++;
1029- try {
1030- String argsJson = bstrToString (bstrArgsJson );
1031- Object args = JSON .parse (argsJson .toCharArray ());
1032- result = function .function ((Object []) args );
1033- } catch (Throwable e ) {
1034- result = WebBrowser .CreateErrorString (e .getLocalizedMessage ());
1035- } finally {
1036- inCallback --;
1032+ static class HandleCoreWebView2SwtHost implements ICoreWebView2SwtHost {
1033+ private final Map <Integer , BrowserFunction > functions ;
1034+ public HandleCoreWebView2SwtHost (Map <Integer , BrowserFunction > functions ) {
1035+ this .functions = functions ;
1036+ }
1037+ @ Override
1038+ public long CallJava (int index , long bstrToken , long bstrArgsJson ) {
1039+ Object result = null ;
1040+ String token = bstrToString (bstrToken );
1041+ BrowserFunction function = functions .get (index );
1042+ if (function != null && token .equals (function .token )) {
1043+ inCallback ++;
1044+ try {
1045+ String argsJson = bstrToString (bstrArgsJson );
1046+ Object args = JSON .parse (argsJson .toCharArray ());
1047+ result = function .function ((Object []) args );
1048+ } catch (Throwable e ) {
1049+ result = WebBrowser .CreateErrorString (e .getLocalizedMessage ());
1050+ } finally {
1051+ inCallback --;
1052+ }
10371053 }
1038- }
1039- String json = JSON . stringify ( result );
1040- return COM . SysAllocStringLen ( json . toCharArray (), json . length ());
1054+ String json = JSON . stringify ( result );
1055+ return COM . SysAllocStringLen ( json . toCharArray (), json . length () );
1056+ }
10411057}
10421058
10431059int handleFrameNavigationStarting (long pView , long pArgs ) {
0 commit comments