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 "components/spellcheck/browser/spelling_service_client.h" | 5 #include "components/spellcheck/browser/spelling_service_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 "\"originCountry\":\"%s\"," | 95 "\"originCountry\":\"%s\"," |
96 "\"key\":%s" | 96 "\"key\":%s" |
97 "}" | 97 "}" |
98 "}"; | 98 "}"; |
99 std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey()); | 99 std::string api_key = base::GetQuotedJSONString(google_apis::GetAPIKey()); |
100 std::string request = base::StringPrintf( | 100 std::string request = base::StringPrintf( |
101 kSpellingRequest, type, encoded_text.c_str(), language_code.c_str(), | 101 kSpellingRequest, type, encoded_text.c_str(), language_code.c_str(), |
102 country_code.c_str(), api_key.c_str()); | 102 country_code.c_str(), api_key.c_str()); |
103 | 103 |
104 GURL url = GURL(kSpellingServiceURL); | 104 GURL url = GURL(kSpellingServiceURL); |
105 net::URLFetcher* fetcher = CreateURLFetcher(url).release(); | 105 |
| 106 // Create traffic annotation tag. |
| 107 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 108 net::DefineNetworkTrafficAnnotation("spellcheck_lookup", R"( |
| 109 semantics { |
| 110 sender: "spellcheck" |
| 111 description: |
| 112 "Google Chrome can provide smarter spell-checking by sending " |
| 113 "text you type into the browser to Google's servers, allowing " |
| 114 "you to use the same spell-checking technology used by Google " |
| 115 "products, such as Docs. If the feature is enabled, Chrome will " |
| 116 "send the entire contents of text fields as you type in them to " |
| 117 "Google along with the browser’s default language. Google " |
| 118 "returns a list of suggested spellings, which will be displayed " |
| 119 "in the context menu." |
| 120 trigger: "User types text into a text field or asks to correct a " |
| 121 "misspelled word." |
| 122 data: "Text a user has typed into a text field. No user identifier " |
| 123 "is sent along with the text." |
| 124 destination: GOOGLE_OWNED_SERVICE |
| 125 } |
| 126 policy { |
| 127 cookies_allowed: false |
| 128 setting: |
| 129 "You can enable or disable this feature via 'Use a web service to " |
| 130 "help resolve spelling errors.' in Chrome's settings under " |
| 131 "Advanced. The feature is disabled by default." |
| 132 policy { |
| 133 SpellCheckServiceEnabled { |
| 134 policy_options {mode: MANDATORY} |
| 135 value: false |
| 136 } |
| 137 } |
| 138 })"); |
| 139 |
| 140 net::URLFetcher* fetcher = |
| 141 CreateURLFetcher(url, traffic_annotation).release(); |
106 data_use_measurement::DataUseUserData::AttachToFetcher( | 142 data_use_measurement::DataUseUserData::AttachToFetcher( |
107 fetcher, data_use_measurement::DataUseUserData::SPELL_CHECKER); | 143 fetcher, data_use_measurement::DataUseUserData::SPELL_CHECKER); |
108 fetcher->SetRequestContext( | 144 fetcher->SetRequestContext( |
109 content::BrowserContext::GetDefaultStoragePartition(context) | 145 content::BrowserContext::GetDefaultStoragePartition(context) |
110 ->GetURLRequestContext()); | 146 ->GetURLRequestContext()); |
111 fetcher->SetUploadData("application/json", request); | 147 fetcher->SetUploadData("application/json", request); |
112 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 148 fetcher->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
113 net::LOAD_DO_NOT_SAVE_COOKIES); | 149 net::LOAD_DO_NOT_SAVE_COOKIES); |
114 spellcheck_fetchers_[fetcher] = base::MakeUnique<TextCheckCallbackData>( | 150 spellcheck_fetchers_[fetcher] = base::MakeUnique<TextCheckCallbackData>( |
115 base::WrapUnique(fetcher), callback, text); | 151 base::WrapUnique(fetcher), callback, text); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 source->GetResponseAsString(&data); | 298 source->GetResponseAsString(&data); |
263 success = ParseResponse(data, &results); | 299 success = ParseResponse(data, &results); |
264 } | 300 } |
265 | 301 |
266 // The callback may release the last (transitive) dependency on |this|. It | 302 // The callback may release the last (transitive) dependency on |this|. It |
267 // MUST be the last function called. | 303 // MUST be the last function called. |
268 callback_data->callback.Run(success, callback_data->text, results); | 304 callback_data->callback.Run(success, callback_data->text, results); |
269 } | 305 } |
270 | 306 |
271 std::unique_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( | 307 std::unique_ptr<net::URLFetcher> SpellingServiceClient::CreateURLFetcher( |
272 const GURL& url) { | 308 const GURL& url, |
273 return net::URLFetcher::Create(url, net::URLFetcher::POST, this); | 309 net::NetworkTrafficAnnotationTag traffic_annotation) { |
| 310 return net::URLFetcher::Create(url, net::URLFetcher::POST, this, |
| 311 traffic_annotation); |
274 } | 312 } |
OLD | NEW |