From 72147b4e0e81fb69c0835236df18f9ebc780eca8 Mon Sep 17 00:00:00 2001 From: sbx320 Date: Wed, 12 Aug 2015 12:25:26 +0200 Subject: [PATCH] Added Lua-based Ajax handling functionality via setBrowserAjaxHandler / Browser.setAjaxHandler Currently GET-only due to CEF limitations --- MTA10/core/CAjaxResourceHandler.cpp | 90 +++++++++++++++++++ MTA10/core/CAjaxResourceHandler.h | 48 ++++++++++ MTA10/core/CWebCore.cpp | 58 ++++++++++-- MTA10/core/CWebCore.h | 2 +- MTA10/core/CWebView.cpp | 26 ++++++ MTA10/core/CWebView.h | 8 +- MTA10/core/_Core 2008.vcxproj | 2 + MTA10/core/_Core 2008.vcxproj.filters | 6 ++ MTA10/mods/shared_logic/CClientWebBrowser.cpp | 35 ++++++++ MTA10/mods/shared_logic/CClientWebBrowser.h | 7 ++ .../lua/CLuaFunctionDefs.Browser.cpp | 88 ++++++++++++++++++ .../mods/shared_logic/lua/CLuaFunctionDefs.h | 1 + MTA10/mods/shared_logic/lua/CLuaMain.cpp | 1 + MTA10/mods/shared_logic/lua/CLuaManager.cpp | 1 + .../sdk/core/CAjaxResourceHandlerInterface.h | 19 ++++ MTA10/sdk/core/CWebBrowserEventsInterface.h | 2 + MTA10/sdk/core/CWebViewInterface.h | 6 ++ 17 files changed, 389 insertions(+), 11 deletions(-) create mode 100644 MTA10/core/CAjaxResourceHandler.cpp create mode 100644 MTA10/core/CAjaxResourceHandler.h create mode 100644 MTA10/sdk/core/CAjaxResourceHandlerInterface.h diff --git a/MTA10/core/CAjaxResourceHandler.cpp b/MTA10/core/CAjaxResourceHandler.cpp new file mode 100644 index 0000000000..36837e887d --- /dev/null +++ b/MTA10/core/CAjaxResourceHandler.cpp @@ -0,0 +1,90 @@ +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: core/AjaxResourceHandler.cpp +* PURPOSE: CEF Handler for Ajax Requests with delayed results +* +*****************************************************************************/ + +#include "StdInc.h" +#include "CWebCore.h" +#include "CWebView.h" +#include "CAjaxResourceHandler.h" + +CAjaxResourceHandler::CAjaxResourceHandler ( std::vector& vecGet, std::vector& vecPost, const CefString& strMime) + : m_vecGetData(vecGet), m_vecPostData(vecPost), m_strMime(strMime) +{ +} + +std::vector& CAjaxResourceHandler::GetGetData () +{ + return m_vecGetData; +} + +std::vector& CAjaxResourceHandler::GetPostData () +{ + return m_vecPostData; +} + + +void CAjaxResourceHandler::SetResponse ( const SString& data ) +{ + m_strResponse = data; + m_bHasData = true; + m_callback->Continue (); +} + +// CefResourceHandler implementation +void CAjaxResourceHandler::Cancel () +{ +} + +bool CAjaxResourceHandler::CanGetCookie ( const CefCookie& cookie ) +{ + return false; +} + +bool CAjaxResourceHandler::CanSetCookie ( const CefCookie& cookie ) +{ + return false; +} + +void CAjaxResourceHandler::GetResponseHeaders ( CefRefPtr< CefResponse > response, int64& response_length, CefString& redirectUrl ) +{ + response->SetStatus ( 200 ); + response->SetStatusText ( "OK" ); + response->SetMimeType ( m_strMime ); + response_length = -1; +} + +bool CAjaxResourceHandler::ProcessRequest ( CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback ) +{ + // Since we have nothing to process yet, continue + callback->Continue (); + return true; +} + + +bool CAjaxResourceHandler::ReadResponse ( void* data_out, int bytes_to_read, int& bytes_read, CefRefPtr< CefCallback > callback ) +{ + if ( m_bHasRead ) + return false; + + if ( !m_bHasData ) + { + bytes_read = 0; + m_callback = callback; + callback->Continue (); + return true; + } + + // +1 due to terminating \0 + int copyBytes = min ( (uint)bytes_to_read, m_strResponse.length () +1 ); + memcpy ( data_out, m_strResponse.c_str (), copyBytes ); + ((char*)data_out) [copyBytes] = '\0'; + bytes_read = copyBytes; + m_bHasRead = true; + + return true; +} diff --git a/MTA10/core/CAjaxResourceHandler.h b/MTA10/core/CAjaxResourceHandler.h new file mode 100644 index 0000000000..f8115488b9 --- /dev/null +++ b/MTA10/core/CAjaxResourceHandler.h @@ -0,0 +1,48 @@ +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: core/AjaxResourceHandler.h +* PURPOSE: CEF Handler for Ajax Requests with delayed results +* +* Multi Theft Auto is available from http://www.multitheftauto.com/ +* +*****************************************************************************/ +#pragma once + +#include +#include +#include + +class CWebView; + +class CAjaxResourceHandler : public CefResourceHandler, public CAjaxResourceHandlerInterface +{ +public: + CAjaxResourceHandler ( std::vector& vecGet, std::vector& vecPost, const CefString& mimeType); + + virtual std::vector& GetGetData (); + virtual std::vector& GetPostData (); + virtual void SetResponse ( const SString& data ); + + // CefResourceHandler + virtual void Cancel () override; + virtual bool CanGetCookie ( const CefCookie& cookie ) override; + virtual bool CanSetCookie ( const CefCookie& cookie ) override; + virtual void GetResponseHeaders ( CefRefPtr< CefResponse > response, int64& response_length, CefString& redirectUrl ) override; + virtual bool ProcessRequest ( CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback ) override; + virtual bool ReadResponse ( void* data_out, int bytes_to_read, int& bytes_read, CefRefPtr< CefCallback > callback ) override; + + IMPLEMENT_REFCOUNTING ( CAjaxResourceHandler ); + DISALLOW_COPY_AND_ASSIGN ( CAjaxResourceHandler ); + +private: + // + CefRefPtr< CefCallback > m_callback; + std::vector m_vecGetData; + std::vector m_vecPostData; + SString m_strResponse; + CefString m_strMime; + bool m_bHasData = false; + bool m_bHasRead = false; +}; \ No newline at end of file diff --git a/MTA10/core/CWebCore.cpp b/MTA10/core/CWebCore.cpp index fd6ea85e96..f2cd060eea 100644 --- a/MTA10/core/CWebCore.cpp +++ b/MTA10/core/CWebCore.cpp @@ -12,6 +12,7 @@ #include "CWebCore.h" #include "CWebView.h" #include "CWebsiteRequests.h" +#include "CAjaxResourceHandler.h" #include #include #include @@ -797,23 +798,62 @@ CefRefPtr CCefApp::Create ( CefRefPtr browser, C // Get full path SString path = UTF16ToMbUTF8 ( urlParts.path.str ).substr ( 2 ); - if ( !pWebView->GetFullPathFromLocal ( path ) ) - return nullptr; // Get mime type from extension CefString mimeType; - size_t pos = path.find_last_of('.'); - if (pos != std::string::npos) + size_t pos = path.find_last_of ( '.' ); + if ( pos != std::string::npos ) mimeType = CefGetMimeType ( path.substr ( pos + 1 ) ); - + // Make sure we provide a mime type, even // when we cannot deduct it from the file extension - if ( mimeType.empty( ) ) + if ( mimeType.empty () ) mimeType = "application/octet-stream"; - auto stream = CefStreamReader::CreateForFile ( path ); - if ( stream.get () ) - return new CefStreamResourceHandler ( mimeType, stream ); + + if( pWebView->HasAjaxHandler ( path ) ) + { + std::vector vecGet; + std::vector vecPost; + + SString strGet = UTF16ToMbUTF8(urlParts.query.str); + std::vector vecTmp; + strGet.Split ( "&", vecTmp, 0, 0 ); + + SString key; SString value; + for ( auto&& param : vecTmp ) + { + param.Split ( "=", &key, &value ); + vecGet.push_back ( key ); + vecGet.push_back ( value ); + } + + // ToDo: POST Information is Empty for non-standard URI schemes + // Getting POST parameters into Lua will require changing + // mtalocal:// to a standard scheme first + /* + CefPostData::ElementVector vecPostElements; + request->GetPostData ().get ()->GetElements ( vecPostElements ); + + for ( auto&& post : vecPostElements ) + { + // ToDo: Parse POST data into our vector + } + */ + + auto handler = new CAjaxResourceHandler ( vecGet, vecPost, mimeType ); + pWebView->HandleAjaxRequest ( path, handler ); + return handler; + } + else + { + if ( !pWebView->GetFullPathFromLocal ( path ) ) + return nullptr; + + auto stream = CefStreamReader::CreateForFile ( path ); + if ( stream.get () ) + return new CefStreamResourceHandler ( mimeType, stream ); + } return nullptr; } diff --git a/MTA10/core/CWebCore.h b/MTA10/core/CWebCore.h index 225a8ae7be..c9750c1b66 100644 --- a/MTA10/core/CWebCore.h +++ b/MTA10/core/CWebCore.h @@ -93,7 +93,7 @@ class CWebCore : public CWebCoreInterface static bool StaticFetchRevisionProgress ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bComplete, int iError ); static bool StaticFetchWhitelistProgress ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bComplete, int iError ); static bool StaticFetchBlacklistProgress ( double dDownloadNow, double dDownloadTotal, char* pCompletedData, size_t completedLength, void *pObj, bool bComplete, int iError ); - + private: typedef std::pair WebFilterPair; diff --git a/MTA10/core/CWebView.cpp b/MTA10/core/CWebView.cpp index f247b88511..88acc532fc 100644 --- a/MTA10/core/CWebView.cpp +++ b/MTA10/core/CWebView.cpp @@ -9,6 +9,7 @@ *****************************************************************************/ #include "StdInc.h" #include "CWebView.h" +#include "CAjaxResourceHandler.h" #include #include #include @@ -320,6 +321,30 @@ bool CWebView::GetFullPathFromLocal ( SString& strPath ) return m_pEventsInterface->Events_OnResourcePathCheck ( strPath ); } +bool CWebView::RegisterAjaxHandler ( const SString& strURL ) +{ + auto result = m_AjaxHandlers.insert ( strURL ); + return result.second; +} + +bool CWebView::UnregisterAjaxHandler ( const SString& strURL ) +{ + return m_AjaxHandlers.erase ( strURL ) == 1; +} + + +bool CWebView::HasAjaxHandler ( const SString& strURL ) +{ + auto iterCB = m_AjaxHandlers.find ( strURL ); + return iterCB != m_AjaxHandlers.end (); +} + +void CWebView::HandleAjaxRequest ( const SString& strURL, CAjaxResourceHandler * pHandler ) +{ + auto func = std::bind ( &CWebBrowserEventsInterface::Events_OnAjaxRequest, m_pEventsInterface, pHandler, strURL ); + g_pCore->GetWebCore ()->AddEventToEventQueue ( func, this, "AjaxResourceRequest" ); +} + //////////////////////////////////////////////////////////////////// // // @@ -824,3 +849,4 @@ void CWebView::ConvertURL ( const CefString& url, SString& convertedURL ) convertedURL = ""; } } + diff --git a/MTA10/core/CWebView.h b/MTA10/core/CWebView.h index d55ba55fb7..5ff5af3f3e 100644 --- a/MTA10/core/CWebView.h +++ b/MTA10/core/CWebView.h @@ -75,6 +75,11 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH void GetSourceCode ( const std::function& callback ); bool GetFullPathFromLocal ( SString& strPath ); + + virtual bool RegisterAjaxHandler ( const SString& strURL ) override; + virtual bool UnregisterAjaxHandler ( const SString& strURL ) override; + virtual bool HasAjaxHandler ( const SString& strURL ); + virtual void HandleAjaxRequest ( const SString& strURL, class CAjaxResourceHandler * pHandler ); // CefClient methods virtual CefRefPtr GetRenderHandler() override { return this; }; @@ -136,7 +141,8 @@ class CWebView : public CWebViewInterface, private CefClient, private CefRenderH int m_RenderPopupOffsetX, m_RenderPopupOffsetY; std::map m_Properties; bool m_bHasInputFocus; - + std::set m_AjaxHandlers; + CWebBrowserEventsInterface* m_pEventsInterface; public: diff --git a/MTA10/core/_Core 2008.vcxproj b/MTA10/core/_Core 2008.vcxproj index 1dd24f27b7..dc173bfc18 100644 --- a/MTA10/core/_Core 2008.vcxproj +++ b/MTA10/core/_Core 2008.vcxproj @@ -218,6 +218,7 @@ + @@ -396,6 +397,7 @@ + diff --git a/MTA10/core/_Core 2008.vcxproj.filters b/MTA10/core/_Core 2008.vcxproj.filters index e8032f3426..746103ea6a 100644 --- a/MTA10/core/_Core 2008.vcxproj.filters +++ b/MTA10/core/_Core 2008.vcxproj.filters @@ -371,6 +371,9 @@ Source Files + + Source Files + @@ -1288,5 +1291,8 @@ Header Files\sdk\core + + Header Files + \ No newline at end of file diff --git a/MTA10/mods/shared_logic/CClientWebBrowser.cpp b/MTA10/mods/shared_logic/CClientWebBrowser.cpp index 99e679ab80..fb25cd4b7f 100644 --- a/MTA10/mods/shared_logic/CClientWebBrowser.cpp +++ b/MTA10/mods/shared_logic/CClientWebBrowser.cpp @@ -256,6 +256,39 @@ void CClientWebBrowser::Events_OnResourceBlocked ( const SString& strURL, const CallEvent ( "onClientBrowserResourceBlocked", Arguments, false ); } +void CClientWebBrowser::Events_OnAjaxRequest ( CAjaxResourceHandlerInterface* pHandler, const SString& strURL ) +{ + auto callbackMapEntry = m_mapAjaxCallback.find ( strURL ); + + if ( callbackMapEntry == m_mapAjaxCallback.end () ) + { + pHandler->SetResponse ( "" ); + return; + } + + auto callback = callbackMapEntry->second; + SString result = callback ( pHandler->GetGetData (), pHandler->GetPostData () ); + pHandler->SetResponse ( result ); +} + + +bool CClientWebBrowser::AddAjaxHandler ( const SString& strURL, ajax_callback_t& handler ) +{ + if ( !m_pWebView->RegisterAjaxHandler ( strURL ) ) + return false; + + m_mapAjaxCallback.insert ( std::make_pair ( strURL, handler ) ); + return true; +} + + +bool CClientWebBrowser::RemoveAjaxHandler ( const SString& strURL ) +{ + if ( !m_pWebView->UnregisterAjaxHandler ( strURL ) ) + return false; + + return m_mapAjaxCallback.erase ( strURL ) == 1; +} CClientGUIWebBrowser::CClientGUIWebBrowser ( bool isLocal, bool isTransparent, uint width, uint height, CClientManager* pManager, CLuaMain* pLuaMain, CGUIElement* pCGUIElement, ElementID ID ) @@ -268,3 +301,5 @@ CClientGUIWebBrowser::CClientGUIWebBrowser ( bool isLocal, bool isTransparent, u // Set our owner resource m_pBrowser->SetResource ( pLuaMain->GetResource () ); } + + diff --git a/MTA10/mods/shared_logic/CClientWebBrowser.h b/MTA10/mods/shared_logic/CClientWebBrowser.h index 4cd155e6f4..693a184e3e 100644 --- a/MTA10/mods/shared_logic/CClientWebBrowser.h +++ b/MTA10/mods/shared_logic/CClientWebBrowser.h @@ -12,6 +12,7 @@ #define __CCLIENTWEBBROWSER_H #include +#include #include class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterface @@ -54,6 +55,10 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa void GetSourceCode ( const std::function& callback ); + using ajax_callback_t = const std::function& vecGet, std::vector& vecPost )>; + + bool AddAjaxHandler ( const SString& strURL, ajax_callback_t& handler ); + bool RemoveAjaxHandler ( const SString& strURL ); // CWebBrowserEventsInterface implementation void Events_OnCreated () override; @@ -68,10 +73,12 @@ class CClientWebBrowser : public CClientTexture, public CWebBrowserEventsInterfa void Events_OnInputFocusChanged ( bool bGainedFocus ) override; bool Events_OnResourcePathCheck ( SString& strURL ) override; void Events_OnResourceBlocked ( const SString& strURL, const SString& strDomain, unsigned char reason ) override; + void Events_OnAjaxRequest ( CAjaxResourceHandlerInterface* pHandler, const SString& strURL ) override; private: CWebViewInterface* m_pWebView; CResource* m_pResource; + std::map m_mapAjaxCallback; }; class CClientGUIWebBrowser : public CClientGUIElement diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp index 62246ded18..e279618422 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.Browser.cpp @@ -622,3 +622,91 @@ int CLuaFunctionDefs::GUIGetBrowser ( lua_State* luaVM ) // Or rather guiGetBrow lua_pushboolean ( luaVM, false ); return 1; } + +int CLuaFunctionDefs::SetBrowserAjaxHandler ( lua_State* luaVM ) +{ + // bool setBrowserAjaxHandler ( browser browser, string URL[, function callback] ) + CClientWebBrowser* pWebBrowser; SString strURL; CLuaFunctionRef callbackFunction; + + CScriptArgReader argStream ( luaVM ); + argStream.ReadUserData ( pWebBrowser ); + argStream.ReadString ( strURL ); + + if ( argStream.NextIsNil () || argStream.NextIsNone () ) + { + if ( !argStream.HasErrors () ) + { + lua_pushboolean ( luaVM, pWebBrowser->RemoveAjaxHandler ( strURL ) ); + return 1; + } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + } + else + { + argStream.ReadFunction ( callbackFunction ); + argStream.ReadFunctionComplete (); + if ( !argStream.HasErrors () ) + { + CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine ( luaVM ); + if ( pLuaMain && VERIFY_FUNCTION ( callbackFunction ) ) + { + CResource* pResource = pLuaMain->GetResource (); + CResourceManager * pResourceManager = m_pResourceManager; + auto netId = pResource->GetNetID (); + + bool bResult = pWebBrowser->AddAjaxHandler ( strURL, + [=] ( std::vector& vecGet, std::vector& vecPost ) -> const SString + { + // Make sure the resource is still running + if ( !pResourceManager->Exists ( pResource ) || pResource->GetNetID() != netId ) + { + return ""; + } + + // Make sure the function is valid + if ( VERIFY_FUNCTION ( callbackFunction ) ) + { + CLuaArguments arguments; + CLuaArguments getArguments; + CLuaArguments postArguments; + + for ( auto&& param : vecGet ) + getArguments.PushString ( param ); + + for ( auto&& param : vecPost ) + postArguments.PushString ( param ); + + arguments.PushTable ( &getArguments ); + arguments.PushTable ( &postArguments ); + + CLuaArguments result; + + arguments.Call ( pLuaMain, callbackFunction, &result ); + + if ( result.Count () == 0 ) + return ""; + + + CLuaArgument* returnedValue = *result.IterBegin (); + if ( returnedValue->GetType () == LUA_TSTRING ) + return returnedValue->GetString (); + else + return ""; + } + else + return ""; + + } ); + + lua_pushboolean ( luaVM, bResult ); + return 1; + } + } + else + m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); + } + + lua_pushboolean ( luaVM, false ); + return 1; +} \ No newline at end of file diff --git a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h index 56f2aef5ee..b8c2538755 100644 --- a/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h +++ b/MTA10/mods/shared_logic/lua/CLuaFunctionDefs.h @@ -1045,6 +1045,7 @@ class CLuaFunctionDefs LUA_DECLARE ( GetBrowserProperty ); LUA_DECLARE ( GetBrowserSettings ); LUA_DECLARE ( GetBrowserSource ); + LUA_DECLARE ( SetBrowserAjaxHandler ); LUA_DECLARE ( GUICreateBrowser ); LUA_DECLARE ( GUIGetBrowser ); diff --git a/MTA10/mods/shared_logic/lua/CLuaMain.cpp b/MTA10/mods/shared_logic/lua/CLuaMain.cpp index 18288fd347..de16c31ed5 100644 --- a/MTA10/mods/shared_logic/lua/CLuaMain.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaMain.cpp @@ -1647,6 +1647,7 @@ void CLuaMain::AddBrowserClass ( lua_State* luaVM ) lua_classfunction ( luaVM, "setProperty", "setBrowserProperty" ); lua_classfunction ( luaVM, "getProperty", "getBrowserProperty" ); lua_classfunction ( luaVM, "getSource", "getBrowserSource" ); + lua_classfunction ( luaVM, "setAjaxHandler", "setBrowserAjaxHandler" ); lua_classfunction ( luaVM, "requestDomains", "requestBrowserDomains" ); lua_classfunction ( luaVM, "isDomainBlocked", "isBrowserDomainBlocked" ); diff --git a/MTA10/mods/shared_logic/lua/CLuaManager.cpp b/MTA10/mods/shared_logic/lua/CLuaManager.cpp index e5e6318ceb..a9cf57c42c 100644 --- a/MTA10/mods/shared_logic/lua/CLuaManager.cpp +++ b/MTA10/mods/shared_logic/lua/CLuaManager.cpp @@ -1220,6 +1220,7 @@ void CLuaManager::LoadCFunctions ( void ) CLuaCFunctions::AddFunction ( "getBrowserProperty", CLuaFunctionDefs::GetBrowserProperty ); CLuaCFunctions::AddFunction ( "getBrowserSettings", CLuaFunctionDefs::GetBrowserSettings ); CLuaCFunctions::AddFunction ( "getBrowserSource", CLuaFunctionDefs::GetBrowserSource ); + CLuaCFunctions::AddFunction ( "setBrowserAjaxHandler", CLuaFunctionDefs::SetBrowserAjaxHandler ); CLuaCFunctions::AddFunction ( "guiCreateBrowser", CLuaFunctionDefs::GUICreateBrowser ); CLuaCFunctions::AddFunction ( "guiGetBrowser", CLuaFunctionDefs::GUIGetBrowser ); diff --git a/MTA10/sdk/core/CAjaxResourceHandlerInterface.h b/MTA10/sdk/core/CAjaxResourceHandlerInterface.h new file mode 100644 index 0000000000..62f34ac328 --- /dev/null +++ b/MTA10/sdk/core/CAjaxResourceHandlerInterface.h @@ -0,0 +1,19 @@ +/***************************************************************************** +* +* PROJECT: Multi Theft Auto v1.0 +* LICENSE: See LICENSE in the top level directory +* FILE: sdk/core/AjaxResourceHandler.h +* PURPOSE: Interface for CEF Handler for Ajax Requests with delayed results +* +* Multi Theft Auto is available from http://www.multitheftauto.com/ +* +*****************************************************************************/ +#pragma once + +class CAjaxResourceHandlerInterface +{ +public: + virtual std::vector& GetGetData () = 0; + virtual std::vector& GetPostData () = 0; + virtual void SetResponse ( const SString& data ) = 0; +}; diff --git a/MTA10/sdk/core/CWebBrowserEventsInterface.h b/MTA10/sdk/core/CWebBrowserEventsInterface.h index 071a5ea329..14c92646f3 100644 --- a/MTA10/sdk/core/CWebBrowserEventsInterface.h +++ b/MTA10/sdk/core/CWebBrowserEventsInterface.h @@ -11,6 +11,7 @@ #ifndef __CWEBBROWSEREVENTSINTERFACE_H #define __CWEBBROWSEREVENTSINTERFACE_H +class CAjaxResourceHandlerInterface; class CWebBrowserEventsInterface { public: @@ -26,6 +27,7 @@ class CWebBrowserEventsInterface virtual void Events_OnInputFocusChanged ( bool bGainedFocus ) = 0; virtual bool Events_OnResourcePathCheck ( SString& strURL ) = 0; virtual void Events_OnResourceBlocked ( const SString& strURL, const SString& strDomain, unsigned char reason ) = 0; + virtual void Events_OnAjaxRequest ( CAjaxResourceHandlerInterface* pHandler, const SString& strURL ) = 0; }; #endif diff --git a/MTA10/sdk/core/CWebViewInterface.h b/MTA10/sdk/core/CWebViewInterface.h index cde7bf7634..5ba6b060bb 100644 --- a/MTA10/sdk/core/CWebViewInterface.h +++ b/MTA10/sdk/core/CWebViewInterface.h @@ -49,6 +49,12 @@ class CWebViewInterface virtual bool SetAudioVolume ( float fVolume ) = 0; virtual void GetSourceCode ( const std::function& callback ) = 0; + + // Ajax Handlers + using ajax_callback_t = const std::function& vecGet, std::vector& vecPost )>; + + virtual bool RegisterAjaxHandler ( const SString& strURL ) = 0; + virtual bool UnregisterAjaxHandler ( const SString& strURL ) = 0; }; #endif