| 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/search_provider_logos/google_logo_api.h" | 5 #include "components/search_provider_logos/google_logo_api.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 | 16 |
| 17 namespace search_provider_logos { | 17 namespace search_provider_logos { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 const char kResponsePreamble[] = ")]}'"; | 20 const char kResponsePreamble[] = ")]}'"; |
| 21 } | 21 } |
| 22 | 22 |
| 23 GURL GoogleAppendQueryparamsToLogoURL(const GURL& logo_url, | 23 GURL GoogleAppendQueryparamsToLogoURL(const GURL& logo_url, |
| 24 const std::string& fingerprint, | 24 const std::string& fingerprint, |
| 25 bool wants_cta, | 25 bool wants_cta, |
| 26 bool transparent) { | 26 bool gray_background) { |
| 27 // Note: we can't just use net::AppendQueryParameter() because it escapes | 27 // Note: we can't just use net::AppendQueryParameter() because it escapes |
| 28 // ":" to "%3A", but the server requires the colon not to be escaped. | 28 // ":" to "%3A", but the server requires the colon not to be escaped. |
| 29 // See: http://crbug.com/413845 | 29 // See: http://crbug.com/413845 |
| 30 | 30 |
| 31 // TODO(newt): Switch to using net::AppendQueryParameter once it no longer | 31 // TODO(newt): Switch to using net::AppendQueryParameter once it no longer |
| 32 // escapes ":" | 32 // escapes ":" |
| 33 if (!fingerprint.empty() || wants_cta) { | 33 if (!fingerprint.empty() || wants_cta) { |
| 34 std::string query(logo_url.query()); | 34 std::string query(logo_url.query()); |
| 35 if (!query.empty()) | 35 if (!query.empty()) |
| 36 query += "&"; | 36 query += "&"; |
| 37 | 37 |
| 38 query += "async="; | 38 query += "async="; |
| 39 std::vector<std::string> params; | 39 std::vector<std::string> params; |
| 40 if (!fingerprint.empty()) | 40 if (!fingerprint.empty()) |
| 41 params.push_back("es_dfp:" + fingerprint); | 41 params.push_back("es_dfp:" + fingerprint); |
| 42 | 42 |
| 43 if (wants_cta) | 43 if (wants_cta) |
| 44 params.push_back("cta:1"); | 44 params.push_back("cta:1"); |
| 45 | 45 |
| 46 if (transparent) { | 46 if (gray_background) { |
| 47 params.push_back("transp:1"); | 47 params.push_back("transp:1"); |
| 48 params.push_back("graybg:1"); | 48 params.push_back("graybg:1"); |
| 49 } | 49 } |
| 50 | 50 |
| 51 query += base::JoinString(params, ","); | 51 query += base::JoinString(params, ","); |
| 52 GURL::Replacements replacements; | 52 GURL::Replacements replacements; |
| 53 replacements.SetQueryStr(query); | 53 replacements.SetQueryStr(query); |
| 54 return logo_url.ReplaceComponents(replacements); | 54 return logo_url.ReplaceComponents(replacements); |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 logo->metadata.can_show_after_expiration = true; | 143 logo->metadata.can_show_after_expiration = true; |
| 144 } | 144 } |
| 145 logo->metadata.expiration_time = response_time + time_to_live; | 145 logo->metadata.expiration_time = response_time + time_to_live; |
| 146 | 146 |
| 147 // If this point is reached, parsing has succeeded. | 147 // If this point is reached, parsing has succeeded. |
| 148 *parsing_failed = false; | 148 *parsing_failed = false; |
| 149 return logo; | 149 return logo; |
| 150 } | 150 } |
| 151 | 151 |
| 152 } // namespace search_provider_logos | 152 } // namespace search_provider_logos |
| OLD | NEW |