summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/devtools_rpc.cc
blob: c19e3731a8cdb33471edf0ee8122c19b70d452b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// TODO(pfeldman): Remove these once JSON is available in
// WebCore namespace.

#include "PlatformString.h"
#undef LOG

#include "base/json_reader.h"
#include "base/json_writer.h"
#include "base/values.h"
#include "webkit/glue/devtools/devtools_rpc.h"
#include "webkit/glue/glue_util.h"

DevToolsRpc::DevToolsRpc(Delegate* delegate) : delegate_(delegate) {
}

DevToolsRpc::~DevToolsRpc() {
}

void DevToolsRpc::SendValueMessage(const Value* value) {
  std::string json;
  JSONWriter::Write(value, false, &json);
  delegate_->SendRpcMessage(json);
}

// static
Value* DevToolsRpc::ParseMessage(const std::string& raw_msg) {
  return JSONReader::Read(raw_msg, false);
}

// static
void DevToolsRpc::GetListValue(
    const ListValue& message,
    int index,
    bool* value) {
  message.GetBoolean(index, value);
}

// static
void DevToolsRpc::GetListValue(
    const ListValue& message,
    int index,
    int* value) {
  message.GetInteger(index, value);
}

// static
void DevToolsRpc::GetListValue(
    const ListValue& message,
    int index,
    String* value) {
  std::string tmp;
  message.GetString(index, &tmp);
  *value = webkit_glue::StdStringToString(tmp);
}

// static
void DevToolsRpc::GetListValue(
    const ListValue& message,
    int index,
    std::string* value) {
  message.GetString(index, value);
}

// static
void DevToolsRpc::GetListValue(
    const ListValue& message,
    int index,
    Value** value) {
  message.Get(index, value);
}

// static
Value* DevToolsRpc::CreateValue(const String* value) {
  return Value::CreateStringValue(
      webkit_glue::StringToStdString(*value));
}

// static
Value* DevToolsRpc::CreateValue(const std::string* value) {
  return Value::CreateStringValue(*value);
}

// static
Value* DevToolsRpc::CreateValue(int* value) {
  return Value::CreateIntegerValue(*value);
}

// static
Value* DevToolsRpc::CreateValue(bool* value) {
  return Value::CreateBooleanValue(*value);
}

// static
Value* DevToolsRpc::CreateValue(const Value* value) {
  return value->DeepCopy();
}