Skip to content

Commit d59358c

Browse files
committed
Edge: Implement AuthenticationListener handling for BasicAuth
Differences to IE engine: - Location attribute: - IE does not provide the 'location' for the callback, so this has to be guessed from lastNavigateURL which does not work consistently, e.g. after an immediate Browser.setUrl(); - Edge does provide the 'location' information consistently - When returning invalid credentials - IE does not call the authentication handler again for further attempts - Edge calls the authentication handler again and again. Keeping track of this is out-of-scope for SWT. There is no retryCount field or similar in the event. AuthenticationHandler implementations need to account for unbounded repetitive calls in case the server does not bail out. Resolves #730.
1 parent a588c9a commit d59358c

File tree

6 files changed

+175
-1
lines changed

6 files changed

+175
-1
lines changed

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/Edge.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ class WebViewProvider {
289289

290290
private CompletableFuture<ICoreWebView2> webViewFuture = new CompletableFuture<>();
291291
private CompletableFuture<ICoreWebView2_2> webView_2Future = new CompletableFuture<>();
292+
private CompletableFuture<ICoreWebView2_10> webView_10Future = new CompletableFuture<>();
292293
private CompletableFuture<ICoreWebView2_11> webView_11Future = new CompletableFuture<>();
293294
private CompletableFuture<ICoreWebView2_12> webView_12Future = new CompletableFuture<>();
294295
private CompletableFuture<ICoreWebView2_13> webView_13Future = new CompletableFuture<>();
@@ -300,6 +301,7 @@ ICoreWebView2 initializeWebView(ICoreWebView2Controller controller) {
300301
controller.get_CoreWebView2(ppv);
301302
final ICoreWebView2 webView = new ICoreWebView2(ppv[0]);
302303
initializeWebView_2(webView);
304+
initializeWebView_10(webView);
303305
initializeWebView_11(webView);
304306
initializeWebView_12(webView);
305307
initializeWebView_13(webView);
@@ -317,6 +319,16 @@ private void initializeWebView_2(ICoreWebView2 webView) {
317319
}
318320
}
319321

322+
private void initializeWebView_10(ICoreWebView2 webView) {
323+
long[] ppv = new long[1];
324+
int hr = webView.QueryInterface(COM.IID_ICoreWebView2_10, ppv);
325+
if (hr == COM.S_OK) {
326+
webView_10Future.complete(new ICoreWebView2_10(ppv[0]));
327+
} else {
328+
webView_10Future.cancel(true);
329+
}
330+
}
331+
320332
private void initializeWebView_11(ICoreWebView2 webView) {
321333
long[] ppv = new long[1];
322334
int hr = webView.QueryInterface(COM.IID_ICoreWebView2_11, ppv);
@@ -366,6 +378,18 @@ boolean isWebView_2Available() {
366378
return !webView_2Future.isCancelled();
367379
}
368380

381+
ICoreWebView2_10 getWebView_10(boolean waitForPendingWebviewTasksToFinish) {
382+
if(waitForPendingWebviewTasksToFinish) {
383+
waitForFutureToFinish(lastWebViewTask);
384+
}
385+
return webView_10Future.join();
386+
}
387+
388+
boolean isWebView_10Available() {
389+
waitForFutureToFinish(webView_10Future);
390+
return !webView_10Future.isCancelled();
391+
}
392+
369393
ICoreWebView2_11 getWebView_11(boolean waitForPendingWebviewTasksToFinish) {
370394
if(waitForPendingWebviewTasksToFinish) {
371395
waitForFutureToFinish(lastWebViewTask);
@@ -637,6 +661,11 @@ void setupBrowser(int hr, long pv) {
637661
webViewProvider.getWebView_2(false).add_DOMContentLoaded(handler, token);
638662
handler.Release();
639663
}
664+
if (webViewProvider.isWebView_10Available()) {
665+
handler = newCallback(this::handleBasicAuthenticationRequested);
666+
webViewProvider.getWebView_10(false).add_BasicAuthenticationRequested(handler, token);
667+
handler.Release();
668+
}
640669
if (webViewProvider.isWebView_11Available()) {
641670
handler = newCallback(this::handleContextMenuRequested);
642671
webViewProvider.getWebView_11(false).add_ContextMenuRequested(handler, token);
@@ -971,6 +1000,34 @@ private static String escapeForSingleQuotedJSString(String str) {
9711000
.replace("\n", "\\n");
9721001
}
9731002

1003+
int handleBasicAuthenticationRequested(long pView, long pArgs) {
1004+
ICoreWebView2BasicAuthenticationRequestedEventArgs args = new ICoreWebView2BasicAuthenticationRequestedEventArgs(pArgs);
1005+
1006+
long[] ppv = new long[1];
1007+
1008+
args.get_Uri(ppv);
1009+
String uri = wstrToString(ppv[0], true);
1010+
1011+
for (AuthenticationListener authenticationListener : this.authenticationListeners) {
1012+
AuthenticationEvent event = new AuthenticationEvent (browser);
1013+
event.location = uri;
1014+
authenticationListener.authenticate (event);
1015+
if (!event.doit) {
1016+
args.put_Cancel(true);
1017+
return COM.S_OK;
1018+
}
1019+
if (event.user != null && event.password != null) {
1020+
args.get_Response(ppv);
1021+
ICoreWebView2BasicAuthenticationResponse response = new ICoreWebView2BasicAuthenticationResponse(ppv[0]);
1022+
response.put_UserName(stringToWstr(event.user));
1023+
response.put_Password(stringToWstr(event.password));
1024+
return COM.S_OK;
1025+
}
1026+
}
1027+
1028+
return COM.S_OK;
1029+
}
1030+
9741031
int handleContextMenuRequested(long pView, long pArgs) {
9751032
ICoreWebView2ContextMenuRequestedEventArgs args = new ICoreWebView2ContextMenuRequestedEventArgs(pArgs);
9761033

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32/COM.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public class COM extends OS {
8686
public static final GUID CGID_Explorer = IIDFromString("{000214D0-0000-0000-C000-000000000046}"); //$NON-NLS-1$
8787
public static final GUID IID_ICoreWebView2Environment2 = IIDFromString("{41F3632B-5EF4-404F-AD82-2D606C5A9A21}"); //$NON-NLS-1$
8888
public static final GUID IID_ICoreWebView2_2 = IIDFromString("{9E8F0CF8-E670-4B5E-B2BC-73E061E3184C}"); //$NON-NLS-1$
89+
public static final GUID IID_ICoreWebView2_10 = IIDFromString("{B1690564-6F5A-4983-8E48-31D1143FECDB}"); //$NON-NLS-1$
8990
public static final GUID IID_ICoreWebView2_11 = IIDFromString("{0BE78E56-C193-4051-B943-23B460C08BDB}"); //$NON-NLS-1$
9091
public static final GUID IID_ICoreWebView2_12 = IIDFromString("{35D69927-BCFA-4566-9349-6B3E0D154CAC}"); //$NON-NLS-1$
9192
public static final GUID IID_ICoreWebView2_13 = IIDFromString("{F75F09A8-667E-4983-88D6-C8773F315E84}"); //$NON-NLS-1$
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 SAP SE and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* SAP SE - initial implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.internal.ole.win32;
15+
16+
public class ICoreWebView2BasicAuthenticationRequestedEventArgs extends IUnknown {
17+
18+
public ICoreWebView2BasicAuthenticationRequestedEventArgs(long address) {
19+
super(address);
20+
}
21+
22+
public int get_Uri(long[] value) {
23+
return COM.VtblCall(3, address, value);
24+
}
25+
26+
public int get_Challenge(long[] challenge) {
27+
return COM.VtblCall(4, address, challenge);
28+
}
29+
30+
public int get_Response(long[] response) {
31+
return COM.VtblCall(5, address, response);
32+
}
33+
34+
public int get_Cancel(int[] cancel) {
35+
return COM.VtblCall(6, address, cancel);
36+
}
37+
38+
public int put_Cancel(boolean cancel) {
39+
return COM.VtblCall(7, address, cancel ? 1 : 0);
40+
}
41+
42+
/* 8:
43+
DECLSPEC_XFGVIRT(ICoreWebView2BasicAuthenticationRequestedEventArgs, GetDeferral)
44+
HRESULT ( STDMETHODCALLTYPE *GetDeferral )(
45+
ICoreWebView2BasicAuthenticationRequestedEventArgs * This,
46+
ICoreWebView2Deferral **deferral);
47+
*/
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 SAP SE and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* SAP SE - initial implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.internal.ole.win32;
15+
16+
public class ICoreWebView2BasicAuthenticationResponse extends IUnknown {
17+
18+
public ICoreWebView2BasicAuthenticationResponse(long address) {
19+
super(address);
20+
}
21+
22+
public int get_UserName(long[] userName) {
23+
return COM.VtblCall(3, address, userName);
24+
}
25+
26+
public int put_UserName(char[] userName) {
27+
return COM.VtblCall(4, address, userName);
28+
}
29+
30+
public int get_Password(long[] password) {
31+
return COM.VtblCall(5, address, password);
32+
}
33+
34+
public int put_Password(char[] password) {
35+
return COM.VtblCall(6, address, password);
36+
}
37+
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 SAP SE and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* SAP SE - initial implementation
13+
*******************************************************************************/
14+
package org.eclipse.swt.internal.ole.win32;
15+
16+
public class ICoreWebView2_10 extends ICoreWebView2_2 {
17+
18+
public ICoreWebView2_10(long address) {
19+
super(address);
20+
}
21+
22+
public int add_BasicAuthenticationRequested(IUnknown eventHandler, long[] token) {
23+
return COM.VtblCall(97, address, eventHandler.getAddress(), token);
24+
}
25+
26+
public int remove_BasicAuthenticationRequested(long[] token) {
27+
return COM.VtblCall(98, address, token);
28+
}
29+
30+
}

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/ole/win32/ICoreWebView2_11.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*******************************************************************************/
1414
package org.eclipse.swt.internal.ole.win32;
1515

16-
public class ICoreWebView2_11 extends ICoreWebView2_2 {
16+
public class ICoreWebView2_11 extends ICoreWebView2_10 {
1717

1818
public ICoreWebView2_11(long address) {
1919
super(address);

0 commit comments

Comments
 (0)