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_engines/template_url.h" | 5 #include "components/search_engines/template_url.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
12 #include "base/i18n/icu_string_conversions.h" | 12 #include "base/i18n/icu_string_conversions.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
17 #include "base/rand_util.h" | |
18 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
20 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
21 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
24 #include "build/build_config.h" | 23 #include "build/build_config.h" |
25 #include "components/google/core/browser/google_util.h" | 24 #include "components/google/core/browser/google_util.h" |
26 #include "components/metrics/proto/omnibox_input_type.pb.h" | 25 #include "components/metrics/proto/omnibox_input_type.pb.h" |
27 #include "components/search_engines/search_engines_switches.h" | 26 #include "components/search_engines/search_engines_switches.h" |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 } | 269 } |
271 | 270 |
272 bool TemplateURLRef::EncodeFormData(const PostParams& post_params, | 271 bool TemplateURLRef::EncodeFormData(const PostParams& post_params, |
273 PostContent* post_content) const { | 272 PostContent* post_content) const { |
274 if (post_params.empty()) | 273 if (post_params.empty()) |
275 return true; | 274 return true; |
276 if (!post_content) | 275 if (!post_content) |
277 return false; | 276 return false; |
278 | 277 |
279 const char kUploadDataMIMEType[] = "multipart/form-data; boundary="; | 278 const char kUploadDataMIMEType[] = "multipart/form-data; boundary="; |
280 const char kMultipartBoundary[] = "----+*+----%016" PRIx64 "----+*+----"; | |
281 // Each name/value pair is stored in a body part which is preceded by a | 279 // Each name/value pair is stored in a body part which is preceded by a |
282 // boundary delimiter line. Uses random number generator here to create | 280 // boundary delimiter line. |
283 // a unique boundary delimiter for form data encoding. | 281 std::string boundary = net::GenerateMimeMultipartBoundary(); |
284 std::string boundary = base::StringPrintf(kMultipartBoundary, | |
285 base::RandUint64()); | |
286 // Sets the content MIME type. | 282 // Sets the content MIME type. |
287 post_content->first = kUploadDataMIMEType; | 283 post_content->first = kUploadDataMIMEType; |
288 post_content->first += boundary; | 284 post_content->first += boundary; |
289 // Encodes the post parameters. | 285 // Encodes the post parameters. |
290 std::string* post_data = &post_content->second; | 286 std::string* post_data = &post_content->second; |
291 post_data->clear(); | 287 post_data->clear(); |
292 for (const auto& param : post_params) { | 288 for (const auto& param : post_params) { |
293 DCHECK(!param.name.empty()); | 289 DCHECK(!param.name.empty()); |
294 net::AddMultipartValueForUpload(param.name, param.value, boundary, | 290 net::AddMultipartValueForUpload(param.name, param.value, boundary, |
295 param.content_type, post_data); | 291 param.content_type, post_data); |
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1478 // patterns. This means that given patterns | 1474 // patterns. This means that given patterns |
1479 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1475 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
1480 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1476 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
1481 // return false. This is important for at least Google, where such URLs | 1477 // return false. This is important for at least Google, where such URLs |
1482 // are invalid. | 1478 // are invalid. |
1483 return !search_terms->empty(); | 1479 return !search_terms->empty(); |
1484 } | 1480 } |
1485 } | 1481 } |
1486 return false; | 1482 return false; |
1487 } | 1483 } |
OLD | NEW |