OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Samsung Electronics. All rights reserved. | 2 * Copyright (C) 2012 Samsung Electronics. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 WebInspector = {}; | 25 WebInspector = {}; |
26 | 26 |
27 InspectorTest = {}; | 27 InspectorTest = {}; |
28 InspectorTest._dispatchTable = []; | 28 InspectorTest._dispatchTable = []; |
29 InspectorTest._requestId = -1; | 29 InspectorTest._requestId = -1; |
| 30 InspectorTest.eventHandler = {}; |
30 | 31 |
31 /** | 32 /** |
32 * @param {string} method | 33 * @param {string} method |
33 * @param {object} params | 34 * @param {object} params |
34 * @param {function({object} messageObject)=} handler | 35 * @param {function({object} messageObject)=} handler |
35 */ | 36 */ |
36 InspectorTest.sendCommand = function(method, params, handler) | 37 InspectorTest.sendCommand = function(method, params, handler) |
37 { | 38 { |
38 this._dispatchTable[++this._requestId] = handler; | 39 this._dispatchTable[++this._requestId] = handler; |
39 | 40 |
40 var messageObject = { "method": method, | 41 var messageObject = { "method": method, |
41 "params": params, | 42 "params": params, |
42 "id": this._requestId }; | 43 "id": this._requestId }; |
43 | 44 |
44 InspectorFrontendHost.sendMessageToBackend(JSON.stringify(messageObject)); | 45 InspectorFrontendHost.sendMessageToBackend(JSON.stringify(messageObject)); |
45 | 46 |
46 return this._requestId; | 47 return this._requestId; |
47 } | 48 } |
48 | 49 |
49 /** | 50 /** |
50 * @param {object} messageObject | 51 * @param {object} messageObject |
51 */ | 52 */ |
52 WebInspector.dispatchMessageFromBackend = function(messageObject) | 53 WebInspector.dispatchMessageFromBackend = function(messageObject) |
53 { | 54 { |
54 var messageId = messageObject["id"]; | 55 var messageId = messageObject["id"]; |
55 if (typeof messageId === "number") { | 56 if (typeof messageId === "number") { |
56 var handler = InspectorTest._dispatchTable[messageId]; | 57 var handler = InspectorTest._dispatchTable[messageId]; |
57 if (handler && typeof handler === "function") | 58 if (handler && typeof handler === "function") |
58 handler(messageObject); | 59 handler(messageObject); |
| 60 } else { |
| 61 var eventName = messageObject["method"]; |
| 62 var eventHandler = InspectorTest.eventHandler[eventName]; |
| 63 if (eventHandler) |
| 64 eventHandler(messageObject); |
59 } | 65 } |
60 } | 66 } |
61 | 67 |
62 /** | 68 /** |
63 * Logs message to document. | 69 * Logs message to document. |
64 * @param {string} message | 70 * @param {string} message |
65 */ | 71 */ |
66 InspectorTest.log = function(message) | 72 InspectorTest.log = function(message) |
67 { | 73 { |
68 this.sendCommand("Runtime.evaluate", { "expression": "log(" + JSON.stringify
(message) + ")" } ); | 74 this.sendCommand("Runtime.evaluate", { "expression": "log(" + JSON.stringify
(message) + ")" } ); |
(...skipping 15 matching lines...) Expand all Loading... |
84 } | 90 } |
85 | 91 |
86 window.addEventListener("message", function(event) { | 92 window.addEventListener("message", function(event) { |
87 try { | 93 try { |
88 eval(event.data); | 94 eval(event.data); |
89 } catch (e) { | 95 } catch (e) { |
90 alert(e.stack); | 96 alert(e.stack); |
91 throw e; | 97 throw e; |
92 } | 98 } |
93 }); | 99 }); |
OLD | NEW |