| Index: components/omnibox/search_suggestion_parser.cc
|
| diff --git a/components/omnibox/search_suggestion_parser.cc b/components/omnibox/search_suggestion_parser.cc
|
| index 965662fd0e2cfb0f74453362c6bdf65bd48bb73c..91d59cdfcdcb4d33e401222a3c7ae5a93b6fe4ce 100644
|
| --- a/components/omnibox/search_suggestion_parser.cc
|
| +++ b/components/omnibox/search_suggestion_parser.cc
|
| @@ -65,6 +65,7 @@ SearchSuggestionParser::SuggestResult::SuggestResult(
|
| const base::string16& annotation,
|
| const base::string16& answer_contents,
|
| const base::string16& answer_type,
|
| + scoped_ptr<SuggestionAnswer> answer,
|
| const std::string& suggest_query_params,
|
| const std::string& deletion_url,
|
| bool from_keyword_provider,
|
| @@ -83,14 +84,49 @@ SearchSuggestionParser::SuggestResult::SuggestResult(
|
| suggest_query_params_(suggest_query_params),
|
| answer_contents_(answer_contents),
|
| answer_type_(answer_type),
|
| + answer_(answer.Pass()),
|
| should_prefetch_(should_prefetch) {
|
| match_contents_ = match_contents;
|
| DCHECK(!match_contents_.empty());
|
| ClassifyMatchContents(true, input_text);
|
| }
|
|
|
| +SearchSuggestionParser::SuggestResult::SuggestResult(
|
| + const SuggestResult& result)
|
| + : Result(result),
|
| + suggestion_(result.suggestion_),
|
| + match_contents_prefix_(result.match_contents_prefix_),
|
| + annotation_(result.annotation_),
|
| + suggest_query_params_(result.suggest_query_params_),
|
| + answer_contents_(result.answer_contents_),
|
| + answer_type_(result.answer_type_),
|
| + answer_(result.answer_.get() ?
|
| + new SuggestionAnswer(*result.answer_) : NULL),
|
| + should_prefetch_(result.should_prefetch_) {
|
| +}
|
| +
|
| SearchSuggestionParser::SuggestResult::~SuggestResult() {}
|
|
|
| +SearchSuggestionParser::SuggestResult&
|
| + SearchSuggestionParser::SuggestResult::operator=(
|
| + const SuggestResult& result) {
|
| + if (this == &result)
|
| + return *this;
|
| +
|
| + Result::operator=(result);
|
| + suggestion_ = result.suggestion_;
|
| + match_contents_prefix_ = result.match_contents_prefix_;
|
| + annotation_ = result.annotation_;
|
| + suggest_query_params_ = result.suggest_query_params_;
|
| + answer_contents_ = result.answer_contents_;
|
| + answer_type_ = result.answer_type_;
|
| + answer_.reset(
|
| + result.answer_.get() ? new SuggestionAnswer(*result.answer_) : NULL);
|
| + should_prefetch_ = result.should_prefetch_;
|
| +
|
| + return *this;
|
| +}
|
| +
|
| void SearchSuggestionParser::SuggestResult::ClassifyMatchContents(
|
| const bool allow_bolding_all,
|
| const base::string16& input_text) {
|
| @@ -440,6 +476,7 @@ bool SearchSuggestionParser::ParseSuggestResults(
|
| base::string16 annotation;
|
| base::string16 answer_contents;
|
| base::string16 answer_type;
|
| + scoped_ptr<SuggestionAnswer> answer;
|
| std::string suggest_query_params;
|
|
|
| if (suggestion_details) {
|
| @@ -456,12 +493,20 @@ bool SearchSuggestionParser::ParseSuggestResults(
|
| // Extract Answers, if provided.
|
| const base::DictionaryValue* answer_json = NULL;
|
| if (suggestion_detail->GetDictionary("ansa", &answer_json)) {
|
| - match_type = AutocompleteMatchType::SEARCH_SUGGEST_ANSWER;
|
| - GetAnswersImageURLs(answer_json, &results->answers_image_urls);
|
| - std::string contents;
|
| + std::string contents, type;
|
| base::JSONWriter::Write(answer_json, &contents);
|
| - answer_contents = base::UTF8ToUTF16(contents);
|
| - suggestion_detail->GetString("ansb", &answer_type);
|
| + answer.reset(new SuggestionAnswer());
|
| + if (SuggestionAnswer::ParseAnswer(answer_json, answer.get())) {
|
| + match_type = AutocompleteMatchType::SEARCH_SUGGEST_ANSWER;
|
| + answer_contents = base::UTF8ToUTF16(contents);
|
| + suggestion_detail->GetString("ansb", &answer_type);
|
| + answer->SetType(answer_type);
|
| + GetAnswersImageURLs(*answer, &results->answers_image_urls);
|
| + } else {
|
| + answer.reset();
|
| + DLOG(ERROR) << "Invalid suggestion answer json: "
|
| + << answer_contents;
|
| + }
|
| }
|
| }
|
| }
|
| @@ -472,8 +517,8 @@ bool SearchSuggestionParser::ParseSuggestResults(
|
| base::CollapseWhitespace(suggestion, false), match_type,
|
| base::CollapseWhitespace(match_contents, false),
|
| match_contents_prefix, annotation, answer_contents, answer_type,
|
| - suggest_query_params, deletion_url, is_keyword_result, relevance,
|
| - relevances != NULL, should_prefetch, trimmed_input));
|
| + answer.Pass(), suggest_query_params, deletion_url, is_keyword_result,
|
| + relevance, relevances != NULL, should_prefetch, trimmed_input));
|
| }
|
| }
|
| results->relevances_from_server = relevances != NULL;
|
| @@ -482,32 +527,10 @@ bool SearchSuggestionParser::ParseSuggestResults(
|
|
|
| // static
|
| void SearchSuggestionParser::GetAnswersImageURLs(
|
| - const base::DictionaryValue* answer_json,
|
| + const SuggestionAnswer& answer,
|
| std::vector<GURL>* urls) {
|
| - DCHECK(answer_json);
|
| -
|
| - const base::ListValue* lines = NULL;
|
| - if (!answer_json->GetList("l", &lines) || !lines || lines->GetSize() == 0)
|
| - return;
|
| -
|
| - for (base::ListValue::const_iterator iter = lines->begin();
|
| - iter != lines->end();
|
| - ++iter) {
|
| - const base::DictionaryValue* line = NULL;
|
| - if (!(*iter)->GetAsDictionary(&line) || !line)
|
| - continue;
|
| -
|
| - std::string image_host_and_path;
|
| - if (!line->GetString("il.i.d", &image_host_and_path) ||
|
| - image_host_and_path.empty())
|
| - continue;
|
| - // Concatenate scheme and host/path using only ':' as separator. This is
|
| - // due to the results delivering strings of the form '//host/path', which
|
| - // is web-speak for "use the enclosing page's scheme", but not a valid path
|
| - // of an URL.
|
| - GURL image_url(
|
| - GURL(std::string(url::kHttpsScheme) + ":" + image_host_and_path));
|
| - if (image_url.is_valid())
|
| - urls->push_back(image_url);
|
| - }
|
| + if (answer.first_line().HasImageURL())
|
| + urls->push_back(answer.first_line().image_url());
|
| + if (answer.second_line().HasImageURL())
|
| + urls->push_back(answer.second_line().image_url());
|
| }
|
|
|