11/*******************************************************************************
2- * Copyright (c) 2010, 2025 IBM Corporation and others.
2+ * Copyright (c) 2010, 2026 IBM Corporation and others.
33 *
44 * This program and the accompanying materials
55 * are made available under the terms of the Eclipse Public License 2.0
@@ -322,13 +322,15 @@ private static String getStackTrace() {
322322 @ Override
323323 String getJavaCallDeclaration () {
324324 // callJava does a synchronous XMLHttpRequest, which is handled by RequestProc.
325- return "if (!window.callJava) { window.callJava = function(index, token, args) {\n "
326- + "var xhr = new XMLHttpRequest();\n "
327- + "var uri = 'swt://browserfunction/' + index + '/' + token + '?' + encodeURIComponent(JSON.stringify(args));\n "
328- + "xhr.open('POST', uri, false);\n "
329- + "xhr.send(null);\n "
330- + "return JSON.parse(xhr.responseText);\n "
331- + "}}\n " ;
325+ return """
326+ if (!window.callJava) { window.callJava = function(index, token, args) {
327+ var xhr = new XMLHttpRequest();
328+ var uri = 'swt://browserfunction/' + index + '/' + token + '?' + encodeURIComponent(JSON.stringify(args));
329+ xhr.open('POST', uri, false);
330+ xhr.send(null);
331+ return JSON.parse(xhr.responseText);
332+ }}
333+ """ ;
332334 }
333335
334336 /**
@@ -345,7 +347,7 @@ private static int[] internalGetWebkitVersion(){
345347
346348 private static String internalGetWebKitVersionStr () {
347349 int [] vers = internalGetWebkitVersion ();
348- return String .valueOf (vers [0 ]) + "." + String . valueOf ( vers [1 ]) + "." + String . valueOf ( vers [2 ]) ;
350+ return String .valueOf (vers [0 ]) + "." + vers [1 ] + "." + vers [2 ];
349351 }
350352
351353
@@ -419,12 +421,12 @@ static long JSDOMEventProc (long arg0, long event, long user_data) {
419421 if ((state [0 ] & GDK .GDK_MOD1_MASK ) != 0 ) keyEvent .stateMask |= SWT .ALT ;
420422 if ((state [0 ] & GDK .GDK_SHIFT_MASK ) != 0 ) keyEvent .stateMask |= SWT .SHIFT ;
421423 if ((state [0 ]& GDK .GDK_CONTROL_MASK ) != 0 ) keyEvent .stateMask |= SWT .CONTROL ;
422- try { // to avoid deadlocks, evaluate() should not block during listener. See Bug 512001
423- // I.e, evaluate() can be called and script will be executed, but no return value will be provided.
424+ try { // to avoid deadlocks, evaluate() should not block during listener. See Bug
425+ // 512001
426+ // I.e, evaluate() can be called and script will be executed, but no return
427+ // value will be provided.
424428 nonBlockingEvaluate ++;
425- browser .webBrowser .sendKeyEvent (keyEvent );
426- } catch (Exception e ) {
427- throw e ;
429+ browser .webBrowser .sendKeyEvent (keyEvent );
428430 } finally {
429431 nonBlockingEvaluate --;
430432 }
@@ -580,16 +582,14 @@ long webkit_authenticate (long web_view, long request){
580582
581583 String location = getUrl ();
582584
583- for (int i = 0 ; i < authenticationListeners . length ; i ++ ) {
585+ for (AuthenticationListener listener : authenticationListeners ) {
584586 AuthenticationEvent event = new AuthenticationEvent (browser );
585587 event .location = location ;
586588
587589 try { // to avoid deadlocks, evaluate() should not block during authentication listener. See Bug 512001
588590 // I.e, evaluate() can be called and script will be executed, but no return value will be provided.
589591 nonBlockingEvaluate ++;
590- authenticationListeners [i ].authenticate (event );
591- } catch (Exception e ) {
592- throw e ;
592+ listener .authenticate (event );
593593 } finally {
594594 nonBlockingEvaluate --;
595595 }
@@ -683,9 +683,9 @@ public void create (Composite parent, int style) {
683683 Browser parentBrowser = WebKit .parentBrowser ;
684684 if (parentBrowser == null && parentShell != null ) {
685685 Control [] children = parentShell .getChildren ();
686- for (int i = 0 ; i < children . length ; i ++ ) {
687- if (children [ i ] instanceof Browser ) {
688- parentBrowser = ( Browser ) children [ i ] ;
686+ for (Control child : children ) {
687+ if (child instanceof Browser b ) {
688+ parentBrowser = b ;
689689 break ;
690690 }
691691 }
@@ -1041,7 +1041,7 @@ static void removeObject(int id) {
10411041 static int getNextId () {
10421042 int value = 0 ;
10431043 boolean unique = false ;
1044- while (unique == false ) {
1044+ while (! unique ) {
10451045 value = nextCallbackId ;
10461046 unique = !usedCallbackIds .contains (value );
10471047 if (nextCallbackId != Integer .MAX_VALUE )
@@ -1099,7 +1099,7 @@ static Object runjavascript(String script, Browser browser, long webView) {
10991099 } else {
11001100 // Callback logic: Initiate an async callback and wait for it to finish.
11011101 // The callback comes back in runjavascript_callback(..) below.
1102- Consumer <Integer > asyncFunc = ( callbackId ) -> {
1102+ Consumer <Integer > asyncFunc = callbackId -> {
11031103 if (GTK .GTK4 ) {
11041104 byte [] wcsToMbcs = Converter .wcsToMbcs (script , false );
11051105 WebKitGTK .webkit_web_view_evaluate_javascript (webView , wcsToMbcs , wcsToMbcs .length , 0 , 0 , 0 ,
@@ -1215,7 +1215,7 @@ private static void getText_callback(long WebResource, long GAsyncResult, long u
12151215 long guchar_data = WebKitGTK .webkit_web_resource_get_data_finish (WebResource , GAsyncResult , gsize_len , gerrorRes );
12161216 if (gerrorRes [0 ] != 0 || guchar_data == 0 ) {
12171217 OS .g_error_free (gerrorRes [0 ]);
1218- retObj .returnValue = ( String ) "" ;
1218+ retObj .returnValue = "" ;
12191219 } else {
12201220 int len = (int ) gsize_len [0 ];
12211221 byte [] buffer = new byte [len ];
@@ -1352,9 +1352,8 @@ private static void getCookie_callback(long cookieManager, long result, long use
13521352 Object resultObject = GDBus .convertGVariantToJava (user_data );
13531353
13541354 // We are expecting a GVariant tuple, anything else means something went wrong
1355- if (resultObject instanceof Object []) {
1355+ if (resultObject instanceof Object [] nameAndId ) {
13561356 // Unpack callback ID and cookie name
1357- Object [] nameAndId = (Object []) resultObject ;
13581357 String cookieName = (String ) nameAndId [0 ];
13591358 int callbackId = ((Number ) nameAndId [1 ]).intValue ();
13601359 Webkit2AsyncReturnObj retObj = CallBackMap .getObj (callbackId );
@@ -1796,8 +1795,7 @@ boolean handleMouseEvent (String type, int screenX, int screenY, int detail, int
17961795 * coordinates relative to themselves rather than relative to their top-
17971796 * level page. Convert screen-relative coordinates to be browser-relative.
17981797 */
1799- Point position = new Point (screenX , screenY );
1800- position = browser .getDisplay ().map (null , browser , position );
1798+ Point position = browser .getDisplay ().map (null , browser , screenX , screenY );
18011799
18021800 Event mouseEvent = new Event ();
18031801 mouseEvent .widget = browser ;
@@ -1886,8 +1884,8 @@ long handleLoadCommitted (long uri, boolean top) {
18861884 event .top = top ;
18871885 Runnable fireLocationChanged = () -> {
18881886 if (browser .isDisposed ()) return ;
1889- for (int i = 0 ; i < locationListeners . length ; i ++ ) {
1890- locationListeners [ i ] .changed (event );
1887+ for (LocationListener listener : locationListeners ) {
1888+ listener .changed (event );
18911889 }
18921890 };
18931891 browser .getDisplay ().asyncExec (fireLocationChanged );
@@ -1910,8 +1908,8 @@ private void fireProgressCompletedEvent(){
19101908 progress .widget = browser ;
19111909 progress .current = MAX_PROGRESS ;
19121910 progress .total = MAX_PROGRESS ;
1913- for (int i = 0 ; i < progressListeners . length ; i ++ ) {
1914- progressListeners [ i ] .completed (progress );
1911+ for (ProgressListener listener : progressListeners ) {
1912+ listener .completed (progress );
19151913 }
19161914 };
19171915 browser .getDisplay ().asyncExec (fireProgressEvents );
@@ -2121,14 +2119,13 @@ public boolean setUrl (String url, String postData, String[] headers) {
21212119 */
21222120 long settings = WebKitGTK .webkit_web_view_get_settings (webView );
21232121 if (headers != null ) {
2124- for (int i = 0 ; i < headers .length ; i ++) {
2125- String current = headers [i ];
2122+ for (String current : headers ) {
21262123 if (current != null ) {
21272124 int index = current .indexOf (':' );
21282125 if (index != -1 ) {
21292126 String key = current .substring (0 , index ).trim ();
21302127 String value = current .substring (index + 1 ).trim ();
2131- if (key .length () > 0 && value .length () > 0 ) {
2128+ if (! key .isEmpty () && ! value .isEmpty () ) {
21322129 if (key .equalsIgnoreCase (USER_AGENT )) {
21332130 byte [] bytes = Converter .wcsToMbcs (value , true );
21342131 OS .g_object_set (settings , WebKitGTK .user_agent , bytes , 0 );
@@ -2171,8 +2168,7 @@ public boolean setUrl (String url, String postData, String[] headers) {
21712168 try {
21722169 URL base = new URI (base_url ).toURL ();
21732170 URLConnection url_conn = base .openConnection ();
2174- if (url_conn instanceof HttpURLConnection ) {
2175- HttpURLConnection conn = (HttpURLConnection ) url_conn ;
2171+ if (url_conn instanceof HttpURLConnection conn ) {
21762172
21772173 { // Configure connection.
21782174 conn .setRequestMethod ("POST" ); //$NON-NLS-1$
@@ -2287,8 +2283,8 @@ long webkit_close_web_view (long web_view) {
22872283 newEvent .widget = browser ;
22882284 Runnable fireCloseWindowListeners = () -> {
22892285 if (browser .isDisposed ()) return ;
2290- for (int i = 0 ; i < closeWindowListeners . length ; i ++ ) {
2291- closeWindowListeners [ i ] .close (newEvent );
2286+ for (CloseWindowListener closeWindowListener : closeWindowListeners ) {
2287+ closeWindowListener .close (newEvent );
22922288 }
22932289 browser .dispose ();
22942290 };
@@ -2305,17 +2301,16 @@ long webkit_create_web_view (long web_view, long frame) {
23052301 newEvent .required = true ;
23062302 Runnable fireOpenWindowListeners = () -> {
23072303 if (openWindowListeners != null ) {
2308- for (int i = 0 ; i < openWindowListeners . length ; i ++ ) {
2309- openWindowListeners [ i ] .open (newEvent );
2304+ for (OpenWindowListener listener : openWindowListeners ) {
2305+ listener .open (newEvent );
23102306 }
23112307 }
23122308 };
23132309 try {
23142310 nonBlockingEvaluate ++; // running evaluate() inside openWindowListener and waiting for return leads to deadlock. Bug 512001
23152311 parentBrowser = browser ;
23162312 fireOpenWindowListeners .run ();// Permit evaluate()/execute() to execute scripts in listener, but do not provide return value.
2317- } catch (Exception e ) {
2318- throw e ; // rethrow exception if thrown, but decrement counter first.
2313+ // rethrow exception if thrown, but decrement counter first.
23192314 } finally {
23202315 parentBrowser = null ;
23212316 nonBlockingEvaluate --;
@@ -2415,8 +2410,8 @@ long webkit_hovering_over_link (long web_view, long title, long uri) {
24152410 event .text = text ;
24162411 Runnable fireStatusTextListener = () -> {
24172412 if (browser .isDisposed () || statusTextListeners == null ) return ;
2418- for (int i = 0 ; i < statusTextListeners . length ; i ++ ) {
2419- statusTextListeners [ i ] .changed (event );
2413+ for (StatusTextListener listener : statusTextListeners ) {
2414+ listener .changed (event );
24202415 }
24212416 };
24222417 browser .getDisplay ().asyncExec (fireStatusTextListener );
@@ -2464,12 +2459,10 @@ long webkit_decide_policy (long web_view, long decision, int decision_type, long
24642459 try {
24652460 nonBlockingEvaluate ++;
24662461 if (locationListeners != null ) {
2467- for (int i = 0 ; i < locationListeners . length ; i ++ ) {
2468- locationListeners [ i ] .changing (newEvent );
2462+ for (LocationListener listener : locationListeners ) {
2463+ listener .changing (newEvent );
24692464 }
24702465 }
2471- } catch (Exception e ) {
2472- throw e ;
24732466 } finally {
24742467 nonBlockingEvaluate --;
24752468 }
@@ -2576,44 +2569,17 @@ long webkit_load_failed_tls (long web_view, long failing_uri, long certificate,
25762569 OS .g_object_ref (certificate );
25772570 tlsErrorCertificate = certificate ;
25782571 convertUri (failing_uri );
2579- switch ((int )error ) {
2580- case WebKitGTK .G_TLS_CERTIFICATE_UNKNOWN_CA : {
2581- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_UnknownCA" );
2582- break ;
2583- }
2584- case WebKitGTK .G_TLS_CERTIFICATE_BAD_IDENTITY : {
2585- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_BadIdentity" );
2586- break ;
2587- }
2588- case WebKitGTK .G_TLS_CERTIFICATE_NOT_ACTIVATED : {
2589- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_NotActivated" );
2590- break ;
2591- }
2592- case WebKitGTK .G_TLS_CERTIFICATE_EXPIRED : {
2593- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_Expired" );
2594- break ;
2595- }
2596- case WebKitGTK .G_TLS_CERTIFICATE_REVOKED : {
2597- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_Revoked" );
2598- break ;
2599- }
2600- case WebKitGTK .G_TLS_CERTIFICATE_INSECURE : {
2601- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_Insecure" );
2602- break ;
2603- }
2604- case WebKitGTK .G_TLS_CERTIFICATE_GENERIC_ERROR : {
2605- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_GenericError" );
2606- break ;
2607- }
2608- case WebKitGTK .G_TLS_CERTIFICATE_VALIDATE_ALL : {
2609- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_ValidateAll" );
2610- break ;
2611- }
2612- default : {
2613- tlsErrorType = SWT .getMessage ("SWT_InvalidCert_GenericError" );
2614- break ;
2615- }
2616- }
2572+ tlsErrorType = switch ((int ) error ) {
2573+ case WebKitGTK .G_TLS_CERTIFICATE_UNKNOWN_CA -> SWT .getMessage ("SWT_InvalidCert_UnknownCA" );
2574+ case WebKitGTK .G_TLS_CERTIFICATE_BAD_IDENTITY -> SWT .getMessage ("SWT_InvalidCert_BadIdentity" );
2575+ case WebKitGTK .G_TLS_CERTIFICATE_NOT_ACTIVATED -> SWT .getMessage ("SWT_InvalidCert_NotActivated" );
2576+ case WebKitGTK .G_TLS_CERTIFICATE_EXPIRED -> SWT .getMessage ("SWT_InvalidCert_Expired" );
2577+ case WebKitGTK .G_TLS_CERTIFICATE_REVOKED -> SWT .getMessage ("SWT_InvalidCert_Revoked" );
2578+ case WebKitGTK .G_TLS_CERTIFICATE_INSECURE -> SWT .getMessage ("SWT_InvalidCert_Insecure" );
2579+ case WebKitGTK .G_TLS_CERTIFICATE_GENERIC_ERROR -> SWT .getMessage ("SWT_InvalidCert_GenericError" );
2580+ case WebKitGTK .G_TLS_CERTIFICATE_VALIDATE_ALL -> SWT .getMessage ("SWT_InvalidCert_ValidateAll" );
2581+ default -> SWT .getMessage ("SWT_InvalidCert_GenericError" );
2582+ };
26172583 }
26182584 return 0 ;
26192585}
@@ -2653,8 +2619,8 @@ long webkit_notify_progress (long web_view, long pspec) {
26532619 event .total = MAX_PROGRESS ;
26542620 Runnable fireProgressChangedEvents = () -> {
26552621 if (browser .isDisposed () || progressListeners == null ) return ;
2656- for (int i = 0 ; i < progressListeners . length ; i ++ ) {
2657- progressListeners [ i ] .changed (event );
2622+ for (ProgressListener listener : progressListeners ) {
2623+ listener .changed (event );
26582624 }
26592625 };
26602626 browser .getDisplay ().asyncExec (fireProgressChangedEvents );
@@ -2685,8 +2651,8 @@ long webkit_notify_title (long web_view, long pspec) {
26852651 event .widget = browser ;
26862652 event .title = titleString ;
26872653 Runnable fireTitleListener = () -> {
2688- for (int i = 0 ; i < titleListeners . length ; i ++ ) {
2689- titleListeners [ i ] .changed (event );
2654+ for (TitleListener listener : titleListeners ) {
2655+ listener .changed (event );
26902656 }
26912657 };
26922658 browser .getDisplay ().asyncExec (fireTitleListener );
@@ -2717,14 +2683,13 @@ long webkit_context_menu (long web_view, long context_menu, long eventXXX, long
27172683}
27182684
27192685private void addRequestHeaders (long requestHeaders , String [] headers ){
2720- for (int i = 0 ; i < headers .length ; i ++) {
2721- String current = headers [i ];
2686+ for (String current : headers ) {
27222687 if (current != null ) {
27232688 int index = current .indexOf (':' );
27242689 if (index != -1 ) {
27252690 String key = current .substring (0 , index ).trim ();
27262691 String value = current .substring (index + 1 ).trim ();
2727- if (key .length () > 0 && value .length () > 0 ) {
2692+ if (! key .isEmpty () && ! value .isEmpty () ) {
27282693 byte [] nameBytes = Converter .wcsToMbcs (key , true );
27292694 byte [] valueBytes = Converter .wcsToMbcs (value , true );
27302695 WebKitGTK .soup_message_headers_append (requestHeaders , nameBytes , valueBytes );
@@ -2771,8 +2736,8 @@ long webkit_web_view_ready (long web_view) {
27712736
27722737 Runnable fireVisibilityListeners = () -> {
27732738 if (browser .isDisposed ()) return ;
2774- for (int i = 0 ; i < visibilityWindowListeners . length ; i ++ ) {
2775- visibilityWindowListeners [ i ] .show (newEvent );
2739+ for (VisibilityWindowListener listener : visibilityWindowListeners ) {
2740+ listener .show (newEvent );
27762741 }
27772742 };
27782743 // Postpone execution of listener, to avoid deadlocks in case evaluate() is
0 commit comments