-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathbinding_test2.html
More file actions
131 lines (122 loc) · 4.79 KB
/
binding_test2.html
File metadata and controls
131 lines (122 loc) · 4.79 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
<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 doPersistent() {
document.getElementById('persist').value = '';
window.cefQuery({
request: 'doPersistent',
persistent: true,
onSuccess: function(response) {
document.getElementById('persist').value += ' MESSAGE: [ ' + response + '];';
},
onFailure: function(error_code, error_message) {
document.getElementById('persist').value += ' FINISHED: ' + error_code + ' ' + error_message;
}
});
}
function doBinary() {
document.getElementById('binary').value = 'ORIGINAL: [';
const binaryData = new Uint8Array([10, 20, 30, 40, 50]);
for (let i = 0; i < binaryData.length; i++) {
document.getElementById('binary').value += ' ' + binaryData.at(i);
}
document.getElementById('binary').value += ' ];';
window.cefQuery({
request: binaryData.buffer,
persistent: true,
onSuccess: function(response) {
document.getElementById('binary').value += ' RESPONSE: [';
const echoedBinaryData = new Uint8Array(response);
for (let i = 0; i < echoedBinaryData.length; i++) {
document.getElementById('binary').value += ' ' + echoedBinaryData.at(i);
}
document.getElementById('binary').value += ' ];';
},
onFailure: function(error_code, error_message) {
document.getElementById('binary').value += ' FINISHED: ' + error_code + ' ' + error_message;
}
});
}
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 />
<br/><p>This button tests persistent queries. When the button is pressed, it clears the output,
and when it receives a success message, it appends it to the output. When it finally receives
a failure message, it appends the error_code followed by the error_message.</p>
<input type="button" onclick="doPersistent();" value="Persist"/>
<input type="text" id="persist" size="80" readonly />
<br/><p>This button tests binary queries. When the button is pressed, it clears the output and
replaces it with a representation of the binary data sent in the query. When it receives a
success message, it appends a similar representation of the binary data received (which has
been reversed by Java). When it finally receives a failure message, it appends the error_code
followed by the error_message.</p>
<input type="button" onclick="doBinary();" value="Binary"/>
<input type="text" id="binary" size="80" readonly />
</form>
</body>
</html>