Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: components/omnibox/search_suggestion_parser.cc

Issue 470403003: [AiS] Fix parsing for Answers Images. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to HEAD Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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();
493 lines->GetDictionary(line, &imageLine); 494 ++iter) {
494 if (!imageLine) 495 const base::DictionaryValue* line = NULL;
496 if (!(*iter)->GetAsDictionary(&line) || !line)
495 continue; 497 continue;
496 const base::DictionaryValue* imageData = NULL; 498
497 imageLine->GetDictionary("i", &imageData); 499 std::string image_host_and_path;
498 if (!imageData) 500 if (!line->GetString("il.i.d", &image_host_and_path) ||
501 image_host_and_path.empty())
499 continue; 502 continue;
500 std::string imageUrl; 503 // Concatenate scheme and host/path using only ':' as separator. This is
501 imageData->GetString("d", &imageUrl); 504 // due to the results delivering strings of the form '//host/path', which
502 urls->push_back(GURL(imageUrl)); 505 // is web-speak for "use the enclosing page's scheme", but not a valid path
506 // of an URL.
507 GURL image_url(
508 GURL(std::string(url::kHttpsScheme) + ":" + image_host_and_path));
509 if (image_url.is_valid())
510 urls->push_back(image_url);
503 } 511 }
504 } 512 }
OLDNEW
« no previous file with comments | « components/omnibox/search_suggestion_parser.h ('k') | components/omnibox/search_suggestion_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698