Refactor OnContextInitialized out as part of IBrowserProcessHandler interface

Add OnScheduleMessagePumpWork for use with integrating into existing message loop - probably better for WinForms integration, will look at providing an example later
This commit is contained in:
amaitland
2016-07-20 13:08:47 +10:00
parent 20503f2289
commit 63ef6beb5f
8 changed files with 106 additions and 43 deletions
+2 -18
View File
@@ -6,6 +6,7 @@ using System;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using CefSharp.Example.Handlers;
using CefSharp.Example.Properties;
using CefSharp.Example.Proxy;
using CefSharp.Internals;
@@ -165,24 +166,7 @@ namespace CefSharp.Example
settings.FocusedNodeChangedEnabled = true;
//The Request Context has been initialized, you can now set preferences, like proxy server settings
Cef.OnContextInitialized = delegate
{
var cookieManager = Cef.GetGlobalCookieManager();
cookieManager.SetStoragePath("cookies", true);
cookieManager.SetSupportedSchemes("custom");
//Dispose of context when finished - preferable not to keep a reference if possible.
using (var context = Cef.GetGlobalRequestContext())
{
string errorMessage;
//You can set most preferences using a `.` notation rather than having to create a complex set of dictionaries.
//The default is true, you can change to false to disable
context.SetPreference("webkit.webprefs.plugins_enabled", true, out errorMessage);
}
};
if (!Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: !DebuggingSubProcess))
if (!Cef.Initialize(settings, performDependencyCheck: !DebuggingSubProcess, browserProcessHandler: new BrowserProcessHandler()))
{
throw new Exception("Unable to Initialize Cef");
}
+1
View File
@@ -77,6 +77,7 @@
<Compile Include="FlashResourceHandler.cs" />
<Compile Include="FlashResourceHandlerFactory.cs" />
<Compile Include="Filters\PassThruResponseFilter.cs" />
<Compile Include="Handlers\BrowserProcessHandler.cs" />
<Compile Include="InMemorySchemeAndResourceHandlerFactory.cs" />
<Compile Include="ScriptedMethodsBoundObject.cs" />
<Compile Include="ExceptionTestBoundObject.cs" />
@@ -0,0 +1,31 @@
// Copyright © 2010-2016 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
namespace CefSharp.Example.Handlers
{
public class BrowserProcessHandler : IBrowserProcessHandler
{
void IBrowserProcessHandler.OnContextInitialized()
{
//The Request Context has been initialized, you can now set preferences, like proxy server settings
var cookieManager = Cef.GetGlobalCookieManager();
cookieManager.SetStoragePath("cookies", true);
cookieManager.SetSupportedSchemes("custom");
//Dispose of context when finished - preferable not to keep a reference if possible.
using (var context = Cef.GetGlobalRequestContext())
{
string errorMessage;
//You can set most preferences using a `.` notation rather than having to create a complex set of dictionaries.
//The default is true, you can change to false to disable
context.SetPreference("webkit.webprefs.plugins_enabled", true, out errorMessage);
}
}
void IBrowserProcessHandler.OnScheduleMessagePumpWork(long delay)
{
//TODO: Schedule work on the UI thread - call Cef.DoMessageLoopWork
}
}
}