Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Alex Maitland edited this pageDec 1, 2015 ·12 revisions

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.

  • ExposeIFrame andIBrowser interfaces.

  • Access to the underlying popup browser wrappers.

  • New CEF binary files need to be included withlibcef.dll, etc.:

  • natives_blob.bin

  • snapshot_blob.bin

  • Breaking changes for many handlers

  • Built-in PDF viewer removed. See#1144 for workaround.

  • The following are now deprecated:

    • IWebBrowser.CanReload, useIWebBrowser.IsLoading instead (will be removed from the threeChromiumWebBrowser instances).
    • FrameLoadStartEventArgs.IsMainFrame useFrameLoadStartEventArgs.Frame.IsMain instead
    • FrameLoadEndEventArgs.IsMainFrame useFrameLoadEndEventArgs.Frame.IsMain instead
  • PR's tagged asbreaking change can be found athttps://github.com/cefsharp/CefSharp/issues?utf8=%E2%9C%93&q=label%3Abreaking-change+is%3Amerged+milestone%3A43.0.0

  • WCF can now be disabled viaCefSharpSettings.WcfEnabled = false;. Disables JavaScript object binding. Native ChromeIPC used instead for allIPC,ExecuteScriptAsync andEvaluateScriptAsync.

  • Changed to usingprocess-per-tab model (OneRender Process perChromiumWebBrowser instance). This is to workaround a problem with the nativeIPC andJavascriptBinding.

Breaking Changes

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.

ISchemeHandlerFactory

//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();}}

ISchemeHandler

//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;}}

Handler Interfaces

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;}}

BrowserSettings

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

Anyone with a GitHub account can edit this wiki, contributions are encouraged and welcomed.

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp