OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/spelling_menu_observer.h" | 5 #include "chrome/browser/tab_contents/spelling_menu_observer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/json/string_escape.h" | 10 #include "base/json/string_escape.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 succeeded_ = ParseResponse(response, data); | 166 succeeded_ = ParseResponse(response, data); |
167 if (!succeeded_) | 167 if (!succeeded_) |
168 result_ = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_CORRECT); | 168 result_ = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_CORRECT); |
169 | 169 |
170 // Update the menu item with the result text. We enable this item only when | 170 // Update the menu item with the result text. We enable this item only when |
171 // the request text has misspelled words. (We disable this item not only when | 171 // the request text has misspelled words. (We disable this item not only when |
172 // we receive a server error but also when the input text consists only of | 172 // we receive a server error but also when the input text consists only of |
173 // well-spelled words. For either case, we do not need to replace the input | 173 // well-spelled words. For either case, we do not need to replace the input |
174 // text.) | 174 // text.) |
175 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, | 175 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, |
176 result_); | 176 false, result_); |
177 } | 177 } |
178 | 178 |
179 bool SpellingMenuObserver::ParseResponse(int response, | 179 bool SpellingMenuObserver::ParseResponse(int response, |
180 const std::string& data) { | 180 const std::string& data) { |
181 // When this JSON-RPC call finishes successfully, the Spelling service returns | 181 // When this JSON-RPC call finishes successfully, the Spelling service returns |
182 // an JSON object listed below. | 182 // an JSON object listed below. |
183 // * result - an envelope object representing the result from the APIARY | 183 // * result - an envelope object representing the result from the APIARY |
184 // server, which is the JSON-API front-end for the Spelling service. This | 184 // server, which is the JSON-API front-end for the Spelling service. This |
185 // object consists of the following variable: | 185 // object consists of the following variable: |
186 // - spellingCheckResponse (SpellingCheckResponse). | 186 // - spellingCheckResponse (SpellingCheckResponse). |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return; | 264 return; |
265 | 265 |
266 // Append '.' characters to the end of "Checking". | 266 // Append '.' characters to the end of "Checking". |
267 loading_frame_ = (loading_frame_ + 1) & 3; | 267 loading_frame_ = (loading_frame_ + 1) & 3; |
268 string16 loading_message = loading_message_; | 268 string16 loading_message = loading_message_; |
269 for (int i = 0; i < loading_frame_; ++i) | 269 for (int i = 0; i < loading_frame_; ++i) |
270 loading_message.push_back('.'); | 270 loading_message.push_back('.'); |
271 | 271 |
272 // Update the menu item with the text. We disable this item to prevent users | 272 // Update the menu item with the text. We disable this item to prevent users |
273 // from selecting it. | 273 // from selecting it. |
274 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, | 274 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, false, |
275 loading_message); | 275 loading_message); |
276 } | 276 } |
OLD | NEW |