From 30c8c64e4599ad7ba0497d20575fd2dca3ecbb2b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 6 Jan 2024 03:19:48 +0100 Subject: [PATCH] Allow changing wxWebViewBackendChromium data directory path Use the value provided via wxWebViewConfiguration::SetDataPath() if any. --- include/wx/webview_chromium.h | 2 +- interface/wx/webview.h | 6 ++++-- src/common/webview_chromium.cpp | 32 ++++++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/include/wx/webview_chromium.h b/include/wx/webview_chromium.h index 4552ca82e0..6563ceac51 100644 --- a/include/wx/webview_chromium.h +++ b/include/wx/webview_chromium.h @@ -173,7 +173,7 @@ private: friend class wxWebViewChromiumModule; static bool ms_cefInitialized; - static bool InitCEF(); + static bool InitCEF(const wxWebViewConfiguration& config); static void ShutdownCEF(); diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 7bbda33d1b..b37d237247 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -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; }; diff --git a/src/common/webview_chromium.cpp b/src/common/webview_chromium.cpp index d6c5c2bfee..93fe8b7f27 100644 --- a/src/common/webview_chromium.cpp +++ b/src/common/webview_chromium.cpp @@ -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;