| 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" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 272 } |
| 273 | 273 |
| 274 bool TemplateURLRef::EncodeFormData(const PostParams& post_params, | 274 bool TemplateURLRef::EncodeFormData(const PostParams& post_params, |
| 275 PostContent* post_content) const { | 275 PostContent* post_content) const { |
| 276 if (post_params.empty()) | 276 if (post_params.empty()) |
| 277 return true; | 277 return true; |
| 278 if (!post_content) | 278 if (!post_content) |
| 279 return false; | 279 return false; |
| 280 | 280 |
| 281 const char kUploadDataMIMEType[] = "multipart/form-data; boundary="; | 281 const char kUploadDataMIMEType[] = "multipart/form-data; boundary="; |
| 282 const char kMultipartBoundary[] = "----+*+----%016" PRIx64 "----+*+----"; | |
| 283 // Each name/value pair is stored in a body part which is preceded by a | 282 // Each name/value pair is stored in a body part which is preceded by a |
| 284 // boundary delimiter line. Uses random number generator here to create | 283 // boundary delimiter line. |
| 285 // a unique boundary delimiter for form data encoding. | 284 std::string boundary = net::GenerateMimeMultipartBoundary(); |
| 286 std::string boundary = base::StringPrintf(kMultipartBoundary, | |
| 287 base::RandUint64()); | |
| 288 // Sets the content MIME type. | 285 // Sets the content MIME type. |
| 289 post_content->first = kUploadDataMIMEType; | 286 post_content->first = kUploadDataMIMEType; |
| 290 post_content->first += boundary; | 287 post_content->first += boundary; |
| 291 // Encodes the post parameters. | 288 // Encodes the post parameters. |
| 292 std::string* post_data = &post_content->second; | 289 std::string* post_data = &post_content->second; |
| 293 post_data->clear(); | 290 post_data->clear(); |
| 294 for (const auto& param : post_params) { | 291 for (const auto& param : post_params) { |
| 295 DCHECK(!param.name.empty()); | 292 DCHECK(!param.name.empty()); |
| 296 net::AddMultipartValueForUpload(param.name, param.value, boundary, | 293 net::AddMultipartValueForUpload(param.name, param.value, boundary, |
| 297 param.content_type, post_data); | 294 param.content_type, post_data); |
| (...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 // patterns. This means that given patterns | 1511 // patterns. This means that given patterns |
| 1515 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1512 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1516 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1513 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1517 // return false. This is important for at least Google, where such URLs | 1514 // return false. This is important for at least Google, where such URLs |
| 1518 // are invalid. | 1515 // are invalid. |
| 1519 return !search_terms->empty(); | 1516 return !search_terms->empty(); |
| 1520 } | 1517 } |
| 1521 } | 1518 } |
| 1522 return false; | 1519 return false; |
| 1523 } | 1520 } |
| OLD | NEW |