OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2013 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 // The background page of the gdb chrome packaged app exists solely to | 9 // The background page of the gdb chrome packaged app exists solely to |
10 // manage the set of operations that can only be performed in a v2 chrome app, | 10 // manage the set of operations that can only be performed in a v2 chrome app, |
11 // namely those requiring sockets access. | 11 // namely those requiring sockets access. |
12 // | 12 // |
13 // runGdb - Create a nacl module for gdb and marshall its messages. | 13 // runGdb - Create a nacl module for gdb and marshall its messages. |
14 // rspContinue - Allow a nacl module to run, waiting for it to exit or fault. | 14 // rspContinue - Allow a nacl module to run, waiting for it to exit or fault. |
15 // rspDetach - Allow a nacl module to run without monitoring it. | 15 // rspDetach - Allow a nacl module to run without monitoring it. |
16 // rspKill - Kill a nacl module by way of its debug port. | 16 // rspKill - Kill a nacl module by way of its debug port. |
17 | 17 |
18 | 18 |
19 /** | 19 /** |
20 * Compute the checksum of a remote stub command. | 20 * Compute the checksum of a remote stub command. |
21 * @param {string} cmd Command to checksum. | 21 * @param {string} cmd Command to checksum. |
22 * @return {string} Two digit hex checksum of command. | 22 * @return {string} Two digit hex checksum of command. |
23 */ | 23 */ |
24 function rspChecksum_(cmd) { | 24 function rspChecksum_(cmd) { |
25 var checksum = 0; | 25 var checksum = 0; |
26 for (var i = 0; i < cmd.length; i++) { | 26 var i; |
| 27 for (i = 0; i < cmd.length; i++) { |
27 checksum = (checksum + cmd.charCodeAt(i)) & 0xff; | 28 checksum = (checksum + cmd.charCodeAt(i)) & 0xff; |
28 } | 29 } |
29 var checksumStr = '0' + checksum.toString(16); | 30 var checksumStr = '0' + checksum.toString(16); |
30 checksumStr = checksumStr.substr(checksumStr.length - 2); | 31 checksumStr = checksumStr.substr(checksumStr.length - 2); |
31 return checksumStr; | 32 return checksumStr; |
32 } | 33 } |
33 | 34 |
34 /** | 35 /** |
35 * Convert a string to an ArrayBuffer. | 36 * Convert a string to an ArrayBuffer. |
36 * @param {string} str. | 37 * @param {string} str. |
37 * @return {ArrayBuffer}. | 38 * @return {ArrayBuffer}. |
38 */ | 39 */ |
39 function stringToArrayBuffer_(str) { | 40 function stringToArrayBuffer_(str) { |
40 var buf = new ArrayBuffer(str.length); | 41 var buf = new ArrayBuffer(str.length); |
41 var view = new Uint8Array(buf); | 42 var view = new Uint8Array(buf); |
42 for (var i = 0; i < str.length; i++) { | 43 var i; |
| 44 for (i = 0; i < str.length; i++) { |
43 view[i] = str.charCodeAt(i); | 45 view[i] = str.charCodeAt(i); |
44 } | 46 } |
45 return buf; | 47 return buf; |
46 } | 48 } |
47 | 49 |
48 /** | 50 /** |
49 * Add markers and checksum to a remote stub command. | 51 * Add markers and checksum to a remote stub command. |
50 * @param {string} cmd Command to checksum. | 52 * @param {string} cmd Command to checksum. |
51 * @return {string} A ready to send checksumed remote stub message string. | 53 * @return {string} A ready to send checksumed remote stub message string. |
52 */ | 54 */ |
(...skipping 11 matching lines...) Expand all Loading... |
64 } | 66 } |
65 | 67 |
66 /** | 68 /** |
67 * Decode a remote stub message. | 69 * Decode a remote stub message. |
68 * @param {string} msg Message to decode. | 70 * @param {string} msg Message to decode. |
69 * @return {string} The decoded text. | 71 * @return {string} The decoded text. |
70 */ | 72 */ |
71 function rspDecode_(msg) { | 73 function rspDecode_(msg) { |
72 var view = new Uint8Array(msg); | 74 var view = new Uint8Array(msg); |
73 var result = ''; | 75 var result = ''; |
74 for (var i = 0; i < msg.byteLength; i++) { | 76 var i; |
| 77 for (i = 0; i < msg.byteLength; i++) { |
75 result += String.fromCharCode(view[i]); | 78 result += String.fromCharCode(view[i]); |
76 } | 79 } |
77 return result; | 80 return result; |
78 } | 81 } |
79 | 82 |
80 /** | 83 /** |
81 * Manage a single debug connection. | 84 * Manage a single debug connection. |
82 * @private | 85 * @private |
83 * @constructor | 86 * @constructor |
84 */ | 87 */ |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 if (navigator.userAgent.indexOf('ChromeTestAgent/') < 0) { | 439 if (navigator.userAgent.indexOf('ChromeTestAgent/') < 0) { |
437 // TODO(bradnelson): Enable this check once a production extension id is | 440 // TODO(bradnelson): Enable this check once a production extension id is |
438 // known for the debugger extension. | 441 // known for the debugger extension. |
439 //if (port.sender.id !== 'blessed-id') { | 442 //if (port.sender.id !== 'blessed-id') { |
440 // port.disconnect(); | 443 // port.disconnect(); |
441 // return; | 444 // return; |
442 //} | 445 //} |
443 } | 446 } |
444 var dc = new DebugConnection_(port); | 447 var dc = new DebugConnection_(port); |
445 }); | 448 }); |
OLD | NEW |