forked from CCBlueX/java-cef
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinding_test2.html
More file actions
81 lines (74 loc) · 2.57 KB
/
binding_test2.html
File metadata and controls
81 lines (74 loc) · 2.57 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
<html>
<head>
<title>Binding Test - Part 2</title>
<script language="JavaScript">
function toggleButton() {
window.cefQuery({
request: 'hasExtension',
onSuccess: function(response) {
document.getElementById('jcefOn').disabled = true;
document.getElementById('jcefOff').disabled = false;
},
onFailure: function(error_code, error_message) {
document.getElementById('jcefOn').disabled = false;
document.getElementById('jcefOff').disabled = true;
}
});
}
function execute(cmd) {
window.cefQuery({
request: cmd,
onSuccess: function(response) {
location.reload();
},
onFailure: function(error_code, error_message) {
document.getElementById('result').value = 'Error: '+error_message;
}
});
}
function getJavaVersion() {
if ("myQuery" in window) {
window.myQuery({
request: 'jcefJava',
onSuccess: function(response) {
document.getElementById('result').value = 'Java Version: '+response;
},
onFailure: function(error_code, error_message) {
document.getElementById('result').value = 'Error: '+error_message;
}
});
} else {
document.getElementById('result').value = 'Error: myQuery isn\'t enabled';
}
}
</script>
<head>
<body bgcolor="white" onload="toggleButton()">
<form>
<h1>JavaScript Binding Test - Part 2</h1>
<p>While this page was loaded, the JavaScript function
<pre>window.cefRequest(request: 'hasExtension')</pre>
was executed for enabling/disabling the buttons below.
<br/> <br/>
If you press "Enable myQuery", the JavaScript function
<pre>window.cefRequest(request: 'enableExt')</pre>
is executed. This causes Java to create a second instance of
<pre>CefMessageRouter</pre>
In this case the name of the JavaScript query function is set to "myQuery" and
<br/>a handler for the request 'jcefJava' is registered. Pressing the "Test"
<br/>button will execute the JavaScript code
<pre>window.myRequest(request: 'jcefJava')</pre>
which returns your current Java version on success or an error message in case
<br/>of an error.
</p>
<p><b>Please note:</b> If you leave this page (myQuery enabled) and you return
<br/>after a while - without closing the browser - the JavaScript binding is
<br/>still enabled.</p>
Second message router:
<input type="button" id="jcefOn" value="Enable myQuery" onclick="execute('enableExt');" />
<input type="button" id="jcefOff" value="Disable myQuery" onclick="execute('disableExt');" />
<br/><input type="button" onclick="getJavaVersion();" value="Test"/>
<input type="text" id="result" size="80" readonly />
</form>
</body>
</html>