From 630ac240738d3d5da476bffa580bee2c5fcf72fd Mon Sep 17 00:00:00 2001 From: Maciej Kolanski Date: Fri, 20 May 2022 14:33:19 +0200 Subject: [PATCH] [EB][ARRISEOS-41993] Use string arguments in IBrowser interface IStringIterator arguments were causing crash of wpeframework. --- WebKitBrowser/WebKitImplementation.cpp | 95 +++++++++++--------------- 1 file changed, 39 insertions(+), 56 deletions(-) diff --git a/WebKitBrowser/WebKitImplementation.cpp b/WebKitBrowser/WebKitImplementation.cpp index 6aeed782e5..96633bc92b 100644 --- a/WebKitBrowser/WebKitImplementation.cpp +++ b/WebKitBrowser/WebKitImplementation.cpp @@ -825,8 +825,8 @@ static GSourceFuncs _handlerIntervention = , _frameCount(0) , _lastDumpTime(g_get_monotonic_time()) , _allowMixedContent(true) - , _userScripts() - , _userStyleSheets() + , _userScript() + , _userStyleSheet() , _securityProfileName() { // Register an @Exit, in case we are killed, with an incorrect ref count !! @@ -866,12 +866,12 @@ static GSourceFuncs _handlerIntervention = public: #ifdef WEBKIT_GLIB_API - uint32_t Headers(IStringIterator*& header) const override { return Core::ERROR_UNAVAILABLE; } - uint32_t Headers(IStringIterator* const header) override { return Core::ERROR_UNAVAILABLE; } - uint32_t UserScripts(IStringIterator*& uris) const override { return Core::ERROR_UNAVAILABLE; } - uint32_t UserScripts(IStringIterator* const uris) override { return Core::ERROR_UNAVAILABLE; } - uint32_t UserStyleSheets(IStringIterator*& uris) const override { return Core::ERROR_UNAVAILABLE; } - uint32_t UserStyleSheets(IStringIterator* const uris) override { return Core::ERROR_UNAVAILABLE; } + uint32_t Headers(string& header) const override { return Core::ERROR_UNAVAILABLE; } + uint32_t Headers(const string& header) override { return Core::ERROR_UNAVAILABLE; } + uint32_t UserScripts(string& uri) const override { return Core::ERROR_UNAVAILABLE; } + uint32_t UserScripts(const string& uri) override { return Core::ERROR_UNAVAILABLE; } + uint32_t UserStyleSheets(string& uri) const override { return Core::ERROR_UNAVAILABLE; } + uint32_t UserStyleSheets(const string& uri) override { return Core::ERROR_UNAVAILABLE; } uint32_t HeaderList(string& headerlist) const override { return Core::ERROR_UNAVAILABLE; } uint32_t HeaderList(const string& headerlist) override { return Core::ERROR_UNAVAILABLE; } uint32_t UserAgent(string& ua) const override { return Core::ERROR_UNAVAILABLE; } @@ -885,39 +885,31 @@ static GSourceFuncs _handlerIntervention = uint32_t MixedContentPolicy(MixedContentPolicyType& policy) const override { return Core::ERROR_UNAVAILABLE; } uint32_t MixedContentPolicy(const MixedContentPolicyType policy) override { return Core::ERROR_UNAVAILABLE; } #else - uint32_t Headers(IStringIterator*& header) const override + uint32_t Headers(string& header) const override { return Core::ERROR_NONE; } - uint32_t Headers(IStringIterator* const header) override + uint32_t Headers(const string& header) override { return Core::ERROR_NONE; } - uint32_t UserScripts(IStringIterator*& uris) const override + uint32_t UserScripts(string& uri) const override { _adminLock.Lock(); - uris = Core::Service::Create(_userScripts); + uri = _userScript; _adminLock.Unlock(); return Core::ERROR_NONE; } - uint32_t UserScripts(IStringIterator* const uris) override + uint32_t UserScripts(const string& uri) override { - string entry; - std::vector userScriptsContent; - std::list userScriptsUris; - while (uris->Next(entry)) { - auto content = GetFileContent(entry); - if (!content.empty()) { - userScriptsUris.push_back(entry); - userScriptsContent.push_back(content); - } - TRACE_L1("Adding user's script (uri: %s, empty: %d)", entry.c_str(), content.empty()); - } - using SetUserScriptsData = std::tuple, std::vector>; - auto* data = new SetUserScriptsData(this, userScriptsUris, userScriptsContent); + const auto content = GetFileContent(uri); + TRACE_L1("Setting user's script (uri: %s, empty: %d)", uri.c_str(), content.empty()); + + using SetUserScriptsData = std::tuple; + auto* data = new SetUserScriptsData(this, uri, content); g_main_context_invoke_full( _context, @@ -925,20 +917,19 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); - std::list scriptsUris = std::get<1>(data); - std::vector scriptsContent = std::get<2>(data); + const auto& scriptUri = std::get<1>(data); + const auto& scriptContent = std::get<2>(data); object->_adminLock.Lock(); - object->_userScripts = scriptsUris; + object->_userScript = scriptUri; object->_adminLock.Unlock(); // Remove all user scripts WKPageGroupRemoveAllUserScripts(object->_pageGroup); - - for (string entry : scriptsContent) { + if (!scriptContent.empty()) { WKPageGroupAddUserScript( object->_pageGroup, - WKStringCreateWithUTF8CString(entry.c_str()), + WKStringCreateWithUTF8CString(scriptContent.c_str()), nullptr, nullptr, nullptr, @@ -946,6 +937,7 @@ static GSourceFuncs _handlerIntervention = kWKInjectAtDocumentStart); } + return G_SOURCE_REMOVE; }, data, @@ -956,28 +948,20 @@ static GSourceFuncs _handlerIntervention = return Core::ERROR_NONE; } - uint32_t UserStyleSheets(IStringIterator*& uris) const override + uint32_t UserStyleSheets(string& uri) const override { _adminLock.Lock(); - uris = Core::Service::Create(_userStyleSheets); + uri = _userStyleSheet; _adminLock.Unlock(); return Core::ERROR_NONE; } - uint32_t UserStyleSheets(IStringIterator* const uris) override + uint32_t UserStyleSheets(const string& uri) override { - string entry; - std::vector userStyleSheetsContent; - std::list userStyleSheetsUris; - while (uris->Next(entry)) { - auto content = GetFileContent(entry); - if (!content.empty()) { - userStyleSheetsUris.push_back(entry); - userStyleSheetsContent.push_back(content); - } - TRACE_L1("Adding user's style sheet (uri: %s, empty: %d)", entry.c_str(), content.empty()); - } - using SetUserStyleSheetsData = std::tuple, std::vector>; - auto* data = new SetUserStyleSheetsData(this, userStyleSheetsUris, userStyleSheetsContent); + const auto content = GetFileContent(uri); + TRACE_L1("Setting user's style sheet (uri: %s, empty: %d)", uri.c_str(), content.empty()); + + using SetUserStyleSheetsData = std::tuple; + auto* data = new SetUserStyleSheetsData(this, uri, content); g_main_context_invoke_full( _context, @@ -985,20 +969,19 @@ static GSourceFuncs _handlerIntervention = [](gpointer customdata) -> gboolean { auto& data = *static_cast(customdata); WebKitImplementation* object = std::get<0>(data); - std::list styleSheetsUris = std::get<1>(data); - std::vector styleSheetsContent = std::get<2>(data); + const auto& styleSheetUri = std::get<1>(data); + const auto& styleSheetContent = std::get<2>(data); object->_adminLock.Lock(); - object->_userStyleSheets = styleSheetsUris; + object->_userStyleSheet = styleSheetUri; object->_adminLock.Unlock(); // Remove all style sheets WKPageGroupRemoveAllUserStyleSheets(object->_pageGroup); - - for (string entry : styleSheetsContent) { + if (!styleSheetContent.empty()) { WKPageGroupAddUserStyleSheet( object->_pageGroup, - WKStringCreateWithUTF8CString(entry.c_str()), + WKStringCreateWithUTF8CString(styleSheetContent.c_str()), nullptr, nullptr, nullptr, @@ -3163,8 +3146,8 @@ static GSourceFuncs _handlerIntervention = unsigned _frameCount; gint64 _lastDumpTime; bool _allowMixedContent; - std::list _userScripts; - std::list _userStyleSheets; + string _userScript; + string _userStyleSheet; string _securityProfileName; };