-
-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Lua-based Ajax handling functionality via
setBrowserAjaxHandler / Browser.setAjaxHandler Currently GET-only due to CEF limitations
- Loading branch information
Showing
17 changed files
with
389 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SString>& vecGet, std::vector<SString>& vecPost, const CefString& strMime) | ||
: m_vecGetData(vecGet), m_vecPostData(vecPost), m_strMime(strMime) | ||
{ | ||
} | ||
|
||
std::vector<SString>& CAjaxResourceHandler::GetGetData () | ||
{ | ||
return m_vecGetData; | ||
} | ||
|
||
std::vector<SString>& 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <core/CAjaxResourceHandlerInterface.h> | ||
#include <cef3/include/cef_resource_handler.h> | ||
#include <SString.h> | ||
|
||
class CWebView; | ||
|
||
class CAjaxResourceHandler : public CefResourceHandler, public CAjaxResourceHandlerInterface | ||
{ | ||
public: | ||
CAjaxResourceHandler ( std::vector<SString>& vecGet, std::vector<SString>& vecPost, const CefString& mimeType); | ||
|
||
virtual std::vector<SString>& GetGetData (); | ||
virtual std::vector<SString>& 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<SString> m_vecGetData; | ||
std::vector<SString> m_vecPostData; | ||
SString m_strResponse; | ||
CefString m_strMime; | ||
bool m_bHasData = false; | ||
bool m_bHasRead = false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.