diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs new file mode 100644 index 000000000..e4b2e3989 --- /dev/null +++ b/CefSharp.Example/CefExample.cs @@ -0,0 +1,44 @@ +using System; +using System.Linq; + +namespace CefSharp.Example +{ + public static class CefExample + { + public const string DefaultUrl = "custom://cefsharp/home"; + + // Use when debugging the actual SubProcess, to make breakpoints etc. inside that project work. + private const bool debuggingSubProcess = false; + + public static void Init() + { + var settings = new CefSettings(); + settings.RemoteDebuggingPort = 8088; + + if (debuggingSubProcess) + { + settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\x86\\Debug\\CefSharp.BrowserSubprocess.exe"; + } + + settings.RegisterScheme(new CefCustomScheme + { + SchemeName = CefSharpSchemeHandlerFactory.SchemeName, + SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() + }); + + if (!Cef.Initialize(settings)) + { + if (Environment.GetCommandLineArgs().Contains("--type=renderer")) + { + Environment.Exit(0); + } + else + { + return; + } + } + + Cef.RegisterJsObject("bound", new BoundObject()); + } + } +} diff --git a/CefSharp.Example/CefSharp.Example.csproj b/CefSharp.Example/CefSharp.Example.csproj index f6591c4cc..8abc6f4ef 100644 --- a/CefSharp.Example/CefSharp.Example.csproj +++ b/CefSharp.Example/CefSharp.Example.csproj @@ -85,6 +85,7 @@ + diff --git a/CefSharp.Example/ExamplePresenter.cs b/CefSharp.Example/ExamplePresenter.cs index bc7501422..903011b88 100644 --- a/CefSharp.Example/ExamplePresenter.cs +++ b/CefSharp.Example/ExamplePresenter.cs @@ -1,50 +1,11 @@ using System; using System.IO; -using System.Linq; -using System.Net; using System.Text; namespace CefSharp.Example { public class ExamplePresenter : IRequestHandler { - // Use when debugging the actual SubProcess, to make breakpoints etc. inside that project work. - private const bool debuggingSubProcess = false; - - public static void Init() - { - var settings = new CefSettings(); - settings.RemoteDebuggingPort = 8088; - - if (debuggingSubProcess) - { - settings.BrowserSubprocessPath = "..\\..\\..\\..\\CefSharp.BrowserSubprocess\\bin\\x86\\Debug\\CefSharp.BrowserSubprocess.exe"; - } - - //NOTE: Add command line args before Cef.Initialize() called - //settings.CefCommandLineArgs.Add("user-agent", "me"); - settings.RegisterScheme(new CefCustomScheme - { - SchemeName = CefSharpSchemeHandlerFactory.SchemeName, - SchemeHandlerFactory = new CefSharpSchemeHandlerFactory() - }); - - if (!Cef.Initialize(settings)) - { - if (Environment.GetCommandLineArgs().Contains("--type=renderer")) - { - Environment.Exit(0); - } - else - { - return; - } - } - - Cef.RegisterJsObject("bound", new BoundObject()); - } - - public static string DefaultUrl = "custom://cefsharp/home"; private static readonly Uri resource_url = new Uri("http://test/resource/load"); private readonly IWebBrowser model; diff --git a/CefSharp.WinForms.Example/BrowserForm.cs b/CefSharp.WinForms.Example/BrowserForm.cs index 4201cd6d1..f8ff1d6cb 100644 --- a/CefSharp.WinForms.Example/BrowserForm.cs +++ b/CefSharp.WinForms.Example/BrowserForm.cs @@ -19,7 +19,7 @@ namespace CefSharp.WinForms.Example Text = "CefSharp"; WindowState = FormWindowState.Maximized; - browser = new ChromiumWebBrowser(ExamplePresenter.DefaultUrl) + browser = new ChromiumWebBrowser(CefExample.DefaultUrl) { Dock = DockStyle.Fill, }; diff --git a/CefSharp.WinForms.Example/Program.cs b/CefSharp.WinForms.Example/Program.cs index 1974884aa..86aa2c101 100644 --- a/CefSharp.WinForms.Example/Program.cs +++ b/CefSharp.WinForms.Example/Program.cs @@ -9,7 +9,7 @@ namespace CefSharp.WinForms.Example [STAThread] static void Main() { - ExamplePresenter.Init(); + CefExample.Init(); var browser = new BrowserForm(); Application.Run(browser); diff --git a/CefSharp.Wpf.Example/App.xaml.cs b/CefSharp.Wpf.Example/App.xaml.cs index 6d17f6793..7018df835 100644 --- a/CefSharp.Wpf.Example/App.xaml.cs +++ b/CefSharp.Wpf.Example/App.xaml.cs @@ -11,7 +11,7 @@ namespace CefSharp.Wpf.Example { private App() { - ExamplePresenter.Init(); + CefExample.Init(); } } } \ No newline at end of file diff --git a/CefSharp.Wpf.Example/MainWindow.xaml.cs b/CefSharp.Wpf.Example/MainWindow.xaml.cs index 7ce33905c..cd251257b 100644 --- a/CefSharp.Wpf.Example/MainWindow.xaml.cs +++ b/CefSharp.Wpf.Example/MainWindow.xaml.cs @@ -63,7 +63,7 @@ namespace CefSharp.Wpf.Example private void MainWindowLoaded(object sender, RoutedEventArgs e) { - CreateNewTab(ExamplePresenter.DefaultUrl, true); + CreateNewTab(CefExample.DefaultUrl, true); } private void CreateNewTab(string url = DefaultUrlForAddedTabs, bool showSideBar = false) diff --git a/CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs b/CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs index 3a1d19fff..b202b25ad 100644 --- a/CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs +++ b/CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs @@ -76,7 +76,7 @@ namespace CefSharp.Wpf.Example.ViewModels AddressEditable = Address; GoCommand = new DelegateCommand(Go, () => !String.IsNullOrWhiteSpace(Address)); - HomeCommand = new DelegateCommand(() => AddressEditable = Address = ExamplePresenter.DefaultUrl); + HomeCommand = new DelegateCommand(() => AddressEditable = Address = CefExample.DefaultUrl); ExecuteJavaScriptCommand = new DelegateCommand(ExecuteJavaScript, s => !String.IsNullOrWhiteSpace(s)); EvaluateJavaScriptCommand = new DelegateCommand(EvaluateJavaScript, s => !String.IsNullOrWhiteSpace(s));