-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Clean up WebView comments #30742
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
Clean up WebView comments #30742
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,22 +6,8 @@ | |
using Microsoft.AspNetCore.Components.RenderTree; | ||
using Microsoft.JSInterop; | ||
|
||
// Sync vs Async APIs for this. | ||
// This mainly depends on the underlying support for the browser. Assuming that there is no synchronous API | ||
// communication is safer, since it's not guaranteed. | ||
// In that scenario, some APIs need to expose the async nature of the communication. That happens when some | ||
// component like the renderer needs to know the results of the operation. For example when updating the UI | ||
// since more code needs to execute afterwards. | ||
// In other cases like when we try to attach a component to the document, we don't necessarily need to do that | ||
// since we only care about errors that might happen while attaching the component and the renderer doesn't | ||
// necessarily need to know about those if we are terminating the component/host as a result. | ||
// If we decide we need to expose the async nature of the communication channel, then we will need to keep track | ||
// of all the message pairs/completions across the IPC channel. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments refer to an entirely different earlier incarnation of the IPC implementation. |
||
namespace Microsoft.AspNetCore.Components.WebView | ||
{ | ||
// These are all the messages .NET needs to know how to dispatch to JS | ||
// TODO: Proper serialization, error handling, etc. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The serialization is already adequate. Error handling is something we're tightening up as part of implementing unit tests. |
||
|
||
// Handles comunication between the component abstractions (Renderer, NavigationManager, JSInterop, etc.) | ||
// and the underlying transport channel | ||
internal class IpcSender | ||
|
@@ -47,39 +33,26 @@ public void ApplyRenderBatch(long batchId, RenderBatch renderBatch) | |
DispatchMessageWithErrorHandling(message); | ||
} | ||
|
||
// This is called by the navigation manager and needs to be forwarded to the WebView | ||
// It might trigger the WebView to change the location of the URL and cause a LocationUpdated event. | ||
public void Navigate(string uri, bool forceLoad) | ||
{ | ||
DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.Navigate, uri, forceLoad)); | ||
} | ||
|
||
// TODO: Make these APIs async if we want the renderer to be able to deal with errors. | ||
// Called from Renderer to attach a new component ID to a given selector. | ||
public void AttachToDocument(int componentId, string selector) | ||
{ | ||
DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.AttachToDocument, componentId, selector)); | ||
} | ||
|
||
// Called from the WebView to detach a root component from the document. | ||
public void DetachFromDocument(int componentId) | ||
{ | ||
DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.DetachFromDocument, componentId)); | ||
} | ||
|
||
// Interop calls emitted by the JSRuntime | ||
public void BeginInvokeJS(long taskId, string identifier, string argsJson, JSCallResultType resultType, long targetInstanceId) | ||
{ | ||
DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.BeginInvokeJS, taskId, identifier, argsJson, resultType, targetInstanceId)); | ||
} | ||
|
||
// TODO: We need to think about this, the invocation result contains the triplet [callId, successOrError, resultOrError] | ||
// serialized as JSON with the options provided by the JSRuntime. The host can't operate on the "unserialized" | ||
// data since it needs to deal with DotNetObjectReferences and JSObjectReference which the host doesn't have any visibility | ||
// over how to serialize or deserialize. | ||
// The strongest limitation we can find on a platform is that we might only be able to communicate with the host via "strings" (post-message) | ||
// and in that situation we can define a separator within the string like (callId,success,resultOrError) that the | ||
// side running in the browser can parse for processing. | ||
public void EndInvokeDotNet(string callId, bool success, string invocationResultOrError) | ||
{ | ||
DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.EndInvokeDotNet, callId, success, invocationResultOrError)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's any concern here. Nothing would go wrong unless we receives one of these messages before the first page connection, and that's impossible, because it's the page that sends them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully the exception here will keep us honest!