chromiumembedded / cef

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
https://bitbucket.org/chromiumembedded/cef/
Other
3.27k stars 457 forks source link

When cache_path is empty, CEF fails to load resource using a custom scheme #3633

Closed ckearney-nitro closed 8 months ago

ckearney-nitro commented 8 months ago

Describe the bug CEF is unable to load resource when using a custom schemes and the browser is in incognito mode (cache_path is empty).

To Reproduce

CefSettings settings = {};
settings.root_cache_path = C:/myapp/cef_cache/

I have a class ClientApp which is derived from CefApp and implements OnRegisterCustomSchemes to add my custom scheme

void ClientApp::OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar)
{
    registrar->AddCustomScheme("dll-resource", cef_scheme_options_t::CEF_SCHEME_OPTION_DISPLAY_ISOLATED);
}

I call 'CefInitialize' with my client app and settings listed above and I can see the 'OnRegisterCustomSchemes' callback being called. After a successful CefInitialize, I then register my scheme handler factory. Class dll_resource_scheme_handler implements the create function CefSchemeHandlerFactory

CefRefPtr<CefSchemeHandlerFactory> dll_scheme_handler_factory{new dll_resource_scheme_handler{}};
CefRegisterSchemeHandlerFactory("dll-resource", "id", dll_scheme_handler_factory);

When it comes to creating the browser:

CefBrowserSettings settings = {};
CefRequestContextSettings context_settings = {};
auto request_context = CefRequestContext::CreateContext(context_settings, nullptr);
return CefBrowserHost::CreateBrowser(<windowInfo>, <client_handler>, "dll-resource://id/919", settings, nullptr, request_context);

The object passed into client_handler parameter implements the OnLoadError function, and that function is called with these parmeters by CEF.

OnLoadError(<browser>, <frame>, -320, "ERR_UNKNOWN_URL_SCHEME", "dll-resource://id/919")

Expected behavior I would expect the URL scheme to be known if the is the browser is in incognito mode.

When the browser is not in incognito mode (the cache_path for both CefRequestContextSettings and CefSettings to be the same as root_cahe_path). I don't get the OnLoadError call.

Screenshots The screenshot shows the order of some functions being call from handlers. On the left is a successful run, when the application is not in incognito mode and on the right is when the application is in incognito mode.

image

Versions (please complete the following information):

magreenblatt commented 8 months ago

the cache_path for both CefRequestContextSettings and CefSettings to be the same as root_cahe_path

This uses the same global request context, so global scheme registration is used.

CefRequestContextSettings context_settings = {}; auto request_context = CefRequestContext::CreateContext(context_settings, nullptr);

This creates a new/isolated request context, so you need to call CefRequestContext::RegisterSchemeHandlerFactory.