-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathBrowserClient
170 lines (122 loc) · 5.94 KB
/
BrowserClient
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
167
168
169
170
#ifndef OSGEARTH_CEF_BrowserClient
#define OSGEARTH_CEF_BrowserClient 1
#include "include/cef_client.h"
#include "include/cef_render_handler.h"
#include "include/wrapper/cef_message_router.h"
#include "ExecuteCallback"
#include <osgViewer/CompositeViewer>
#include <osgViewer/View>
#include <osgEarth/MapNode>
namespace osgEarth { namespace Cef
{
// forward declarations
class MapExecuteCallback;
#ifdef WIN32
class NativeEventHandlerWin;
#endif
// for manual render handler
class BrowserClient : public CefClient, public CefRenderHandler, public CefRequestHandler, public CefLifeSpanHandler, public CefMessageRouterBrowserSide::Handler, public CefDisplayHandler
{
public:
BrowserClient(osgViewer::CompositeViewer* viewer, const std::string& url, int width, int height);
~BrowserClient();
osgViewer::View* getMapView(const std::string& name);
osgEarth::MapNode* getMapNode(const std::string& name);
osgViewer::CompositeViewer* getViewer() { return _viewer.get(); }
CefBrowser* getBrowser() { return _browser.get(); }
osg::Image* getImage() { return _image.get(); }
void setSize(unsigned int width, unsigned int height);
void addExecuteCallback( ExecuteCallback* callback );
bool getInFocus() { return _inFocus; }
void setInFocus(bool focus) { _inFocus = focus; }
// CefClient methods
public:
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() { return this; }
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() { return this; }
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() { return this; }
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message);
// CefRenderHandler methods
public:
bool GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect);
bool GetViewRect(CefRefPtr<CefBrowser> browser, CefRect &rect);
bool GetScreenPoint(CefRefPtr<CefBrowser> browser, int viewX, int viewY, int& screenX, int& screenY);
//bool GetScreenInfo(CefRefPtr<CefBrowser> browser, CefScreenInfo& screen_info);
void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show);
void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect);
void OnPaint(CefRefPtr<CefBrowser> browser, PaintElementType type, const RectList &dirtyRects, const void *buffer, int width, int height);
void OnCursorChange( CefRefPtr<CefBrowser> browser, CefCursorHandle cursor, CursorType type, const CefCursorInfo& custom_cursor_info );
// CefRequestHandler methods
public:
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool is_redirect) OVERRIDE;
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser, TerminationStatus status) OVERRIDE;
// CefLifeSpanHandler methods
public:
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
const CefString& target_frame_name,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
bool* no_javascript_access) OVERRIDE;
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefMessageRouterBrowserSide::Handler methods
public:
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64 query_id,
const CefString& request,
bool persistent,
CefRefPtr<Callback> callback) OVERRIDE;
virtual void OnQueryCanceled(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int64 query_id) OVERRIDE;
// CefDisplayHandler methods
public:
void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) OVERRIDE;
void OnFaviconURLChange(CefRefPtr<CefBrowser> browser,
const std::vector<CefString>& icon_urls) OVERRIDE;
protected:
friend class MapExecuteCallback;
void initBrowser(const std::string& url);
void setupMainView(unsigned int width, unsigned int height);
void setupRTTCamera();
void addMapView(const std::string& id, osgViewer::View* mapView);
//CefRefPtr<RenderHandler> _renderHandler;
CefRefPtr<CefBrowser> _browser;
CefRefPtr<CefMessageRouterBrowserSide> _messageRouter;
typedef std::vector<CefMessageRouterBrowserSide::Handler*> MessageHandlerSet;
osg::ref_ptr<osgViewer::CompositeViewer> _viewer;
osg::ref_ptr<osgViewer::View> _mainView;
std::map<std::string, osg::ref_ptr<osgViewer::View>> _mapViews;
std::map<std::string, osg::ref_ptr<osgEarth::MapNode>> _mapNodes;
osg::ref_ptr<osgGA::GUIEventHandler> _mainEventHandler;
#ifdef WIN32
NativeEventHandlerWin* _nativeEventHandler;
#endif
typedef std::vector< osg::ref_ptr<ExecuteCallback> > ExecuteCallbacks;
ExecuteCallbacks _callbacks;
unsigned int _width;
unsigned int _height;
osg::ref_ptr<osg::Image> _image;
osg::ref_ptr<osg::Geode> _imageGeode;
osg::ref_ptr<osg::Image> _popupImage;
osg::ref_ptr<osg::Vec3Array> _popupVerts;
osg::ref_ptr<osg::Geode> _popupNode;
osg::ref_ptr<osg::Geometry> _popupGeom;
bool _inFocus;
osg::ref_ptr<osg::Image> _rttImage;
osg::ref_ptr<osg::Camera> _rttCamera;
IMPLEMENT_REFCOUNTING(BrowserClient);
};
} }
#endif