| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/spellchecker/spelling_service_client.h" | 5 #include "chrome/browser/spellchecker/spelling_service_client.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // "misspellings": [{ | 146 // "misspellings": [{ |
| 147 // "charStart": 10, | 147 // "charStart": 10, |
| 148 // "charLength": 5, | 148 // "charLength": 5, |
| 149 // "suggestions": [{ "suggestion": "quack" }], | 149 // "suggestions": [{ "suggestion": "quack" }], |
| 150 // "canAutoCorrect": false | 150 // "canAutoCorrect": false |
| 151 // }] | 151 // }] |
| 152 // } | 152 // } |
| 153 // } | 153 // } |
| 154 // } | 154 // } |
| 155 scoped_ptr<DictionaryValue> value( | 155 scoped_ptr<DictionaryValue> value( |
| 156 static_cast<DictionaryValue*>(base::JSONReader::Read(data, true))); | 156 static_cast<DictionaryValue*>( |
| 157 base::JSONReader::Read(data, base::JSON_ALLOW_TRAILING_COMMAS))); |
| 157 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) | 158 if (!value.get() || !value->IsType(base::Value::TYPE_DICTIONARY)) |
| 158 return false; | 159 return false; |
| 159 | 160 |
| 160 // Retrieve the array of Misspelling objects. When an internal error happens | 161 // Retrieve the array of Misspelling objects. When an internal error happens |
| 161 // in the Spelling service, it returns a JSON representing the internal error. | 162 // in the Spelling service, it returns a JSON representing the internal error. |
| 162 // (In this case, its HTTP status is 200.) We just return false for this case. | 163 // (In this case, its HTTP status is 200.) We just return false for this case. |
| 163 ListValue* misspellings = NULL; | 164 ListValue* misspellings = NULL; |
| 164 const char kMisspellings[] = "result.spellingCheckResponse.misspellings"; | 165 const char kMisspellings[] = "result.spellingCheckResponse.misspellings"; |
| 165 if (!value->GetList(kMisspellings, &misspellings)) | 166 if (!value->GetList(kMisspellings, &misspellings)) |
| 166 return false; | 167 return false; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 187 if (!suggestions->GetDictionary(0, &suggestion) || | 188 if (!suggestions->GetDictionary(0, &suggestion) || |
| 188 !suggestion->GetString("suggestion", &replacement)) { | 189 !suggestion->GetString("suggestion", &replacement)) { |
| 189 return false; | 190 return false; |
| 190 } | 191 } |
| 191 SpellCheckResult result( | 192 SpellCheckResult result( |
| 192 SpellCheckResult::SPELLING, start, length, replacement); | 193 SpellCheckResult::SPELLING, start, length, replacement); |
| 193 results->push_back(result); | 194 results->push_back(result); |
| 194 } | 195 } |
| 195 return true; | 196 return true; |
| 196 } | 197 } |
| OLD | NEW |