author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 07 Jun 2010 16:51:19 -0700 | |
changeset 355 | 8726e95bcbba |
parent 2 | e4420d2515f1 |
permissions | -rw-r--r-- |
2 | 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 |
|
3 |
// found in the LICENSE file. |
|
4 |
||
5 |
package org.chromium.sdk.internal.tools.v8; |
|
6 |
||
7 |
import org.chromium.sdk.Breakpoint; |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
8 |
import org.chromium.sdk.JavascriptVm; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
9 |
import org.chromium.sdk.SyncCallback; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
10 |
import org.chromium.sdk.internal.protocol.data.BreakpointInfo; |
2 | 11 |
|
12 |
/** |
|
13 |
* A generic implementation of the Breakpoint interface. |
|
14 |
*/ |
|
15 |
public class BreakpointImpl implements Breakpoint { |
|
16 |
||
17 |
/** |
|
18 |
* The breakpoint type. |
|
19 |
*/ |
|
20 |
private final Type type; |
|
21 |
||
22 |
/** |
|
23 |
* The breakpoint id as reported by the JavaScript VM. |
|
24 |
*/ |
|
25 |
private long id; |
|
26 |
||
27 |
/** |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
28 |
* The corresponding script name as reported by the JavaScript VM. May be null. |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
29 |
*/ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
30 |
private String scriptName; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
31 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
32 |
/** |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
33 |
* The corresponding script id as reported by the JavaScript VM. May be null. |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
34 |
*/ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
35 |
private Long scriptId; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
36 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
37 |
/** |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
38 |
* Breakpoint line number. May become invalidated by LiveEdit actions. |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
39 |
*/ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
40 |
private long lineNumber; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
41 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
42 |
/** |
2 | 43 |
* Whether the breakpoint is enabled. |
44 |
*/ |
|
45 |
private boolean isEnabled; |
|
46 |
||
47 |
/** |
|
48 |
* The number of times the breakpoint should be ignored |
|
49 |
* by the JavaScript VM until it fires. |
|
50 |
*/ |
|
51 |
private int ignoreCount; |
|
52 |
||
53 |
/** |
|
54 |
* The breakpoint condition (plain JavaScript) that should be {@code true} |
|
55 |
* for the breakpoint to fire. |
|
56 |
*/ |
|
57 |
private String condition; |
|
58 |
||
59 |
/** |
|
60 |
* The breakpoint manager that manages this breakpoint. |
|
61 |
*/ |
|
62 |
private final BreakpointManager breakpointManager; |
|
63 |
||
64 |
/** |
|
65 |
* Whether the breakpoint data have changed with respect |
|
66 |
* to the JavaScript VM data. |
|
67 |
*/ |
|
68 |
private volatile boolean isDirty = false; |
|
69 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
70 |
public BreakpointImpl(Type type, long id, String scriptName, Long scriptId, long lineNumber, |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
71 |
boolean enabled, int ignoreCount, String condition, BreakpointManager breakpointManager) { |
2 | 72 |
this.type = type; |
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
73 |
this.scriptName = scriptName; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
74 |
this.scriptId = scriptId; |
2 | 75 |
this.id = id; |
76 |
this.isEnabled = enabled; |
|
77 |
this.ignoreCount = ignoreCount; |
|
78 |
this.condition = condition; |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
79 |
this.lineNumber = lineNumber; |
2 | 80 |
this.breakpointManager = breakpointManager; |
81 |
} |
|
82 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
83 |
public BreakpointImpl(BreakpointInfo info, BreakpointManager breakpointManager) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
84 |
this.type = getType(info); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
85 |
this.id = info.number(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
86 |
this.breakpointManager = breakpointManager; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
87 |
updateFromRemote(info); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
88 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
89 |
public void updateFromRemote(BreakpointInfo info) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
90 |
if (this.type != getType(info)) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
91 |
throw new IllegalArgumentException(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
92 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
93 |
if (this.id != info.number()) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
94 |
throw new IllegalArgumentException(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
95 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
96 |
this.lineNumber = info.line(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
97 |
this.isEnabled = info.active(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
98 |
this.ignoreCount = (int) info.ignoreCount(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
99 |
this.condition = info.condition(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
100 |
this.scriptName = info.script_name(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
101 |
this.scriptId = info.script_id(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
102 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
103 |
|
2 | 104 |
public boolean isEnabled() { |
105 |
return isEnabled; |
|
106 |
} |
|
107 |
||
108 |
public Type getType() { |
|
109 |
return type; |
|
110 |
} |
|
111 |
||
112 |
public long getId() { |
|
113 |
return id; |
|
114 |
} |
|
115 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
116 |
public String getScriptName() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
117 |
return scriptName; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
118 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
119 |
|
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
120 |
public Long getScriptId() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
121 |
return scriptId; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
122 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
123 |
|
2 | 124 |
public int getIgnoreCount() { |
125 |
return ignoreCount; |
|
126 |
} |
|
127 |
||
128 |
public String getCondition() { |
|
129 |
return condition; |
|
130 |
} |
|
131 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
132 |
public long getLineNumber() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
133 |
return lineNumber; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
134 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
135 |
|
2 | 136 |
public void setEnabled(boolean enabled) { |
137 |
if (this.isEnabled != enabled) { |
|
138 |
setDirty(true); |
|
139 |
} |
|
140 |
this.isEnabled = enabled; |
|
141 |
} |
|
142 |
||
143 |
public void setIgnoreCount(int ignoreCount) { |
|
144 |
if (this.ignoreCount != ignoreCount) { |
|
145 |
setDirty(true); |
|
146 |
} |
|
147 |
this.ignoreCount = ignoreCount; |
|
148 |
} |
|
149 |
||
150 |
||
151 |
public void setCondition(String condition) { |
|
152 |
if (!eq(this.condition, condition)) { |
|
153 |
setDirty(true); |
|
154 |
} |
|
155 |
this.condition = condition; |
|
156 |
} |
|
157 |
||
158 |
private boolean eq(Object left, Object right) { |
|
159 |
return left == right || (left != null && left.equals(right)); |
|
160 |
} |
|
161 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
162 |
public void clear(JavascriptVm.BreakpointCallback callback, SyncCallback syncCallback) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
163 |
breakpointManager.clearBreakpoint(this, callback, syncCallback); |
2 | 164 |
// The order must be preserved, otherwise the breakpointProcessor will not be able |
165 |
// to identify the original breakpoint ID. |
|
166 |
this.id = INVALID_ID; |
|
167 |
} |
|
168 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
169 |
public void flush(final JavascriptVm.BreakpointCallback callback, SyncCallback syncCallback) { |
2 | 170 |
if (!isDirty()) { |
171 |
if (callback != null) { |
|
172 |
callback.success(this); |
|
173 |
} |
|
174 |
return; |
|
175 |
} |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
176 |
breakpointManager.changeBreakpoint(this, callback, syncCallback); |
2 | 177 |
setDirty(false); |
178 |
} |
|
179 |
||
180 |
private void setDirty(boolean isDirty) { |
|
181 |
this.isDirty = isDirty; |
|
182 |
} |
|
183 |
||
184 |
private boolean isDirty() { |
|
185 |
return isDirty; |
|
186 |
} |
|
187 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
188 |
private static Type getType(BreakpointInfo info) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
189 |
BreakpointInfo.Type infoType = info.type(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
190 |
switch (infoType) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
191 |
case scriptId: return Type.SCRIPT_ID; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
192 |
case scriptName: return Type.SCRIPT_NAME; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
193 |
case function: return Type.FUNCTION; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
194 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
195 |
throw new RuntimeException("Unknown type: " + infoType); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
196 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
197 |
} |