Chromium Code Reviews| 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 const 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); |
| 128 ~SuggestResult() override; | 130 ~SuggestResult() override; |
| 129 | 131 |
| 130 const base::string16& suggestion() const { return suggestion_; } | 132 const base::string16& suggestion() const { return suggestion_; } |
| 131 const base::string16& match_contents_prefix() const { | 133 const base::string16& match_contents_prefix() const { |
| 132 return match_contents_prefix_; | 134 return match_contents_prefix_; |
| 133 } | 135 } |
| 134 const base::string16& annotation() const { return annotation_; } | 136 const base::string16& annotation() const { return annotation_; } |
| 135 const std::string& suggest_query_params() const { | 137 const std::string& suggest_query_params() const { |
| 136 return suggest_query_params_; | 138 return suggest_query_params_; |
| 137 } | 139 } |
| 138 | 140 |
| 139 const base::string16& answer_contents() const { return answer_contents_; } | 141 const base::string16& answer_contents() const { return answer_contents_; } |
| 140 const base::string16& answer_type() const { return answer_type_; } | 142 const base::string16& answer_type() const { return answer_type_; } |
| 143 const SuggestionAnswer& answer() const { return answer_; } | |
| 141 | 144 |
| 142 bool should_prefetch() const { return should_prefetch_; } | 145 bool should_prefetch() const { return should_prefetch_; } |
| 143 | 146 |
| 144 // Fills in |match_contents_class_| to reflect how |match_contents_| should | 147 // Fills in |match_contents_class_| to reflect how |match_contents_| should |
| 145 // be displayed and bolded against the current |input_text|. If | 148 // be displayed and bolded against the current |input_text|. If |
| 146 // |allow_bolding_all| is false and |match_contents_class_| would have all | 149 // |allow_bolding_all| is false and |match_contents_class_| would have all |
| 147 // of |match_contents_| bolded, do nothing. | 150 // of |match_contents_| bolded, do nothing. |
| 148 void ClassifyMatchContents(const bool allow_bolding_all, | 151 void ClassifyMatchContents(const bool allow_bolding_all, |
| 149 const base::string16& input_text); | 152 const base::string16& input_text); |
| 150 | 153 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 163 base::string16 match_contents_prefix_; | 166 base::string16 match_contents_prefix_; |
| 164 | 167 |
| 165 // Optional annotation for the |match_contents_| for disambiguation. | 168 // Optional annotation for the |match_contents_| for disambiguation. |
| 166 // This may be displayed in the autocomplete match contents, but is defined | 169 // This may be displayed in the autocomplete match contents, but is defined |
| 167 // separately to facilitate different formatting. | 170 // separately to facilitate different formatting. |
| 168 base::string16 annotation_; | 171 base::string16 annotation_; |
| 169 | 172 |
| 170 // Optional additional parameters to be added to the search URL. | 173 // Optional additional parameters to be added to the search URL. |
| 171 std::string suggest_query_params_; | 174 std::string suggest_query_params_; |
| 172 | 175 |
| 176 // TODO(jdonnelly): Remove the following two properties once the downstream | |
| 177 // clients are using the SuggestionAnswer. | |
| 173 // Optional formatted Answers result. | 178 // Optional formatted Answers result. |
| 174 base::string16 answer_contents_; | 179 base::string16 answer_contents_; |
| 175 | 180 |
| 176 // Type of optional formatted Answers result. | 181 // Type of optional formatted Answers result. |
| 177 base::string16 answer_type_; | 182 base::string16 answer_type_; |
| 178 | 183 |
| 184 // Optional short answer to the input that produced this suggestion. | |
| 185 SuggestionAnswer answer_; | |
| 186 | |
| 179 // Should this result be prefetched? | 187 // Should this result be prefetched? |
| 180 bool should_prefetch_; | 188 bool should_prefetch_; |
| 181 }; | 189 }; |
| 182 | 190 |
| 183 class NavigationResult : public Result { | 191 class NavigationResult : public Result { |
| 184 public: | 192 public: |
| 185 NavigationResult(const AutocompleteSchemeClassifier& scheme_classifier, | 193 NavigationResult(const AutocompleteSchemeClassifier& scheme_classifier, |
| 186 const GURL& url, | 194 const GURL& url, |
| 187 AutocompleteMatchType::Type type, | 195 AutocompleteMatchType::Type type, |
| 188 const base::string16& description, | 196 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. | 265 // The JSON metadata associated with this server response. |
| 258 std::string metadata; | 266 std::string metadata; |
| 259 | 267 |
| 260 // If the active suggest field trial (if any) has triggered. | 268 // If the active suggest field trial (if any) has triggered. |
| 261 bool field_trial_triggered; | 269 bool field_trial_triggered; |
| 262 | 270 |
| 263 // If the relevance values of the results are from the server. | 271 // If the relevance values of the results are from the server. |
| 264 bool relevances_from_server; | 272 bool relevances_from_server; |
| 265 | 273 |
| 266 // URLs of any images in Answers results. | 274 // URLs of any images in Answers results. |
| 267 std::vector<GURL> answers_image_urls; | 275 SuggestionAnswer::URLs answers_image_urls; |
| 268 | 276 |
| 269 private: | 277 private: |
| 270 DISALLOW_COPY_AND_ASSIGN(Results); | 278 DISALLOW_COPY_AND_ASSIGN(Results); |
| 271 }; | 279 }; |
| 272 | 280 |
| 273 // Extracts JSON data fetched by |source| and converts it to UTF-8. | 281 // Extracts JSON data fetched by |source| and converts it to UTF-8. |
| 274 static std::string ExtractJsonData(const net::URLFetcher* source); | 282 static std::string ExtractJsonData(const net::URLFetcher* source); |
| 275 | 283 |
| 276 // Parses JSON response received from the provider, stripping XSSI | 284 // Parses JSON response received from the provider, stripping XSSI |
| 277 // protection if needed. Returns the parsed data if successful, NULL | 285 // protection if needed. Returns the parsed data if successful, NULL |
| 278 // otherwise. | 286 // otherwise. |
| 279 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); | 287 static scoped_ptr<base::Value> DeserializeJsonData(std::string json_data); |
| 280 | 288 |
| 281 // Parses results from the suggest server and updates the appropriate suggest | 289 // Parses results from the suggest server and updates the appropriate suggest |
| 282 // and navigation result lists in |results|. |is_keyword_result| indicates | 290 // and navigation result lists in |results|. |is_keyword_result| indicates |
| 283 // whether the response was received from the keyword provider. | 291 // whether the response was received from the keyword provider. |
| 284 // Returns whether the appropriate result list members were updated. | 292 // Returns whether the appropriate result list members were updated. |
| 285 static bool ParseSuggestResults( | 293 static bool ParseSuggestResults( |
| 286 const base::Value& root_val, | 294 const base::Value& root_val, |
| 287 const AutocompleteInput& input, | 295 const AutocompleteInput& input, |
| 288 const AutocompleteSchemeClassifier& scheme_classifier, | 296 const AutocompleteSchemeClassifier& scheme_classifier, |
| 289 int default_result_relevance, | 297 int default_result_relevance, |
| 290 const std::string& languages, | 298 const std::string& languages, |
| 291 bool is_keyword_result, | 299 bool is_keyword_result, |
| 292 Results* results); | 300 Results* results); |
| 293 | 301 |
| 294 private: | 302 private: |
| 295 FRIEND_TEST_ALL_PREFIXES(SearchSuggestionParser, | |
|
groby-ooo-7-16
2014/10/28 00:50:02
Yay for less friends!
| |
| 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); | 303 DISALLOW_COPY_AND_ASSIGN(SearchSuggestionParser); |
| 305 }; | 304 }; |
| 306 | 305 |
| 307 #endif // COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ | 306 #endif // COMPONENTS_OMNIBOX_SEARCH_SUGGESTION_PARSER_H_ |
| OLD | NEW |