Beispiel #1
0
        private void HandleScriptNotify(object sender, WebViewControlScriptNotifyEventArgs eventArgs)
        {
            var value = eventArgs.Value;

            if (value.StartsWith("ipc:"))
            {
                var spacePos  = value.IndexOf(' ');
                var eventName = value.Substring(4, spacePos - 4);
                var argsJson  = value.Substring(spacePos + 1);
                var args      = JsonSerializer.Deserialize <object[]>(argsJson);

                Action <object>[] callbacksCopy;
                lock (_registrations)
                {
                    if (!_registrations.TryGetValue(eventName, out var callbacks))
                    {
                        return;
                    }

                    callbacksCopy = callbacks.ToArray();
                }

                foreach (var callback in callbacksCopy)
                {
                    callback(args);
                }
            }
        }
Beispiel #2
0
 private void sc(object sender, WebViewControlScriptNotifyEventArgs e)
 {
     if (e.Value.StartsWith("mdn"))
     {
         Console.WriteLine("Mouse down");
         mouseDownF(int.Parse(e.Value.Split(';')[1]), int.Parse(e.Value.Split(';')[2]));
     }
     else if (e.Value.StartsWith("mup"))
     {
         Console.WriteLine("Mouse up");
         mouseUpF(int.Parse(e.Value.Split(';')[1]), int.Parse(e.Value.Split(';')[2]));
     }
     else if (e.Value.StartsWith("mmm"))
     {
         Console.WriteLine("Mouse move");
         mouseMoveF(int.Parse(e.Value.Split(';')[1]), int.Parse(e.Value.Split(';')[2]));
     }
     else if (e.Value.StartsWith("dbl"))
     {
         Console.WriteLine("Double click");
         mouseDBLF(int.Parse(e.Value.Split(';')[1]), int.Parse(e.Value.Split(';')[2]));
     }
     else if (e.Value.StartsWith("kkk"))
     {
         Console.WriteLine("Key");
         keyF(e.Value.Split(';')[1]);
     }
     else if (e.Value.StartsWith("whl"))
     {
         Console.WriteLine("Wheel");
         resizeWheel(double.Parse(e.Value.Split(';')[1], CultureInfo.InvariantCulture));
     }
 }
Beispiel #3
0
        private void WebView_ScriptNotify(object sender, WebViewControlScriptNotifyEventArgs e)
        {
            Debug.WriteLine($"{callerName()} {e.Value}");
            switch (e.Value[0])
            {
            case 'i':
                StatusLine.Value = e.Value.Substring(2);
                break;

            case 'o':
                LMonitor.ResumeStatusLine();
                break;

            //case 'c':
            //    CopyCommand.Execute(e.Value.Substring(2));
            //    break;
            default:
                Debug.Assert(false, $"unknown command:{e.Value}");
                break;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles the <see cref="IWebView.ScriptNotify" /> event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="WebViewControlScriptNotifyEventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// Since there may be other uses of <code>window.external.notify</code> in use, this method checks to see if the
        /// message came from a URI within <see cref="AllowedScriptNotifyUris"/> and the bridge before processing it. If it did,
        /// it triggers processing of all queued messages within the bridge asynchronously.
        /// </remarks>
        /// <seealso cref="AllowedScriptNotifyUris"/>
        /// <seealso cref="IsJavaScriptBridgeMessage"/>
        /// <seealso cref="FlushAsync"/>
        private void OnWebViewScriptNotify(object sender, WebViewControlScriptNotifyEventArgs e)
        {
            Trace.WriteLine($"Entering {typeof(JavaScriptBridge).FullName}.{nameof(OnWebViewScriptNotify)}", Constants.TraceName);

            // White list
            // WinForms/WPF do not validate the origins for ScriptNotify like UWP does
            // This needs to be done manually for security
            if (e.Uri != null && AllowedScriptNotifyUris != null && AllowedScriptNotifyUris.Contains(e.Uri))
            {
                var message = e.Value;

                if (sender is IWebView webView && IsJavaScriptBridgeMessage(message))
                {
                    Trace.WriteLine($"Received command {message}", Constants.TraceName);

                    // Asynchronously flush the messages from the JavaScript bridge
                    FlushAsync();
                }
            }
            else
            {
                Trace.WriteLine($"{nameof(IWebView.ScriptNotify)} received from unknown origin {e.Uri?.Host}", Constants.TraceName);
            }
        }
Beispiel #5
0
 private void OnScriptNotify(object sender, WebViewControlScriptNotifyEventArgs e)
 {
     Context.DispatchEvent("TRACE", e.Value);
 }
Beispiel #6
0
 private void WebView1_OnScriptNotify(object sender, WebViewControlScriptNotifyEventArgs e)
 {
     MessageBox.Show(e.Value, e.Uri?.ToString() ?? string.Empty);
 }
 private void ScriptNotify(object sender, WebViewControlScriptNotifyEventArgs e)
 {
     Close();
 }
Beispiel #8
0
 private static void OnScriptNotify(object sender, WebViewControlScriptNotifyEventArgs e)
 {
     Context.DispatchEvent(WebViewEvent.JsCallbackEvent, e.Value);
 }
 private async void Webview_ScriptNotify(IWebViewControl sender, WebViewControlScriptNotifyEventArgs e)
 {
     await bridge.HandleScriptCall(e.Value);
 }
Beispiel #10
0
 /// <summary>
 /// Event handler for script notifications from Edge.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="eventArgs">The event arguments.</param>
 private void Webview_ScriptNotify(object sender, WebViewControlScriptNotifyEventArgs eventArgs)
 {
     this.OnWebMessageReceived?.Invoke(this, eventArgs.Value);
 }
Beispiel #11
0
 private void GPlayWebView_ScriptNotify(object sender, WebViewControlScriptNotifyEventArgs e)
 {
     // Shows messagebox if script notifications are needed
     MessageBox.Show(e.Value, e.Uri?.ToString() ?? string.Empty);
 }