Skip to content

Commit 9fdb3fd

Browse files
committed
Added a WinForm project to support WinForm for CefSharp3
1 parent d2beffa commit 9fdb3fd

File tree

13 files changed

+666
-124
lines changed

13 files changed

+666
-124
lines changed

CefSharp.Example/ExamplePresenter.cs

Lines changed: 117 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
2+
using System.ComponentModel;
3+
using System.IO;
24
using System.Linq;
5+
using System.Net;
6+
using System.Text;
37

48
namespace CefSharp.Example
59
{
6-
public class ExamplePresenter
10+
public class ExamplePresenter : IRequestHandler
711
{
812
public static void Init()
913
{
@@ -35,7 +39,7 @@ public static void Init()
3539
}
3640

3741
public static string DefaultUrl = "custom://cefsharp/home";
38-
// private static readonly Uri resource_url = new Uri("http://test/resource/load");
42+
private static readonly Uri resource_url = new Uri("http://test/resource/load");
3943
// private static readonly Uri scheme_url = new Uri("test://test/SchemeTest.html");
4044
// private static readonly Uri bind_url = new Uri("test://test/BindingTest.html");
4145
// private static readonly Uri tooltip_url = new Uri("test://test/TooltipTest.html");
@@ -49,84 +53,88 @@ public static void Init()
4953
// "green",
5054
// };
5155

52-
// private readonly IWebBrowser model;
53-
// private readonly IExampleView view;
54-
// private readonly Action<Action> uiThreadInvoke;
56+
private readonly IWebBrowser model;
57+
private readonly IExampleView view;
58+
private readonly Action<Action> uiThreadInvoke;
5559

56-
// public ExamplePresenter(IWebBrowser model, IExampleView view, Action<Action> uiThreadInvoke)
57-
// {
58-
// this.model = model;
59-
// this.view = view;
60-
// this.uiThreadInvoke = uiThreadInvoke;
61-
62-
// model.RequestHandler = this;
63-
// model.PropertyChanged += OnModelPropertyChanged;
64-
// model.ConsoleMessage += OnModelConsoleMessage;
65-
66-
// // file
67-
// view.ShowDevToolsActivated += OnViewShowDevToolsActivated;
68-
// view.CloseDevToolsActivated += OnViewCloseDevToolsActivated;
69-
// view.ExitActivated += OnViewExitActivated;
70-
71-
// // edit
72-
// view.UndoActivated += OnViewUndoActivated;
73-
// view.RedoActivated += OnViewRedoActivated;
74-
// view.CutActivated += OnViewCutActivated;
75-
// view.CopyActivated += OnViewCopyActivated;
76-
// view.PasteActivated += OnViewPasteActivated;
77-
// view.DeleteActivated += OnViewDeleteActivated;
78-
// view.SelectAllActivated += OnViewSelectAllActivated;
79-
80-
// // test
81-
// view.TestResourceLoadActivated += OnViewTestResourceLoadActivated;
82-
// view.TestSchemeLoadActivated += OnViewTestSchemeLoadActivated;
83-
// view.TestExecuteScriptActivated += OnViewTestExecuteScriptActivated;
84-
// view.TestEvaluateScriptActivated += OnViewTestEvaluateScriptActivated;
85-
// view.TestBindActivated += OnViewTestBindActivated;
86-
// view.TestConsoleMessageActivated += OnViewTestConsoleMessageActivated;
87-
// view.TestTooltipActivated += OnViewTestTooltipActivated;
88-
// view.TestPopupActivated += OnViewTestPopupActivated;
89-
// view.TestLoadStringActivated += OnViewTestLoadStringActivated;
90-
// view.TestCookieVisitorActivated += OnViewTestCookieVisitorActivated;
91-
92-
// // navigation
93-
// view.UrlActivated += OnViewUrlActivated;
94-
// view.ForwardActivated += OnViewForwardActivated;
95-
// view.BackActivated += OnViewBackActivated;
96-
// }
60+
public ExamplePresenter(IWebBrowser model, IExampleView view, Action<Action> uiThreadInvoke)
61+
{
62+
this.model = model;
63+
this.view = view;
64+
this.uiThreadInvoke = uiThreadInvoke;
65+
66+
var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}",
67+
Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion);
68+
view.DisplayOutput(version);
69+
70+
model.RequestHandler = this;
71+
model.PropertyChanged += OnModelPropertyChanged;
72+
//model.ConsoleMessage += OnModelConsoleMessage;
73+
74+
//// file
75+
//view.ShowDevToolsActivated += OnViewShowDevToolsActivated;
76+
//view.CloseDevToolsActivated += OnViewCloseDevToolsActivated;
77+
//view.ExitActivated += OnViewExitActivated;
78+
79+
//// edit
80+
//view.UndoActivated += OnViewUndoActivated;
81+
//view.RedoActivated += OnViewRedoActivated;
82+
//view.CutActivated += OnViewCutActivated;
83+
//view.CopyActivated += OnViewCopyActivated;
84+
//view.PasteActivated += OnViewPasteActivated;
85+
//view.DeleteActivated += OnViewDeleteActivated;
86+
//view.SelectAllActivated += OnViewSelectAllActivated;
87+
88+
//// test
89+
//view.TestResourceLoadActivated += OnViewTestResourceLoadActivated;
90+
//view.TestSchemeLoadActivated += OnViewTestSchemeLoadActivated;
91+
//view.TestExecuteScriptActivated += OnViewTestExecuteScriptActivated;
92+
//view.TestEvaluateScriptActivated += OnViewTestEvaluateScriptActivated;
93+
//view.TestBindActivated += OnViewTestBindActivated;
94+
//view.TestConsoleMessageActivated += OnViewTestConsoleMessageActivated;
95+
//view.TestTooltipActivated += OnViewTestTooltipActivated;
96+
//view.TestPopupActivated += OnViewTestPopupActivated;
97+
//view.TestLoadStringActivated += OnViewTestLoadStringActivated;
98+
//view.TestCookieVisitorActivated += OnViewTestCookieVisitorActivated;
99+
100+
//// navigation
101+
view.UrlActivated += OnViewUrlActivated;
102+
//view.ForwardActivated += OnViewForwardActivated;
103+
//view.BackActivated += OnViewBackActivated;
104+
}
97105

98-
// private void OnModelPropertyChanged(object sender, PropertyChangedEventArgs e)
99-
// {
100-
// switch (e.PropertyName)
101-
// {
102-
// case "IsBrowserInitialized":
103-
// if (model.IsBrowserInitialized)
104-
// {
105-
// //model.Load(DefaultUrl);
106-
// }
107-
// break;
108-
109-
// case "Title":
110-
// uiThreadInvoke(() => view.SetTitle(model.Title));
111-
// break;
112-
113-
// case "Uri":
114-
// uiThreadInvoke(() => view.SetAddress(model.Address));
115-
// break;
116-
117-
// case "CanGoBack":
118-
// uiThreadInvoke(() => view.SetCanGoBack(model.CanGoBack));
119-
// break;
120-
121-
// case "CanGoForward":
122-
// uiThreadInvoke(() => view.SetCanGoForward(model.CanGoForward));
123-
// break;
124-
125-
// case "IsLoading":
126-
// uiThreadInvoke(() => view.SetIsLoading(model.IsLoading));
127-
// break;
128-
// }
129-
// }
106+
private void OnModelPropertyChanged(object sender, PropertyChangedEventArgs e)
107+
{
108+
switch (e.PropertyName)
109+
{
110+
//case "IsBrowserInitialized":
111+
// if (model.IsBrowserInitialized)
112+
// {
113+
// //model.Load(DefaultUrl);
114+
// }
115+
// break;
116+
117+
case "Title":
118+
uiThreadInvoke(() => view.SetTitle(model.Title));
119+
break;
120+
121+
case "Address":
122+
uiThreadInvoke(() => view.SetAddress(model.Address));
123+
break;
124+
125+
case "CanGoBack":
126+
uiThreadInvoke(() => view.SetCanGoBack(model.CanGoBack));
127+
break;
128+
129+
case "CanGoForward":
130+
uiThreadInvoke(() => view.SetCanGoForward(model.CanGoForward));
131+
break;
132+
133+
case "IsLoading":
134+
uiThreadInvoke(() => view.SetIsLoading(model.IsLoading));
135+
break;
136+
}
137+
}
130138

131139
// private void OnModelConsoleMessage(object sender, ConsoleMessageEventArgs e)
132140
// {
@@ -257,10 +265,10 @@ public static void Init()
257265
// Cef.VisitAllCookies(this);
258266
// }
259267

260-
// private void OnViewUrlActivated(object sender, string address)
261-
// {
262-
// //model.Load(address);
263-
// }
268+
private void OnViewUrlActivated(object sender, string address)
269+
{
270+
model.Load(address);
271+
}
264272

265273
// private void OnViewBackActivated(object sender, EventArgs e)
266274
// {
@@ -272,39 +280,39 @@ public static void Init()
272280
// model.Forward();
273281
// }
274282

275-
// bool IRequestHandler.OnBeforeBrowse(IWebBrowser browser, IRequest request, NavigationType naigationvType, bool isRedirect)
276-
// {
277-
// return false;
278-
// }
283+
bool IRequestHandler.OnBeforeBrowse(IWebBrowser browser, IRequest request, NavigationType naigationvType, bool isRedirect)
284+
{
285+
return false;
286+
}
279287

280-
// bool IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse)
281-
// {
282-
// IRequest request = requestResponse.Request;
283-
// if (request.Url.StartsWith(resource_url.ToString()))
284-
// {
285-
// Stream resourceStream = new MemoryStream(Encoding.UTF8.GetBytes(
286-
// "<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>"));
287-
// requestResponse.RespondWith(resourceStream, "text/html");
288-
// }
288+
bool IRequestHandler.OnBeforeResourceLoad(IWebBrowser browser, IRequestResponse requestResponse)
289+
{
290+
IRequest request = requestResponse.Request;
291+
if (request.Url.StartsWith(resource_url.ToString()))
292+
{
293+
Stream resourceStream = new MemoryStream(Encoding.UTF8.GetBytes(
294+
"<html><body><h1>Success</h1><p>This document is loaded from a System.IO.Stream</p></body></html>"));
295+
requestResponse.RespondWith(resourceStream, "text/html");
296+
}
289297

290-
// return false;
291-
// }
298+
return false;
299+
}
292300

293-
// void IRequestHandler.OnResourceResponse(IWebBrowser browser, string url, int status, string statusText, string mimeType, WebHeaderCollection headers)
294-
// {
301+
void IRequestHandler.OnResourceResponse(IWebBrowser browser, string url, int status, string statusText, string mimeType, WebHeaderCollection headers)
302+
{
295303

296-
// }
304+
}
297305

298-
// bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, out IDownloadHandler handler)
299-
// {
300-
// handler = new DownloadHandler();
301-
// return true;
302-
// }
306+
bool IRequestHandler.GetDownloadHandler(IWebBrowser browser, out IDownloadHandler handler)
307+
{
308+
handler = new DownloadHandler();
309+
return true;
310+
}
303311

304-
// bool IRequestHandler.GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme, ref string username, ref string password)
305-
// {
306-
// return false;
307-
// }
312+
bool IRequestHandler.GetAuthCredentials(IWebBrowser browser, bool isProxy, string host, int port, string realm, string scheme, ref string username, ref string password)
313+
{
314+
return false;
315+
}
308316

309317
// bool ICookieVisitor.Visit(Cookie cookie, int count, int total, ref bool deleteCookie)
310318
// {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{882505AD-246D-402A-8414-347EFB8E2C8D}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>CefSharp.WinForm</RootNamespace>
11+
<AssemblyName>CefSharp.WinForm</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
<PlatformTarget>x86</PlatformTarget>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
35+
<PlatformTarget>x64</PlatformTarget>
36+
<OutputPath>bin\x64\Debug\</OutputPath>
37+
</PropertyGroup>
38+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
39+
<PlatformTarget>x64</PlatformTarget>
40+
<OutputPath>bin\x64\Release\</OutputPath>
41+
</PropertyGroup>
42+
<PropertyGroup>
43+
<SignAssembly>true</SignAssembly>
44+
</PropertyGroup>
45+
<PropertyGroup>
46+
<AssemblyOriginatorKeyFile>..\CefSharp.snk</AssemblyOriginatorKeyFile>
47+
</PropertyGroup>
48+
<ItemGroup>
49+
<Reference Include="System" />
50+
<Reference Include="System.Core" />
51+
<Reference Include="System.Windows.Forms" />
52+
<Reference Include="System.Xml.Linq" />
53+
<Reference Include="System.Data.DataSetExtensions" />
54+
<Reference Include="Microsoft.CSharp" />
55+
<Reference Include="System.Data" />
56+
<Reference Include="System.Xml" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Compile Include="Properties\AssemblyInfo.cs" />
60+
<Compile Include="WebView.cs">
61+
<SubType>Component</SubType>
62+
</Compile>
63+
</ItemGroup>
64+
<ItemGroup>
65+
<ProjectReference Include="..\CefSharp\CefSharp.vcxproj">
66+
<Project>{7b495581-2271-4f41-9476-acb86e8c864f}</Project>
67+
<Name>CefSharp</Name>
68+
</ProjectReference>
69+
</ItemGroup>
70+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
71+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
72+
Other similar extension points exist, see Microsoft.Common.targets.
73+
<Target Name="BeforeBuild">
74+
</Target>
75+
<Target Name="AfterBuild">
76+
</Target>
77+
-->
78+
</Project>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("CefSharp.WinForm")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Health Communication Network")]
12+
[assembly: AssemblyProduct("CefSharp.WinForm")]
13+
[assembly: AssemblyCopyright("Copyright © Health Communication Network 2013")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("eee96178-7e5c-49a2-854c-b2fabe0b8ecf")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)