OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Injects 'injected' object into the inspectable page. | 6 * @fileoverview Injects 'injected' object into the inspectable page. |
7 */ | 7 */ |
8 | 8 |
9 /** | 9 /** |
10 * Dispatches host calls into the injected function calls. | 10 * Dispatches host calls into the injected function calls. |
(...skipping 10 matching lines...) Expand all Loading... | |
21 /** | 21 /** |
22 * Main dispatch method, all calls from the host go through this one. | 22 * Main dispatch method, all calls from the host go through this one. |
23 * @param {string} functionName Function to call | 23 * @param {string} functionName Function to call |
24 * @param {string} json_args JSON-serialized call parameters. | 24 * @param {string} json_args JSON-serialized call parameters. |
25 * @return {string} JSON-serialized result of the dispatched call. | 25 * @return {string} JSON-serialized result of the dispatched call. |
26 */ | 26 */ |
27 function devtools$$dispatch(functionName, json_args) { | 27 function devtools$$dispatch(functionName, json_args) { |
28 var params = JSON.parse(json_args); | 28 var params = JSON.parse(json_args); |
29 var result = devtools$$obj[functionName].apply(devtools$$obj, params); | 29 var result = devtools$$obj[functionName].apply(devtools$$obj, params); |
30 return JSON.stringify(result); | 30 return JSON.stringify(result); |
31 }; | 31 } |
32 | |
33 | |
34 /** | |
35 * Removes malicious functions from the objects so that the pure JSON.stringify | |
36 * was used. | |
37 */ | |
38 function sanitizeJson(obj) { | |
39 for (var name in obj) { | |
40 var property = obj[name]; | |
41 var type = typeof property; | |
42 if (type === "function") { | |
43 obj[name] = null; | |
yurys
2009/08/26 11:51:42
is it safe to do in the 'for in' loop?
| |
44 } else if (type === "object") { | |
45 sanitizeJson(property); | |
yurys
2009/08/26 11:51:42
this will fail if property is null because typeof
| |
46 } | |
47 } | |
48 return obj; | |
49 } | |
32 | 50 |
33 | 51 |
34 /** | 52 /** |
35 * This is called by the InspectorFrontend for serialization. | 53 * This is called by the InspectorFrontend for serialization. |
36 * We serialize the call and send it to the client over the IPC | 54 * We serialize the call and send it to the client over the IPC |
37 * using dispatchOut bound method. | 55 * using dispatchOut bound method. |
38 */ | 56 */ |
39 var dispatch = function(method, var_args) { | 57 var dispatch = function(method, var_args) { |
40 // Handle all messages with non-primitieve arguments here. | 58 // Handle all messages with non-primitieve arguments here. |
41 var args = Array.prototype.slice.call(arguments); | 59 var args = Array.prototype.slice.call(arguments); |
42 | 60 |
43 if (method == 'inspectedWindowCleared' || | 61 if (method == 'inspectedWindowCleared' || |
44 method == 'reset' || | 62 method == 'reset' || |
45 method == 'setAttachedWindow') { | 63 method == 'setAttachedWindow') { |
46 // Filter out messages we don't need here. | 64 // Filter out messages we don't need here. |
47 // We do it on the sender side since they may have non-serializable | 65 // We do it on the sender side since they may have non-serializable |
48 // parameters. | 66 // parameters. |
49 return; | 67 return; |
50 } | 68 } |
51 var call = JSON.stringify(args); | 69 |
70 var call = JSON.stringify(sanitizeJson(args)); | |
52 DevToolsAgentHost.dispatch(call); | 71 DevToolsAgentHost.dispatch(call); |
53 }; | 72 }; |
OLD | NEW |