CEFInterfaceBrowserHandler.h
11.1 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
// Engine/Source/Runtime/WebBrowser/Private/CEF/CEFBrowserHandler.h
#pragma once
#include "CoreMinimal.h"
#if WITH_CEF3
#if PLATFORM_WINDOWS
#include "Windows/WindowsHWrapper.h"
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/AllowWindowsPlatformAtomics.h"
#endif
#pragma push_macro("OVERRIDE")
#undef OVERRIDE // cef headers provide their own OVERRIDE macro
THIRD_PARTY_INCLUDES_START
#if PLATFORM_APPLE
PRAGMA_DISABLE_DEPRECATION_WARNINGS
#endif
#include "include/cef_client.h"
#if PLATFORM_APPLE
PRAGMA_ENABLE_DEPRECATION_WARNINGS
#endif
THIRD_PARTY_INCLUDES_END
#pragma pop_macro("OVERRIDE")
#if PLATFORM_WINDOWS
#include "Windows/HideWindowsPlatformAtomics.h"
#include "Windows/HideWindowsPlatformTypes.h"
#endif
#include "IWebInterfaceBrowserWindow.h"
#endif
class IWebInterfaceBrowserWindow;
struct Rect;
class FCEFWebInterfaceBrowserWindow;
class FCEFInterfaceBrowserPopupFeatures;
#if WITH_CEF3
/**
* Implements CEF Client and other Browser level interfaces.
*/
class FCEFInterfaceBrowserHandler
: public CefClient
, public CefDisplayHandler
, public CefLifeSpanHandler
, public CefLoadHandler
, public CefRenderHandler
, public CefRequestHandler
, public CefKeyboardHandler
, public CefJSDialogHandler
, public CefContextMenuHandler
, public CefDragHandler
{
public:
/** Default constructor. */
FCEFInterfaceBrowserHandler(bool InUseTransparency, const TArray<FString>& AltRetryDomains = TArray<FString>());
public:
/**
* Pass in a pointer to our Browser Window so that events can be passed on.
*
* @param InBrowserWindow The browser window this will be handling.
*/
void SetBrowserWindow(TSharedPtr<FCEFWebInterfaceBrowserWindow> InBrowserWindow);
/**
* Sets the browser window features and settings for popups which will be passed along when creating the new window.
*
* @param InPopupFeatures The popup features and settings for the window.
*/
void SetPopupFeatures(const TSharedPtr<FCEFInterfaceBrowserPopupFeatures>& InPopupFeatures)
{
BrowserPopupFeatures = InPopupFeatures;
}
public:
// CefClient Interface
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() override
{
return this;
}
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override
{
return this;
}
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() override
{
return this;
}
virtual CefRefPtr<CefRenderHandler> GetRenderHandler() override
{
return this;
}
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() override
{
return this;
}
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() override
{
return this;
}
virtual CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() override
{
return this;
}
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override
{
return this;
}
virtual CefRefPtr<CefDragHandler> GetDragHandler() override
{
return this;
}
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> Browser,
CefProcessId SourceProcess,
CefRefPtr<CefProcessMessage> Message) override;
public:
// CefDisplayHandler Interface
virtual void OnTitleChange(CefRefPtr<CefBrowser> Browser, const CefString& Title) override;
virtual void OnAddressChange(CefRefPtr<CefBrowser> Browser, CefRefPtr<CefFrame> Frame, const CefString& Url) override;
virtual bool OnTooltip(CefRefPtr<CefBrowser> Browser, CefString& Text) override;
virtual bool OnConsoleMessage(
CefRefPtr<CefBrowser> Browser,
const CefString& Message,
const CefString& Source,
int Line) override;
public:
// CefLifeSpanHandler Interface
virtual void OnAfterCreated(CefRefPtr<CefBrowser> Browser) override;
virtual bool DoClose(CefRefPtr<CefBrowser> Browser) override;
virtual void OnBeforeClose(CefRefPtr<CefBrowser> Browser) override;
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
const CefString& Target_Url,
const CefString& Target_Frame_Name,
CefLifeSpanHandler::WindowOpenDisposition /* Target_Disposition */,
bool /* User_Gesture */,
const CefPopupFeatures& PopupFeatures,
CefWindowInfo& WindowInfo,
CefRefPtr<CefClient>& Client,
CefBrowserSettings& Settings,
bool* no_javascript_access) override
{
return OnBeforePopup(Browser, Frame, Target_Url, Target_Frame_Name, PopupFeatures, WindowInfo, Client, Settings, no_javascript_access);
}
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) ;
public:
// CefLoadHandler Interface
virtual void OnLoadError(CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
CefLoadHandler::ErrorCode InErrorCode,
const CefString& ErrorText,
const CefString& FailedUrl) override;
virtual void OnLoadingStateChange(
CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward) override;
#if PLATFORM_LINUX
virtual void OnLoadStart(
CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame) override;
#else
virtual void OnLoadStart(
CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
TransitionType CefTransitionType) override;
#endif
public:
// CefRenderHandler Interface
virtual bool GetRootScreenRect(CefRefPtr<CefBrowser> Browser, CefRect& Rect) override;
virtual bool GetViewRect(CefRefPtr<CefBrowser> Browser, CefRect& Rect) override;
virtual void OnPaint(CefRefPtr<CefBrowser> Browser,
PaintElementType Type,
const RectList& DirtyRects,
const void* Buffer,
int Width, int Height) override;
virtual void OnCursorChange(CefRefPtr<CefBrowser> Browser,
CefCursorHandle Cursor,
CefRenderHandler::CursorType Type,
const CefCursorInfo& CustomCursorInfo) override;
virtual void OnPopupShow(CefRefPtr<CefBrowser> Browser, bool bShow) override;
virtual void OnPopupSize(CefRefPtr<CefBrowser> Browser, const CefRect& Rect) override;
virtual bool GetScreenInfo(CefRefPtr<CefBrowser> Browser, CefScreenInfo& ScreenInfo) override;
#if !PLATFORM_LINUX
virtual void OnImeCompositionRangeChanged(
CefRefPtr<CefBrowser> Browser,
const CefRange& SelectionRange,
const CefRenderHandler::RectList& CharacterBounds) override;
#endif
public:
// CefRequestHandler Interface
virtual ReturnValue OnBeforeResourceLoad(
CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
CefRefPtr<CefRequest> Request,
CefRefPtr<CefRequestCallback> Callback) override;
virtual void OnResourceLoadComplete(CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
CefRefPtr<CefRequest> Request,
CefRefPtr<CefResponse> Response,
URLRequestStatus Status,
int64 Received_content_length) override;
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> Browser, TerminationStatus Status) override;
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
CefRefPtr<CefRequest> Request,
bool IsRedirect) override;
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
CefRefPtr<CefRequest> Request ) override;
virtual bool OnCertificateError(
CefRefPtr<CefBrowser> Browser,
cef_errorcode_t CertError,
const CefString& RequestUrl,
CefRefPtr<CefSSLInfo> SslInfo,
CefRefPtr<CefRequestCallback> Callback ) override;
public:
// CefKeyboardHandler interface
virtual bool OnKeyEvent(CefRefPtr<CefBrowser> Browser,
const CefKeyEvent& Event,
CefEventHandle OsEvent) override;
public:
// CefJSDialogHandler interface
#if PLATFORM_LINUX
virtual bool OnJSDialog(
CefRefPtr<CefBrowser> Browser,
const CefString& OriginUrl,
const CefString& AcceptLang,
JSDialogType DialogType,
const CefString& MessageText,
const CefString& DefaultPromptText,
CefRefPtr<CefJSDialogCallback> Callback,
bool& OutSuppressMessage) override;
#else
virtual bool OnJSDialog(
CefRefPtr<CefBrowser> Browser,
const CefString& OriginUrl,
JSDialogType DialogType,
const CefString& MessageText,
const CefString& DefaultPromptText,
CefRefPtr<CefJSDialogCallback> Callback,
bool& OutSuppressMessage) override;
#endif
virtual bool OnBeforeUnloadDialog(CefRefPtr<CefBrowser> Browser, const CefString& MessageText, bool IsReload, CefRefPtr<CefJSDialogCallback> Callback) override;
virtual void OnResetDialogState(CefRefPtr<CefBrowser> Browser) override;
public:
// CefContextMenuHandler
virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> Browser,
CefRefPtr<CefFrame> Frame,
CefRefPtr<CefContextMenuParams> Params,
CefRefPtr<CefMenuModel> Model) override;
public:
// CefDragHandler interface
virtual void OnDraggableRegionsChanged(
CefRefPtr<CefBrowser> Browser,
const std::vector<CefDraggableRegion>& Regions) override;
public:
IWebInterfaceBrowserWindow::FOnBeforePopupDelegate& OnBeforePopup()
{
return BeforePopupDelegate;
}
IWebInterfaceBrowserWindow::FOnCreateWindow& OnCreateWindow()
{
return CreateWindowDelegate;
}
typedef TMap<FString, FString> FRequestHeaders;
DECLARE_DELEGATE_ThreeParams(FOnBeforeResourceLoadDelegate, const CefString& /*URL*/, CefRequest::ResourceType /*Type*/, FRequestHeaders& /*AdditionalHeaders*/);
FOnBeforeResourceLoadDelegate& OnBeforeResourceLoad()
{
return BeforeResourceLoadDelegate;
}
DECLARE_DELEGATE_FourParams(FOnResourceLoadCompleteDelegate, const CefString& /*URL*/, CefRequest::ResourceType /*Type*/, CefRequestHandler::URLRequestStatus /*Status*/, int64 /*ContentLength*/);
FOnResourceLoadCompleteDelegate& OnResourceLoadComplete()
{
return ResourceLoadCompleteDelegate;
}
DECLARE_DELEGATE_FourParams(FOnConsoleMessageDelegate, CefRefPtr<CefBrowser> /*Browser*/, const CefString& /*Message*/, const CefString& /*Source*/, int /*Line*/);
FOnConsoleMessageDelegate& OnConsoleMessage()
{
return ConsoleMessageDelegate;
}
private:
bool ShowDevTools(const CefRefPtr<CefBrowser>& Browser);
bool bUseTransparency;
TArray<FString> AltRetryDomains;
uint32 AltRetryDomainIdx = 0;
/** Delegate for notifying that a popup window is attempting to open. */
IWebInterfaceBrowserWindow::FOnBeforePopupDelegate BeforePopupDelegate;
/** Delegate for handling requests to create new windows. */
IWebInterfaceBrowserWindow::FOnCreateWindow CreateWindowDelegate;
/** Delegate for handling adding additional headers to requests */
FOnBeforeResourceLoadDelegate BeforeResourceLoadDelegate;
/** Delegate that allows response to the status of resource loads */
FOnResourceLoadCompleteDelegate ResourceLoadCompleteDelegate;
/** Delegate that allows for response to console logs. Typically used to capture and mirror web logs in client application logs. */
FOnConsoleMessageDelegate ConsoleMessageDelegate;
/** Weak Pointer to our Web Browser window so that events can be passed on while it's valid.*/
TWeakPtr<FCEFWebInterfaceBrowserWindow> BrowserWindowPtr;
/** Pointer to the parent web browser handler */
CefRefPtr<FCEFInterfaceBrowserHandler> ParentHandler;
/** Stores popup window features and settings */
TSharedPtr<FCEFInterfaceBrowserPopupFeatures> BrowserPopupFeatures;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(FCEFInterfaceBrowserHandler);
};
#endif