OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ | 5 #ifndef COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ |
6 #define COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ | 6 #define COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "components/omnibox/autocomplete_match.h" | 14 #include "components/omnibox/autocomplete_match.h" |
15 #include "components/omnibox/autocomplete_match_type.h" | 15 #include "components/omnibox/autocomplete_match_type.h" |
| 16 #include "components/omnibox/suggestion_answer.h" |
16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
17 | 18 |
18 class AutocompleteInput; | 19 class AutocompleteInput; |
19 class AutocompleteSchemeClassifier; | 20 class AutocompleteSchemeClassifier; |
20 | 21 |
21 namespace base { | 22 namespace base { |
22 class DictionaryValue; | 23 class DictionaryValue; |
23 class Value; | 24 class Value; |
24 } | 25 } |
25 | 26 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 112 |
112 class SuggestResult : public Result { | 113 class SuggestResult : public Result { |
113 public: | 114 public: |
114 SuggestResult(const base::string16& suggestion, | 115 SuggestResult(const base::string16& suggestion, |
115 AutocompleteMatchType::Type type, | 116 AutocompleteMatchType::Type type, |
116 const base::string16& match_contents, | 117 const base::string16& match_contents, |
117 const base::string16& match_contents_prefix, | 118 const base::string16& match_contents_prefix, |
118 const base::string16& annotation, | 119 const base::string16& annotation, |
119 const base::string16& answer_contents, | 120 const base::string16& answer_contents, |
120 const base::string16& answer_type, | 121 const base::string16& answer_type, |
| 122 scoped_ptr<SuggestionAnswer> answer, |
121 const std::string& suggest_query_params, | 123 const std::string& suggest_query_params, |
122 const std::string& deletion_url, | 124 const std::string& deletion_url, |
123 bool from_keyword_provider, | 125 bool from_keyword_provider, |
124 int relevance, | 126 int relevance, |
125 bool relevance_from_server, | 127 bool relevance_from_server, |
126 bool should_prefetch, | 128 bool should_prefetch, |
127 const base::string16& input_text); | 129 const base::string16& input_text); |
| 130 SuggestResult(const SuggestResult& result); |
128 ~SuggestResult() override; | 131 ~SuggestResult() override; |
129 | 132 |
| 133 SuggestResult& operator=(const SuggestResult& rhs); |
| 134 |
130 const base::string16& suggestion() const { return suggestion_; } | 135 const base::string16& suggestion() const { return suggestion_; } |
131 const base::string16& match_contents_prefix() const { | 136 const base::string16& match_contents_prefix() const { |
132 return match_contents_prefix_; | 137 return match_contents_prefix_; |
133 } | 138 } |
134 const base::string16& annotation() const { return annotation_; } | 139 const base::string16& annotation() const { return annotation_; } |
135 const std::string& suggest_query_params() const { | 140 const std::string& suggest_query_params() const { |
136 return suggest_query_params_; | 141 return suggest_query_params_; |
137 } | 142 } |
138 | 143 |
139 const base::string16& answer_contents() const { return answer_contents_; } | 144 const base::string16& answer_contents() const { return answer_contents_; } |
140 const base::string16& answer_type() const { return answer_type_; } | 145 const base::string16& answer_type() const { return answer_type_; } |
| 146 const SuggestionAnswer* answer() const { return answer_.get(); } |
141 | 147 |
142 bool should_prefetch() const { return should_prefetch_; } | 148 bool should_prefetch() const { return should_prefetch_; } |
143 | 149 |
144 // Fills in |match_contents_class_| to reflect how |match_contents_| should | 150 // Fills in |match_contents_class_| to reflect how |match_contents_| should |
145 // be displayed and bolded against the current |input_text|. If | 151 // be displayed and bolded against the current |input_text|. If |
146 // |allow_bolding_all| is false and |match_contents_class_| would have all | 152 // |allow_bolding_all| is false and |match_contents_class_| would have all |
147 // of |match_contents_| bolded, do nothing. | 153 // of |match_contents_| bolded, do nothing. |
148 void ClassifyMatchContents(const bool allow_bolding_all, | 154 void ClassifyMatchContents(const bool allow_bolding_all, |
149 const base::string16& input_text); | 155 const base::string16& input_text); |
150 | 156 |
(...skipping 12 matching lines...) Expand all Loading... |
163 base::string16 match_contents_prefix_; | 169 base::string16 match_contents_prefix_; |
164 | 170 |
165 // Optional annotation for the |match_contents_| for disambiguation. | 171 // Optional annotation for the |match_contents_| for disambiguation. |
166 // This may be displayed in the autocomplete match contents, but is defined | 172 // This may be displayed in the autocomplete match contents, but is defined |
167 // separately to facilitate different formatting. | 173 // separately to facilitate different formatting. |
168 base::string16 annotation_; | 174 base::string16 annotation_; |
169 | 175 |
170 // Optional additional parameters to be added to the search URL. | 176 // Optional additional parameters to be added to the search URL. |
171 std::string suggest_query_params_; | 177 std::string suggest_query_params_; |
172 | 178 |
| 179 // TODO(jdonnelly): Remove the following two properties once the downstream |
| 180 // clients are using the SuggestionAnswer. |
173 // Optional formatted Answers result. | 181 // Optional formatted Answers result. |
174 base::string16 answer_contents_; | 182 base::string16 answer_contents_; |
175 | 183 |
176 // Type of optional formatted Answers result. | 184 // Type of optional formatted Answers result. |
177 base::string16 answer_type_; | 185 base::string16 answer_type_; |
178 | 186 |
| 187 // Optional short answer to the input that produced this suggestion. |
| 188 scoped_ptr<SuggestionAnswer> answer_; |
| 189 |
179 // Should this result be prefetched? | 190 // Should this result be prefetched? |
180 bool should_prefetch_; | 191 bool should_prefetch_; |
181 }; | 192 }; |
182 | 193 |
183 class NavigationResult : public Result { | 194 class NavigationResult : public Result { |
184 public: | 195 public: |
185 NavigationResult(const AutocompleteSchemeClassifier& scheme_classifier, | 196 NavigationResult(const AutocompleteSchemeClassifier& scheme_classifier, |
186 const GURL& url, | 197 const GURL& url, |
187 AutocompleteMatchType::Type type, | 198 AutocompleteMatchType::Type type, |
188 const base::string16& description, | 199 const base::string16& description, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 // The JSON metadata associated with this server response. | 268 // The JSON metadata associated with this server response. |
258 std::string metadata; | 269 std::string metadata; |
259 | 270 |
260 // If the active suggest field trial (if any) has triggered. | 271 // If the active suggest field trial (if any) has triggered. |
261 bool field_trial_triggered; | 272 bool field_trial_triggered; |
262 | 273 |
263 // If the relevance values of the results are from the server. | 274 // If the relevance values of the results are from the server. |
264 bool relevances_from_server; | 275 bool relevances_from_server; |
265 | 276 |
266 // URLs of any images in Answers results. | 277 // URLs of any images in Answers results. |
267 std::vector<GURL> answers_image_urls; | 278 SuggestionAnswer::URLs answers_image_urls; |
268 | 279 |
269 private: | 280 private: |
270 DISALLOW_COPY_AND_ASSIGN(Results); | 281 DISALLOW_COPY_AND_ASSIGN(Results); |
271 }; | 282 }; |
272 | 283 |
273 // Extracts JSON data fetched by |source| and converts it to UTF-8. | 284 // Extracts JSON data fetched by |source| and converts it to UTF-8. |
274 static std::string ExtractJsonData(const net::URLFetcher* source); | 285 static std::string ExtractJsonData(const net::URLFetcher* source); |
275 | 286 |
276 // Parses JSON response received from the provider, stripping XSSI | 287 // Parses JSON response received from the provider, stripping XSSI |
277 // protection if needed. Returns the parsed data if successful, NULL | 288 // protection if needed. Returns the parsed data if successful, NULL |
278 // otherwise. | 289 // otherwise. |
279 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); | 290 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); |
280 | 291 |
281 // Parses results from the suggest server and updates the appropriate suggest | 292 // Parses results from the suggest server and updates the appropriate suggest |
282 // and navigation result lists in |results|. |is_keyword_result| indicates | 293 // and navigation result lists in |results|. |is_keyword_result| indicates |
283 // whether the response was received from the keyword provider. | 294 // whether the response was received from the keyword provider. |
284 // Returns whether the appropriate result list members were updated. | 295 // Returns whether the appropriate result list members were updated. |
285 static bool ParseSuggestResults( | 296 static bool ParseSuggestResults( |
286 const base::Value& root_val, | 297 const base::Value& root_val, |
287 const AutocompleteInput& input, | 298 const AutocompleteInput& input, |
288 const AutocompleteSchemeClassifier& scheme_classifier, | 299 const AutocompleteSchemeClassifier& scheme_classifier, |
289 int default_result_relevance, | 300 int default_result_relevance, |
290 const std::string& languages, | 301 const std::string& languages, |
291 bool is_keyword_result, | 302 bool is_keyword_result, |
292 Results* results); | 303 Results* results); |
293 | 304 |
294 private: | 305 private: |
295 FRIEND_TEST_ALL_PREFIXES(SearchSuggestionParser, | |
296 GetAnswersImageURLsWithoutImagelines); | |
297 FRIEND_TEST_ALL_PREFIXES(SearchSuggestionParser, | |
298 GetAnswersImageURLsWithValidImage); | |
299 | |
300 // Gets URLs of any images in Answers results. | |
301 static void GetAnswersImageURLs(const base::DictionaryValue* answer_json, | |
302 std::vector<GURL>* urls); | |
303 | |
304 DISALLOW_COPY_AND_ASSIGN(SearchSuggestionParser); | 306 DISALLOW_COPY_AND_ASSIGN(SearchSuggestionParser); |
305 }; | 307 }; |
306 | 308 |
307 #endif // COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ | 309 #endif // COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ |
OLD | NEW |