6 import org.chromium.sdk.Breakpoint; |
6 import org.chromium.sdk.Breakpoint; |
7 import org.chromium.sdk.BrowserTab; |
7 import org.chromium.sdk.BrowserTab; |
8 import org.chromium.sdk.JavascriptVm.BreakpointCallback; |
8 import org.chromium.sdk.JavascriptVm.BreakpointCallback; |
9 import org.chromium.sdk.internal.DebugSession; |
9 import org.chromium.sdk.internal.DebugSession; |
10 import org.chromium.sdk.internal.protocol.BreakpointBody; |
10 import org.chromium.sdk.internal.protocol.BreakpointBody; |
11 import org.chromium.sdk.internal.protocol.CommandResponse; |
|
12 import org.chromium.sdk.internal.protocol.SuccessCommandResponse; |
11 import org.chromium.sdk.internal.protocol.SuccessCommandResponse; |
13 import org.chromium.sdk.internal.protocolparser.JsonProtocolParseException; |
12 import org.chromium.sdk.internal.protocolparser.JsonProtocolParseException; |
14 import org.chromium.sdk.internal.tools.v8.request.DebuggerMessageFactory; |
13 import org.chromium.sdk.internal.tools.v8.request.DebuggerMessageFactory; |
15 |
14 |
16 public class BreakpointManager { |
15 public class BreakpointManager { |
33 toNullableInteger(position), enabled, condition, |
32 toNullableInteger(position), enabled, condition, |
34 toNullableInteger(ignoreCount)), |
33 toNullableInteger(ignoreCount)), |
35 true, |
34 true, |
36 callback == null |
35 callback == null |
37 ? null |
36 ? null |
38 : new V8CommandProcessor.V8HandlerCallback() { |
37 : new V8CommandCallbackBase() { |
39 public void messageReceived(CommandResponse response) { |
38 @Override |
40 SuccessCommandResponse successResponse = response.asSuccess(); |
39 public void success(SuccessCommandResponse successResponse) { |
41 if (successResponse != null) { |
40 BreakpointBody body; |
42 BreakpointBody body; |
41 try { |
43 try { |
42 body = successResponse.getBody().asBreakpointBody(); |
44 body = successResponse.getBody().asBreakpointBody(); |
43 } catch (JsonProtocolParseException e) { |
45 } catch (JsonProtocolParseException e) { |
44 throw new RuntimeException(e); |
46 throw new RuntimeException(e); |
45 } |
47 } |
46 long id = body.getBreakpoint(); |
48 long id = body.getBreakpoint(); |
|
49 |
47 |
50 final BreakpointImpl breakpoint = |
48 final BreakpointImpl breakpoint = |
51 new BreakpointImpl(type, id, enabled, ignoreCount, |
49 new BreakpointImpl(type, id, enabled, ignoreCount, |
52 condition, BreakpointManager.this); |
50 condition, BreakpointManager.this); |
53 |
51 |
54 callback.success(breakpoint); |
52 callback.success(breakpoint); |
55 idToBreakpoint.put(breakpoint.getId(), breakpoint); |
53 idToBreakpoint.put(breakpoint.getId(), breakpoint); |
56 } else { |
|
57 callback.failure(response.asFailure().getMessage()); |
|
58 } |
|
59 } |
54 } |
|
55 @Override |
60 public void failure(String message) { |
56 public void failure(String message) { |
61 if (callback != null) { |
57 if (callback != null) { |
62 callback.failure(message); |
58 callback.failure(message); |
63 } |
59 } |
64 } |
60 } |
78 } |
74 } |
79 idToBreakpoint.remove(id); |
75 idToBreakpoint.remove(id); |
80 debugSession.sendMessageAsync( |
76 debugSession.sendMessageAsync( |
81 DebuggerMessageFactory.clearBreakpoint(breakpointImpl), |
77 DebuggerMessageFactory.clearBreakpoint(breakpointImpl), |
82 true, |
78 true, |
83 new V8CommandProcessor.V8HandlerCallback() { |
79 new V8CommandCallbackBase() { |
84 public void messageReceived(CommandResponse response) { |
80 @Override |
85 SuccessCommandResponse successResponse = response.asSuccess(); |
81 public void success(SuccessCommandResponse successResponse) { |
86 if (successResponse != null) { |
82 if (callback != null) { |
87 if (callback != null) { |
83 callback.success(null); |
88 callback.success(null); |
|
89 } |
|
90 } else { |
|
91 if (callback != null) { |
|
92 callback.failure(response.asFailure().getMessage()); |
|
93 } |
|
94 } |
84 } |
95 } |
85 } |
|
86 @Override |
96 public void failure(String message) { |
87 public void failure(String message) { |
97 if (callback != null) { |
88 if (callback != null) { |
98 callback.failure(message); |
89 callback.failure(message); |
99 } |
90 } |
100 } |
91 } |
105 public void changeBreakpoint(final BreakpointImpl breakpointImpl, |
96 public void changeBreakpoint(final BreakpointImpl breakpointImpl, |
106 final BreakpointCallback callback) { |
97 final BreakpointCallback callback) { |
107 debugSession.sendMessageAsync( |
98 debugSession.sendMessageAsync( |
108 DebuggerMessageFactory.changeBreakpoint(breakpointImpl), |
99 DebuggerMessageFactory.changeBreakpoint(breakpointImpl), |
109 true, |
100 true, |
110 new V8CommandProcessor.V8HandlerCallback() { |
101 new V8CommandCallbackBase() { |
111 public void messageReceived(CommandResponse response) { |
102 @Override |
|
103 public void success(SuccessCommandResponse successResponse) { |
112 if (callback != null) { |
104 if (callback != null) { |
113 SuccessCommandResponse successResponse = response.asSuccess(); |
105 callback.success(breakpointImpl); |
114 if (successResponse != null) { |
|
115 callback.success(breakpointImpl); |
|
116 } else { |
|
117 callback.failure(response.asFailure().getMessage()); |
|
118 } |
|
119 } |
106 } |
120 } |
107 } |
|
108 @Override |
121 public void failure(String message) { |
109 public void failure(String message) { |
122 if (callback != null) { |
110 if (callback != null) { |
123 callback.failure(message); |
111 callback.failure(message); |
124 } |
112 } |
125 } |
113 } |