Java 类com.facebook.stetho.inspector.jsonrpc.JsonRpcResult 实例源码

项目:Stetho-Couchbase    文件:Database.java   
@ChromeDevtoolsMethod
@SuppressWarnings("unused")
public JsonRpcResult executeSQL(JsonRpcPeer peer, JSONObject params) {
    Timber.d("executeSQL: %s", String.valueOf(params));

    ExecuteSQLResponse response = new ExecuteSQLResponse();
    try {
        ExecuteSQLRequest request = mObjectMapper.convertValue(params, ExecuteSQLRequest.class);
        return mCouchbasePeerManager.executeSQL(request.databaseId, request.query);
    } catch (Exception e) {
        Timber.e(e.toString());
        Error error = new Error();
        error.code = 0;
        error.message = e.getMessage();
        response.sqlError = error;
        return response;
    }
}
项目:stetho    文件:Database.java   
@ChromeDevtoolsMethod
public JsonRpcResult getDatabaseTableNames(JsonRpcPeer peer, JSONObject params)
    throws JsonRpcException {
  GetDatabaseTableNamesRequest request = mObjectMapper.convertValue(params,
      GetDatabaseTableNamesRequest.class);

  String databaseId = request.databaseId;
  DatabaseDescriptorHolder holder =
      mPeerListener.getDatabaseDescriptorHolder(databaseId);

  try {
    GetDatabaseTableNamesResponse response = new GetDatabaseTableNamesResponse();
    response.tableNames = holder.driver.getTableNames(holder.descriptor);
    return response;
  } catch (SQLiteException e) {
    throw new JsonRpcException(
        new JsonRpcError(
            JsonRpcError.ErrorCode.INVALID_REQUEST,
            e.toString(),
            null /* data */));
  }
}
项目:stetho    文件:DOMStorage.java   
@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;
}
项目:stetho-realm    文件:Database.java   
@ChromeDevtoolsMethod
public JsonRpcResult getDatabaseTableNames(JsonRpcPeer peer, JSONObject params) {
    final SharedRealm realm = getRealm(
        objectMapper.convertValue(params, GetDatabaseTableNamesRequest.class).databaseId);
    final int size = (int) realm.size();
    final List<String> tableNames = new ArrayList<>(size);
    for (int i = 0; i < size; ++i) {
        tableNames.add(realm.getTableName(i));
    }

    final GetDatabaseTableNamesResponse response = new GetDatabaseTableNamesResponse();
    response.tableNames = tableNames;
    return response;
}
项目:StethoRealm    文件:Database.java   
@ChromeDevtoolsMethod
@SuppressWarnings("unused")
public JsonRpcResult getDatabaseTableNames(JsonRpcPeer peer, JSONObject params) {
    GetDatabaseTableNamesRequest request = objectMapper.convertValue(params, GetDatabaseTableNamesRequest.class);
    GetDatabaseTableNamesResponse response = new GetDatabaseTableNamesResponse();
    response.tableNames = realmPeerManager.getDatabaseTableNames(request.databaseId, withMetaTables);
    return response;
}
项目:Stetho-Couchbase    文件:Database.java   
@ChromeDevtoolsMethod
@SuppressWarnings("unused")
public JsonRpcResult getDatabaseTableNames(JsonRpcPeer peer, JSONObject params) {
    Timber.d("getAllDocumentIds: %s", String.valueOf(params));
    GetDatabaseTableNamesRequest request = mObjectMapper.convertValue(params, GetDatabaseTableNamesRequest.class);
    GetDatabaseTableNamesResponse response = new GetDatabaseTableNamesResponse();
    response.tableNames = mCouchbasePeerManager.getAllDocumentIds(request.databaseId);
    return response;
}
项目:stetho    文件:Page.java   
@ChromeDevtoolsMethod
public JsonRpcResult getResourceTree(JsonRpcPeer peer, JSONObject params) {
  // The DOMStorage module expects one key/value store per "security origin" which has a 1:1
  // relationship with resource tree frames.
  List<String> prefsTags = SharedPreferencesHelper.getSharedPreferenceTags(mContext);
  Iterator<String> prefsTagsIter = prefsTags.iterator();

  FrameResourceTree tree = createSimpleFrameResourceTree(
      "1",
      null /* parentId */,
      "Stetho",
      prefsTagsIter.hasNext() ? prefsTagsIter.next() : "");
  if (tree.childFrames == null) {
    tree.childFrames = new ArrayList<FrameResourceTree>();
  }

  int nextChildFrameId = 1;
  while (prefsTagsIter.hasNext()) {
    String frameId = "1." + (nextChildFrameId++);
    String prefsTag = prefsTagsIter.next();
    FrameResourceTree child = createSimpleFrameResourceTree(
        frameId,
        "1",
        "Child #" + frameId,
        prefsTag);
    tree.childFrames.add(child);
  }

  GetResourceTreeParams resultParams = new GetResourceTreeParams();
  resultParams.frameTree = tree;
  return resultParams;
}
项目:stetho    文件:DOM.java   
@ChromeDevtoolsMethod
public JsonRpcResult getDocument(JsonRpcPeer peer, JSONObject params) {
  final GetDocumentResponse result = new GetDocumentResponse();

  result.root = mDocument.postAndWait(new UncheckedCallable<Node>() {
    @Override
    public Node call() {
      Object element = mDocument.getRootElement();
      return createNodeForElement(element, mDocument.getDocumentView(), null);
    }
  });

  return result;
}
项目:stetho    文件:CSS.java   
@ChromeDevtoolsMethod
public JsonRpcResult getComputedStyleForNode(JsonRpcPeer peer, JSONObject params) {
  final GetComputedStyleForNodeRequest request = mObjectMapper.convertValue(
      params,
      GetComputedStyleForNodeRequest.class);

  final GetComputedStyleForNodeResult result = new GetComputedStyleForNodeResult();
  result.computedStyle = new ArrayList<>();

  mDocument.postAndWait(new Runnable() {
    @Override
    public void run() {
      Object element = mDocument.getElementForNodeId(request.nodeId);

      if (element == null) {
        LogUtil.e("Tried to get the style of an element that does not exist, using nodeid=" +
            request.nodeId);

        return;
      }

      mDocument.getElementComputedStyles(
          element,
          new ComputedStyleAccumulator() {
            @Override
            public void store(String name, String value) {
              final CSSComputedStyleProperty property = new CSSComputedStyleProperty();
              property.name = name;
              property.value = value;
              result.computedStyle.add(property);
            }
          });
    }
  });

  return result;
}
项目:stetho    文件:MethodDispatcher.java   
public JSONObject invoke(JsonRpcPeer peer, @Nullable JSONObject params)
    throws InvocationTargetException, IllegalAccessException, JSONException, JsonRpcException {
  Object internalResult = mMethod.invoke(mInstance, peer, params);
  if (internalResult == null || internalResult instanceof EmptyResult) {
    return new JSONObject();
  } else {
    JsonRpcResult convertableResult = (JsonRpcResult)internalResult;
    return mObjectMapper.convertValue(convertableResult, JSONObject.class);
  }
}
项目:stetho    文件:MethodDispatcher.java   
/**
 * Determines if the method is a {@link ChromeDevtoolsMethod}, and validates accordingly
 * if it is.
 *
 * @throws IllegalArgumentException Thrown if it is a {@link ChromeDevtoolsMethod} but
 *     it otherwise fails to satisfy requirements.
 */
private static boolean isDevtoolsMethod(Method method) throws IllegalArgumentException {
  if (!method.isAnnotationPresent(ChromeDevtoolsMethod.class)) {
    return false;
  } else {
    Class<?> args[] = method.getParameterTypes();
    String methodName = method.getDeclaringClass().getSimpleName() + "." + method.getName();
    Util.throwIfNot(args.length == 2,
        "%s: expected 2 args, got %s",
        methodName,
        args.length);
    Util.throwIfNot(args[0].equals(JsonRpcPeer.class),
        "%s: expected 1st arg of JsonRpcPeer, got %s",
        methodName,
        args[0].getName());
    Util.throwIfNot(args[1].equals(JSONObject.class),
        "%s: expected 2nd arg of JSONObject, got %s",
        methodName,
        args[1].getName());

    Class<?> returnType = method.getReturnType();
    if (!returnType.equals(void.class)) {
      Util.throwIfNot(JsonRpcResult.class.isAssignableFrom(returnType),
          "%s: expected JsonRpcResult return type, got %s",
          methodName,
          returnType.getName());
    }
    return true;
  }
}
项目:stetho    文件:Worker.java   
@ChromeDevtoolsMethod
public JsonRpcResult canInspectWorkers(JsonRpcPeer peer, JSONObject params) {
  return new SimpleBooleanResult(true);
}
项目:stetho    文件:Page.java   
@ChromeDevtoolsMethod
public JsonRpcResult canScreencast(JsonRpcPeer peer, JSONObject params) {
  return new SimpleBooleanResult(true);
}
项目:stetho    文件:Page.java   
@ChromeDevtoolsMethod
public JsonRpcResult hasTouchInputs(JsonRpcPeer peer, JSONObject params) {
  return new SimpleBooleanResult(false);
}
项目:stetho    文件:HeapProfiler.java   
@ChromeDevtoolsMethod
public JsonRpcResult getProfileHeaders(JsonRpcPeer peer, JSONObject params) {
  ProfileHeaderResponse response = new ProfileHeaderResponse();
  response.headers = Collections.emptyList();
  return response;
}
项目:stetho    文件:Debugger.java   
@ChromeDevtoolsMethod
public JsonRpcResult canSetScriptSource(JsonRpcPeer peer, JSONObject params) {
  return new SimpleBooleanResult(false);
}
项目:stetho    文件:Profiler.java   
@ChromeDevtoolsMethod
public JsonRpcResult getProfileHeaders(JsonRpcPeer peer, JSONObject params) {
  ProfileHeaderResponse response = new ProfileHeaderResponse();
  response.headers = Collections.emptyList();
  return response;
}
项目:stetho    文件:Runtime.java   
@ChromeDevtoolsMethod
public JsonRpcResult evaluate(JsonRpcPeer peer, JSONObject params) {
  return getSession(peer).evaluate(mReplFactory, params);
}
项目:stetho    文件:Runtime.java   
@ChromeDevtoolsMethod
public JsonRpcResult getProperties(JsonRpcPeer peer, JSONObject params) throws JsonRpcException {
  return getSession(peer).getProperties(params);
}