-
Notifications
You must be signed in to change notification settings - Fork 1
/
BrowserHandlers.h
83 lines (55 loc) · 3.35 KB
/
BrowserHandlers.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
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
#pragma once
#include "stdafx.h"
#include <list>
#include "include/cef_base.h"
#include "include/cef_browser.h"
class CCefClientHandler : public CefClient,public CefDisplayHandler,public CefLifeSpanHandler,public CefLoadHandler,public CefRequestHandler, public CefContextMenuHandler,public CefRenderProcessHandler
{
public:
CCefClientHandler();
~CCefClientHandler();
// CefClient methods:
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() override;
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override;
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() override;
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() override;
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override{
return this;
}
void OnWebKitInitialized() override;
// ----------------CefDisplayHandler methods:-------------------
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,const CefString& title) override;
//---------------- CefLifeSpanHandler methods:----------------------------
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;
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
virtual bool DoClose(CefRefPtr<CefBrowser> browser) override;
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;
// ----------------CefLoadHandler methods:---------------------------
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame) override;
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,int httpStatusCode) override;
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,ErrorCode errorCode,const CefString& errorText,const CefString& failedUrl) override;
//-----------------
//菜单处理
virtual void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,CefRefPtr<CefContextMenuParams> params, CefRefPtr<CefMenuModel> model) override;
virtual bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame,CefRefPtr<CefContextMenuParams> params, int command_id, EventFlags event_flags) override;
void CloseHostBrowser(CefRefPtr<CefBrowser>browser, bool force_close) ;
// Request that all existing browser windows close.
void CloseAllBrowsers(bool force_close);
bool IsClosing() const;
void ShowDevelopTools(CefRefPtr<CefBrowser> browser,const CefPoint& inspect_element_at);
void CloseDevelopTools(CefRefPtr<CefBrowser> browser);
public:
//CefRefPtr<CefBrowser> browser_;
HWND hWnd_; //接收消息的句柄
CefString strTitle_; //网址标题
// List of existing browser windows. Only accessed on the CEF UI thread.
typedef std::vector<CefRefPtr<CefBrowser> > BrowserList;
BrowserList browser_list_;
private:
bool is_closing_;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(CCefClientHandler);
//由于CEF采用多线程架构,有必要使用锁和闭包来保证在多不同线程安全的传递数据。IMPLEMENT_LOCKING定义提供了Lock()和Unlock()方法以及AutoLock对象来保证不同代码块同步访问
IMPLEMENT_LOCKING(CCefClientHandler);
};