forked from obsproject/obs-browser
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbrowser-app.hpp
More file actions
166 lines (132 loc) · 4.74 KB
/
browser-app.hpp
File metadata and controls
166 lines (132 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/******************************************************************************
Copyright (C) 2014 by John R. Bradley <jrb@turrettech.com>
Copyright (C) 2018 by Hugh Bailey ("Jim") <jim@obsproject.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
#pragma once
#include <map>
#include <unordered_map>
#include <functional>
#include "cef-headers.hpp"
typedef std::function<void(CefRefPtr<CefBrowser>)> BrowserFunc;
#ifdef USE_QT_LOOP
#include <QObject>
#include <QTimer>
#include <mutex>
#include <deque>
typedef std::function<void()> MessageTask;
class MessageObject : public QObject {
Q_OBJECT
friend void QueueBrowserTask(CefRefPtr<CefBrowser> browser,
BrowserFunc func);
struct Task {
CefRefPtr<CefBrowser> browser;
BrowserFunc func;
inline Task() {}
inline Task(CefRefPtr<CefBrowser> browser_, BrowserFunc func_)
: browser(browser_), func(func_)
{
}
};
std::mutex browserTaskMutex;
std::deque<Task> browserTasks;
public slots:
bool ExecuteNextBrowserTask();
void ExecuteTask(MessageTask task);
void DoCefMessageLoop(int ms);
void Process();
};
extern void QueueBrowserTask(CefRefPtr<CefBrowser> browser, BrowserFunc func);
#endif
class BrowserApp : public CefApp,
public CefRenderProcessHandler,
public CefBrowserProcessHandler,
public CefV8Handler {
private:
void ExecuteJSFunction(CefRefPtr<CefBrowser> browser,
const char *functionName,
CefV8ValueList arguments);
typedef std::map<int, CefRefPtr<CefV8Value>> CallbackMap;
bool shared_texture_available;
CallbackMap callbackMap;
int callbackId = 0;
class APIFunctionItem
{
public:
std::string message;
std::string fullName;
};
std::map<std::string, APIFunctionItem> cefClientFunctions;
public:
inline BrowserApp(bool shared_texture_available_ = false)
: shared_texture_available(shared_texture_available_)
{
}
virtual CefRefPtr<CefRenderProcessHandler>
GetRenderProcessHandler() override;
virtual CefRefPtr<CefBrowserProcessHandler>
GetBrowserProcessHandler() override;
virtual void OnBeforeChildProcessLaunch(
CefRefPtr<CefCommandLine> command_line) override;
virtual void OnRegisterCustomSchemes(
CefRawPtr<CefSchemeRegistrar> registrar) override;
virtual void OnBeforeCommandLineProcessing(
const CefString &process_type,
CefRefPtr<CefCommandLine> command_line) override;
virtual void OnContextCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefV8Context> context) override;
virtual void OnFocusedNodeChanged(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefDOMNode> node) override;
virtual bool
OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) override;
virtual bool Execute(const CefString &name,
CefRefPtr<CefV8Value> object,
const CefV8ValueList &arguments,
CefRefPtr<CefV8Value> &retval,
CefString &exception) override;
#ifdef USE_QT_LOOP
virtual void OnScheduleMessagePumpWork(int64 delay_ms) override;
QTimer frameTimer;
#endif
#if !ENABLE_WASHIDDEN
std::unordered_map<int, bool> browserVis;
void SetFrameDocumentVisibility(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
bool isVisible);
void SetDocumentVisibility(CefRefPtr<CefBrowser> browser,
bool isVisible);
#endif
IMPLEMENT_REFCOUNTING(BrowserApp);
#if ENABLE_CREATE_BROWSER_API
public:
// Gets information from CefBrowserHost::CreateBrowserSync()
virtual void
OnBrowserCreated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDictionaryValue> extra_info) override;
virtual void OnBrowserDestroyed(CefRefPtr<CefBrowser> browser) override;
private:
std::mutex m_createBrowserArgsMutex;
std::map<int, CefRefPtr<CefDictionaryValue>> m_createBrowserArgs;
#endif
private:
void SEBindJavaScriptProperties(CefRefPtr<CefV8Value> globalObj,
CefString containerName,
CefRefPtr<CefDictionaryValue> root);
void SEBindJavaScriptFunctions(CefRefPtr<CefV8Value> globalObj,
CefString containerName,
CefRefPtr<CefDictionaryValue> root);
};