Example #1
0
 internal static void IsAttachWebRendererInteropMessage(string message)
 {
     Assert.True(IpcCommon.TryDeserializeOutgoing(message, out var messageType, out var args));
     Assert.Equal(IpcCommon.OutgoingMessageType.BeginInvokeJS, messageType);
     Assert.Equal(5, args.Count);
     Assert.Equal("Blazor._internal.attachWebRendererInterop", args[1].GetString());
 }
Example #2
0
 internal static void IsAttachToDocumentMessage(string message, int componentId, string selector)
 {
     Assert.True(IpcCommon.TryDeserializeOutgoing(message, out var messageType, out var args));
     Assert.Equal(IpcCommon.OutgoingMessageType.AttachToDocument, messageType);
     Assert.Equal(2, args.Count);
     Assert.Equal(componentId, args[0].GetInt32());
     Assert.Equal(selector, args[1].GetString());
 }
Example #3
0
        internal static RenderBatch IsRenderBatch(string message)
        {
            Assert.True(IpcCommon.TryDeserializeOutgoing(message, out var messageType, out var args));
            Assert.Equal(IpcCommon.OutgoingMessageType.RenderBatch, messageType);
            Assert.Equal(2, args.Count);
            Assert.Equal(1, args[0].GetInt64()); // Batch ID

            // At least validate we can base64 decode the batch data
            var _ = Convert.FromBase64String(args[1].GetString());

            // TODO: Produce the render batch if we want to grab info from it.
            return(default);
Example #4
0
        public void ApplyRenderBatch(long batchId, RenderBatch renderBatch)
        {
            var arrayBuilder = new ArrayBuilder <byte>(2048);

            using var memoryStream = new ArrayBuilderMemoryStream(arrayBuilder);
            using (var renderBatchWriter = new RenderBatchWriter(memoryStream, false))
            {
                renderBatchWriter.Write(in renderBatch);
            }
            var message = IpcCommon.Serialize(IpcCommon.OutgoingMessageType.RenderBatch, batchId, Convert.ToBase64String(arrayBuilder.Buffer, 0, arrayBuilder.Count));

            DispatchMessageWithErrorHandling(message);
        }
Example #5
0
        public async Task OnMessageReceivedAsync(PageContext pageContext, string message)
        {
            // Ignore other messages as they may be unrelated to Blazor WebView
            if (IpcCommon.TryDeserializeIncoming(message, out var messageType, out var args))
            {
                if (messageType == IpcCommon.IncomingMessageType.AttachPage)
                {
                    await _onAttachMessage(args[0].GetString(), args[1].GetString());

                    return;
                }

                // For any other message, you have to have a page attached already
                if (pageContext == null)
                {
                    throw new InvalidOperationException("Cannot receive IPC messages when no page is attached");
                }

                switch (messageType)
                {
                case IpcCommon.IncomingMessageType.BeginInvokeDotNet:
                    BeginInvokeDotNet(pageContext, args[0].GetString(), args[1].GetString(), args[2].GetString(), args[3].GetInt64(), args[4].GetString());
                    break;

                case IpcCommon.IncomingMessageType.EndInvokeJS:
                    EndInvokeJS(pageContext, args[0].GetInt64(), args[1].GetBoolean(), args[2].GetString());
                    break;

                case IpcCommon.IncomingMessageType.ReceiveByteArrayFromJS:
                    ReceiveByteArrayFromJS(pageContext, args[0].GetInt32(), args[1].GetBytesFromBase64());
                    break;

                case IpcCommon.IncomingMessageType.DispatchBrowserEvent:
                    await DispatchBrowserEventAsync(pageContext, args[0], args[1]);

                    break;

                case IpcCommon.IncomingMessageType.OnRenderCompleted:
                    OnRenderCompleted(pageContext, args[0].GetInt64(), args[1].GetString());
                    break;

                case IpcCommon.IncomingMessageType.OnLocationChanged:
                    OnLocationChanged(pageContext, args[0].GetString(), args[1].GetBoolean());
                    break;

                default:
                    throw new InvalidOperationException($"Unknown message type '{messageType}'.");
                }
            }
        }
Example #6
0
        public void NotifyUnhandledException(Exception exception)
        {
            var message = IpcCommon.Serialize(IpcCommon.OutgoingMessageType.NotifyUnhandledException, exception.Message, exception.StackTrace);

            _dispatcher.InvokeAsync(() => _messageDispatcher(message));
        }
Example #7
0
 public void EndInvokeDotNet(string callId, bool success, string invocationResultOrError)
 {
     DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.EndInvokeDotNet, callId, success, invocationResultOrError));
 }
Example #8
0
 public void BeginInvokeJS(long taskId, string identifier, string argsJson, JSCallResultType resultType, long targetInstanceId)
 {
     DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.BeginInvokeJS, taskId, identifier, argsJson, resultType, targetInstanceId));
 }
Example #9
0
 public void DetachFromDocument(int componentId)
 {
     DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.DetachFromDocument, componentId));
 }
Example #10
0
 public void AttachToDocument(int componentId, string selector)
 {
     DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.AttachToDocument, componentId, selector));
 }
Example #11
0
 public void Navigate(string uri, bool forceLoad)
 {
     DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.Navigate, uri, forceLoad));
 }
Example #12
0
 public void SendByteArray(int id, byte[] data)
 {
     DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.SendByteArrayToJS, id, data));
 }
Example #13
0
 public void Navigate(string uri, NavigationOptions options)
 {
     DispatchMessageWithErrorHandling(IpcCommon.Serialize(IpcCommon.OutgoingMessageType.Navigate, uri, options));
 }