+78
-1
lines changedFilter options
+78
-1
lines changed Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1
+
namespace CefSharp.MinimalExample.WinForms
2
+
{
3
+
public class AsyncJavascriptBindingClass
4
+
{
5
+
public double Multiply(double number1, double number2)
6
+
{
7
+
return number1 * number2;
8
+
}
9
+
}
10
+
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
1
+
<!DOCTYPE html>
2
+
3
+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
4
+
<head>
5
+
<meta charset="utf-8" />
6
+
<title>Async Javascript Binding Example</title>
7
+
</head>
8
+
<body>
9
+
<div>
10
+
<h1>Async Binding Example</h1>
11
+
<h2>Multiply</h2>
12
+
<div>
13
+
<table>
14
+
<thead>
15
+
<tr>
16
+
<td>First Number</td>
17
+
<td>Second Number</td>
18
+
<td>Result</td>
19
+
</tr>
20
+
</thead>
21
+
<tbody>
22
+
<tr>
23
+
<td><input id="firstNumber" type="text" value="4" /></td>
24
+
<td><input id="secondNumber" type="text" value="5" /></td>
25
+
<td><input id="result" type="text" readonly="readonly" /></td>
26
+
</tr>
27
+
<tr>
28
+
<td colspan="3"><input type="button" id="calculate" value="Calculate" /></td>
29
+
</tr>
30
+
</tbody>
31
+
</table>
32
+
</div>
33
+
</div>
34
+
<script type="text/javascript">
35
+
(async function ()
36
+
{
37
+
await CefSharp.BindObjectAsync("boundAsync");
38
+
39
+
document.getElementById('calculate').addEventListener('click', async function ()
40
+
{
41
+
var number1 = parseInt(document.getElementById('firstNumber').value, 10);
42
+
var number2 = parseInt(document.getElementById('secondNumber').value, 10);
43
+
44
+
var result = await boundAsync.multiply(number1, number2);
45
+
46
+
document.getElementById('result').value = result;
47
+
});
48
+
})();
49
+
</script>
50
+
</body>
51
+
</html>
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
3
3
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4
4
5
5
using System;
6
+
using System.IO;
6
7
using System.Windows.Forms;
7
8
using CefSharp.MinimalExample.WinForms.Controls;
8
9
using CefSharp.WinForms;
@@ -20,10 +21,11 @@ public BrowserForm()
20
21
Text = "CefSharp";
21
22
WindowState = FormWindowState.Maximized;
22
23
23
-
browser = new ChromiumWebBrowser("www.google.com")
24
+
browser = new ChromiumWebBrowser("http://cefsharp.demo/AsyncJavascriptBindingDemo.html")
24
25
{
25
26
Dock = DockStyle.Fill,
26
27
};
28
+
browser.RegisterResourceHandler("http://cefsharp.demo/AsyncJavascriptBindingDemo.html", File.OpenRead("AsyncJavascriptBindingDemo.html"));
27
29
toolStripContainer.ContentPanel.Controls.Add(browser);
28
30
29
31
browser.IsBrowserInitializedChanged += OnIsBrowserInitializedChanged;
@@ -32,6 +34,14 @@ public BrowserForm()
32
34
browser.StatusMessage += OnBrowserStatusMessage;
33
35
browser.TitleChanged += OnBrowserTitleChanged;
34
36
browser.AddressChanged += OnBrowserAddressChanged;
37
+
browser.JavascriptObjectRepository.ResolveObject += (sender, e) =>
38
+
{
39
+
var repo = e.ObjectRepository;
40
+
if (e.ObjectName == "boundAsync")
41
+
{
42
+
repo.Register("boundAsync", new AsyncJavascriptBindingClass(), isAsync: true);
43
+
}
44
+
};
35
45
36
46
var bitness = Environment.Is64BitProcess ? "x64" : "x86";
37
47
var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}, Environment: {3}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion, bitness);
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@
64
64
<Reference Include="System.Windows.Forms" />
65
65
</ItemGroup>
66
66
<ItemGroup>
67
+
<Compile Include="AsyncJavascriptBindingClass.cs" />
67
68
<Compile Include="BrowserForm.cs">
68
69
<SubType>Form</SubType>
69
70
</Compile>
@@ -109,6 +110,11 @@
109
110
<ItemGroup>
110
111
<None Include="Resources\chromium-256.png" />
111
112
</ItemGroup>
113
+
<ItemGroup>
114
+
<Content Include="AsyncJavascriptBindingDemo.html">
115
+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
116
+
</Content>
117
+
</ItemGroup>
112
118
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
113
119
<Import Project="..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.targets" Condition="Exists('..\packages\CefSharp.Common.65.0.1\build\CefSharp.Common.targets')" />
114
120
<Import Project="..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.targets" Condition="Exists('..\packages\CefSharp.WinForms.65.0.1\build\CefSharp.WinForms.targets')" />
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4