Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge: Implement AuthenticationListener handling for BasicAuth #1571

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ class WebViewProvider {

private CompletableFuture<ICoreWebView2> webViewFuture = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_2> webView_2Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_10> webView_10Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_11> webView_11Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_12> webView_12Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_13> webView_13Future = new CompletableFuture<>();
Expand All @@ -300,6 +301,7 @@ ICoreWebView2 initializeWebView(ICoreWebView2Controller controller) {
controller.get_CoreWebView2(ppv);
final ICoreWebView2 webView = new ICoreWebView2(ppv[0]);
initializeWebView_2(webView);
initializeWebView_10(webView);
initializeWebView_11(webView);
initializeWebView_12(webView);
initializeWebView_13(webView);
Expand All @@ -317,6 +319,16 @@ private void initializeWebView_2(ICoreWebView2 webView) {
}
}

private void initializeWebView_10(ICoreWebView2 webView) {
long[] ppv = new long[1];
int hr = webView.QueryInterface(COM.IID_ICoreWebView2_10, ppv);
if (hr == COM.S_OK) {
webView_10Future.complete(new ICoreWebView2_10(ppv[0]));
} else {
webView_10Future.cancel(true);
}
}

private void initializeWebView_11(ICoreWebView2 webView) {
long[] ppv = new long[1];
int hr = webView.QueryInterface(COM.IID_ICoreWebView2_11, ppv);
Expand Down Expand Up @@ -366,6 +378,18 @@ boolean isWebView_2Available() {
return !webView_2Future.isCancelled();
}

ICoreWebView2_10 getWebView_10(boolean waitForPendingWebviewTasksToFinish) {
if(waitForPendingWebviewTasksToFinish) {
waitForFutureToFinish(lastWebViewTask);
}
return webView_10Future.join();
}

boolean isWebView_10Available() {
waitForFutureToFinish(webView_10Future);
return !webView_10Future.isCancelled();
}

ICoreWebView2_11 getWebView_11(boolean waitForPendingWebviewTasksToFinish) {
if(waitForPendingWebviewTasksToFinish) {
waitForFutureToFinish(lastWebViewTask);
Expand Down Expand Up @@ -637,6 +661,11 @@ void setupBrowser(int hr, long pv) {
webViewProvider.getWebView_2(false).add_DOMContentLoaded(handler, token);
handler.Release();
}
if (webViewProvider.isWebView_10Available()) {
handler = newCallback(this::handleBasicAuthenticationRequested);
webViewProvider.getWebView_10(false).add_BasicAuthenticationRequested(handler, token);
handler.Release();
}
if (webViewProvider.isWebView_11Available()) {
handler = newCallback(this::handleContextMenuRequested);
webViewProvider.getWebView_11(false).add_ContextMenuRequested(handler, token);
Expand Down Expand Up @@ -971,6 +1000,34 @@ private static String escapeForSingleQuotedJSString(String str) {
.replace("\n", "\\n");
}

int handleBasicAuthenticationRequested(long pView, long pArgs) {
ICoreWebView2BasicAuthenticationRequestedEventArgs args = new ICoreWebView2BasicAuthenticationRequestedEventArgs(pArgs);

long[] ppv = new long[1];

args.get_Uri(ppv);
String uri = wstrToString(ppv[0], true);

for (AuthenticationListener authenticationListener : this.authenticationListeners) {
AuthenticationEvent event = new AuthenticationEvent (browser);
event.location = uri;
authenticationListener.authenticate (event);
if (!event.doit) {
args.put_Cancel(true);
return COM.S_OK;
}
if (event.user != null && event.password != null) {
args.get_Response(ppv);
ICoreWebView2BasicAuthenticationResponse response = new ICoreWebView2BasicAuthenticationResponse(ppv[0]);
response.put_UserName(stringToWstr(event.user));
response.put_Password(stringToWstr(event.password));
return COM.S_OK;
}
}

return COM.S_OK;
}

int handleContextMenuRequested(long pView, long pArgs) {
ICoreWebView2ContextMenuRequestedEventArgs args = new ICoreWebView2ContextMenuRequestedEventArgs(pArgs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class COM extends OS {
public static final GUID CGID_Explorer = IIDFromString("{000214D0-0000-0000-C000-000000000046}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2Environment2 = IIDFromString("{41F3632B-5EF4-404F-AD82-2D606C5A9A21}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_2 = IIDFromString("{9E8F0CF8-E670-4B5E-B2BC-73E061E3184C}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_10 = IIDFromString("{B1690564-6F5A-4983-8E48-31D1143FECDB}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_11 = IIDFromString("{0BE78E56-C193-4051-B943-23B460C08BDB}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_12 = IIDFromString("{35D69927-BCFA-4566-9349-6B3E0D154CAC}"); //$NON-NLS-1$
public static final GUID IID_ICoreWebView2_13 = IIDFromString("{F75F09A8-667E-4983-88D6-C8773F315E84}"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*******************************************************************************
* Copyright (c) 2024 SAP SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial implementation
*******************************************************************************/
package org.eclipse.swt.internal.ole.win32;

public class ICoreWebView2BasicAuthenticationRequestedEventArgs extends IUnknown {

public ICoreWebView2BasicAuthenticationRequestedEventArgs(long address) {
super(address);
}

public int get_Uri(long[] value) {
return COM.VtblCall(3, address, value);
}

public int get_Challenge(long[] challenge) {
return COM.VtblCall(4, address, challenge);
}

public int get_Response(long[] response) {
return COM.VtblCall(5, address, response);
}

public int get_Cancel(int[] cancel) {
return COM.VtblCall(6, address, cancel);
}

public int put_Cancel(boolean cancel) {
return COM.VtblCall(7, address, cancel ? 1 : 0);
}

/* 8:
sratz marked this conversation as resolved.
Show resolved Hide resolved
DECLSPEC_XFGVIRT(ICoreWebView2BasicAuthenticationRequestedEventArgs, GetDeferral)
HRESULT ( STDMETHODCALLTYPE *GetDeferral )(
ICoreWebView2BasicAuthenticationRequestedEventArgs * This,
ICoreWebView2Deferral **deferral);
*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2024 SAP SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial implementation
*******************************************************************************/
package org.eclipse.swt.internal.ole.win32;

public class ICoreWebView2BasicAuthenticationResponse extends IUnknown {

public ICoreWebView2BasicAuthenticationResponse(long address) {
super(address);
}

public int get_UserName(long[] userName) {
return COM.VtblCall(3, address, userName);
}

public int put_UserName(char[] userName) {
return COM.VtblCall(4, address, userName);
}

public int get_Password(long[] password) {
return COM.VtblCall(5, address, password);
}

public int put_Password(char[] password) {
return COM.VtblCall(6, address, password);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2024 SAP SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial implementation
*******************************************************************************/
package org.eclipse.swt.internal.ole.win32;

public class ICoreWebView2_10 extends ICoreWebView2_2 {

public ICoreWebView2_10(long address) {
super(address);
}

public int add_BasicAuthenticationRequested(IUnknown eventHandler, long[] token) {
return COM.VtblCall(97, address, eventHandler.getAddress(), token);
}

public int remove_BasicAuthenticationRequested(long[] token) {
return COM.VtblCall(98, address, token);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*******************************************************************************/
package org.eclipse.swt.internal.ole.win32;

public class ICoreWebView2_11 extends ICoreWebView2_2 {
public class ICoreWebView2_11 extends ICoreWebView2_10 {

public ICoreWebView2_11(long address) {
super(address);
Expand Down
Loading