-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_handler.h
260 lines (211 loc) · 9.3 KB
/
client_handler.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
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
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
#define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_
#pragma once
#include <map>
#include <set>
#include <string>
#include "include/cef_client.h"
#include "util.h"
// Define this value to redirect all popup URLs to the main application browser
// window.
// #define TEST_REDIRECT_POPUP_URLS
// ClientHandler implementation.
class ClientHandler : public CefClient,
public CefContextMenuHandler,
public CefDisplayHandler,
public CefDownloadHandler,
//public CefGeolocationHandler,
public CefKeyboardHandler,
public CefLifeSpanHandler,
public CefLoadHandler,
public CefRequestHandler {
public:
bool volatile app_running_;
void *m_watcherHnd;
// Interface for process message delegates. Do not perform work in the
// RenderDelegate constructor.
class ProcessMessageDelegate : public virtual CefBase {
public:
// Called when a process message is received. Return true if the message was
// handled and should not be passed on to other handlers.
// ProcessMessageDelegates should check for unique message names to avoid
// interfering with each other.
virtual bool OnProcessMessageReceived(
CefRefPtr<ClientHandler> handler,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) {
return false;
}
};
typedef std::set<CefRefPtr<ProcessMessageDelegate> >
ProcessMessageDelegateSet;
// Interface for request handler delegates. Do not perform work in the
// RequestDelegate constructor.
class RequestDelegate : public virtual CefBase {
public:
// Called to retrieve a resource handler.
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<ClientHandler> handler,
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) {
return NULL;
}
};
typedef std::set<CefRefPtr<RequestDelegate> > RequestDelegateSet;
ClientHandler();
virtual ~ClientHandler();
// CefClient methods
virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
return this;
}
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message)
OVERRIDE;
// CefContextMenuHandler methods
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;
// CefDisplayHandler methods
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;
virtual void OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) OVERRIDE;
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) OVERRIDE;
/*virtual bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message,
const CefString& source,
int line) OVERRIDE;*/
void ClientHandler::OnBeforeDownload(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
const CefString& suggested_name,
CefRefPtr<CefBeforeDownloadCallback> callback) OVERRIDE;
void ClientHandler::OnDownloadUpdated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback) OVERRIDE;
// CefKeyboardHandler methods
virtual bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
const CefKeyEvent& event,
CefEventHandle os_event,
bool* is_keyboard_shortcut) OVERRIDE;
// CefLifeSpanHandler methods
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 OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
TerminationStatus status) OVERRIDE;
// CefRequestHandler methods
virtual CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) OVERRIDE;
void SetMainHwnd(CefWindowHandle hwnd);
CefWindowHandle GetMainHwnd() { return m_MainHwnd; }
CefRefPtr<CefBrowser> GetBrowser() { return m_Browser; }
int GetBrowserId() { return m_BrowserId; }
std::string GetLogFile();
void SetLastDownloadFile(const std::string& fileName);
std::string GetLastDownloadFile();
// Send a notification to the application. Notifications should not block the
// caller.
enum NotificationType {
NOTIFY_CONSOLE_MESSAGE,
NOTIFY_DOWNLOAD_COMPLETE,
NOTIFY_DOWNLOAD_ERROR,
};
void SendNotification(NotificationType type);
void CloseMainWindow();
void ShowDevTools(CefRefPtr<CefBrowser> browser);
// Returns the startup URL.
std::string GetStartupURL() { return m_StartupURL; }
// Create an external browser window that loads the specified URL.
static void LaunchExternalBrowser(const std::string& url);
bool SetLang(const int langId);
// Returns the full download path for the specified file, or an empty path to
// use the default temp directory.
std::string GetDownloadPath(const std::string& file_name);
bool Save(const std::string& path, const std::string& data);
protected:
void SetLoading(bool isLoading);
// Create all of ProcessMessageDelegate objects.
static void CreateProcessMessageDelegates(
ProcessMessageDelegateSet& delegates);
// Create all of RequestDelegateSet objects.
static void CreateRequestDelegates(RequestDelegateSet& delegates);
// The child browser window
CefRefPtr<CefBrowser> m_Browser;
// The main frame window handle
CefWindowHandle m_MainHwnd;
// The child browser id
int m_BrowserId;
// The edit window handle
// CefWindowHandle m_EditHwnd;
// The button window handles
// CefWindowHandle m_BackHwnd;
// CefWindowHandle m_ForwardHwnd;
// CefWindowHandle m_StopHwnd;
// CefWindowHandle m_ReloadHwnd;
// Support for logging.
std::string m_LogFile;
// Support for downloading files.
std::string m_LastDownloadFile;
// True if an editable field currently has focus.
bool m_bFocusOnEditableField;
// Registered delegates.
ProcessMessageDelegateSet process_message_delegates_;
RequestDelegateSet request_delegates_;
// If true DevTools will be opened in an external browser window.
bool m_bExternalDevTools;
// List of open DevTools URLs if not using an external browser window.
std::set<std::string> m_OpenDevToolsURLs;
// The startup URL.
std::string m_StartupURL;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientHandler);
// Include the default locking implementation.
IMPLEMENT_LOCKING(ClientHandler);
};
#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_H_