Skip to content

Chromium NetworkService API Changes #2743

@amaitland

Description

@amaitland

Chromium is moving from an in-process network stack implementation to a separate NetworkService process.

Due to Chromium changes CEF will be implementing some dramatic API changes. Relevant upstream issue is https://bitbucket.org/chromiumembedded/cef/issues/2622/implement-support-for-networkservice

Chromium is moving to a Network Service, this means that network requests will be handled using a separate process, just like rendering, gpu acceleration, etc.

Known behaviour changes:

  • Modifying the newUrl parameter in OnResourceRedirect will no longer result in the method being called an additional time (likely a bug in the old implementation).
  • Modifying the request URL in OnResourceResponse would previously cause a redirect. This behaviour is now deprecated because the NetworkService does not support this functionality when using default network loaders. Temporary support has been added in combination with IResourceHandler usage only. - Other changes to the request object in OnResourceResponse will now cause the request to be restarted. This means that OnBeforeResourceLoad, etc, will be called an additional time with the new request information.
  • IResponse.MimeType will now be empty for non-200 responses.
  • Requests using custom schemes can now be handled via IResourceRequestHandler with the same callback behaviour as builtin schemes.
  • Redirects of custom scheme requests will now be followed as expected.
  • Default handling of builtin schemes can now be disabled by setting disableDefaultHandling to true in GetResourceRequestHandler.
  • Unhandled requests (custom scheme or builtin scheme with default handling disabled) will fail with an Response.Error value of ERR_UNKNOWN_URL_SCHEME.
  • The ISchemeHandlerFactory.Create callback will now include cookie headers.
  • Unsupported chrome hosts no longer redirect to chrome://version.
  • All CachePath values must be relative to a new CefSettings.RootCachePath value.
  • ICookieManager callbacks are now executed on the CEF UI thread (previously the CEF IO thread).
  • Resource-related callbacks have been moved from IRequestHandler to a new IResourceRequestHandler interface which is returned via the IRequestHandler.GetResourceRequestHandler method. If the IRequestHandler declines to handle a resource it can optionally be handled by the IRequestContextHandler, if any, associated with the loading context.
  • The OnProtocolExecution callback has been moved from IRequestHandler to IResourceRequestHandler and will be called if a custom scheme request is unhandled.
  • Cookie send/save permission callbacks have been moved from IRequestHandler and IResourceHandler to IResourceRequestHandler.
  • New methods added to IResourceHandler that better match NetworkService execution sequence expectations. The old methods are now deprecated.
  • New methods added to IRequest and IResponse.
  • All pending and in-progress requests will now be aborted when the CEF context
    or associated browser is destroyed. The OnResourceLoadComplete callback will
    now also be called in this case for in-progress requests that have a handler.
  • The IResourceHandler.Cancel method will now always be called when resource
    handling is complete, irrespective of whether handling completed successfully.
  • Request callbacks that arrive after the OnBeforeClose callback for the
    associated browser (which may happen for in-progress requests that are aborted
    on browser destruction) will now always have a non-nullptr IBrowser
    parameter.
  • Allow empty parameters to IRequest and IResponse methods where it makes
    sense (e.g. resetting default response state, or clearing a referrer value).
  • Modifying the URL in OnBeforeResourceLoad causes an internal redirect response.
  • In cases where the request is cross-origin (containing a non-null "Origin"
    header) the redirect response must include the "Access-Control-Allow-Origin"
    header, otherwise the request will be blocked.
  • For 303 redirects all request methods except HEAD are converted to GET as per
    the latest http draft. For historical reasons the draft also allows POST
    requests to be converted to GETs when following 301/302 redirects. Most major
    browsers do this and so shall we. When a request is converted to GET any POST
    data should also be removed.
  • Use 307 redirects instead if you want the request to be repeated using the same
    method and POST data.

API changes:

  • Add IResourceRequestHandler
  • Add ICookieAccessFilter
  • IRequestHandler.OnBeforeResourceLoad moved to IResourceRequestHandler.OnBeforeResourceLoad
  • IRequestHandler.OnResourceRedirect moved to IResourceRequestHandler.OnResourceRedirect
  • IRequestHandler.OnResourceResponse moved to IResourceRequestHandler.OnResourceResponse
  • IRequestHandler.GetResourceResponseFilter moved to IResourceRequestHandler.GetResourceResponseFilter
  • IRequestHandler.OnResourceLoadComplete moved to IResourceRequestHandler.OnResourceLoadComplete
  • IRequestHandler.OnProtocolExecution moved to IResourceRequestHandler.OnProtocolExecution
  • IRequestHandler.GetAuthCredentials signature change, IFrame frame replaced with string originUrl
  • IDragHandler.OnDraggableRegionsChanged now includes the IFrame param

Cookie Handling

  • Cookies are access is now handled using ICookieAccessFilter which is returned using IResourceRequestHandler.GetCookieAccessFilter
  • Removed IRequestHandler.CanGetCookie
  • Removed IRequestHandler.CanSetCookie
  • Removed IResourceHandler.CanGetCookie
  • Removed IResourceHandler.CanSetCookie
  • Removed ICookieManager.CreateManager
  • Removed ICookieManager.GetBlockingManager
  • Removed ICookieManager.SetStoragePath
  • Removed IRequestContextHandler.GetCookieManager
  • IRequestContext.GetDefaultCookieManager renamed to IRequestContext.GetCookieManager
  • ICookieManager.SetSupportedSchemes has additional bool includeDefaults param.

Request/Scheme Handling

The IRequestHandler interface has been rewritten as the CEF API changed

ResourceHandler Headers

IRequest now has SetHeaderByName and GetHeaderByName which greatly simplifies header get/set.

CefSharp Specific API Changes

  • IResourceHandler.ProcessRequestAsync now returns CefReturnValue instead of bool.
  • IResourceHandler.ProcessRequestAsync is now called in IResourceHandler.Open which is a new method, as the structure has changed.
  • IResourceHandler.GetResponse has been removed
  • 'DefaultRequestHandler' renamed to RequestHandler (DefaultRequestHandler exists as a class for now that's marked as Obsolete)
  • RequestHandler now implements IRequestHandler explicitly an exposes protected virtual methods to override, previously they were public.
  • ISchemeRegistrar.AddCustomScheme now takes a set of SchemeOptions flags to represent the different options instead of a bool for each param type. Brings the interface in line with the CEF API.
  • CefSharp.Legacy.LegacyResourceHandlerFactory has been removed.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions