-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathCefControlEvent.h
More file actions
435 lines (355 loc) · 22.6 KB
/
CefControlEvent.h
File metadata and controls
435 lines (355 loc) · 22.6 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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#ifndef UI_CEF_CONTROL_CEF_CONTROL_EVENT_H_
#define UI_CEF_CONTROL_CEF_CONTROL_EVENT_H_
#include "duilib/duilib_config.h"
#pragma warning (push)
#pragma warning (disable:4100)
#include "include/cef_client.h"
#include <functional>
/** Cef控件事件处理接口(分为回调函数和接口类两种,使用时可以二选一)
* @copyright (c) 2016, NetEase Inc. All rights reserved
* @author Redrain
* @date 2016/7/22
*/
namespace ui
{
//JS相关的回调函数
typedef std::function<void(bool has_error, const std::string& result)> ReportResultFunction;
typedef std::function<void(const std::string& result)> CallJsFunctionCallback;
typedef std::function<void(const std::string& params, ReportResultFunction callback)> CppFunction;
//浏览器控件相关的回调函数
//导航前回调函数(回调函数的调用线程:CEF的UI线程)
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool user_gesture,
bool is_redirect)> OnBeforeBrowseEvent;
//资源加载前回调函数(回调函数的调用线程:CEF的IO线程)
typedef std::function<cef_return_value_t (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback)> OnBeforeResourceLoadEvent;
//资源重定向回调函数(回调函数的调用线程:CEF的IO线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
CefString& new_url)> OnResourceRedirectEvent;
//资源收到回应回调函数(回调函数的调用线程:CEF的IO线程)
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response)> OnResourceResponseEvent;
//资源加载完成回调函数(回调函数的调用线程:CEF的IO线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
cef_urlrequest_status_t status,
int64_t received_content_length)> OnResourceLoadCompleteEvent;
//资源执行协议回调函数(回调函数的调用线程:CEF的IO线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool& allow_os_execution)> OnProtocolExecutionEvent;
//页面加载状态发生变化的回调函数(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward)> OnLoadingStateChangeEvent;
//页面开始加载的回调函数(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
cef_transition_type_t transition_type)> OnLoadStartEvent;
//页面加载完成的回调函数(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode)> OnLoadEndEvent;
//页面加载发生错误的回调函数(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
cef_errorcode_t errorCode,
const DString& errorText,
const DString& failedUrl)> OnLoadErrorEvent;
//Browser对象创建完成(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser)> OnAfterCreatedEvent;
//Browser对象即将关闭(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser)> OnBeforeCloseEvent;
//菜单弹出(回调函数的调用线程:CEF的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
CefRefPtr<CefMenuModel> model)> OnBeforeContextMenuEvent;
//执行了菜单命令(回调函数的调用线程:CEF的UI线程)
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
int command_id,
cef_event_flags_t event_flags)> OnContextMenuCommandEvent;
//菜单消失(回调函数的调用线程:CEF的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame)> OnContextMenuDismissedEvent;
//标题变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
const DString& title)> OnTitleChangeEvent;
//URL变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const DString& url)> OnUrlChangeEvent;
//主Frame的URL变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (const DString& oldUrl,
const DString& newUrl)> OnMainUrlChangeEvent;
//FaviconURL变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
const std::vector<CefString>& icon_urls)> OnFaviconURLChangeEvent;
//全屏状态变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
bool bFullscreen)> OnFullscreenModeChangeEvent;
//状态信息变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
const DString& value)> OnStatusMessageEvent;
//加载进度变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
double progress)> OnLoadingProgressChangeEvent;
//多媒体访问情况变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
bool has_video_access,
bool has_audio_access)> OnMediaAccessChangeEvent;
//点击了超级链接,即将弹出新窗口(回调函数的调用线程:CEF的UI线程)
//由于部分编译器的std::placeholders最多支持10个占位符,所以参数要控制在最多10个
struct BeforePopupEventParam
{
CefString target_frame_name;
CefLifeSpanHandler::WindowOpenDisposition target_disposition;
bool user_gesture;
CefPopupFeatures popupFeatures;
};
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int popup_id,
const CefString& target_url,
const BeforePopupEventParam& param,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings,
CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access)> OnBeforePopupEvent;
//弹出新窗口失败的通知(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
int popup_id)> OnBeforePopupAbortedEvent;
//开发者工具的显示属性发生变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (bool bVisible, bool bPopup)> OnDevToolAttachedStateChangeEvent;
//是否可以下载文件(回调函数的调用线程:CEF的UI线程)
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
const CefString& url,
const CefString& request_method)> OnCanDownloadEvent;
//下载文件之前事件的回调函数,CEF109版本忽略返回值(回调函数的调用线程:CEF的UI线程)
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
const CefString& suggested_name,
CefRefPtr<CefBeforeDownloadCallback> callback)> OnBeforeDownloadEvent;
//下载文件信息更新事件的回调函数(回调函数的调用线程:CEF的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback)> OnDownloadUpdatedEvent;
//打开文件/保存文件/选择文件夹对话框的回调函数(回调函数的调用线程:CEF的UI线程)
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
cef_file_dialog_mode_t mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
const std::vector<CefString>& accept_extensions,
const std::vector<CefString>& accept_descriptions,
CefRefPtr<CefFileDialogCallback> callback)> OnFileDialogEvent;
//主框架的文档加载完成的回调函数(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser)> OnDocumentAvailableInMainFrameEvent;
//网站图标下载完成事件(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
const CefString& image_url,
int http_status_code,
CefRefPtr<CefImage> image)> OnDownloadFavIconFinishedEvent;
//CefDragHandler接口
//拖动操作(回调函数的调用线程:CEF的UI线程)
typedef std::function<bool (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
CefDragHandler::DragOperationsMask mask)> OnDragEnterEvent;
//可拖动区域发生变化(回调函数的调用线程:主进程的UI线程)
typedef std::function<void (CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const std::vector<CefDraggableRegion>& regions)> OnDraggableRegionsChangedEvent;
}
namespace ui
{
/** Cef控件事件处理接口
*/
class CefControlEvent
{
public:
/** Browser对象创建完成(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) {}
/** Browser对象即将关闭(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) {}
/** 菜单弹出(回调函数的调用线程:CEF的UI线程)
*/
virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
CefRefPtr<CefMenuModel> model) {}
/** 执行了菜单命令(回调函数的调用线程:CEF的UI线程)
*/
virtual bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
int command_id,
cef_event_flags_t event_flags) { return false; }
/** 菜单消失(回调函数的调用线程:CEF的UI线程)
*/
virtual void OnContextMenuDismissed(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame) {}
/** 标题变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser, const DString& title) {}
/** URL变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnUrlChange(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const DString& url) {}
/** 主Frame的URL变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnMainUrlChange(const DString& oldUrl, const DString& newUrl) {}
/** FaviconURL变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnFaviconURLChange(CefRefPtr<CefBrowser> browser, const std::vector<CefString>& icon_urls) {}
/** 全屏状态变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnFullscreenModeChange(CefRefPtr<CefBrowser> browser, bool bFullscreen) {}
/** 状态信息变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnStatusMessage(CefRefPtr<CefBrowser> browser, const DString& value) {}
/** 加载进度变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnLoadingProgressChange(CefRefPtr<CefBrowser> browser, double progress) {}
/** 多媒体访问情况变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnMediaAccessChange(CefRefPtr<CefBrowser> browser, bool has_video_access, bool has_audio_access) {}
/** 点击了超级链接,即将弹出新窗口(回调函数的调用线程:CEF的UI线程)
*/
virtual bool OnBeforePopup(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int popup_id,
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,
CefRefPtr<CefDictionaryValue>& extra_info,
bool* no_javascript_access) { return true; }
/** 弹出新窗口失败的通知(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnBeforePopupAborted(CefRefPtr<CefBrowser> browser, int popup_id) {}
/** 导航前回调函数(回调函数的调用线程:CEF的UI线程)
*/
virtual bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool user_gesture,
bool is_redirect) { return false; }
/** 资源加载前回调函数(回调函数的调用线程:CEF的IO线程)
*/
virtual cef_return_value_t OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback) { return RV_CONTINUE; }
/** 资源重定向回调函数(回调函数的调用线程:CEF的IO线程)
*/
virtual void OnResourceRedirect(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
CefString& new_url) {}
/** 资源收到回应回调函数(回调函数的调用线程:CEF的IO线程)
*/
virtual bool OnResourceResponse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response) { return false; }
/** 资源加载完成回调函数(回调函数的调用线程:CEF的IO线程)
*/
virtual void OnResourceLoadComplete(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response,
cef_urlrequest_status_t status,
int64_t received_content_length) {}
/** 资源执行协议回调函数(回调函数的调用线程:CEF的IO线程)
*/
virtual void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool& allow_os_execution) {}
/** 页面加载状态发生变化的回调函数(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser, bool isLoading, bool canGoBack, bool canGoForward) {}
/** 页面开始加载的回调函数(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, cef_transition_type_t transition_type) {}
/** 页面加载完成的回调函数(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) {}
/** 页面加载发生错误的回调函数(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
cef_errorcode_t errorCode,
const DString& errorText,
const DString& failedUrl) {}
/** 开发者工具的显示属性发生变化(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnDevToolAttachedStateChange(bool bVisible) {}
/** 是否可以下载文件(回调函数的调用线程:CEF的UI线程)
*/
virtual bool OnCanDownload(CefRefPtr<CefBrowser> browser,
const CefString& url,
const CefString& request_method) { return true; }
/** 下载文件之前事件的回调函数,CEF109版本忽略返回值(回调函数的调用线程:CEF的UI线程)
*/
virtual bool OnBeforeDownload(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
const CefString& suggested_name,
CefRefPtr<CefBeforeDownloadCallback> callback) { return true; }
/** 下载文件信息更新事件的回调函数(回调函数的调用线程:CEF的UI线程)
*/
virtual void OnDownloadUpdated(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback) {}
/** 打开文件/保存文件/选择文件夹对话框的回调函数(回调函数的调用线程:CEF的UI线程)
*/
virtual bool OnFileDialog(CefRefPtr<CefBrowser> browser,
cef_file_dialog_mode_t mode,
const CefString& title,
const CefString& default_file_path,
const std::vector<CefString>& accept_filters,
const std::vector<CefString>& accept_extensions,
const std::vector<CefString>& accept_descriptions,
CefRefPtr<CefFileDialogCallback> callback) { return false; }
/** 主框架的文档加载完成的回调函数(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnDocumentAvailableInMainFrame(CefRefPtr<CefBrowser> browser) {}
/** 网站图标下载完成事件(回调函数的调用线程:主进程的UI线程)
*/
virtual void OnDownloadFavIconFinished(CefRefPtr<CefBrowser> browser,
const CefString& image_url,
int http_status_code,
CefRefPtr<CefImage> image) {}
//CefDragHandler接口
//拖动操作(回调函数的调用线程:CEF的UI线程)
virtual bool OnDragEnter(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDragData> dragData, CefDragHandler::DragOperationsMask mask) { return false; };
//可拖动区域发生变化(回调函数的调用线程:主进程的UI线程)
virtual void OnDraggableRegionsChanged(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, const std::vector<CefDraggableRegion>& regions) {};
public:
virtual ~CefControlEvent() = default;
};
}
#pragma warning (pop)
#endif //UI_CEF_CONTROL_CEF_CONTROL_EVENT_H_