forked from chromiumembedded/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCefClientHandler.java
More file actions
317 lines (275 loc) · 9.69 KB
/
CefClientHandler.java
File metadata and controls
317 lines (275 loc) · 9.69 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<
8000
/div>
305
306
307
308
309
310
311
312
313
314
315
316
317
// Copyright (c) 2014 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.
package org.cef.handler;
import org.cef.browser.CefBrowser;
import org.cef.browser.CefMessageRouter;
import org.cef.callback.CefNative;
import java.util.HashMap;
import java.util.Vector;
/**
* Implement this interface to provide handler implementations.
*/
public abstract class CefClientHandler implements CefNative {
// Used internally to store a pointer to the CEF object.
private HashMap<String, Long> N_CefHandle = new HashMap<String, Long>();
private Vector<CefMessageRouter> msgRouters = new Vector<>();
@Override
public void setNativeRef(String identifer, long nativeRef) {
synchronized (N_CefHandle) {
N_CefHandle.put(identifer, nativeRef);
}
}
@Override
public long getNativeRef(String identifer) {
synchronized (N_CefHandle) {
if (N_CefHandle.containsKey(identifer)) return N_CefHandle.get(identifer);
}
return 0;
}
public CefClientHandler() {
try {
N_CefClientHandler_CTOR();
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void dispose() {
try {
// Call native DTOR if handler will be destroyed
for (int i = 0; i < msgRouters.size(); i++) {
msgRouters.get(i).dispose();
}
msgRouters.clear();
N_CefClientHandler_DTOR();
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
/**
* Returns the java part of the browser implementation.
* @param identifer the unique identifier of the browser.
* @return The found browser or null if none is found.
*/
abstract protected CefBrowser getBrowser(int identifier);
/**
* Returns a list of all browser instances.
* @return an array of browser Instances.
*/
abstract protected Object[] getAllBrowser();
/**
* Return the handler for context menus. If no handler is provided the
* default implementation will be used.
*/
abstract protected CefContextMenuHandler getContextMenuHandler();
/**
* Return the handler for dialogs. If no handler is provided the
* default implementation will be used.
*/
abstract protected CefDialogHandler getDialogHandler();
/**
* Return the handler for browser display state events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefDisplayHandler getDisplayHandler();
/**
* Return the handler for download events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefDownloadHandler getDownloadHandler();
/**
* Return the handler for drag events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefDragHandler getDragHandler();
/**
* Return the handler for focus events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefFocusHandler getFocusHandler();
/**
* Return the handler for javascript dialog requests.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefJSDialogHandler getJSDialogHandler();
/**
* Return the handler for keyboard events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefKeyboardHandler getKeyboardHandler();
/**
* Return the handler for browser life span events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefLifeSpanHandler getLifeSpanHandler();
/**
* Return the handler for browser load status events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefLoadHandler getLoadHandler();
/**
* Return the handler for printing on Linux. If a print handler is not
* provided then printing will not be supported on the Linux platform.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefPrintHandler getPrintHandler();
/**
* Return the handler for off-screen rendering events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefRenderHandler getRenderHandler();
/**
* Return the handler for browser request events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefRequestHandler getRequestHandler();
/**
* Return the handler for windowed rendering events.
* This method is a callback method and is called by
* the native code.
*/
abstract protected CefWindowHandler getWindowHandler();
protected synchronized void addMessageRouter(CefMessageRouter h) {
try {
msgRouters.add(h);
N_addMessageRouter(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeContextMenuHandler(CefContextMenuHandler h) {
try {
N_removeContextMenuHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeDialogHandler(CefDialogHandler h) {
try {
N_removeDialogHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeDisplayHandler(CefDisplayHandler h) {
try {
N_removeDisplayHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeDownloadHandler(CefDisplayHandler h) {
try {
N_removeDownloadHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeDragHandler(CefDragHandler h) {
try {
N_removeDragHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeFocusHandler(CefFocusHandler h) {
try {
N_removeFocusHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeJSDialogHandler(CefJSDialogHandler h) {
try {
N_removeJSDialogHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeKeyboardHandler(CefKeyboardHandler h) {
try {
N_removeKeyboardHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeLifeSpanHandler(CefLifeSpanHandler h) {
try {
N_removeLifeSpanHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeLoadHandler(CefLoadHandler h) {
try {
N_removeLoadHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removePrintHandler(CefPrintHandler h) {
try {
N_removePrintHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected synchronized void removeMessageRouter(CefMessageRouter h) {
try {
msgRouters.remove(h);
N_removeMessageRouter(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeRenderHandler(CefRenderHandler h) {
try {
N_removeRenderHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeRequestHandler(CefRequestHandler h) {
try {
N_removeRequestHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
protected void removeWindowHandler(CefWindowHandler h) {
try {
N_removeWindowHandler(h);
} catch (UnsatisfiedLinkError err) {
err.printStackTrace();
}
}
private final native void N_CefClientHandler_CTOR();
private final native void N_addMessageRouter(CefMessageRouter h);
private final native void N_removeContextMenuHandler(CefContextMenuHandler h);
private final native void N_removeDialogHandler(CefDialogHandler h);
private final native void N_removeDisplayHandler(CefDisplayHandler h);
private final native void N_removeDownloadHandler(CefDisplayHandler h);
private final native void N_removeDragHandler(CefDragHandler h);
private final native void N_removeFocusHandler(CefFocusHandler h);
private final native void N_removeJSDialogHandler(CefJSDialogHandler h);
private final native void N_removeKeyboardHandler(CefKeyboardHandler h);
private final native void N_removeLifeSpanHandler(CefLifeSpanHandler h);
private final native void N_removeLoadHandler(CefLoadHandler h);
private final native void N_removePrintHandler(CefPrintHandler h);
private final native void N_removeMessageRouter(CefMessageRouter h);
private final native void N_removeRenderHandler(CefRenderHandler h);
private final native void N_removeRequestHandler(CefRequestHandler h);
private final native void N_removeWindowHandler(CefWindowHandler h);
private final native void N_CefClientHandler_DTOR();
}