Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3k
CefSharp 43
CefSharp 43 provides much better access to the underlyingCEF API and as such there are many changes over version41. A number of changes will be required when updating. This document provides some information, if you have something to add then please be aware that any registeredGitHub user an contribute.
Expose
IFrameandIBrowserinterfaces.Access to the underlying popup browser wrappers.
New CEF binary files need to be included with
libcef.dll, etc.:natives_blob.binsnapshot_blob.binBreaking changes for many handlers
Built-in PDF viewer removed. See#1144 for workaround.
The following are now deprecated:
IWebBrowser.CanReload, useIWebBrowser.IsLoadinginstead (will be removed from the threeChromiumWebBrowserinstances).FrameLoadStartEventArgs.IsMainFrameuseFrameLoadStartEventArgs.Frame.IsMaininsteadFrameLoadEndEventArgs.IsMainFrameuseFrameLoadEndEventArgs.Frame.IsMaininstead
PR's tagged as
breaking changecan be found athttps://github.com/cefsharp/CefSharp/issues?utf8=%E2%9C%93&q=label%3Abreaking-change+is%3Amerged+milestone%3A43.0.0WCF can now be disabled via
CefSharpSettings.WcfEnabled = false;. Disables JavaScript object binding. Native ChromeIPCused instead for allIPC,ExecuteScriptAsyncandEvaluateScriptAsync.Changed to using
process-per-tabmodel (OneRender ProcessperChromiumWebBrowserinstance). This is to workaround a problem with the nativeIPCandJavascriptBinding.
Most of the public facingAPI has breaking changes, the scheme handler implementation was totally rewritten to simplify the underlying code, give you access to underlyingAPI. The Handler interfaces have also undergone major changes, the key concepts are outlined below. There are unfortunately too many changes to list them all.
//To upgrade: add new parameters. Code logic does not need to change.publicSchemeHandlerFactory:ISchemeHandlerFactory{//OldISchemeHandlerCreate(){returnhandler;}//NewpublicIResourceHandlerCreate(IBrowserbrowser,IFrameframe,stringschemeName,IRequestrequest){//To read a file of disk no need to implement your own handlerif(schemeName==SchemeName&&request.Url.EndsWith("CefSharp.Core.xml",System.StringComparison.OrdinalIgnoreCase)){//Display the CefSharp.Core.xml file in the browserreturnResourceHandler.FromFileName("CefSharp.Core.xml",".xml");}returnnewCefSharpSchemeHandler();}}
//NOTE: ISchemeHandler renamed to IResourceHandler (shares code with ResourceHandler implementation)publicclassCefSharpSchemeHandler:IResourceHandler{//Old:publicboolProcessRequestAsync(IRequestrequest,ISchemeHandlerResponseresponse,OnRequestCompletedHandlerrequestCompletedCallback){//Processing goes here...returntrue;}//New://To upgrade: store the response stream in a class field, then call callback.Continue() instead of the old `requestCompletedCallback`.//See here for example of new usage: https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp.Example/CefSharpSchemeHandler.cspublicboolProcessRequestAsync(IRequestrequest,ICallbackcallback){Task.Run(()=>{// Base to dispose of callback as it wraps a managed resourceusing(callback){//Perform processing here// When processing complete call continuecallback.Continue();}});returntrue;}publicStreamGetResponse(IResponseresponse,outlongresponseLength,outstringredirectUrl){//How long is your stream?responseLength=stream.Length;//Set to null if not redirecting to a different urlredirectUrl=null;//Set response related stuff hereresponse.StatusCode=(int)HttpStatusCode.OK;response.StatusText="OK";response.MimeType=mimeType;//Return your populated streamreturnstream;}}
Most handler interfaces,IKeyboardHandler,IRequestHandler, etc no provide access to the underlyingCefBrowser through theIBrowser interface.IMenuHandler was renamed toIContextMenuHandler (matches the underlying CefContextMenuHandler naming).WhilstIBrowser wraps a managed resource, please don't callDispose(),CefSharp will take care of this.Some handlers will also exposeIFrame interface which wrapsCefFrame, again, don'tDispose(). You will also note the appearance of many callbackinterfaces, for exampleIRequestCallback. You can now perform tasks in an async operation. We do reccomend youDispose() of the callbacks when your finished as they wrap anunmanaged resource. (Easiest way is ausing() block.
Example of the updated IKeyboardHandler interface
publicclassKeyboardHandler:IKeyboardHandler{//Old:publicboolOnKeyEvent(IWebBrowserbrowserControl,KeyTypetype,intwindowsKeyCode,CefEventFlagsmodifiers,boolisSystemKey){returnfalse;}//New:publicboolOnPreKeyEvent(IWebBrowserbrowserControl,IBrowserbrowser,KeyTypetype,intwindowsKeyCode,intnativeKeyCode,CefEventFlagsmodifiers,boolisSystemKey,refboolisKeyboardShortcut){returnfalse;}}
Seehttps://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp.Example/RequestHandler.cs
publicclassRequestHandler:IRequestHandler{//NOTE: In some cases new methods have been added, check the interface documentation for more details.//e.g. https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp/IRequestHandler.cs#L43boolIRequestHandler.OnOpenUrlFromTab(IWebBrowserbrowserControl,IBrowserbrowser,IFrameframe,stringtargetUrl,WindowOpenDispositiontargetDisposition,booluserGesture){returnfalse;}//NOTE: The IWebBrowser control variable is now called browserControl, you now have access to IBrowser, IFrame and in this instance IRequestCallbackCefReturnValueIRequestHandler.OnBeforeResourceLoad(IWebBrowserbrowserControl,IBrowserbrowser,IFrameframe,IRequestrequest,IRequestCallbackcallback){//NOTE: If you do not wish to implement this method returning false is the default behaviour// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.//callback.Dispose();//return false;//NOTE: When executing the callback in an async fashion need to check to see if it's disposedif(!callback.IsDisposed){using(callback){//Do some stuff here//Callback in async fashion//callback.Continue(true);//return CefReturnValue.ContinueAsync;}}returnCefReturnValue.Continue;}}
The settings have been simplified and now closely mimic the behavior ofCEF.
browserSettings.ImageLoadingDisabled=true;becomesbrowserSettings.ImageLoading=CefState.Disabled;(Theenum has three states CefState.Default,CefState.Enabled,CefState.Disabled