diff --git a/CefSharp.MinimalExample.WinForms/AsyncJavascriptBindingClass.cs b/CefSharp.MinimalExample.WinForms/AsyncJavascriptBindingClass.cs new file mode 100644 index 00000000..644e62c9 --- /dev/null +++ b/CefSharp.MinimalExample.WinForms/AsyncJavascriptBindingClass.cs @@ -0,0 +1,10 @@ +namespace CefSharp.MinimalExample.WinForms +{ + public class AsyncJavascriptBindingClass + { + public double Multiply(double number1, double number2) + { + return number1 * number2; + } + } +} diff --git a/CefSharp.MinimalExample.WinForms/AsyncJavascriptBindingDemo.html b/CefSharp.MinimalExample.WinForms/AsyncJavascriptBindingDemo.html new file mode 100644 index 00000000..78e6af19 --- /dev/null +++ b/CefSharp.MinimalExample.WinForms/AsyncJavascriptBindingDemo.html @@ -0,0 +1,51 @@ + + + + + + Async Javascript Binding Example + + +
+

Async Binding Example

+

Multiply

+
+ + + + + + + + + + + + + + + + + + +
First NumberSecond NumberResult
+
+
+ + + diff --git a/CefSharp.MinimalExample.WinForms/BrowserForm.cs b/CefSharp.MinimalExample.WinForms/BrowserForm.cs index 43053336..f493eef1 100644 --- a/CefSharp.MinimalExample.WinForms/BrowserForm.cs +++ b/CefSharp.MinimalExample.WinForms/BrowserForm.cs @@ -3,6 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. using System; +using System.IO; using System.Windows.Forms; using CefSharp.MinimalExample.WinForms.Controls; using CefSharp.WinForms; @@ -20,10 +21,11 @@ public BrowserForm() Text = "CefSharp"; WindowState = FormWindowState.Maximized; - browser = new ChromiumWebBrowser("www.google.com") + browser = new ChromiumWebBrowser("http://cefsharp.demo/AsyncJavascriptBindingDemo.html") { Dock = DockStyle.Fill, }; + browser.RegisterResourceHandler("http://cefsharp.demo/AsyncJavascriptBindingDemo.html", File.OpenRead("AsyncJavascriptBindingDemo.html")); toolStripContainer.ContentPanel.Controls.Add(browser); browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged; @@ -32,6 +34,14 @@ public BrowserForm() browser.StatusMessage += OnBrowserStatusMessage; browser.TitleChanged += OnBrowserTitleChanged; browser.AddressChanged += OnBrowserAddressChanged; + browser.JavascriptObjectRepository.ResolveObject += (sender, e) => + { + var repo = e.ObjectRepository; + if (e.ObjectName == "boundAsync") + { + repo.Register("boundAsync", new AsyncJavascriptBindingClass(), isAsync: true); + } + }; var bitness = Environment.Is64BitProcess ? "x64" : "x86"; var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}, Environment: {3}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion, bitness); diff --git a/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj b/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj index 78808364..9c41f1e9 100644 --- a/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj +++ b/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.csproj @@ -64,6 +64,7 @@ + Form @@ -109,6 +110,11 @@ + + + Always + +