|
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 |
|
7 import org.chromium.sdk.Breakpoint; |
|
8 import org.chromium.sdk.CallbackSemaphore; |
|
9 import org.chromium.sdk.JavascriptVm; |
|
10 import org.chromium.sdk.internal.tools.v8.MethodIsBlockingException; |
|
11 |
|
12 /** |
|
13 * Base implementation of JavascriptVm. |
|
14 */ |
|
15 public abstract class JavascriptVmImpl implements JavascriptVm { |
|
16 |
|
17 protected JavascriptVmImpl() { |
|
18 } |
|
19 |
|
20 public void suspend(SuspendCallback callback) { |
|
21 getDebugSession().suspend(callback); |
|
22 } |
|
23 |
|
24 public void getScripts(ScriptsCallback callback) throws MethodIsBlockingException { |
|
25 CallbackSemaphore callbackSemaphore = new CallbackSemaphore(); |
|
26 getDebugSession().getScriptLoader().loadAllScripts(callback, callbackSemaphore); |
|
27 |
|
28 boolean res = callbackSemaphore.tryAcquireDefault(); |
|
29 if (!res) { |
|
30 callback.failure("Timeout"); |
|
31 } |
|
32 } |
|
33 |
|
34 public void setBreakpoint(Breakpoint.Type type, String target, int line, |
|
35 int position, boolean enabled, String condition, int ignoreCount, |
|
36 BreakpointCallback callback) { |
|
37 getDebugSession().getBreakpointManager() |
|
38 .setBreakpoint(type, target, line, position, enabled, condition, ignoreCount, callback); |
|
39 } |
|
40 |
|
41 protected abstract DebugSession getDebugSession(); |
|
42 } |