API changes/addition for asynchronous behaviour of new browsers #1406
-
Hi, I've been working on resolving the deadlock issue with the Edge browser. Let me explain the issue in detail. In the embedded Edge browser, we use the WebView provided by Windows to execute tasks. By design, the WebView cannot execute tasks simultaneously; it serializes them instead. Now, imagine a scenario where the embedded browser is executing a task using the WebView and, during this process, we receive a callback from the WebView that requires executing another task. The new task cannot complete because the previous task is still running, and the previous task is waiting for the new one to finish, creating a deadlock. For example, if you use the Edge browser and open the welcome page, then click on "Eclipse Platform" in the "What's New" tab, it opens a new shell, creates a new browser, and navigates to the relevant content. In this case, the creation of the new shell and browser occurs within a WebView callback, and since the browser creation requires another WebView call, a deadlock occurs. In my PR: #1378, I implemented an asynchronous approach where I schedule new tasks asynchronously, allowing them to finish after the current task completes. This approach delays the WebView call to set up the browser environment until after the callback is completed. However, there are additional calls to set the URL or set text on the browser that occur after the browser is created, which need to ensure that they wait until the browser is fully initialized. These calls are also executed asynchronously if the browser's environment is not yet completely initialized. The challenge arises with API compatibility. By design, APIs like execute, setURL, and setText of the Browser class return a boolean value (particularly for setText and setURL, which check if the request status is 200 OK). With asynchronous calls, this is not possible, so we need a way to use CompletableFuture for such requests. In the PR, the implementation mimics synchronous behavior, but the return value for these async calls is explicitly set to true, which does not accurately reflect the intended behavior of these APIs. There are two proposals to address this problem:
Which approach do you think is better? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Some minor comments / additions for clarification:
Changing the return value will not be possible as it would break the API. Instead, the return values could still be boolean but in case the actual processing is done asynchronously, the methods might always return
For existing browsers with a synchronous API (like IE), the new and existing methods would behave the same. I.e., a future returned by a new API would directly yield a value as the execution has already finished synchronously. The two approaches could even be combined:
|
Beta Was this translation helpful? Give feedback.
Thanks for your input. In general, I also like that pattern, but it puts an addition burden on clients, which should actually be unnecessary if the API was designed properly.
In today's dev community call, @akurtakov pointed to the WebKit implementation in SWT already dealing with the asynchronous API of WebKit. Looking at the implementation shows that it has the exact same challenge than Edge. Methods like
setText
andsetUrl
were solved by basically always returningtrue
and delegating delegate asynchronous requests to WebKit, e.g.:eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java
Lines 1918 to 1932 in 248ab17