Skip to content

Commit

Permalink
Edge: Implement ICoreWebView2_12 to send out StatusTextEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
sratz committed Oct 3, 2024
1 parent 70aee87 commit 4ea366e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class WebViewProvider {
private CompletableFuture<ICoreWebView2> webViewFuture = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_2> webView_2Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_11> webView_11Future = new CompletableFuture<>();
private CompletableFuture<ICoreWebView2_12> webView_12Future = new CompletableFuture<>();

private CompletableFuture<Void> lastWebViewTask = webViewFuture.thenRun(() -> {});

Expand All @@ -293,6 +294,7 @@ ICoreWebView2 initializeWebView(ICoreWebView2Controller controller) {
final ICoreWebView2 webView = new ICoreWebView2(ppv[0]);
initializeWebView_2(webView);
initializeWebView_11(webView);
initializeWebView_12(webView);
webViewFuture.complete(webView);
return webView;
}
Expand All @@ -317,6 +319,16 @@ private void initializeWebView_11(ICoreWebView2 webView) {
}
}

private void initializeWebView_12(ICoreWebView2 webView) {
long[] ppv = new long[1];
int hr = webView.QueryInterface(COM.IID_ICoreWebView2_12, ppv);
if (hr == COM.S_OK) {
webView_12Future.complete(new ICoreWebView2_12(ppv[0]));
} else {
webView_12Future.cancel(true);
}
}

ICoreWebView2 getWebView(boolean waitForPendingWebviewTasksToFinish) {
if(waitForPendingWebviewTasksToFinish) {
waitForFutureToFinish(lastWebViewTask);
Expand Down Expand Up @@ -348,6 +360,18 @@ boolean isWebView_11Available() {
return !webView_11Future.isCancelled();
}

ICoreWebView2_12 getWebView_12(boolean waitForPendingWebviewTasksToFinish) {
if(waitForPendingWebviewTasksToFinish) {
waitForFutureToFinish(lastWebViewTask);
}
return webView_12Future.join();
}

boolean isWebView_12Available() {
waitForFutureToFinish(webView_12Future);
return !webView_12Future.isCancelled();
}

/*
* Schedule a given runnable in a queue to execute when the webView is free and
* has finished all the pending tasks queued before it.
Expand Down Expand Up @@ -561,6 +585,11 @@ void setupBrowser(int hr, long pv) {
webViewProvider.getWebView_11(false).add_ContextMenuRequested(handler, token);
handler.Release();
}
if (webViewProvider.isWebView_12Available()) {
handler = newCallback(this::handleStatusBarTextChanged);
webViewProvider.getWebView_12(false).add_StatusBarTextChanged(handler, token);
handler.Release();
}

IUnknown hostDisp = newHostObject(this::handleCallJava);
long[] hostObj = { COM.VT_DISPATCH, hostDisp.getAddress(), 0 }; // VARIANT
Expand All @@ -587,6 +616,7 @@ void browserDispose(Event event) {
if (settings != null) settings.Release();
if (webViewProvider.isWebView_2Available()) webViewProvider.getWebView_2(false).Release();
if (webViewProvider.isWebView_11Available()) webViewProvider.getWebView_11(false).Release();
if (webViewProvider.isWebView_12Available()) webViewProvider.getWebView_12(false).Release();
if(controller != null) {
// Bug in WebView2. Closing the controller from an event handler results
// in a crash. The fix is to delay the closure with asyncExec.
Expand Down Expand Up @@ -866,6 +896,20 @@ int handleContextMenuRequested(long pView, long pArgs) {
return COM.S_OK;
}

int handleStatusBarTextChanged(long pView, long pArgs) {
long ppsz[] = new long[1];
webViewProvider.getWebView_12(true).get_StatusBarText(ppsz);
String text = wstrToString(ppsz[0], true);
StatusTextEvent newEvent5 = new StatusTextEvent(browser);
newEvent5.display = browser.getDisplay();
newEvent5.widget = browser;
newEvent5.text = text;
for (StatusTextListener statusTextListener : statusTextListeners) {
statusTextListener.changed(newEvent5);
}
return COM.S_OK;
}

int handleNavigationCompleted(long pView, long pArgs) {
return handleNavigationCompleted(pView, pArgs, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class COM extends OS {
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_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$

// IA2 related GUIDS
public static final GUID IIDIAccessible2 = IIDFromString("{E89F726E-C4F4-4c19-BB19-B647D7FA8478}"); //$NON-NLS-1$
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* 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_12 extends ICoreWebView2_11 {

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

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

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

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

}

0 comments on commit 4ea366e

Please sign in to comment.