This repository has been archived by the owner on Feb 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
OffscreenBrowserClient.h
executable file
·54 lines (39 loc) · 1.81 KB
/
OffscreenBrowserClient.h
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
/**
* Offscreen browser client class for handling the requests from app side
* Simple example app using Chromium Embedded Framework
* Lassi Maksimainen, 2014
*/
#ifndef OFFSCREENBROWSERCLIENT_H_
#define OFFSCREENBROWSERCLIENT_H_
#include <string>
#include "include/cef_client.h"
#include "include/cef_frame.h"
#include "include/cef_string_visitor.h"
// Handles the "rendering" of the page to off-screen bitmap and other client lifecycle methods
class OffscreenBrowserClient : public CefClient, public CefLifeSpanHandler, public CefRenderHandler, public CefStringVisitor {
private:
CefRefPtr<CefBrowser> mBrowser;
bool visitActive;
std::string pageHtml;
static const int OFFSCREEN_BROWSER_WINDOW_WIDTH = 1400;
static const int OFFSCREEN_BROWSER_WINDOW_HEIGHT = 2000;
public:
OffscreenBrowserClient();
virtual ~OffscreenBrowserClient();
std::string GetHTMLSource();
// CefClient methods
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE { return this; }
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() OVERRIDE { return this; }
// CefLifeSpanHandler methods
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefRenderHandler methods
virtual void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList& dirtyRects, const void* buffer, int width, int height) OVERRIDE;
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) OVERRIDE { rect.Set(0, 0, OFFSCREEN_BROWSER_WINDOW_WIDTH, OFFSCREEN_BROWSER_WINDOW_HEIGHT); return true; };
// CefStringVisitor methods
virtual void Visit(const CefString& html);
// Own methods
CefRefPtr<CefBrowser> GetBrowser() { return mBrowser; }
IMPLEMENT_REFCOUNTING(OffscreenBrowserClient);
};
#endif /* OFFSCREENBROWSERCLIENT_H_ */