Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(482)

Unified Diff: plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/value/JsObjectBase.java

Issue 11662019: Support variable changing in SDK interface and v8 native (Closed) Base URL: https://chromedevtools.googlecode.com/svn/trunk
Patch Set: merge Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/value/JsObjectBase.java
diff --git a/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/value/JsObjectBase.java b/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/value/JsObjectBase.java
index 103b1c9d77986b2d4c6da9da848f0a74a9a80826..f315f5438610e38e34afc63a8ab1aaf150b8c94d 100644
--- a/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/value/JsObjectBase.java
+++ b/plugins/org.chromium.sdk/src/org/chromium/sdk/internal/v8native/value/JsObjectBase.java
@@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
@@ -15,7 +16,11 @@ import java.util.concurrent.atomic.AtomicReference;
import org.chromium.sdk.JsFunction;
import org.chromium.sdk.JsObject;
import org.chromium.sdk.JsVariable;
+import org.chromium.sdk.RelayOk;
+import org.chromium.sdk.SyncCallback;
import org.chromium.sdk.internal.v8native.InternalContext;
+import org.chromium.sdk.internal.v8native.InternalContext.ContextDismissedCheckedException;
+import org.chromium.sdk.internal.v8native.JsEvaluateContextImpl;
import org.chromium.sdk.internal.v8native.protocol.output.EvaluateMessage;
import org.chromium.sdk.util.AsyncFuture;
import org.chromium.sdk.util.MethodIsBlockingException;
@@ -170,10 +175,10 @@ public abstract class JsObjectBase<D> extends JsValueBase implements JsObject {
SubpropertiesMirror subpropertiesMirror =
getRemoteValueMapping().getOrLoadSubproperties(ref);
- List<JsVariableBase.Property> properties =
- wrapProperties(subpropertiesMirror.getProperties(), PropertyMirrorParser.PROPERTY);
+ List<JsVariableBase.Property> properties = wrapProperties(
+ subpropertiesMirror.getProperties(), getRef(), PropertyMirrorParser.PROPERTY);
List<JsVariableBase.Impl> internalProperties = wrapProperties(
- subpropertiesMirror.getInternalProperties(), PropertyMirrorParser.VARIABLE);
+ subpropertiesMirror.getInternalProperties(), null, PropertyMirrorParser.VARIABLE);
BasicPropertyData data = new BasicPropertyData(currentCacheState, properties,
internalProperties, subpropertiesMirror);
@@ -181,11 +186,11 @@ public abstract class JsObjectBase<D> extends JsValueBase implements JsObject {
}
private <V> List<V> wrapProperties(List<? extends PropertyReference> propertyRefs,
- PropertyMirrorParser<V> parser) throws MethodIsBlockingException {
+ Long hostRef, PropertyMirrorParser<V> parser) throws MethodIsBlockingException {
List<ValueMirror> subMirrors = valueLoader.getOrLoadValueFromRefs(propertyRefs);
List<V> wrappedProperties = createPropertiesFromMirror(subMirrors,
- propertyRefs, parser);
+ propertyRefs, hostRef, parser);
return Collections.unmodifiableList(wrappedProperties);
}
};
@@ -267,31 +272,76 @@ public abstract class JsObjectBase<D> extends JsValueBase implements JsObject {
}
private <V> List<V> createPropertiesFromMirror(List<ValueMirror> mirrorProperties,
- List<? extends PropertyReference> propertyRefs, PropertyMirrorParser<V> parser) {
- // TODO(peter.rybin) Maybe assert that context is valid here
+ List<? extends PropertyReference> propertyRefs, Long hostRef,
+ PropertyMirrorParser<V> parser) {
+ JsVariableBase.Host host;
+ if (hostRef == null) {
+ host = null;
+ } else {
+ host = new VariableHost(getInternalContext(), hostRef);
+ }
List<V> result = new ArrayList<V>(mirrorProperties.size());
for (int i = 0; i < mirrorProperties.size(); i++) {
ValueMirror mirror = mirrorProperties.get(i);
Object varName = propertyRefs.get(i).getName();
- result.add(parser.parse(valueLoader, mirror, varName));
+ result.add(parser.parse(host, valueLoader, mirror, varName));
}
return result;
}
+ private static class VariableHost extends JsVariableBase.Host {
+ private final long objectRef;
+
+ protected VariableHost(InternalContext internalContext, long objectRef) {
+ super(internalContext);
+ this.objectRef = objectRef;
+ }
+
+ @Override boolean isMutable() {
+ return true;
+ }
+
+ @Override
+ RelayOk setValue(String variableName, JsValueBase jsValueBase,
+ JsEvaluateContextImpl.CallbackInternal callback, SyncCallback syncCallback) {
+ InternalContext intContext = getInternalContext();
+ JsEvaluateContextImpl evaluateContext =
+ intContext.getUserContext().getGlobalEvaluateContext();
+
+ String expression = "object[name] = value";
+ Map<String, EvaluateMessage.Value> additionalContext =
+ new LinkedHashMap<String, EvaluateMessage.Value>();
+ additionalContext.put("object", EvaluateMessage.Value.createForId(objectRef));
+ additionalContext.put("name", EvaluateMessage.Value.createForValue(variableName));
+ additionalContext.put("value", jsValueBase.getJsonParam(intContext));
+
+ try {
+ return evaluateContext.evaluateAsyncInternal(expression,
+ new ArrayList<Map.Entry<String, EvaluateMessage.Value>>(
+ additionalContext.entrySet()),
+ callback, syncCallback);
+ } catch (ContextDismissedCheckedException e) {
+ return intContext.getDebugSession().maybeRethrowContextException(e, syncCallback);
+ }
+ }
+ }
+
/**
* A helper class that helps parameterize some methods with either variable or property.
* Functionally it contains factory method, that creates either this or that.
* @param <V> variable or property type
*/
private static abstract class PropertyMirrorParser<V> {
- abstract V parse(ValueLoader valueLoader, ValueMirror valueData, Object rawName);
+ abstract V parse(JsVariableBase.Host host, ValueLoader valueLoader, ValueMirror valueData,
+ Object rawName);
static final PropertyMirrorParser<JsVariableBase.Impl> VARIABLE =
new PropertyMirrorParser<JsVariableBase.Impl>() {
@Override
- JsVariableBase.Impl parse(ValueLoader valueLoader, ValueMirror valueData, Object rawName) {
- return new JsVariableBase.Impl(valueLoader, valueData, rawName);
+ JsVariableBase.Impl parse(JsVariableBase.Host host, ValueLoader valueLoader,
+ ValueMirror valueData, Object rawName) {
+ return new JsVariableBase.Impl(host, valueLoader, valueData, rawName);
}
};
@@ -300,9 +350,9 @@ public abstract class JsObjectBase<D> extends JsValueBase implements JsObject {
static final PropertyMirrorParser<JsVariableBase.Property> PROPERTY =
new PropertyMirrorParser<JsVariableBase.Property>() {
@Override
- JsVariableBase.Property parse(ValueLoader valueLoader, ValueMirror valueData,
- Object rawName) {
- return new JsVariableBase.Property(valueLoader, valueData, rawName);
+ JsVariableBase.Property parse(JsVariableBase.Host host, ValueLoader valueLoader,
+ ValueMirror valueData, Object rawName) {
+ return new JsVariableBase.Property(host, valueLoader, valueData, rawName);
}
};
}

Powered by Google App Engine
This is Rietveld 408576698