@@ -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 ();
@@ -91,12 +94,14 @@ bool CWebCore::Initialise(bool gpuEnabled)
9194 settings.multi_threaded_message_loop = true ;
9295 settings.windowless_rendering_enabled = true ;
9396
94- bool state = CefInitialize (mainArgs, settings, app, sandboxInfo);
95-
96- // Register custom scheme handler factory
97- CefRegisterSchemeHandlerFactory (" http" , " mta" , app);
97+ if (const bool state = CefInitialize (mainArgs, settings, app, sandboxInfo); state) [[likely]]
98+ {
99+ // Register custom scheme handler factory only if initialization succeeded
100+ CefRegisterSchemeHandlerFactory (" http" , " mta" , app);
101+ return true ;
102+ }
98103
99- return state ;
104+ return false ;
100105}
101106
102107CWebViewInterface* CWebCore::CreateWebView (unsigned int uiWidth, unsigned int uiHeight, bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem,
@@ -242,19 +247,17 @@ void CWebCore::WaitForTask(std::function<void(bool)> task, CWebView* webView)
242247 {
243248 std::scoped_lock lock (m_TaskQueueMutex);
244249
245- // Prevent unbounded queue growth - if queue is too large, oldest tasks will be dropped during pulse
246- if (m_TaskQueue.size () >= MAX_TASK_QUEUE_SIZE)
250+ // Prevent unbounded queue growth - abort new task if queue is too large
251+ if (m_TaskQueue.size () >= MAX_TASK_QUEUE_SIZE) [[unlikely]]
247252 {
248253#ifdef MTA_DEBUG
249- g_pCore->GetConsole ()->Printf (" Warning: Task queue size limit reached (%d), task will be aborted" , MAX_TASK_QUEUE_SIZE);
254+ static constexpr auto WARNING_MSG = " Warning: Task queue size limit reached (%d), aborting new task" ;
255+ g_pCore->GetConsole ()->Printf (WARNING_MSG, MAX_TASK_QUEUE_SIZE);
250256#endif
251- // Must still queue the task to fulfill the future, but it will be aborted during processing
252- // Removing oldest task to make room
253- if (!m_TaskQueue.empty ())
254- {
255- m_TaskQueue.front ().task (true ); // Abort oldest task
256- m_TaskQueue.pop_front ();
257- }
257+ // Abort the new task immediately to prevent deadlock
258+ // Don't add it to the queue
259+ task (true );
260+ return ;
258261 }
259262
260263 m_TaskQueue.emplace_back (TaskEntry{task, webView});
@@ -268,14 +271,14 @@ void CWebCore::RemoveWebViewTasks(CWebView* webView)
268271{
269272 std::scoped_lock lock (m_TaskQueueMutex);
270273
271- for ( auto iter = m_TaskQueue. begin (); iter != m_TaskQueue. end (); ++iter)
272- {
273- if (iter-> webView != webView)
274- continue ;
275-
276- iter-> task ( true );
277- iter = m_TaskQueue. erase (iter) ;
278- }
274+ std::erase_if ( m_TaskQueue, [webView](TaskEntry& entry) {
275+ if (entry. webView == webView)
276+ {
277+ entry. task ( true ) ;
278+ return true ;
279+ }
280+ return false ;
281+ });
279282}
280283
281284void CWebCore::DoTaskQueuePulse ()
@@ -297,12 +300,12 @@ eURLState CWebCore::GetDomainState(const SString& strURL, bool bOutputDebug)
297300 std::lock_guard<std::recursive_mutex> lock (m_FilterMutex);
298301
299302 // Initialize wildcard whitelist (be careful with modifying) | Todo: Think about the following
300- static SString wildcardWhitelist[] = {" *.googlevideo.com" , " *.google.com" , " *.youtube.com" , " *.ytimg.com" ,
301- " *.vimeocdn.com" , " *.gstatic.com" , " *.googleapis.com" , " *.ggpht.com" };
303+ static constexpr const char * wildcardWhitelist[] = {" *.googlevideo.com" , " *.google.com" , " *.youtube.com" , " *.ytimg.com" ,
304+ " *.vimeocdn.com" , " *.gstatic.com" , " *.googleapis.com" , " *.ggpht.com" };
302305
303- for (int i = 0 ; i < sizeof ( wildcardWhitelist) / sizeof (SString); ++i )
306+ for (const auto & pattern : wildcardWhitelist)
304307 {
305- if (WildcardMatch (wildcardWhitelist[i] , strURL))
308+ if (WildcardMatch (pattern , strURL))
306309 return eURLState::WEBPAGE_ALLOWED;
307310 }
308311
@@ -552,7 +555,8 @@ void CWebCore::OnFPSLimitChange(std::uint16_t fps)
552555 dassert (g_pCore->GetNetwork () != nullptr ); // Ensure network module is loaded
553556 for (auto & webView : m_WebViews)
554557 {
555- webView->GetCefBrowser ()->GetHost ()->SetWindowlessFrameRate (fps);
558+ if (auto browser = webView->GetCefBrowser (); browser) [[likely]]
559+ browser->GetHost ()->SetWindowlessFrameRate (fps);
556560 }
557561}
558562
@@ -610,6 +614,11 @@ bool CWebCore::SetGlobalAudioVolume(float fVolume)
610614 return true ;
611615}
612616
617+ CWebViewInterface* CWebCore::GetFocusedWebView ()
618+ {
619+ return m_pFocusedWebView;
620+ }
621+
613622bool CWebCore::UpdateListsFromMaster ()
614623{
615624 if (!m_pXmlConfig)
@@ -821,7 +830,7 @@ void CWebCore::GetFilterEntriesByType(std::vector<std::pair<SString, bool>>& out
821830 outEntries.push_back (std::pair<SString, bool >(iter->first , iter->second .first ));
822831 else if (state == eWebFilterState::WEBFILTER_ALLOWED && iter->second .first == true )
823832 outEntries.push_back (std::pair<SString, bool >(iter->first , iter->second .first ));
824- else
833+ else if (state == eWebFilterState::WEBFILTER_DISALLOWED && iter-> second . first == false )
825834 outEntries.push_back (std::pair<SString, bool >(iter->first , iter->second .first ));
826835 }
827836 }
@@ -830,6 +839,9 @@ void CWebCore::GetFilterEntriesByType(std::vector<std::pair<SString, bool>>& out
830839void CWebCore::StaticFetchRevisionFinished (const SHttpDownloadResult& result)
831840{
832841 CWebCore* pWebCore = static_cast <CWebCore*>(result.pObj );
842+ if (!pWebCore) [[unlikely]]
843+ return ;
844+
833845 if (result.bSuccess )
834846 {
835847 SString strData = result.pData ;
@@ -870,6 +882,9 @@ void CWebCore::StaticFetchWhitelistFinished(const SHttpDownloadResult& result)
870882 return ;
871883
872884 CWebCore* pWebCore = static_cast <CWebCore*>(result.pObj );
885+ if (!pWebCore) [[unlikely]]
886+ return ;
887+
873888 if (!pWebCore->m_pXmlConfig )
874889 return ;
875890
@@ -913,6 +928,9 @@ void CWebCore::StaticFetchBlacklistFinished(const SHttpDownloadResult& result)
913928 return ;
914929
915930 CWebCore* pWebCore = static_cast <CWebCore*>(result.pObj );
931+ if (!pWebCore) [[unlikely]]
932+ return ;
933+
916934 if (!pWebCore->m_pXmlConfig )
917935 return ;
918936
0 commit comments