OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @fileoverview Implementation of debugger inter-process communication. | |
7 * Debugger UI can send messages to the DebuggerHost object living in | |
8 * Chrome browser process. The messages are either processed by DebuggerHost | |
9 * itself or trigger IPC message(such as break, evaluate script etc) from | |
10 * browser process to the renderer where the v8 instance being debugged | |
11 * will process them. | |
12 */ | |
13 | |
14 var DebuggerIPC = {}; | |
15 | |
16 /** | |
17 * Set up default debugger UI. | |
18 * @param {DebuggerPanel|DebuggerConsole} debuggerUI | |
19 */ | |
20 DebuggerIPC.init = function(debuggerUI) { | |
21 DebuggerIPC.debuggerUI = debuggerUI; | |
22 } | |
23 | |
24 /** | |
25 * Sends JSON message to DebuggerHost. | |
26 * @param {Array.<Object>} nameAndArguments | |
27 */ | |
28 DebuggerIPC.sendMessage = function(nameAndArguments) { | |
29 //alert("DebuggerIPC.sendMessage " + nameAndArguments); | |
30 dprint("DebuggerIPC.callMethod([" + nameAndArguments + "])"); | |
31 // convert all arguments to strings | |
32 // TODO(yurys): extend chrome.send to accept array of any value | |
33 // objects not only strings | |
34 for (var i = 0; i < nameAndArguments.length; i++) { | |
35 if (typeof nameAndArguments[i] != "string") { | |
36 nameAndArguments[i] = "" + nameAndArguments[i]; | |
37 } | |
38 } | |
39 | |
40 chrome.send("DebuggerHostMessage", nameAndArguments); | |
41 }; | |
42 | |
43 /** | |
44 * Handles messages from DebuggerHost. | |
45 * @param {Object} msg An object representing the message. | |
46 */ | |
47 DebuggerIPC.onMessageReceived = function(msg) { | |
48 //alert("DebuggerIPC.onMessageReceived " + msg.event); | |
49 var ui = DebuggerIPC.debuggerUI; | |
50 dprint("onMessageReceived: " + (msg && msg.event)); | |
51 if (msg.type == "event") { | |
52 if (msg.event == "setDebuggerBreak") { | |
53 var val = msg.body.argument; | |
54 ui.setDebuggerBreak(val); | |
55 } else if (msg.event == "appendText") { | |
56 var text = msg.body.text; | |
57 ui.appendText(text); | |
58 } else if (msg.event == "focusOnCommandLine") { | |
59 dprint("focusOnCommandLine event received"); | |
60 // messages to DebugShell | |
61 } else if (msg.event == "initDebugShell") { | |
62 // DebugShell.initDebugShell(); | |
63 dprint(msg.event + " done"); | |
64 } else if (msg.event == "on_attach") { | |
65 if (DebugShell.singleton) { | |
66 var args = msg.body.arguments; | |
67 if (!args || args.length != 1) { | |
68 dprint(msg.event + " failed: invalid arguments"); | |
69 return; | |
70 } | |
71 var title = args[0]; | |
72 DebugShell.singleton.on_attach(title); | |
73 dprint(msg.event + " done"); | |
74 } else { | |
75 dprint(msg.event + " failed: DebugShell.singleton == null"); | |
76 } | |
77 } else if (msg.event == "on_disconnect") { | |
78 if (DebugShell.singleton) { | |
79 DebugShell.singleton.on_disconnect(); | |
80 dprint(msg.event + " done"); | |
81 } else { | |
82 dprint(msg.event + " failed: DebugShell.singleton == null"); | |
83 } | |
84 } else if (msg.event == "exit") { | |
85 if (DebugShell.singleton) { | |
86 DebugShell.singleton.exit(); | |
87 dprint(msg.event + " done"); | |
88 } else { | |
89 dprint(msg.event + " failed: DebugShell.singleton == null"); | |
90 } | |
91 } else if (msg.event == "response") { | |
92 if (DebugShell.singleton) { | |
93 var args = msg.body.arguments; | |
94 if (!args || args.length != 1) { | |
95 dprint(msg.event + " failed: invalid argument"); | |
96 return; | |
97 } | |
98 DebugShell.singleton.response(args[0]); | |
99 dprint(msg.event + " done"); | |
100 } else { | |
101 ui.appendText(msg.event + " failed: DebugShell.singleton == null"); | |
102 } | |
103 } else { | |
104 ui.appendText("Unknown event: " + msg.event); | |
105 } | |
106 } else { | |
107 ui.appendText("Unknown message type: " + msg.type); | |
108 } | |
109 }; | |
OLD | NEW |