| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.sdk.internal.v8native; | 5 package org.chromium.sdk.internal.v8native; |
| 6 | 6 |
| 7 import static org.chromium.sdk.util.BasicUtil.getSafe; | 7 import static org.chromium.sdk.util.BasicUtil.getSafe; |
| 8 import static org.chromium.sdk.util.BasicUtil.removeSafe; | 8 import static org.chromium.sdk.util.BasicUtil.removeSafe; |
| 9 | 9 |
| 10 import java.util.Collection; | 10 import java.util.Collection; |
| 11 import java.util.Collections; | 11 import java.util.Collections; |
| 12 import java.util.HashMap; | 12 import java.util.HashMap; |
| 13 import java.util.HashSet; | 13 import java.util.HashSet; |
| 14 import java.util.List; | 14 import java.util.List; |
| 15 import java.util.Map; | 15 import java.util.Map; |
| 16 | 16 |
| 17 import org.chromium.sdk.Script; | 17 import org.chromium.sdk.Script; |
| 18 import org.chromium.sdk.Script.Type; | 18 import org.chromium.sdk.Script.Type; |
| 19 import org.chromium.sdk.internal.ScriptBase; | |
| 20 import org.chromium.sdk.internal.ScriptBase.Descriptor; | 19 import org.chromium.sdk.internal.ScriptBase.Descriptor; |
| 21 import org.chromium.sdk.internal.v8native.protocol.V8ProtocolUtil; | 20 import org.chromium.sdk.internal.v8native.protocol.V8ProtocolUtil; |
| 22 import org.chromium.sdk.internal.v8native.protocol.input.data.ScriptHandle; | 21 import org.chromium.sdk.internal.v8native.protocol.input.data.ScriptHandle; |
| 23 import org.chromium.sdk.internal.v8native.protocol.input.data.SomeHandle; | 22 import org.chromium.sdk.internal.v8native.protocol.input.data.SomeHandle; |
| 24 | 23 |
| 25 /** | 24 /** |
| 26 * Manages scripts known in the corresponding browser tab. | 25 * Manages scripts known in the corresponding browser tab. |
| 27 */ | 26 */ |
| 28 public class ScriptManager { | 27 public class ScriptManager { |
| 29 | 28 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 54 | 53 |
| 55 /** | 54 /** |
| 56 * Adds a script using a "script" V8 response. | 55 * Adds a script using a "script" V8 response. |
| 57 * | 56 * |
| 58 * @param scriptBody to add the script from | 57 * @param scriptBody to add the script from |
| 59 * @param refs that contain the associated script debug context | 58 * @param refs that contain the associated script debug context |
| 60 * @return the new script, or {@code null} if the response does not contain | 59 * @return the new script, or {@code null} if the response does not contain |
| 61 * a valid script JSON | 60 * a valid script JSON |
| 62 */ | 61 */ |
| 63 public Script addScript(ScriptHandle scriptBody, List<SomeHandle> refs) { | 62 public Script addScript(ScriptHandle scriptBody, List<SomeHandle> refs) { |
| 63 ScriptImpl theScript = addScriptImpl(scriptBody, refs); |
| 64 if (theScript != null) { |
| 65 debugSession.getSessionManager().getDebugEventListener().scriptLoaded(theS
cript); |
| 66 } |
| 67 return theScript; |
| 68 } |
| 69 |
| 70 ScriptImpl addScriptImpl(ScriptHandle scriptBody, List<SomeHandle> refs) { |
| 64 ScriptImpl theScript = findById(V8ProtocolUtil.getScriptIdFromResponse(scrip
tBody)); | 71 ScriptImpl theScript = findById(V8ProtocolUtil.getScriptIdFromResponse(scrip
tBody)); |
| 65 | |
| 66 synchronized (this) { | 72 synchronized (this) { |
| 67 if (theScript == null) { | 73 if (theScript == null) { |
| 68 Descriptor<Long> desc = createDescriptor(scriptBody, refs, contextFilter
); | 74 Descriptor<Long> desc = createDescriptor(scriptBody, refs, contextFilter
); |
| 69 if (desc == null) { | 75 if (desc == null) { |
| 70 return null; | 76 return null; |
| 71 } | 77 } |
| 72 theScript = new ScriptImpl(desc, debugSession); | 78 theScript = new ScriptImpl(desc, debugSession); |
| 73 idToScript.put(desc.id, theScript); | 79 idToScript.put(desc.id, theScript); |
| 74 } | 80 } |
| 75 if (scriptBody.source() != null) { | 81 if (scriptBody.source() != null) { |
| 76 setSourceCode(scriptBody, theScript); | 82 setSourceCode(scriptBody, theScript); |
| 77 } | 83 } |
| 78 } | 84 } |
| 79 | |
| 80 debugSession.getSessionManager().getDebugEventListener().scriptLoaded(theScr
ipt); | |
| 81 return theScript; | 85 return theScript; |
| 82 } | 86 } |
| 83 | 87 |
| 84 public void scriptCollected(long scriptId) { | 88 public void scriptCollected(long scriptId) { |
| 85 ScriptImpl script; | 89 ScriptImpl script; |
| 86 synchronized (this) { | 90 synchronized (this) { |
| 87 script = removeSafe(idToScript, scriptId); | 91 script = removeSafe(idToScript, scriptId); |
| 88 if (script == null) { | 92 if (script == null) { |
| 89 return; | 93 return; |
| 90 } | 94 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 203 } |
| 200 } | 204 } |
| 201 | 205 |
| 202 public static Long convertAlienScriptId(Object scriptIdObj) { | 206 public static Long convertAlienScriptId(Object scriptIdObj) { |
| 203 if (scriptIdObj instanceof Long == false) { | 207 if (scriptIdObj instanceof Long == false) { |
| 204 throw new IllegalStateException("Script id must be of type Long"); | 208 throw new IllegalStateException("Script id must be of type Long"); |
| 205 } | 209 } |
| 206 return (Long) scriptIdObj; | 210 return (Long) scriptIdObj; |
| 207 } | 211 } |
| 208 } | 212 } |
| OLD | NEW |