|
1 | | -/***************************************************************************** |
2 | | - * |
3 | | - * PROJECT: Multi Theft Auto v1.0 |
4 | | - * (Shared logic for modifications) |
5 | | - * LICENSE: See LICENSE in the top level directory |
6 | | - * FILE: ceflauncher/CCefApp.h |
7 | | - * PURPOSE: CefApp implementation |
8 | | - * |
9 | | - *****************************************************************************/ |
10 | | -#include <cef3/include/cef_app.h> |
11 | | -#include <string> |
12 | | -#include <sstream> |
13 | | -#include "V8Helpers.h" |
14 | | -using V8Helpers::CV8Handler; |
15 | | - |
16 | | -class CCefApp : public CefApp, public CefRenderProcessHandler |
17 | | -{ |
18 | | -public: |
19 | | - CCefApp() {} |
20 | | - virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override { return this; }; |
21 | | - |
22 | | - // http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRenderProcessHandler.html#OnFocusedNodeChanged(CefRefPtr%3CCefBrowser%3E,CefRefPtr%3CCefFrame%3E,CefRefPtr%3CCefDOMNode%3E) |
23 | | - virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefDOMNode> node) override |
24 | | - { |
25 | | - if (m_bHasInputFocus) |
26 | | - { |
27 | | - if (node) |
28 | | - return; |
29 | | - |
30 | | - // Tell MTA that we lost input focus |
31 | | - auto message = CefProcessMessage::Create("InputFocus"); |
32 | | - message->GetArgumentList()->SetBool(0, false); |
33 | | - browser->GetMainFrame()->SendProcessMessage(PID_BROWSER, message); |
34 | | - |
35 | | - // Set variable to ensure that the event does not trigger twice |
36 | | - m_bHasInputFocus = false; |
37 | | - return; |
38 | | - } |
39 | | - else |
40 | | - { |
41 | | - if (!node) |
42 | | - return; |
43 | | - |
44 | | - if (node->GetType() == CefDOMNode::Type::DOM_NODE_TYPE_ELEMENT && !node->GetFormControlElementType().empty()) |
45 | | - { |
46 | | - auto message = CefProcessMessage::Create("InputFocus"); |
47 | | - message->GetArgumentList()->SetBool(0, true); |
48 | | - browser->GetMainFrame()->SendProcessMessage(PID_BROWSER, message); |
49 | | - |
50 | | - // Set variable to ensure that the event does not trigger twice |
51 | | - m_bHasInputFocus = true; |
52 | | - } |
53 | | - } |
54 | | - } |
55 | | - |
56 | | - virtual void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) override |
57 | | - { |
58 | | - // Register custom MTA scheme (has to be called in all proceseses) |
59 | | - registrar->AddCustomScheme("mtalocal", CEF_SCHEME_OPTION_CSP_BYPASSING); |
60 | | - } |
61 | | - |
62 | | - // http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRenderProcessHandler.html#OnContextCreated(CefRefPtr%3CCefBrowser%3E,CefRefPtr%3CCefFrame%3E,CefRefPtr%3CCefV8Context%3E) |
63 | | - // // |
64 | | - virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override |
65 | | - { |
66 | | - // Get global object and create a v8 handler instance |
67 | | - CefRefPtr<CefV8Value> globalObject = context->GetGlobal(); |
68 | | - CefRefPtr<CV8Handler> handler = new CV8Handler(frame); |
69 | | - |
70 | | - // Create MTA object |
71 | | - CefRefPtr<CefV8Value> mtaObject = CefV8Value::CreateObject(nullptr, nullptr); |
72 | | - |
73 | | - // Bind V8 --> C++ functions |
74 | | - V8Helpers::BindV8Function(handler, mtaObject, "triggerEvent", Javascript_triggerEvent); |
75 | | - |
76 | | - // Assign mtaObject to global object |
77 | | - globalObject->SetValue("mta", mtaObject, V8_PROPERTY_ATTRIBUTE_NONE); |
78 | | - } |
79 | | - |
80 | | - static void Javascript_triggerEvent(CefRefPtr<CefFrame> frame, const CefV8ValueList& arguments) |
81 | | - { |
82 | | - if (arguments.size() == 0) |
83 | | - return; |
84 | | - |
85 | | - CefRefPtr<CefProcessMessage> message = V8Helpers::SerialiseV8Arguments("TriggerLuaEvent", arguments); |
86 | | - frame->GetBrowser()->GetMainFrame()->SendProcessMessage(PID_BROWSER, message); |
87 | | - } |
88 | | - |
89 | | -public: |
90 | | - IMPLEMENT_REFCOUNTING(CCefApp); |
91 | | - |
92 | | -private: |
93 | | - bool m_bHasInputFocus = false; |
94 | | -}; |
| 1 | +/***************************************************************************** |
| 2 | + * |
| 3 | + * PROJECT: Multi Theft Auto v1.0 |
| 4 | + * (Shared logic for modifications) |
| 5 | + * LICENSE: See LICENSE in the top level directory |
| 6 | + * FILE: ceflauncher/CCefApp.h |
| 7 | + * PURPOSE: CefApp implementation |
| 8 | + * |
| 9 | + *****************************************************************************/ |
| 10 | +#include <cef3/include/cef_app.h> |
| 11 | +#include <string> |
| 12 | +#include <sstream> |
| 13 | +#include "V8Helpers.h" |
| 14 | +using V8Helpers::CV8Handler; |
| 15 | + |
| 16 | +class CCefApp : public CefApp, public CefRenderProcessHandler |
| 17 | +{ |
| 18 | +public: |
| 19 | + CCefApp() {} |
| 20 | + virtual CefRefPtr<CefRenderProcessHandler> GetRenderProcessHandler() override { return this; }; |
| 21 | + |
| 22 | + // http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRenderProcessHandler.html#OnFocusedNodeChanged(CefRefPtr%3CCefBrowser%3E,CefRefPtr%3CCefFrame%3E,CefRefPtr%3CCefDOMNode%3E) |
| 23 | + virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefDOMNode> node) override |
| 24 | + { |
| 25 | + if (m_bHasInputFocus) |
| 26 | + { |
| 27 | + if (node) |
| 28 | + return; |
| 29 | + |
| 30 | + // Tell MTA that we lost input focus |
| 31 | + auto message = CefProcessMessage::Create("InputFocus"); |
| 32 | + message->GetArgumentList()->SetBool(0, false); |
| 33 | + browser->GetMainFrame()->SendProcessMessage(PID_BROWSER, message); |
| 34 | + |
| 35 | + // Set variable to ensure that the event does not trigger twice |
| 36 | + m_bHasInputFocus = false; |
| 37 | + return; |
| 38 | + } |
| 39 | + else |
| 40 | + { |
| 41 | + if (!node) |
| 42 | + return; |
| 43 | + |
| 44 | + if (node->GetType() == CefDOMNode::Type::DOM_NODE_TYPE_ELEMENT && !node->GetFormControlElementType().empty()) |
| 45 | + { |
| 46 | + auto message = CefProcessMessage::Create("InputFocus"); |
| 47 | + message->GetArgumentList()->SetBool(0, true); |
| 48 | + browser->GetMainFrame()->SendProcessMessage(PID_BROWSER, message); |
| 49 | + |
| 50 | + // Set variable to ensure that the event does not trigger twice |
| 51 | + m_bHasInputFocus = true; |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + virtual void OnRegisterCustomSchemes(CefRawPtr<CefSchemeRegistrar> registrar) override |
| 57 | + { |
| 58 | + // Register custom MTA scheme (has to be called in all proceseses) |
| 59 | + registrar->AddCustomScheme("mtalocal", CEF_SCHEME_OPTION_CSP_BYPASSING); |
| 60 | + } |
| 61 | + |
| 62 | + // http://magpcss.org/ceforum/apidocs3/projects/(default)/CefRenderProcessHandler.html#OnContextCreated(CefRefPtr%3CCefBrowser%3E,CefRefPtr%3CCefFrame%3E,CefRefPtr%3CCefV8Context%3E) |
| 63 | + // // |
| 64 | + virtual void OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefV8Context> context) override |
| 65 | + { |
| 66 | + // Get global object and create a v8 handler instance |
| 67 | + CefRefPtr<CefV8Value> globalObject = context->GetGlobal(); |
| 68 | + CefRefPtr<CV8Handler> handler = new CV8Handler(frame); |
| 69 | + |
| 70 | + // Create MTA object |
| 71 | + CefRefPtr<CefV8Value> mtaObject = CefV8Value::CreateObject(nullptr, nullptr); |
| 72 | + |
| 73 | + // Bind V8 --> C++ functions |
| 74 | + V8Helpers::BindV8Function(handler, mtaObject, "triggerEvent", Javascript_triggerEvent); |
| 75 | + |
| 76 | + // Assign mtaObject to global object |
| 77 | + globalObject->SetValue("mta", mtaObject, V8_PROPERTY_ATTRIBUTE_NONE); |
| 78 | + } |
| 79 | + |
| 80 | + static void Javascript_triggerEvent(CefRefPtr<CefFrame> frame, const CefV8ValueList& arguments) |
| 81 | + { |
| 82 | + if (arguments.size() == 0) |
| 83 | + return; |
| 84 | + |
| 85 | + CefRefPtr<CefProcessMessage> message = V8Helpers::SerialiseV8Arguments("TriggerLuaEvent", arguments); |
| 86 | + frame->GetBrowser()->GetMainFrame()->SendProcessMessage(PID_BROWSER, message); |
| 87 | + } |
| 88 | + |
| 89 | +public: |
| 90 | + IMPLEMENT_REFCOUNTING(CCefApp); |
| 91 | + |
| 92 | +private: |
| 93 | + bool m_bHasInputFocus = false; |
| 94 | +}; |
0 commit comments