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