author | Eugene Ostroukhov <eugeneo@symbian.org> |
Mon, 07 Jun 2010 16:51:19 -0700 | |
changeset 355 | 8726e95bcbba |
parent 276 | f2f4a1259de8 |
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; |
|
6 |
||
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
7 |
import java.util.ArrayList; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
8 |
import java.util.Collection; |
2 | 9 |
import java.util.Collections; |
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
10 |
import java.util.List; |
2 | 11 |
|
12 |
import org.chromium.sdk.Breakpoint; |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
13 |
import org.chromium.sdk.DebugContext; |
2 | 14 |
import org.chromium.sdk.DebugEventListener; |
15 |
import org.chromium.sdk.InvalidContextException; |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
16 |
import org.chromium.sdk.Script; |
2 | 17 |
import org.chromium.sdk.SyncCallback; |
18 |
import org.chromium.sdk.Version; |
|
19 |
import org.chromium.sdk.JavascriptVm.ScriptsCallback; |
|
20 |
import org.chromium.sdk.JavascriptVm.SuspendCallback; |
|
21 |
import org.chromium.sdk.internal.InternalContext.ContextDismissedCheckedException; |
|
22 |
import org.chromium.sdk.internal.protocol.CommandResponse; |
|
23 |
import org.chromium.sdk.internal.protocol.SuccessCommandResponse; |
|
24 |
import org.chromium.sdk.internal.tools.v8.BreakpointManager; |
|
25 |
import org.chromium.sdk.internal.tools.v8.DefaultResponseHandler; |
|
26 |
import org.chromium.sdk.internal.tools.v8.V8BlockingCallback; |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
27 |
import org.chromium.sdk.internal.tools.v8.V8CommandCallbackBase; |
2 | 28 |
import org.chromium.sdk.internal.tools.v8.V8CommandOutput; |
29 |
import org.chromium.sdk.internal.tools.v8.V8CommandProcessor; |
|
30 |
import org.chromium.sdk.internal.tools.v8.V8Helper; |
|
31 |
import org.chromium.sdk.internal.tools.v8.V8ProtocolUtil; |
|
32 |
import org.chromium.sdk.internal.tools.v8.request.ContextlessDebuggerMessage; |
|
33 |
import org.chromium.sdk.internal.tools.v8.request.DebuggerMessageFactory; |
|
34 |
||
35 |
/** |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
36 |
* A class that holds and administers main parts of debug protocol implementation. |
2 | 37 |
*/ |
38 |
public class DebugSession { |
|
39 |
||
40 |
/** The script manager for the associated tab. */ |
|
41 |
private final ScriptManager scriptManager; |
|
42 |
||
43 |
private final V8CommandProcessor v8CommandProcessor; |
|
44 |
||
45 |
/** A helper for performing complex V8-related actions. */ |
|
46 |
private final V8Helper v8Helper = new V8Helper(this); |
|
47 |
||
48 |
private final ContextBuilder contextBuilder; |
|
49 |
||
50 |
/** Our manager. */ |
|
51 |
private DebugSessionManager sessionManager; |
|
52 |
||
53 |
/** Context owns breakpoint manager. */ |
|
54 |
private final BreakpointManager breakpointManager; |
|
55 |
||
56 |
private final ScriptLoader scriptLoader = new ScriptLoader(); |
|
57 |
||
58 |
private final DefaultResponseHandler defaultResponseHandler; |
|
59 |
||
60 |
public DebugSession(DebugSessionManager sessionManager, V8ContextFilter contextFilter, |
|
61 |
V8CommandOutput v8CommandOutput) { |
|
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
62 |
this.scriptManager = new ScriptManager(contextFilter, this); |
2 | 63 |
this.sessionManager = sessionManager; |
64 |
this.breakpointManager = new BreakpointManager(this); |
|
65 |
||
66 |
this.defaultResponseHandler = new DefaultResponseHandler(this); |
|
67 |
this.v8CommandProcessor = new V8CommandProcessor(v8CommandOutput, defaultResponseHandler); |
|
68 |
this.contextBuilder = new ContextBuilder(this); |
|
69 |
} |
|
70 |
||
71 |
public ScriptManager getScriptManager() { |
|
72 |
return scriptManager; |
|
73 |
} |
|
74 |
||
75 |
public V8CommandProcessor getV8CommandProcessor() { |
|
76 |
return v8CommandProcessor; |
|
77 |
} |
|
78 |
||
79 |
public DebugSessionManager getSessionManager() { |
|
80 |
return sessionManager; |
|
81 |
} |
|
82 |
||
83 |
public void onDebuggerDetached() { |
|
84 |
getSessionManager().onDebuggerDetached(); |
|
85 |
getScriptManager().reset(); |
|
86 |
contextBuilder.forceCancelContext(); |
|
87 |
} |
|
88 |
||
89 |
/** |
|
90 |
* Sends V8 command messages, but only those which doesn't depend on context. |
|
91 |
* Use {@code InternalContext} if you need to send context-specific commands. |
|
92 |
*/ |
|
93 |
public void sendMessageAsync(ContextlessDebuggerMessage message, boolean isImmediate, |
|
94 |
V8CommandProcessor.V8HandlerCallback commandCallback, SyncCallback syncCallback) { |
|
95 |
v8CommandProcessor.sendV8CommandAsync(message, isImmediate, |
|
96 |
commandCallback, syncCallback); |
|
97 |
} |
|
98 |
||
99 |
/** |
|
100 |
* Gets invoked when a navigation event is reported by the browser tab. |
|
101 |
*/ |
|
102 |
public void navigated() { |
|
103 |
getScriptManager().reset(); |
|
104 |
} |
|
105 |
||
106 |
/** |
|
107 |
* @return the DebugEventListener associated with this context |
|
108 |
*/ |
|
109 |
public DebugEventListener getDebugEventListener() { |
|
110 |
return getSessionManager().getDebugEventListener(); |
|
111 |
} |
|
112 |
||
113 |
public BreakpointManager getBreakpointManager() { |
|
114 |
return breakpointManager; |
|
115 |
} |
|
116 |
||
117 |
public ScriptLoader getScriptLoader() { |
|
118 |
return scriptLoader; |
|
119 |
} |
|
120 |
||
121 |
public V8Helper getV8Helper() { |
|
122 |
return v8Helper; |
|
123 |
} |
|
124 |
||
125 |
public ContextBuilder getContextBuilder() { |
|
126 |
return contextBuilder; |
|
127 |
} |
|
128 |
||
355
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
129 |
/** |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
130 |
* Drops current context and creates a new one. This is useful if context is known to have changed |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
131 |
* (e.g. experimental feature LiveEdit may change current stack while execution is suspended). |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
132 |
* The method is asynchronous and returns immediately. |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
133 |
* Does nothing if currently there is no active context. Otherwise dismisses current context, |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
134 |
* invokes {@link DebugEventListener#resumed()} and initiates downloading stack frame descriptions |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
135 |
* and building new context. When the context is built, |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
136 |
* calls {@link DebugEventListener#suspended(DebugContext)}. |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
137 |
* <p> |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
138 |
* Must be called from Dispatch Thread. |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
139 |
* @return true if context has been actually dropped. |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
140 |
*/ |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
141 |
public boolean recreateCurrentContext() { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
142 |
ContextBuilder.ExpectingBacktraceStep step = contextBuilder.startRebuildCurrentContext(); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
143 |
if (step == null) { |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
144 |
return false; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
145 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
146 |
defaultResponseHandler.getBreakpointProcessor().processNextStep(step); |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
147 |
return true; |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
148 |
} |
8726e95bcbba
Initial commit of updated Chrome Java SDK
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
276
diff
changeset
|
149 |
|
2 | 150 |
public void suspend(final SuspendCallback suspendCallback) { |
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
151 |
V8CommandProcessor.V8HandlerCallback v8Callback = new V8CommandCallbackBase() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
152 |
@Override |
2 | 153 |
public void failure(String message) { |
154 |
if (suspendCallback != null) { |
|
155 |
suspendCallback.failure(new Exception(message)); |
|
156 |
} |
|
157 |
} |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
158 |
@Override |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
159 |
public void success(SuccessCommandResponse successResponse) { |
2 | 160 |
if (suspendCallback != null) { |
161 |
suspendCallback.success(); |
|
162 |
} |
|
163 |
||
164 |
ContextBuilder.ExpectingBreakEventStep step1 = contextBuilder.buildNewContextWhenIdle(); |
|
165 |
if (step1 == null) { |
|
166 |
return; |
|
167 |
} |
|
168 |
ContextBuilder.ExpectingBacktraceStep step2 = |
|
169 |
step1.setContextState(Collections.<Breakpoint>emptyList(), null); |
|
170 |
defaultResponseHandler.getBreakpointProcessor().processNextStep(step2); |
|
171 |
} |
|
172 |
}; |
|
173 |
sendMessageAsync(DebuggerMessageFactory.suspend(), true, v8Callback, null); |
|
174 |
} |
|
175 |
||
176 |
public class ScriptLoader { |
|
177 |
||
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
178 |
private final Object monitor = new Object(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
179 |
/** |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
180 |
* Stores the callbacks that are waiting for result. |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
181 |
* This field being reset to null means that result is ready (loaded into ScriptManager) |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
182 |
* and no more callbacks are accepted. |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
183 |
*/ |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
184 |
private List<ScriptsCallback> pendingCallbacks = new ArrayList<ScriptsCallback>(2); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
185 |
private List<SyncCallback> pendingSyncCallbacks = new ArrayList<SyncCallback>(2); |
2 | 186 |
|
187 |
/** |
|
188 |
* Loads all scripts from the remote if necessary, and feeds them into the |
|
189 |
* callback provided (if any). |
|
190 |
*/ |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
191 |
public void loadAllScripts(ScriptsCallback callback, SyncCallback syncCallback) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
192 |
boolean resultIsReady; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
193 |
boolean sendMessage; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
194 |
synchronized (monitor) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
195 |
if (pendingCallbacks == null) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
196 |
resultIsReady = true; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
197 |
sendMessage = false; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
198 |
} else { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
199 |
resultIsReady = false; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
200 |
sendMessage = pendingCallbacks.isEmpty(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
201 |
pendingCallbacks.add(callback); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
202 |
pendingSyncCallbacks.add(syncCallback); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
203 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
204 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
205 |
if (resultIsReady) { |
2 | 206 |
try { |
207 |
if (callback != null) { |
|
208 |
callback.success(getScriptManager().allScripts()); |
|
209 |
} |
|
210 |
} finally { |
|
211 |
if (syncCallback != null) { |
|
212 |
syncCallback.callbackDone(null); |
|
213 |
} |
|
214 |
} |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
215 |
return; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
216 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
217 |
if (sendMessage) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
218 |
sendAsyncMessage(); |
2 | 219 |
} |
220 |
} |
|
276
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
221 |
private void sendAsyncMessage() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
222 |
V8Helper.ScriptLoadCallback groupCallback = new V8Helper.ScriptLoadCallback() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
223 |
public void success() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
224 |
final Collection<Script> scripts = scriptManager.allScripts(); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
225 |
processCall(new CallbackCaller() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
226 |
@Override |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
227 |
void call(ScriptsCallback callback) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
228 |
callback.success(scripts); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
229 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
230 |
}); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
231 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
232 |
|
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
233 |
public void failure(final String message) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
234 |
processCall(new CallbackCaller() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
235 |
@Override |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
236 |
void call(ScriptsCallback callback) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
237 |
callback.failure(message); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
238 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
239 |
}); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
240 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
241 |
|
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
242 |
private void processCall(CallbackCaller caller) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
243 |
List<ScriptsCallback> savedCallbacks; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
244 |
synchronized (monitor) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
245 |
savedCallbacks = pendingCallbacks; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
246 |
pendingCallbacks = null; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
247 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
248 |
for (ScriptsCallback callback : savedCallbacks) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
249 |
if (callback != null) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
250 |
caller.call(callback); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
251 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
252 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
253 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
254 |
abstract class CallbackCaller { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
255 |
abstract void call(ScriptsCallback callback); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
256 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
257 |
}; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
258 |
|
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
259 |
SyncCallback groupSyncCallback = new SyncCallback() { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
260 |
public void callbackDone(RuntimeException e) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
261 |
List<SyncCallback> savedCallbacks; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
262 |
synchronized (monitor) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
263 |
savedCallbacks = pendingSyncCallbacks; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
264 |
pendingSyncCallbacks = null; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
265 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
266 |
for (SyncCallback callback : savedCallbacks) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
267 |
if (callback != null) { |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
268 |
callback.callbackDone(e); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
269 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
270 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
271 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
272 |
}; |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
273 |
|
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
274 |
V8Helper.reloadAllScriptsAsync(DebugSession.this, groupCallback, groupSyncCallback); |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
275 |
} |
f2f4a1259de8
Bug 2065 - Pull updated Chrome Developer Tools into the workspace
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
2
diff
changeset
|
276 |
|
2 | 277 |
} |
278 |
||
279 |
/** |
|
280 |
* Checks version of V8 and check if it in running state. |
|
281 |
*/ |
|
282 |
public void startCommunication() { |
|
283 |
V8BlockingCallback<Void> callback = new V8BlockingCallback<Void>() { |
|
284 |
@Override |
|
285 |
public Void messageReceived(CommandResponse response) { |
|
286 |
SuccessCommandResponse successResponse = response.asSuccess(); |
|
287 |
if (successResponse == null) { |
|
288 |
return null; |
|
289 |
} |
|
290 |
Version vmVersion = V8ProtocolUtil.parseVersionResponse(successResponse); |
|
291 |
||
292 |
if (V8VersionMilestones.isRunningAccurate(vmVersion)) { |
|
293 |
Boolean running = successResponse.running(); |
|
294 |
if (running == Boolean.FALSE) { |
|
295 |
ContextBuilder.ExpectingBreakEventStep step1 = contextBuilder.buildNewContextWhenIdle(); |
|
296 |
// If step is not null -- we are already in process of building a context. |
|
297 |
if (step1 != null) { |
|
298 |
ContextBuilder.ExpectingBacktraceStep step2 = |
|
299 |
step1.setContextState(Collections.<Breakpoint>emptyList(), null); |
|
300 |
||
301 |
defaultResponseHandler.getBreakpointProcessor().processNextStep(step2); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
305 |
return null; |
|
306 |
} |
|
307 |
||
308 |
@Override |
|
309 |
protected Void handleSuccessfulResponse(SuccessCommandResponse response) { |
|
310 |
throw new UnsupportedOperationException(); |
|
311 |
} |
|
312 |
}; |
|
313 |
||
314 |
V8Helper.callV8Sync(this.v8CommandProcessor, DebuggerMessageFactory.version(), callback); |
|
315 |
} |
|
316 |
||
317 |
public void maybeRethrowContextException(ContextDismissedCheckedException e) { |
|
318 |
// TODO(peter.rybin): make some kind of option out of this |
|
319 |
final boolean strictPolicy = true; |
|
320 |
if (strictPolicy) { |
|
321 |
throw new InvalidContextException(e); |
|
322 |
} |
|
323 |
} |
|
324 |
} |