| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 "\"key\":\"" SPELLING_SERVICE_KEY "\"" | 133 "\"key\":\"" SPELLING_SERVICE_KEY "\"" |
| 134 "}" | 134 "}" |
| 135 "}"; | 135 "}"; |
| 136 std::string request = base::StringPrintf(kSpellingRequest, | 136 std::string request = base::StringPrintf(kSpellingRequest, |
| 137 encoded_text.c_str(), | 137 encoded_text.c_str(), |
| 138 language, country); | 138 language, country); |
| 139 | 139 |
| 140 static const char kSpellingServiceURL[] = SPELLING_SERVICE_URL; | 140 static const char kSpellingServiceURL[] = SPELLING_SERVICE_URL; |
| 141 GURL url = GURL(kSpellingServiceURL); | 141 GURL url = GURL(kSpellingServiceURL); |
| 142 fetcher_.reset(new URLFetcher(url, URLFetcher::POST, this)); | 142 fetcher_.reset(new URLFetcher(url, URLFetcher::POST, this)); |
| 143 fetcher_->set_request_context(context); | 143 fetcher_->SetRequestContext(context); |
| 144 fetcher_->set_upload_data("application/json", request); | 144 fetcher_->SetUploadData("application/json", request); |
| 145 fetcher_->Start(); | 145 fetcher_->Start(); |
| 146 | 146 |
| 147 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), | 147 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), |
| 148 this, &SpellingMenuObserver::OnAnimationTimerExpired); | 148 this, &SpellingMenuObserver::OnAnimationTimerExpired); |
| 149 | 149 |
| 150 return true; | 150 return true; |
| 151 } | 151 } |
| 152 | 152 |
| 153 void SpellingMenuObserver::OnURLFetchComplete(const URLFetcher* source) { | 153 void SpellingMenuObserver::OnURLFetchComplete( |
| 154 const content::URLFetcher* source) { |
| 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 155 | 156 |
| 156 fetcher_.reset(); | 157 fetcher_.reset(); |
| 157 animation_timer_.Stop(); | 158 animation_timer_.Stop(); |
| 158 | 159 |
| 159 // Parse the response JSON and replace misspelled words in the |result_| text | 160 // Parse the response JSON and replace misspelled words in the |result_| text |
| 160 // with their suggestions. | 161 // with their suggestions. |
| 161 std::string data; | 162 std::string data; |
| 162 source->GetResponseAsString(&data); | 163 source->GetResponseAsString(&data); |
| 163 succeeded_ = ParseResponse(source->response_code(), data); | 164 succeeded_ = ParseResponse(source->GetResponseCode(), data); |
| 164 if (!succeeded_) | 165 if (!succeeded_) |
| 165 result_ = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_CORRECT); | 166 result_ = l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_SPELLING_CORRECT); |
| 166 | 167 |
| 167 // Update the menu item with the result text. We enable this item only when | 168 // Update the menu item with the result text. We enable this item only when |
| 168 // the request text has misspelled words. (We disable this item not only when | 169 // the request text has misspelled words. (We disable this item not only when |
| 169 // we receive a server error but also when the input text consists only of | 170 // we receive a server error but also when the input text consists only of |
| 170 // well-spelled words. For either case, we do not need to replace the input | 171 // well-spelled words. For either case, we do not need to replace the input |
| 171 // text.) | 172 // text.) |
| 172 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, | 173 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, succeeded_, |
| 173 result_); | 174 result_); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 loading_frame_ = (loading_frame_ + 1) & 3; | 265 loading_frame_ = (loading_frame_ + 1) & 3; |
| 265 string16 loading_message = loading_message_; | 266 string16 loading_message = loading_message_; |
| 266 for (int i = 0; i < loading_frame_; ++i) | 267 for (int i = 0; i < loading_frame_; ++i) |
| 267 loading_message.push_back('.'); | 268 loading_message.push_back('.'); |
| 268 | 269 |
| 269 // Update the menu item with the text. We disable this item to prevent users | 270 // Update the menu item with the text. We disable this item to prevent users |
| 270 // from selecting it. | 271 // from selecting it. |
| 271 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, | 272 proxy_->UpdateMenuItem(IDC_CONTENT_CONTEXT_SPELLING_SUGGESTION, false, |
| 272 loading_message); | 273 loading_message); |
| 273 } | 274 } |
| OLD | NEW |