This repository was archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 601
Expand file tree
/
Copy pathclient_handler.h
More file actions
365 lines (308 loc) · 12.8 KB
/
client_handler.h
File metadata and controls
365 lines (308 loc) · 12.8 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
// 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_BROWSER_CLIENT_HANDLER_H_
#define CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_H_
#pragma once
#include <set>
#include <string>
#include "include/cef_client.h"
#include "include/wrapper/cef_helpers.h"
#include "include/wrapper/cef_message_router.h"
#include "include/wrapper/cef_resource_manager.h"
#include "appshell/browser/client_types.h"
#if defined(OS_LINUX)
#include "appshell/browser/dialog_handler_gtk.h"
// Brackets specific change.
#include "appshell/client_handler.h"
#endif
namespace client {
// Client handler abstract base class. Provides common functionality shared by
// all concrete client handler implementations.
// Brackets specific change.
// On Linux we are going to be using this client handler instead of
// appshell/ClientHandler.
class ClientHandler :
#ifdef OS_LINUX
public ::ClientHandler,
public CefDownloadHandler {
#else
public CefClient,
public CefContextMenuHandler,
public CefDisplayHandler,
public CefDownloadHandler,
public CefDragHandler,
public CefKeyboardHandler,
public CefLifeSpanHandler,
public CefLoadHandler,
public CefRequestHandler {
#endif
public:
typedef ::ClientHandler _parent;
// Implement this interface to receive notification of ClientHandler
// events. The methods of this class will be called on the main thread.
class Delegate {
public:
// Called when the browser is created.
virtual void OnBrowserCreated(CefRefPtr<CefBrowser> browser) = 0;
// Called when the browser is closing.
virtual void OnBrowserClosing(CefRefPtr<CefBrowser> browser) = 0;
// Called when the browser has been closed.
virtual void OnBrowserClosed(CefRefPtr<CefBrowser> browser) = 0;
// Set the window URL address.
virtual void OnSetAddress(const std::string& url) = 0;
// Set the window title.
virtual void OnSetTitle(const std::string& title) = 0;
// Set fullscreen mode.
virtual void OnSetFullscreen(bool fullscreen) = 0;
// Set the loading state.
virtual void OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) = 0;
// Set the draggable regions.
virtual void OnSetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) = 0;
protected:
virtual ~Delegate() {}
};
typedef std::set<CefMessageRouterBrowserSide::Handler*> MessageHandlerSet;
// Constructor may be called on any thread.
// |delegate| must outlive this object or DetachDelegate() must be called.
ClientHandler(Delegate* delegate,
bool is_osr,
const std::string& startup_url);
// This object may outlive the Delegate object so it's necessary for the
// Delegate to detach itself before destruction.
void DetachDelegate();
// CefClient methods
CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
return this;
}
CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
return this;
}
CefRefPtr<CefDownloadHandler> GetDownloadHandler() OVERRIDE {
return this;
}
#ifndef OS_LINUX
CefRefPtr<CefDragHandler> GetDragHandler() OVERRIDE {
return this;
}
#endif
CefRefPtr<CefKeyboardHandler> GetKeyboardHandler() OVERRIDE {
return this;
}
CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
return this;
}
CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
return this;
}
CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
return this;
}
virtual bool OnProcessMessageReceived(CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE;
#if defined(OS_LINUX)
CefRefPtr<CefDialogHandler> GetDialogHandler() OVERRIDE {
return dialog_handler_;
}
CefRefPtr<CefJSDialogHandler> GetJSDialogHandler() OVERRIDE {
return dialog_handler_;
}
#endif
// CefContextMenuHandler methods
void OnBeforeContextMenu(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
CefRefPtr<CefMenuModel> model) OVERRIDE;
bool OnContextMenuCommand(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefContextMenuParams> params,
int command_id,
EventFlags event_flags) OVERRIDE;
// CefDisplayHandler methods
void OnAddressChange(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& url) OVERRIDE;
void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) OVERRIDE;
void OnFullscreenModeChange(CefRefPtr<CefBrowser> browser,
bool fullscreen) OVERRIDE;
// CefDownloadHandler methods
void OnBeforeDownload(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
const CefString& suggested_name,
CefRefPtr<CefBeforeDownloadCallback> callback) OVERRIDE;
void OnDownloadUpdated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback) OVERRIDE;
// CefDragHandler methods
#ifndef OS_LINUX
bool OnDragEnter(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDragData> dragData,
CefDragHandler::DragOperationsMask mask) OVERRIDE;
#endif
#ifndef OS_LINUX
//We do not plan to add any feature to parent class(::ClientHandler) implementation of this function.
//So override is useless, modern compilers will complain about this.
void OnDraggableRegionsChanged(
CefRefPtr<CefBrowser> browser,
const std::vector<CefDraggableRegion>& regions) OVERRIDE;
#endif
// CefKeyboardHandler methods
bool OnPreKeyEvent(CefRefPtr<CefBrowser> browser,
const CefKeyEvent& event,
CefEventHandle os_event,
bool* is_keyboard_shortcut) OVERRIDE;
// CefLifeSpanHandler methods
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;
void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefLoadHandler methods
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;
void OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl) OVERRIDE;
// CefRequestHandler methods
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool is_redirect);
bool OnOpenURLFromTab(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& target_url,
CefRequestHandler::WindowOpenDisposition target_disposition,
bool user_gesture) OVERRIDE;
cef_return_value_t OnBeforeResourceLoad(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> callback) OVERRIDE;
CefRefPtr<CefResourceHandler> GetResourceHandler(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request) OVERRIDE;
CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefResponse> response) OVERRIDE;
bool OnQuotaRequest(CefRefPtr<CefBrowser> browser,
const CefString& origin_url,
int64 new_size,
CefRefPtr<CefRequestCallback> callback) OVERRIDE;
void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
const CefString& url,
bool& allow_os_execution) OVERRIDE;
bool OnCertificateError(
CefRefPtr<CefBrowser> browser,
ErrorCode cert_error,
const CefString& request_url,
CefRefPtr<CefSSLInfo> ssl_info,
CefRefPtr<CefRequestCallback> callback) OVERRIDE;
void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
TerminationStatus status) OVERRIDE;
// Returns the number of browsers currently using this handler. Can only be
// called on the CEF UI thread.
int GetBrowserCount() const;
// Show a new DevTools popup window.
virtual void ShowDevTools(CefRefPtr<CefBrowser> browser,
const CefPoint& inspect_element_at);
// Close the existing DevTools popup window, if any.
void CloseDevTools(CefRefPtr<CefBrowser> browser);
// Returns the startup URL.
std::string startup_url() const { return startup_url_; }
// Returns true if this handler uses off-screen rendering.
bool is_osr() const { return is_osr_; }
private:
// Create a new popup window using the specified information. |is_devtools|
// will be true if the window will be used for DevTools. Return true to
// proceed with popup browser creation or false to cancel the popup browser.
// May be called on any thead.
bool CreatePopupWindow(
CefRefPtr<CefBrowser> browser,
bool is_devtools,
const CefPopupFeatures& popupFeatures,
CefWindowInfo& windowInfo,
CefRefPtr<CefClient>& client,
CefBrowserSettings& settings);
// Execute Delegate notifications on the main thread.
void NotifyBrowserCreated(CefRefPtr<CefBrowser> browser);
void NotifyBrowserClosing(CefRefPtr<CefBrowser> browser);
void NotifyBrowserClosed(CefRefPtr<CefBrowser> browser);
void NotifyAddress(const CefString& url);
void NotifyTitle(const CefString& title);
void NotifyFullscreen(bool fullscreen);
void NotifyLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward);
void NotifyDraggableRegions(
const std::vector<CefDraggableRegion>& regions);
// Test context menu creation.
void BuildTestMenu(CefRefPtr<CefMenuModel> model);
bool ExecuteTestMenu(int command_id);
// THREAD SAFE MEMBERS
// The following members may be accessed from any thread.
// True if this handler uses off-screen rendering.
const bool is_osr_;
// The startup URL.
const std::string startup_url_;
// True if mouse cursor change is disabled.
bool mouse_cursor_change_disabled_;
#if defined(OS_LINUX)
// Custom dialog handler for GTK.
CefRefPtr<ClientDialogHandlerGtk> dialog_handler_;
#endif
// Handles the browser side of query routing. The renderer side is handled
// in client_renderer.cc.
CefRefPtr<CefMessageRouterBrowserSide> message_router_;
// Manages the registration and delivery of resources.
CefRefPtr<CefResourceManager> resource_manager_;
// MAIN THREAD MEMBERS
// The following members will only be accessed on the main thread. This will
// be the same as the CEF UI thread except when using multi-threaded message
// loop mode on Windows.
Delegate* delegate_;
// UI THREAD MEMBERS
// The following members will only be accessed on the CEF UI thread.
// Track state information for the text context menu.
struct TestMenuState {
TestMenuState() : check_item(true), radio_item(0) {}
bool check_item;
int radio_item;
} test_menu_state_;
// The current number of browsers using this handler.
int browser_count_;
// Console logging state.
const std::string console_log_file_;
bool first_console_message_;
// True if an editable field currently has focus.
bool focus_on_editable_field_;
// Set of Handlers registered with the message router.
MessageHandlerSet message_handler_set_;
DISALLOW_COPY_AND_ASSIGN(ClientHandler);
};
} // namespace client
#endif // CEF_TESTS_CEFCLIENT_BROWSER_CLIENT_HANDLER_H_