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

Side by Side Diff: ipc/ipc_message_utils.cc

Issue 251093: Modify extension request IPC messages to pass a ListValue instead of a string. (Closed)
Patch Set: notreached messages Created 11 years, 2 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 unified diff | Download patch
« no previous file with comments | « chrome/renderer/render_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "ipc/ipc_message_utils.h" 5 #include "ipc/ipc_message_utils.h"
6 6
7 #include "base/json_writer.h" 7 #include "base/json_writer.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 11
12 namespace IPC { 12 namespace IPC {
13 13
14 const int kMaxRecursionDepth = 100; 14 const int kMaxRecursionDepth = 100;
15 15
16 // Value serialization 16 // Value serialization
17 17
18 static bool ReadValue(const Message* m, void** iter, Value** value, 18 static bool ReadValue(const Message* m, void** iter, Value** value,
19 int recursion); 19 int recursion);
20 20
21 static void WriteValue(Message* m, const Value* value, int recursion) { 21 static void WriteValue(Message* m, const Value* value, int recursion) {
22 if (recursion > kMaxRecursionDepth) { 22 if (recursion > kMaxRecursionDepth) {
23 LOG(WARNING) << "Max recursion depth hit in WriteValue."; 23 LOG(WARNING) << "Max recursion depth hit in WriteValue.";
24 return; 24 return;
25 } 25 }
26 26
27 m->WriteInt(value->GetType()); 27 m->WriteInt(value->GetType());
28 28
29 switch (value->GetType()) { 29 switch (value->GetType()) {
30 case Value::TYPE_NULL: 30 case Value::TYPE_NULL:
31 break; 31 break;
32 case Value::TYPE_BOOLEAN: { 32 case Value::TYPE_BOOLEAN: {
33 bool val; 33 bool val;
34 value->GetAsBoolean(&val); 34 value->GetAsBoolean(&val);
35 WriteParam(m, val); 35 WriteParam(m, val);
36 break; 36 break;
37 } 37 }
38 case Value::TYPE_INTEGER: { 38 case Value::TYPE_INTEGER: {
39 int val; 39 int val;
40 value->GetAsInteger(&val); 40 value->GetAsInteger(&val);
41 WriteParam(m, val); 41 WriteParam(m, val);
42 break; 42 break;
43 } 43 }
44 case Value::TYPE_REAL: { 44 case Value::TYPE_REAL: {
45 double val; 45 double val;
46 value->GetAsReal(&val); 46 value->GetAsReal(&val);
47 WriteParam(m, val); 47 WriteParam(m, val);
48 break; 48 break;
49 } 49 }
50 case Value::TYPE_STRING: { 50 case Value::TYPE_STRING: {
51 std::string val; 51 std::string val;
52 value->GetAsString(&val); 52 value->GetAsString(&val);
53 WriteParam(m, val); 53 WriteParam(m, val);
54 break; 54 break;
55 } 55 }
56 case Value::TYPE_BINARY: { 56 case Value::TYPE_BINARY: {
57 NOTREACHED() << "Don't send BinaryValues over IPC."; 57 const BinaryValue* binary = static_cast<const BinaryValue*>(value);
58 m->WriteData(binary->GetBuffer(), binary->GetSize());
59 break;
58 } 60 }
59 case Value::TYPE_DICTIONARY: { 61 case Value::TYPE_DICTIONARY: {
60 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); 62 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value);
61 63
62 WriteParam(m, static_cast<int>(dict->GetSize())); 64 WriteParam(m, static_cast<int>(dict->GetSize()));
63 65
64 for (DictionaryValue::key_iterator it = dict->begin_keys(); 66 for (DictionaryValue::key_iterator it = dict->begin_keys();
65 it != dict->end_keys(); ++it) { 67 it != dict->end_keys(); ++it) {
66 Value* subval; 68 Value* subval;
67 if (dict->Get(*it, &subval)) { 69 if (dict->Get(*it, &subval)) {
68 WriteParam(m, *it); 70 WriteParam(m, *it);
69 WriteValue(m, subval, recursion + 1); 71 WriteValue(m, subval, recursion + 1);
70 } else { 72 } else {
71 NOTREACHED() << "DictionaryValue iterators are filthy liars."; 73 NOTREACHED() << "DictionaryValue iterators are filthy liars.";
72 } 74 }
73 } 75 }
74 break; 76 break;
75 } 77 }
76 case Value::TYPE_LIST: { 78 case Value::TYPE_LIST: {
77 const ListValue* list = static_cast<const ListValue*>(value); 79 const ListValue* list = static_cast<const ListValue*>(value);
78 WriteParam(m, static_cast<int>(list->GetSize())); 80 WriteParam(m, static_cast<int>(list->GetSize()));
79 for (size_t i = 0; i < list->GetSize(); ++i) { 81 for (size_t i = 0; i < list->GetSize(); ++i) {
80 Value* subval; 82 Value* subval;
81 if (list->Get(i, &subval)) { 83 if (list->Get(i, &subval)) {
82 WriteValue(m, subval, recursion + 1); 84 WriteValue(m, subval, recursion + 1);
83 } else { 85 } else {
84 NOTREACHED() << "ListValue::GetSize is a filthy liar."; 86 NOTREACHED() << "ListValue::GetSize is a filthy liar.";
85 } 87 }
86 } 88 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (recursion > kMaxRecursionDepth) { 134 if (recursion > kMaxRecursionDepth) {
133 LOG(WARNING) << "Max recursion depth hit in ReadValue."; 135 LOG(WARNING) << "Max recursion depth hit in ReadValue.";
134 return false; 136 return false;
135 } 137 }
136 138
137 int type; 139 int type;
138 if (!ReadParam(m, iter, &type)) 140 if (!ReadParam(m, iter, &type))
139 return false; 141 return false;
140 142
141 switch (type) { 143 switch (type) {
142 case Value::TYPE_NULL: 144 case Value::TYPE_NULL:
143 *value = Value::CreateNullValue(); 145 *value = Value::CreateNullValue();
144 break; 146 break;
145 case Value::TYPE_BOOLEAN: { 147 case Value::TYPE_BOOLEAN: {
146 bool val; 148 bool val;
147 if (!ReadParam(m, iter, &val)) 149 if (!ReadParam(m, iter, &val))
148 return false; 150 return false;
149 *value = Value::CreateBooleanValue(val); 151 *value = Value::CreateBooleanValue(val);
150 break; 152 break;
151 } 153 }
152 case Value::TYPE_INTEGER: { 154 case Value::TYPE_INTEGER: {
153 int val; 155 int val;
154 if (!ReadParam(m, iter, &val)) 156 if (!ReadParam(m, iter, &val))
155 return false; 157 return false;
156 *value = Value::CreateIntegerValue(val); 158 *value = Value::CreateIntegerValue(val);
157 break; 159 break;
158 } 160 }
159 case Value::TYPE_REAL: { 161 case Value::TYPE_REAL: {
160 double val; 162 double val;
161 if (!ReadParam(m, iter, &val)) 163 if (!ReadParam(m, iter, &val))
162 return false; 164 return false;
163 *value = Value::CreateRealValue(val); 165 *value = Value::CreateRealValue(val);
164 break; 166 break;
165 } 167 }
166 case Value::TYPE_STRING: { 168 case Value::TYPE_STRING: {
167 std::string val; 169 std::string val;
168 if (!ReadParam(m, iter, &val)) 170 if (!ReadParam(m, iter, &val))
169 return false; 171 return false;
170 *value = Value::CreateStringValue(val); 172 *value = Value::CreateStringValue(val);
171 break; 173 break;
172 } 174 }
173 case Value::TYPE_BINARY: { 175 case Value::TYPE_BINARY: {
174 NOTREACHED() << "Don't send BinaryValues over IPC."; 176 const char* data;
177 int length;
178 if (!m->ReadData(iter, &data, &length))
179 return false;
180 *value = BinaryValue::CreateWithCopiedBuffer(data, length);
175 break; 181 break;
176 } 182 }
177 case Value::TYPE_DICTIONARY: { 183 case Value::TYPE_DICTIONARY: {
178 scoped_ptr<DictionaryValue> val(new DictionaryValue()); 184 scoped_ptr<DictionaryValue> val(new DictionaryValue());
179 if (!ReadDictionaryValue(m, iter, val.get(), recursion)) 185 if (!ReadDictionaryValue(m, iter, val.get(), recursion))
180 return false; 186 return false;
181 *value = val.release(); 187 *value = val.release();
182 break; 188 break;
183 } 189 }
184 case Value::TYPE_LIST: { 190 case Value::TYPE_LIST: {
185 scoped_ptr<ListValue> val(new ListValue()); 191 scoped_ptr<ListValue> val(new ListValue());
186 if (!ReadListValue(m, iter, val.get(), recursion)) 192 if (!ReadListValue(m, iter, val.get(), recursion))
187 return false; 193 return false;
188 *value = val.release(); 194 *value = val.release();
189 break; 195 break;
190 } 196 }
191 default: 197 default:
192 return false; 198 return false;
193 } 199 }
194 200
195 return true; 201 return true;
196 } 202 }
197 203
198 void ParamTraits<DictionaryValue>::Write(Message* m, const param_type& p) { 204 void ParamTraits<DictionaryValue>::Write(Message* m, const param_type& p) {
199 WriteValue(m, &p, 0); 205 WriteValue(m, &p, 0);
200 } 206 }
201 207
(...skipping 24 matching lines...) Expand all
226 232
227 return ReadListValue(m, iter, r, 0); 233 return ReadListValue(m, iter, r, 0);
228 } 234 }
229 235
230 void ParamTraits<ListValue>::Log(const param_type& p, std::wstring* l) { 236 void ParamTraits<ListValue>::Log(const param_type& p, std::wstring* l) {
231 std::string json; 237 std::string json;
232 JSONWriter::Write(&p, false, &json); 238 JSONWriter::Write(&p, false, &json);
233 l->append(UTF8ToWide(json)); 239 l->append(UTF8ToWide(json));
234 } 240 }
235 } // namespace IPC 241 } // namespace IPC
OLDNEW
« no previous file with comments | « chrome/renderer/render_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698