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

Side by Side Diff: third_party/liblouis/nacl_wrapper/liblouis_instance.cc

Issue 589133002: Make undefined Unicode characters show up in a nicer way in braille. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@moretables
Patch Set: Fix typo. Created 6 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
OLDNEW
1 // Copyright 2013 Google Inc. 1 // Copyright 2013 Google Inc.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of 4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at 5 // the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 // Well-known strings used for configuration. 98 // Well-known strings used for configuration.
99 static const char kTablesDirKey[] = "tablesdir"; 99 static const char kTablesDirKey[] = "tablesdir";
100 static const char kTablesDirDefault[] = "tables"; 100 static const char kTablesDirDefault[] = "tables";
101 101
102 // Well-known strings used in JSON messages. 102 // Well-known strings used in JSON messages.
103 static const char kCommandKey[] = "command"; 103 static const char kCommandKey[] = "command";
104 static const char kMessageIdKey[] = "message_id"; 104 static const char kMessageIdKey[] = "message_id";
105 static const char kInReplyToKey[] = "in_reply_to"; 105 static const char kInReplyToKey[] = "in_reply_to";
106 static const char kErrorKey[] = "error"; 106 static const char kErrorKey[] = "error";
107 static const char kTableNameKey[] = "table_name"; 107 static const char kTableNamesKey[] = "table_names";
108 static const char kSuccessKey[] = "success"; 108 static const char kSuccessKey[] = "success";
109 static const char kTextKey[] = "text"; 109 static const char kTextKey[] = "text";
110 static const char kCellsKey[] = "cells"; 110 static const char kCellsKey[] = "cells";
111 static const char kCursorPositionKey[] = "cursor_position"; 111 static const char kCursorPositionKey[] = "cursor_position";
112 static const char kTextToBrailleKey[] = "text_to_braille"; 112 static const char kTextToBrailleKey[] = "text_to_braille";
113 static const char kBrailleToTextKey[] = "braille_to_text"; 113 static const char kBrailleToTextKey[] = "braille_to_text";
114 static const char kCheckTableCommand[] = "CheckTable"; 114 static const char kCheckTableCommand[] = "CheckTable";
115 static const char kTranslateCommand[] = "Translate"; 115 static const char kTranslateCommand[] = "Translate";
116 static const char kBackTranslateCommand[] = "BackTranslate"; 116 static const char kBackTranslateCommand[] = "BackTranslate";
117 117
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 Json::Value reply(Json::objectValue); 201 Json::Value reply(Json::objectValue);
202 reply[kErrorKey] = error_message; 202 reply[kErrorKey] = error_message;
203 reply[kInReplyToKey] = in_reply_to; 203 reply[kInReplyToKey] = in_reply_to;
204 reply[kSuccessKey] = false; 204 reply[kSuccessKey] = false;
205 pp::Var var_reply(writer.write(reply)); 205 pp::Var var_reply(writer.write(reply));
206 PostMessage(var_reply); 206 PostMessage(var_reply);
207 } 207 }
208 208
209 void LibLouisInstance::HandleCheckTable(const Json::Value& message, 209 void LibLouisInstance::HandleCheckTable(const Json::Value& message,
210 const std::string& message_id) { 210 const std::string& message_id) {
211 Json::Value table_name = message[kTableNameKey]; 211 Json::Value table_names = message[kTableNamesKey];
212 if (!table_name.isString()) { 212 if (!table_names.isString()) {
213 PostError("expected table_name to be a string", message_id); 213 PostError("expected table_names to be a string", message_id);
214 return; 214 return;
215 } 215 }
216 PostWorkToBackground(cc_factory_.NewCallback( 216 PostWorkToBackground(cc_factory_.NewCallback(
217 &LibLouisInstance::CheckTableInBackground, 217 &LibLouisInstance::CheckTableInBackground,
218 table_name.asString(), message_id)); 218 table_names.asString(), message_id));
219 } 219 }
220 220
221 void LibLouisInstance::CheckTableInBackground(int32_t result, 221 void LibLouisInstance::CheckTableInBackground(int32_t result,
222 const std::string& table_name, const std::string& message_id) { 222 const std::string& table_names, const std::string& message_id) {
223 if (result != PP_OK) { 223 if (result != PP_OK) {
224 PostError("failed to transfer call to background thread", message_id); 224 PostError("failed to transfer call to background thread", message_id);
225 return; 225 return;
226 } 226 }
227 bool success = liblouis_.CheckTable(table_name); 227 bool success = liblouis_.CheckTable(table_names);
228 Json::Value reply(Json::objectValue); 228 Json::Value reply(Json::objectValue);
229 reply[kSuccessKey] = success; 229 reply[kSuccessKey] = success;
230 PostReply(reply, message_id); 230 PostReply(reply, message_id);
231 } 231 }
232 232
233 void LibLouisInstance::HandleTranslate(const Json::Value& message, 233 void LibLouisInstance::HandleTranslate(const Json::Value& message,
234 const std::string& message_id) { 234 const std::string& message_id) {
235 Json::Value table_name = message[kTableNameKey]; 235 Json::Value table_names = message[kTableNamesKey];
236 Json::Value text = message[kTextKey]; 236 Json::Value text = message[kTextKey];
237 Json::Value cursor_position = message[kCursorPositionKey]; 237 Json::Value cursor_position = message[kCursorPositionKey];
238 if (!table_name.isString()) { 238 if (!table_names.isString()) {
239 PostError("expected table_name to be a string", message_id); 239 PostError("expected table_names to be a string", message_id);
240 return; 240 return;
241 } else if (!text.isString()) { 241 } else if (!text.isString()) {
242 PostError("expected text to be a string", message_id); 242 PostError("expected text to be a string", message_id);
243 return; 243 return;
244 } else if (!cursor_position.isNull() && !cursor_position.isIntegral()) { 244 } else if (!cursor_position.isNull() && !cursor_position.isIntegral()) {
245 PostError("expected cursor_position to be null or integral", message_id); 245 PostError("expected cursor_position to be null or integral", message_id);
246 return; 246 return;
247 } 247 }
248 TranslationParams params; 248 TranslationParams params;
249 params.table_name = table_name.asString(); 249 params.table_names = table_names.asString();
250 params.text = text.asString(); 250 params.text = text.asString();
251 params.cursor_position = cursor_position.isIntegral() ? 251 params.cursor_position = cursor_position.isIntegral() ?
252 cursor_position.asInt() : -1; 252 cursor_position.asInt() : -1;
253 PostWorkToBackground(cc_factory_.NewCallback( 253 PostWorkToBackground(cc_factory_.NewCallback(
254 &LibLouisInstance::TranslateInBackground, 254 &LibLouisInstance::TranslateInBackground,
255 params, message_id)); 255 params, message_id));
256 } 256 }
257 257
258 void LibLouisInstance::TranslateInBackground(int32_t result, 258 void LibLouisInstance::TranslateInBackground(int32_t result,
259 const TranslationParams& params, const std::string& message_id) { 259 const TranslationParams& params, const std::string& message_id) {
(...skipping 17 matching lines...) Expand all
277 reply[kBrailleToTextKey] = braille_to_text; 277 reply[kBrailleToTextKey] = braille_to_text;
278 if (translation_result.cursor_position >= 0) { 278 if (translation_result.cursor_position >= 0) {
279 reply[kCursorPositionKey] = translation_result.cursor_position; 279 reply[kCursorPositionKey] = translation_result.cursor_position;
280 } 280 }
281 } 281 }
282 PostReply(reply, message_id); 282 PostReply(reply, message_id);
283 } 283 }
284 284
285 void LibLouisInstance::HandleBackTranslate(const Json::Value& message, 285 void LibLouisInstance::HandleBackTranslate(const Json::Value& message,
286 const std::string& message_id) { 286 const std::string& message_id) {
287 Json::Value table_name = message[kTableNameKey]; 287 Json::Value table_names = message[kTableNamesKey];
288 Json::Value cells = message[kCellsKey]; 288 Json::Value cells = message[kCellsKey];
289 if (!table_name.isString()) { 289 if (!table_names.isString()) {
290 PostError("expected table_name to be a string", message_id); 290 PostError("expected table_names to be a string", message_id);
291 return; 291 return;
292 } else if (!cells.isString()) { 292 } else if (!cells.isString()) {
293 PostError("expected cells to be a string", message_id); 293 PostError("expected cells to be a string", message_id);
294 return; 294 return;
295 } 295 }
296 std::vector<unsigned char> cells_vector; 296 std::vector<unsigned char> cells_vector;
297 if (!HexStringToBytes(cells.asString(), &cells_vector)) { 297 if (!HexStringToBytes(cells.asString(), &cells_vector)) {
298 PostError("expected cells to be a valid hexadecimal string", message_id); 298 PostError("expected cells to be a valid hexadecimal string", message_id);
299 return; 299 return;
300 } 300 }
301 PostWorkToBackground(cc_factory_.NewCallback( 301 PostWorkToBackground(cc_factory_.NewCallback(
302 &LibLouisInstance::BackTranslateInBackground, 302 &LibLouisInstance::BackTranslateInBackground,
303 table_name.asString(), cells_vector, message_id)); 303 table_names.asString(), cells_vector, message_id));
304 } 304 }
305 305
306 void LibLouisInstance::BackTranslateInBackground(int32_t result, 306 void LibLouisInstance::BackTranslateInBackground(int32_t result,
307 const std::string& table_name, const std::vector<unsigned char>& cells, 307 const std::string& table_names, const std::vector<unsigned char>& cells,
308 const std::string& message_id) { 308 const std::string& message_id) {
309 if (result != PP_OK) { 309 if (result != PP_OK) {
310 PostError("failed to transfer call to background thread", message_id); 310 PostError("failed to transfer call to background thread", message_id);
311 return; 311 return;
312 } 312 }
313 std::string text; 313 std::string text;
314 bool success = liblouis_.BackTranslate(table_name, cells, &text); 314 bool success = liblouis_.BackTranslate(table_names, cells, &text);
315 Json::Value reply(Json::objectValue); 315 Json::Value reply(Json::objectValue);
316 reply[kSuccessKey] = success; 316 reply[kSuccessKey] = success;
317 if (success) { 317 if (success) {
318 reply[kTextKey] = text; 318 reply[kTextKey] = text;
319 } 319 }
320 PostReply(reply, message_id); 320 PostReply(reply, message_id);
321 } 321 }
322 322
323 } // namespace liblouis_nacl 323 } // namespace liblouis_nacl
OLDNEW
« no previous file with comments | « third_party/liblouis/nacl_wrapper/liblouis_instance.h ('k') | third_party/liblouis/nacl_wrapper/liblouis_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698