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 #include "components/omnibox/search_suggestion_parser.h" | 5 #include "components/omnibox/search_suggestion_parser.h" |
6 | 6 |
7 #include "base/i18n/icu_string_conversions.h" | 7 #include "base/i18n/icu_string_conversions.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "components/omnibox/autocomplete_input.h" | 14 #include "components/omnibox/autocomplete_input.h" |
15 #include "components/omnibox/url_prefix.h" | 15 #include "components/omnibox/url_prefix.h" |
16 #include "components/url_fixer/url_fixer.h" | 16 #include "components/url_fixer/url_fixer.h" |
17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
19 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
20 #include "url/url_constants.h" | |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { | 24 AutocompleteMatchType::Type GetAutocompleteMatchType(const std::string& type) { |
24 if (type == "ENTITY") | 25 if (type == "ENTITY") |
25 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; | 26 return AutocompleteMatchType::SEARCH_SUGGEST_ENTITY; |
26 if (type == "INFINITE") | 27 if (type == "INFINITE") |
27 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; | 28 return AutocompleteMatchType::SEARCH_SUGGEST_INFINITE; |
28 if (type == "PERSONALIZED_QUERY") | 29 if (type == "PERSONALIZED_QUERY") |
29 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; | 30 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 } | 477 } |
477 results->relevances_from_server = relevances != NULL; | 478 results->relevances_from_server = relevances != NULL; |
478 return true; | 479 return true; |
479 } | 480 } |
480 | 481 |
481 // static | 482 // static |
482 void SearchSuggestionParser::GetAnswersImageURLs( | 483 void SearchSuggestionParser::GetAnswersImageURLs( |
483 const base::DictionaryValue* answer_json, | 484 const base::DictionaryValue* answer_json, |
484 std::vector<GURL>* urls) { | 485 std::vector<GURL>* urls) { |
485 DCHECK(answer_json); | 486 DCHECK(answer_json); |
487 | |
486 const base::ListValue* lines = NULL; | 488 const base::ListValue* lines = NULL; |
487 answer_json->GetList("l", &lines); | 489 if (!answer_json->GetList("l", &lines) || !lines || lines->GetSize() == 0) |
488 if (!lines || lines->GetSize() == 0) | |
489 return; | 490 return; |
490 | 491 |
491 for (size_t line = 0; line < lines->GetSize(); ++line) { | 492 for (base::ListValue::const_iterator iter = lines->begin(); |
492 const base::DictionaryValue* imageLine = NULL; | 493 iter != lines->end(); ++iter) { |
493 lines->GetDictionary(line, &imageLine); | 494 const base::DictionaryValue* line = NULL; |
494 if (!imageLine) | 495 if (!(*iter)->GetAsDictionary(&line) || !line) |
495 continue; | 496 continue; |
496 const base::DictionaryValue* imageData = NULL; | 497 |
497 imageLine->GetDictionary("i", &imageData); | 498 std::string imageUrl; |
Mark P
2014/08/22 16:21:08
I thought you said you'd use host_and_path?
Regar
groby-ooo-7-16
2014/08/22 18:23:11
Done. Now for real.
| |
498 if (!imageData) | 499 if (!line->GetString("il.i.d", &imageUrl) || imageUrl.empty()) |
499 continue; | 500 continue; |
500 std::string imageUrl; | 501 urls->push_back(GURL(std::string(url::kHttpsScheme) + ":" + imageUrl)); |
Mark P
2014/08/22 16:21:08
Only ":", not "://" (the url::kStandardSchemeSepar
groby-ooo-7-16
2014/08/22 18:23:11
Done.
| |
501 imageData->GetString("d", &imageUrl); | |
502 urls->push_back(GURL(imageUrl)); | |
503 } | 502 } |
504 } | 503 } |
OLD | NEW |