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" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 17 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
| 20 #include "content/common/net/url_fetcher.h" |
20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "unicode/uloc.h" | 24 #include "unicode/uloc.h" |
24 #include "webkit/glue/context_menu.h" | 25 #include "webkit/glue/context_menu.h" |
25 | 26 |
26 #if defined(GOOGLE_CHROME_BUILD) | 27 #if defined(GOOGLE_CHROME_BUILD) |
27 #include "chrome/browser/spellchecker/internal/spellcheck_internal.h" | 28 #include "chrome/browser/spellchecker/internal/spellcheck_internal.h" |
28 #else | 29 #else |
29 // Use a dummy URL and a key on Chromium to avoid build breaks until the | 30 // Use a dummy URL and a key on Chromium to avoid build breaks until the |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 fetcher_->set_request_context(context); | 143 fetcher_->set_request_context(context); |
143 fetcher_->set_upload_data("application/json", request); | 144 fetcher_->set_upload_data("application/json", request); |
144 fetcher_->Start(); | 145 fetcher_->Start(); |
145 | 146 |
146 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), | 147 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), |
147 this, &SpellingMenuObserver::OnAnimationTimerExpired); | 148 this, &SpellingMenuObserver::OnAnimationTimerExpired); |
148 | 149 |
149 return true; | 150 return true; |
150 } | 151 } |
151 | 152 |
152 void SpellingMenuObserver::OnURLFetchComplete( | 153 void SpellingMenuObserver::OnURLFetchComplete(const URLFetcher* source) { |
153 const URLFetcher* source, | |
154 const GURL& url, | |
155 const net::URLRequestStatus& status, | |
156 int response, | |
157 const net::ResponseCookies& cookies, | |
158 const std::string& data) { | |
159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
160 | 155 |
161 fetcher_.reset(); | 156 fetcher_.reset(); |
162 animation_timer_.Stop(); | 157 animation_timer_.Stop(); |
163 | 158 |
164 // Parse the response JSON and replace misspelled words in the |result_| text | 159 // Parse the response JSON and replace misspelled words in the |result_| text |
165 // with their suggestions. | 160 // with their suggestions. |
166 succeeded_ = ParseResponse(response, data); | 161 std::string data; |
| 162 source->GetResponseAsString(&data); |
| 163 succeeded_ = ParseResponse(source->response_code(), data); |
167 if (!succeeded_) | 164 if (!succeeded_) |
168 result_ = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_CORRECT); | 165 result_ = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_CORRECT); |
169 | 166 |
170 // Update the menu item with the result text. We enable this item only when | 167 // 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 | 168 // 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 | 169 // 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 | 170 // well-spelled words. For either case, we do not need to replace the input |
174 // text.) | 171 // text.) |
175 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, | 172 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, |
176 result_); | 173 result_); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 loading_frame_ = (loading_frame_ + 1) & 3; | 264 loading_frame_ = (loading_frame_ + 1) & 3; |
268 string16 loading_message = loading_message_; | 265 string16 loading_message = loading_message_; |
269 for (int i = 0; i < loading_frame_; ++i) | 266 for (int i = 0; i < loading_frame_; ++i) |
270 loading_message.push_back('.'); | 267 loading_message.push_back('.'); |
271 | 268 |
272 // Update the menu item with the text. We disable this item to prevent users | 269 // Update the menu item with the text. We disable this item to prevent users |
273 // from selecting it. | 270 // from selecting it. |
274 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, | 271 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, |
275 loading_message); | 272 loading_message); |
276 } | 273 } |
OLD | NEW |