@@ -31,6 +31,9 @@ CWebCore::CWebCore()
3131 m_bTestmodeEnabled = false ;
3232 m_pXmlConfig = nullptr ;
3333 m_pFocusedWebView = nullptr ;
34+ m_bGPUEnabled = false ;
35+ m_iWhitelistRevision = 0 ;
36+ m_iBlacklistRevision = 0 ;
3437
3538 MakeSureXMLNodesExist ();
3639 InitialiseWhiteAndBlacklist ();
@@ -92,12 +95,14 @@ bool CWebCore::Initialise(bool gpuEnabled)
9295 settings.multi_threaded_message_loop = true ;
9396 settings.windowless_rendering_enabled = true ;
9497
95- bool state = CefInitialize (mainArgs, settings, app, sandboxInfo);
96-
97- // Register custom scheme handler factory
98- CefRegisterSchemeHandlerFactory (" http" , " mta" , app);
98+ if (const bool state = CefInitialize (mainArgs, settings, app, sandboxInfo); state) [[likely]]
99+ {
100+ // Register custom scheme handler factory only if initialization succeeded
101+ CefRegisterSchemeHandlerFactory (" http" , " mta" , app);
102+ return true ;
103+ }
99104
100- return state ;
105+ return false ;
101106}
102107
103108CWebViewInterface* CWebCore::CreateWebView (unsigned int uiWidth, unsigned int uiHeight, bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem,
@@ -243,19 +248,17 @@ void CWebCore::WaitForTask(std::function<void(bool)> task, CWebView* webView)
243248 {
244249 std::scoped_lock lock (m_TaskQueueMutex);
245250
246- // Prevent unbounded queue growth - if queue is too large, oldest tasks will be dropped during pulse
247- if (m_TaskQueue.size () >= MAX_TASK_QUEUE_SIZE)
251+ // Prevent unbounded queue growth - abort new task if queue is too large
252+ if (m_TaskQueue.size () >= MAX_TASK_QUEUE_SIZE) [[unlikely]]
248253 {
249254#ifdef MTA_DEBUG
250- g_pCore->GetConsole ()->Printf (" Warning: Task queue size limit reached (%d), task will be aborted" , MAX_TASK_QUEUE_SIZE);
255+ static constexpr auto WARNING_MSG = " Warning: Task queue size limit reached (%d), aborting new task" ;
256+ g_pCore->GetConsole ()->Printf (WARNING_MSG, MAX_TASK_QUEUE_SIZE);
251257#endif
252- // Must still queue the task to fulfill the future, but it will be aborted during processing
253- // Removing oldest task to make room
254- if (!m_TaskQueue.empty ())
255- {
256- m_TaskQueue.front ().task (true ); // Abort oldest task
257- m_TaskQueue.pop_front ();
258- }
258+ // Abort the new task immediately to prevent deadlock
259+ // Don't add it to the queue
260+ task (true );
261+ return ;
259262 }
260263
261264 m_TaskQueue.emplace_back (TaskEntry{task, webView});
@@ -269,14 +272,19 @@ void CWebCore::RemoveWebViewTasks(CWebView* webView)
269272{
270273 std::scoped_lock lock (m_TaskQueueMutex);
271274
272- for (auto iter = m_TaskQueue.begin (); iter != m_TaskQueue.end (); ++iter)
273- {
274- if (iter->webView != webView)
275- continue ;
276-
277- iter->task (true );
278- iter = m_TaskQueue.erase (iter);
279- }
275+ // C++17-compatible erase-remove idiom (std::erase_if is C++20)
276+ m_TaskQueue.erase (
277+ std::remove_if (m_TaskQueue.begin (), m_TaskQueue.end (),
278+ [webView](TaskEntry& entry) {
279+ if (entry.webView == webView)
280+ {
281+ entry.task (true );
282+ return true ;
283+ }
284+ return false ;
285+ }),
286+ m_TaskQueue.end ()
287+ );
280288}
281289
282290void CWebCore::DoTaskQueuePulse ()
@@ -298,12 +306,12 @@ eURLState CWebCore::GetDomainState(const SString& strURL, bool bOutputDebug)
298306 std::lock_guard<std::recursive_mutex> lock (m_FilterMutex);
299307
300308 // Initialize wildcard whitelist (be careful with modifying) | Todo: Think about the following
301- static SString wildcardWhitelist[] = {" *.googlevideo.com" , " *.google.com" , " *.youtube.com" , " *.ytimg.com" ,
302- " *.vimeocdn.com" , " *.gstatic.com" , " *.googleapis.com" , " *.ggpht.com" };
309+ static constexpr const char * wildcardWhitelist[] = {" *.googlevideo.com" , " *.google.com" , " *.youtube.com" , " *.ytimg.com" ,
310+ " *.vimeocdn.com" , " *.gstatic.com" , " *.googleapis.com" , " *.ggpht.com" };
303311
304- for (int i = 0 ; i < sizeof ( wildcardWhitelist) / sizeof (SString); ++i )
312+ for (const auto & pattern : wildcardWhitelist)
305313 {
306- if (WildcardMatch (wildcardWhitelist[i] , strURL))
314+ if (WildcardMatch (pattern , strURL))
307315 return eURLState::WEBPAGE_ALLOWED;
308316 }
309317
@@ -602,6 +610,11 @@ bool CWebCore::SetGlobalAudioVolume(float fVolume)
602610 return true ;
603611}
604612
613+ CWebViewInterface* CWebCore::GetFocusedWebView ()
614+ {
615+ return m_pFocusedWebView;
616+ }
617+
605618bool CWebCore::UpdateListsFromMaster ()
606619{
607620 if (!m_pXmlConfig)
@@ -813,7 +826,7 @@ void CWebCore::GetFilterEntriesByType(std::vector<std::pair<SString, bool>>& out
813826 outEntries.push_back (std::pair<SString, bool >(iter->first , iter->second .first ));
814827 else if (state == eWebFilterState::WEBFILTER_ALLOWED && iter->second .first == true )
815828 outEntries.push_back (std::pair<SString, bool >(iter->first , iter->second .first ));
816- else
829+ else if (state == eWebFilterState::WEBFILTER_DISALLOWED && iter-> second . first == false )
817830 outEntries.push_back (std::pair<SString, bool >(iter->first , iter->second .first ));
818831 }
819832 }
@@ -822,6 +835,9 @@ void CWebCore::GetFilterEntriesByType(std::vector<std::pair<SString, bool>>& out
822835void CWebCore::StaticFetchRevisionFinished (const SHttpDownloadResult& result)
823836{
824837 CWebCore* pWebCore = static_cast <CWebCore*>(result.pObj );
838+ if (!pWebCore) [[unlikely]]
839+ return ;
840+
825841 if (result.bSuccess )
826842 {
827843 SString strData = result.pData ;
@@ -862,6 +878,9 @@ void CWebCore::StaticFetchWhitelistFinished(const SHttpDownloadResult& result)
862878 return ;
863879
864880 CWebCore* pWebCore = static_cast <CWebCore*>(result.pObj );
881+ if (!pWebCore) [[unlikely]]
882+ return ;
883+
865884 if (!pWebCore->m_pXmlConfig )
866885 return ;
867886
@@ -905,6 +924,9 @@ void CWebCore::StaticFetchBlacklistFinished(const SHttpDownloadResult& result)
905924 return ;
906925
907926 CWebCore* pWebCore = static_cast <CWebCore*>(result.pObj );
927+ if (!pWebCore) [[unlikely]]
928+ return ;
929+
908930 if (!pWebCore->m_pXmlConfig )
909931 return ;
910932
0 commit comments