-
Notifications
You must be signed in to change notification settings - Fork 1
/
browser-client.hpp
89 lines (63 loc) · 4.27 KB
/
browser-client.hpp
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
#pragma once
#include "cef-headers.hpp"
#include <map>
#include <mutex>
struct BrowserSource;
class BrowserClient : public CefClient, public CefDisplayHandler, public CefLifeSpanHandler, public CefRequestHandler, public CefResourceRequestHandler, public CefContextMenuHandler, public CefRenderHandler, public CefAudioHandler, public CefLoadHandler
{
public:
inline BrowserClient(bool reroute_audio_) : m_reroute_audio(reroute_audio_) {}
/* CefClient */
CefRefPtr<CefLoadHandler> GetLoadHandler() override;
CefRefPtr<CefRenderHandler> GetRenderHandler() override;
CefRefPtr<CefDisplayHandler> GetDisplayHandler() override;
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override;
CefRefPtr<CefRequestHandler> GetRequestHandler() override;
CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override;
CefRefPtr<CefAudioHandler> GetAudioHandler() override;
/* CefDisplayHandler */
bool OnConsoleMessage(CefRefPtr<CefBrowser> browser, cef_log_severity_t level, const CefString &message, const CefString &source, int line) override;
/* CefLifeSpanHandler */
bool OnBeforePopup(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const CefString &target_url, const CefString &target_frame_name, cef_window_open_disposition_t target_disposition, bool user_gesture, const CefPopupFeatures &popupFeatures, CefWindowInfo &windowInfo,
CefRefPtr<CefClient> &client, CefBrowserSettings &settings, CefRefPtr<CefDictionaryValue> &extra_info, bool *no_javascript_access) override;
bool OnTooltip(CefRefPtr<CefBrowser> browser, CefString &text) override;
bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefProcessId source_process, CefRefPtr<CefProcessMessage> message) override;
/* CefRequestHandler */
CefRefPtr<CefResourceRequestHandler> GetResourceRequestHandler(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, bool is_navigation, bool is_download, const CefString &request_initiator, bool &disable_default_handling) override;
/* CefResourceRequestHandler */
CefResourceRequestHandler::ReturnValue OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback) override;
/* CefContextMenuHandler */
void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) override;
/* CefRenderHandler */
void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect) override;
void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height) override;
void OnAudioStreamPacket(CefRefPtr<CefBrowser> browser, const float **data, int frames, int64_t pts) override;
void OnAudioStreamStopped(CefRefPtr<CefBrowser> browser) override;
void OnAudioStreamStarted(CefRefPtr<CefBrowser> browser, const CefAudioParameters ¶ms, int channels) override;
void OnAudioStreamError(CefRefPtr<CefBrowser> browser, const CefString &message) override;
const int kFramesPerBuffer = 1024;
virtual bool GetAudioParameters(CefRefPtr<CefBrowser> browser, CefAudioParameters ¶ms) override;
/* CefLoadHandler */
void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, TransitionType transition_type) override;
void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override;
void OnLoadError(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, ErrorCode errorCode, const CefString &errorText, const CefString &failedUrl) override;
int m_channels = 0;
int m_sample_rate = 0;
int m_frames_per_buffer = 0;
ChannelLayout m_channel_layout;
IMPLEMENT_REFCOUNTING(BrowserClient);
public:
CefRefPtr<CefBrowser> GetMostRecentRenderKnown();
CefRefPtr<CefBrowser> PopCallback(const int functionId);
void RegisterCallback(const int functionId, CefRefPtr<CefBrowser> browser);
public:
static std::string cefListValueToJSONString(CefRefPtr<CefListValue> listValue);
private:
void UpdateExtraTexture();
bool valid() const;
bool m_reroute_audio = true;
std::recursive_mutex m_recursiveMutex;
std::map<int, CefRefPtr<CefBrowser>> m_callbackDictionary;
CefRefPtr<CefBrowser> m_Browser;
CefRefPtr<CefBrowser> m_MostRecentRenderKnowOf = nullptr;
};