Allow changing wxWebViewBackendChromium data directory path

Use the value provided via wxWebViewConfiguration::SetDataPath() if any.
This commit is contained in:
Vadim Zeitlin 2024-01-06 03:19:48 +01:00
parent 416e241e6a
commit 30c8c64e45
3 changed files with 33 additions and 7 deletions

View file

@ -173,7 +173,7 @@ private:
friend class wxWebViewChromiumModule;
static bool ms_cefInitialized;
static bool InitCEF();
static bool InitCEF(const wxWebViewConfiguration& config);
static void ShutdownCEF();

View file

@ -339,7 +339,8 @@ public:
local storage, etc.
@param path The path to the data directory.
@note This is only used by the Edge and WebKit2GTK+ backend.
@note This is used by Edge, WebKit2GTK+ and Chromium backends (the
latter creates "UserData" subdirectory under the given path).
*/
void SetDataPath(const wxString& path);
@ -350,7 +351,8 @@ public:
local storage, etc.
@return The path to the data directory.
@note This is only used by the Edge and WebKit2GTK+ backend.
@note This is used by Edge, WebKit2GTK+ and Chromium backends and
always returns empty string for the other ones.
*/
wxString GetDataPath() const;
};

View file

@ -261,6 +261,19 @@ public:
return wxWebViewConfiguration(wxWebViewBackendChromium,
new wxWebViewConfigurationImplChromium);
}
virtual void SetDataPath(const wxString& path) override
{
m_dataPath = path;
}
virtual wxString GetDataPath() const override
{
return m_dataPath;
}
private:
wxString m_dataPath;
};
// ----------------------------------------------------------------------------
@ -675,7 +688,7 @@ bool wxWebViewChromium::Create(wxWindow* parent,
{
return false;
}
if ( !InitCEF() )
if ( !InitCEF(m_implData->m_config) )
return false;
#ifdef __WXMSW__
@ -931,7 +944,7 @@ bool CheckCEFLoadOrder()
#endif // __LINUX__
bool wxWebViewChromium::InitCEF()
bool wxWebViewChromium::InitCEF(const wxWebViewConfiguration& config)
{
if (ms_cefInitialized)
return true;
@ -941,8 +954,19 @@ bool wxWebViewChromium::InitCEF()
return false;
#endif
wxFileName cefDataFolder(wxStandardPaths::Get().GetUserLocalDataDir(), "");
cefDataFolder.AppendDir("CEF");
wxFileName cefDataFolder;
const wxString& dataDir = config.GetDataPath();
if ( !dataDir.empty() )
{
cefDataFolder = wxFileName::DirName(dataDir);
}
else
{
cefDataFolder = wxFileName::DirName(
wxStandardPaths::Get().GetUserLocalDataDir()
);
cefDataFolder.AppendDir("CEF");
}
cefDataFolder.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
CefSettings settings;