use of com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod in project stetho by facebook.
the class DOM method resolveNode.
@ChromeDevtoolsMethod
public ResolveNodeResponse resolveNode(JsonRpcPeer peer, JSONObject params) throws JsonRpcException {
final ResolveNodeRequest request = mObjectMapper.convertValue(params, ResolveNodeRequest.class);
final Object element = mDocument.postAndWait(new UncheckedCallable<Object>() {
@Override
public Object call() {
return mDocument.getElementForNodeId(request.nodeId);
}
});
if (element == null) {
throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INVALID_PARAMS, "No known nodeId=" + request.nodeId, null));
}
int mappedObjectId = Runtime.mapObject(peer, element);
Runtime.RemoteObject remoteObject = new Runtime.RemoteObject();
remoteObject.type = Runtime.ObjectType.OBJECT;
remoteObject.subtype = Runtime.ObjectSubType.NODE;
remoteObject.className = element.getClass().getName();
// not a primitive
remoteObject.value = null;
// not sure what this does...
remoteObject.description = null;
remoteObject.objectId = String.valueOf(mappedObjectId);
ResolveNodeResponse response = new ResolveNodeResponse();
response.object = remoteObject;
return response;
}
use of com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod in project stetho by facebook.
the class DOMStorage method setDOMStorageItem.
@ChromeDevtoolsMethod
public void setDOMStorageItem(JsonRpcPeer peer, JSONObject params) throws JSONException, JsonRpcException {
StorageId storage = mObjectMapper.convertValue(params.getJSONObject("storageId"), StorageId.class);
String key = params.getString("key");
String value = params.getString("value");
if (storage.isLocalStorage) {
SharedPreferences prefs = mContext.getSharedPreferences(storage.securityOrigin, Context.MODE_PRIVATE);
Object existingValue = prefs.getAll().get(key);
try {
if (existingValue == null) {
throw new DOMStorageAssignmentException("Unsupported: cannot add new key " + key + " due to lack of type inference");
} else {
SharedPreferences.Editor editor = prefs.edit();
try {
assignByType(editor, key, SharedPreferencesHelper.valueFromString(value, existingValue));
editor.apply();
} catch (IllegalArgumentException e) {
throw new DOMStorageAssignmentException(String.format(Locale.US, "Type mismatch setting %s to %s (expected %s)", key, value, existingValue.getClass().getSimpleName()));
}
}
} catch (DOMStorageAssignmentException e) {
CLog.writeToConsole(mDOMStoragePeerManager, Console.MessageLevel.ERROR, Console.MessageSource.STORAGE, e.getMessage());
// JsonRpcException but the UI doesn't respect setDOMStorageItem failure.
if (prefs.contains(key)) {
mDOMStoragePeerManager.signalItemUpdated(storage, key, value, SharedPreferencesHelper.valueToString(existingValue));
} else {
mDOMStoragePeerManager.signalItemRemoved(storage, key);
}
}
}
}
use of com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod in project stetho by facebook.
the class DOMStorage method removeDOMStorageItem.
@ChromeDevtoolsMethod
public void removeDOMStorageItem(JsonRpcPeer peer, JSONObject params) throws JSONException {
StorageId storage = mObjectMapper.convertValue(params.getJSONObject("storageId"), StorageId.class);
String key = params.getString("key");
if (storage.isLocalStorage) {
SharedPreferences prefs = mContext.getSharedPreferences(storage.securityOrigin, Context.MODE_PRIVATE);
prefs.edit().remove(key).apply();
}
}
use of com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod in project stetho by facebook.
the class DOMStorage method getDOMStorageItems.
@ChromeDevtoolsMethod
public JsonRpcResult getDOMStorageItems(JsonRpcPeer peer, JSONObject params) throws JSONException {
StorageId storage = mObjectMapper.convertValue(params.getJSONObject("storageId"), StorageId.class);
ArrayList<List<String>> entries = new ArrayList<List<String>>();
String prefTag = storage.securityOrigin;
if (storage.isLocalStorage) {
SharedPreferences prefs = mContext.getSharedPreferences(prefTag, Context.MODE_PRIVATE);
for (Map.Entry<String, ?> prefsEntry : prefs.getAll().entrySet()) {
ArrayList<String> entry = new ArrayList<String>(2);
entry.add(prefsEntry.getKey());
entry.add(SharedPreferencesHelper.valueToString(prefsEntry.getValue()));
entries.add(entry);
}
}
GetDOMStorageItemsResult result = new GetDOMStorageItemsResult();
result.entries = entries;
return result;
}
use of com.facebook.stetho.inspector.protocol.ChromeDevtoolsMethod in project stetho by facebook.
the class Database method executeSQL.
@ChromeDevtoolsMethod
public JsonRpcResult executeSQL(JsonRpcPeer peer, JSONObject params) {
ExecuteSQLRequest request = mObjectMapper.convertValue(params, ExecuteSQLRequest.class);
String databaseId = request.databaseId;
String query = request.query;
DatabaseDriver databaseDriver = getDatabasePeer(databaseId);
try {
return databaseDriver.executeSQL(request.databaseId, request.query, new DatabaseDriver.ExecuteResultHandler<ExecuteSQLResponse>() {
@Override
public ExecuteSQLResponse handleRawQuery() throws SQLiteException {
ExecuteSQLResponse response = new ExecuteSQLResponse();
// This is done because the inspector UI likes to delete rows if you give them no
// name/value list
response.columnNames = Collections.singletonList("success");
response.values = Collections.singletonList("true");
return response;
}
@Override
public ExecuteSQLResponse handleSelect(Cursor result) throws SQLiteException {
ExecuteSQLResponse response = new ExecuteSQLResponse();
response.columnNames = Arrays.asList(result.getColumnNames());
response.values = flattenRows(result, MAX_EXECUTE_RESULTS);
return response;
}
@Override
public ExecuteSQLResponse handleInsert(long insertedId) throws SQLiteException {
ExecuteSQLResponse response = new ExecuteSQLResponse();
response.columnNames = Collections.singletonList("ID of last inserted row");
response.values = Collections.singletonList(String.valueOf(insertedId));
return response;
}
@Override
public ExecuteSQLResponse handleUpdateDelete(int count) throws SQLiteException {
ExecuteSQLResponse response = new ExecuteSQLResponse();
response.columnNames = Collections.singletonList("Modified rows");
response.values = Collections.singletonList(String.valueOf(count));
return response;
}
});
} catch (RuntimeException e) {
LogUtil.e(e, "Exception executing: %s", request.query);
Error error = new Error();
error.code = 0;
error.message = e.getMessage();
ExecuteSQLResponse response = new ExecuteSQLResponse();
response.sqlError = error;
return response;
}
}
Aggregations