|
1 | | -/***************************************************************************** |
2 | | -* |
3 | | -* PROJECT: Multi Theft Auto v1.0 |
4 | | -* LICENSE: See LICENSE in the top level directory |
5 | | -* FILE: core/AjaxResourceHandler.cpp |
6 | | -* PURPOSE: CEF Handler for Ajax Requests with delayed results |
7 | | -* |
8 | | -*****************************************************************************/ |
9 | | - |
10 | | -#include "StdInc.h" |
11 | | -#include "CWebCore.h" |
12 | | -#include "CWebView.h" |
13 | | -#include "CAjaxResourceHandler.h" |
14 | | -#undef min |
15 | | - |
16 | | -CAjaxResourceHandler::CAjaxResourceHandler ( std::vector<SString>& vecGet, std::vector<SString>& vecPost, const CefString& strMime) |
17 | | - : m_vecGetData(vecGet), m_vecPostData(vecPost), m_strMime(strMime) |
18 | | -{ |
19 | | -} |
20 | | - |
21 | | -std::vector<SString>& CAjaxResourceHandler::GetGetData () |
22 | | -{ |
23 | | - return m_vecGetData; |
24 | | -} |
25 | | - |
26 | | -std::vector<SString>& CAjaxResourceHandler::GetPostData () |
27 | | -{ |
28 | | - return m_vecPostData; |
29 | | -} |
30 | | - |
31 | | -void CAjaxResourceHandler::SetResponse ( const SString& data ) |
32 | | -{ |
33 | | - m_strResponse = data; |
34 | | - m_bHasData = true; |
35 | | - |
36 | | - if ( m_callback ) |
37 | | - m_callback->Continue( ); |
38 | | -} |
39 | | - |
40 | | -// CefResourceHandler implementation |
41 | | -void CAjaxResourceHandler::Cancel () |
42 | | -{ |
43 | | -} |
44 | | - |
45 | | -bool CAjaxResourceHandler::CanGetCookie ( const CefCookie& cookie ) |
46 | | -{ |
47 | | - return false; |
48 | | -} |
49 | | - |
50 | | -bool CAjaxResourceHandler::CanSetCookie ( const CefCookie& cookie ) |
51 | | -{ |
52 | | - return false; |
53 | | -} |
54 | | - |
55 | | -void CAjaxResourceHandler::GetResponseHeaders ( CefRefPtr< CefResponse > response, int64& response_length, CefString& redirectUrl ) |
56 | | -{ |
57 | | - response->SetStatus ( 200 ); |
58 | | - response->SetStatusText ( "OK" ); |
59 | | - response->SetMimeType ( m_strMime ); |
60 | | - response_length = -1; |
61 | | -} |
62 | | - |
63 | | -bool CAjaxResourceHandler::ProcessRequest ( CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback ) |
64 | | -{ |
65 | | - // Since we have nothing to process yet, continue |
66 | | - callback->Continue (); |
67 | | - return true; |
68 | | -} |
69 | | - |
70 | | -bool CAjaxResourceHandler::ReadResponse ( void* data_out, int bytes_to_read, int& bytes_read, CefRefPtr< CefCallback > callback ) |
71 | | -{ |
72 | | - // If we have no data yet, wait |
73 | | - if ( !m_bHasData ) |
74 | | - { |
75 | | - bytes_read = 0; |
76 | | - m_callback = callback; |
77 | | - callback->Continue (); |
78 | | - return true; |
79 | | - } |
80 | | - |
81 | | - // Are we done? |
82 | | - if ( m_strResponse.length( ) - m_DataOffset <= 0 ) |
83 | | - return false; |
84 | | - |
85 | | - int copyBytes = std::min ( (uint)bytes_to_read, m_strResponse.length () - m_DataOffset ); |
86 | | - |
87 | | - memcpy ( data_out, m_strResponse.c_str () + m_DataOffset, copyBytes ); |
88 | | - bytes_read = copyBytes; |
89 | | - |
90 | | - m_DataOffset += copyBytes; |
91 | | - |
92 | | - return true; |
93 | | -} |
| 1 | +/***************************************************************************** |
| 2 | +* |
| 3 | +* PROJECT: Multi Theft Auto v1.0 |
| 4 | +* LICENSE: See LICENSE in the top level directory |
| 5 | +* FILE: core/AjaxResourceHandler.cpp |
| 6 | +* PURPOSE: CEF Handler for Ajax Requests with delayed results |
| 7 | +* |
| 8 | +*****************************************************************************/ |
| 9 | + |
| 10 | +#include "StdInc.h" |
| 11 | +#include "CWebCore.h" |
| 12 | +#include "CWebView.h" |
| 13 | +#include "CAjaxResourceHandler.h" |
| 14 | +#undef min |
| 15 | + |
| 16 | +CAjaxResourceHandler::CAjaxResourceHandler ( std::vector<SString>& vecGet, std::vector<SString>& vecPost, const CefString& strMime) |
| 17 | + : m_vecGetData(vecGet), m_vecPostData(vecPost), m_strMime(strMime) |
| 18 | +{ |
| 19 | +} |
| 20 | + |
| 21 | +std::vector<SString>& CAjaxResourceHandler::GetGetData () |
| 22 | +{ |
| 23 | + return m_vecGetData; |
| 24 | +} |
| 25 | + |
| 26 | +std::vector<SString>& CAjaxResourceHandler::GetPostData () |
| 27 | +{ |
| 28 | + return m_vecPostData; |
| 29 | +} |
| 30 | + |
| 31 | +void CAjaxResourceHandler::SetResponse ( const SString& data ) |
| 32 | +{ |
| 33 | + m_strResponse = data; |
| 34 | + m_bHasData = true; |
| 35 | + |
| 36 | + if ( m_callback ) |
| 37 | + m_callback->Continue( ); |
| 38 | +} |
| 39 | + |
| 40 | +// CefResourceHandler implementation |
| 41 | +void CAjaxResourceHandler::Cancel () |
| 42 | +{ |
| 43 | +} |
| 44 | + |
| 45 | +bool CAjaxResourceHandler::CanGetCookie ( const CefCookie& cookie ) |
| 46 | +{ |
| 47 | + return false; |
| 48 | +} |
| 49 | + |
| 50 | +bool CAjaxResourceHandler::CanSetCookie ( const CefCookie& cookie ) |
| 51 | +{ |
| 52 | + return false; |
| 53 | +} |
| 54 | + |
| 55 | +void CAjaxResourceHandler::GetResponseHeaders ( CefRefPtr< CefResponse > response, int64& response_length, CefString& redirectUrl ) |
| 56 | +{ |
| 57 | + response->SetStatus ( 200 ); |
| 58 | + response->SetStatusText ( "OK" ); |
| 59 | + response->SetMimeType ( m_strMime ); |
| 60 | + response_length = -1; |
| 61 | +} |
| 62 | + |
| 63 | +bool CAjaxResourceHandler::ProcessRequest ( CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback ) |
| 64 | +{ |
| 65 | + // Since we have nothing to process yet, continue |
| 66 | + callback->Continue (); |
| 67 | + return true; |
| 68 | +} |
| 69 | + |
| 70 | +bool CAjaxResourceHandler::ReadResponse ( void* data_out, int bytes_to_read, int& bytes_read, CefRefPtr< CefCallback > callback ) |
| 71 | +{ |
| 72 | + // If we have no data yet, wait |
| 73 | + if ( !m_bHasData ) |
| 74 | + { |
| 75 | + bytes_read = 0; |
| 76 | + m_callback = callback; |
| 77 | + callback->Continue (); |
| 78 | + return true; |
| 79 | + } |
| 80 | + |
| 81 | + // Are we done? |
| 82 | + if ( m_strResponse.length( ) - m_DataOffset <= 0 ) |
| 83 | + return false; |
| 84 | + |
| 85 | + int copyBytes = std::min ( (uint)bytes_to_read, m_strResponse.length () - m_DataOffset ); |
| 86 | + |
| 87 | + memcpy ( data_out, m_strResponse.c_str () + m_DataOffset, copyBytes ); |
| 88 | + bytes_read = copyBytes; |
| 89 | + |
| 90 | + m_DataOffset += copyBytes; |
| 91 | + |
| 92 | + return true; |
| 93 | +} |
0 commit comments