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

Side by Side Diff: extensions/browser/api/web_request/form_data_parser.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "extensions/browser/api/web_request/form_data_parser.h" 5 #include "extensions/browser/api/web_request/form_data_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 289
290 DISALLOW_COPY_AND_ASSIGN(FormDataParserMultipart); 290 DISALLOW_COPY_AND_ASSIGN(FormDataParserMultipart);
291 }; 291 };
292 292
293 FormDataParser::Result::Result() {} 293 FormDataParser::Result::Result() {}
294 FormDataParser::Result::~Result() {} 294 FormDataParser::Result::~Result() {}
295 295
296 FormDataParser::~FormDataParser() {} 296 FormDataParser::~FormDataParser() {}
297 297
298 // static 298 // static
299 scoped_ptr<FormDataParser> FormDataParser::Create( 299 std::unique_ptr<FormDataParser> FormDataParser::Create(
300 const net::URLRequest& request) { 300 const net::URLRequest& request) {
301 std::string value; 301 std::string value;
302 const bool found = request.extra_request_headers().GetHeader( 302 const bool found = request.extra_request_headers().GetHeader(
303 net::HttpRequestHeaders::kContentType, &value); 303 net::HttpRequestHeaders::kContentType, &value);
304 return CreateFromContentTypeHeader(found ? &value : NULL); 304 return CreateFromContentTypeHeader(found ? &value : NULL);
305 } 305 }
306 306
307 // static 307 // static
308 scoped_ptr<FormDataParser> FormDataParser::CreateFromContentTypeHeader( 308 std::unique_ptr<FormDataParser> FormDataParser::CreateFromContentTypeHeader(
309 const std::string* content_type_header) { 309 const std::string* content_type_header) {
310 enum ParserChoice {URL_ENCODED, MULTIPART, ERROR_CHOICE}; 310 enum ParserChoice {URL_ENCODED, MULTIPART, ERROR_CHOICE};
311 ParserChoice choice = ERROR_CHOICE; 311 ParserChoice choice = ERROR_CHOICE;
312 std::string boundary; 312 std::string boundary;
313 313
314 if (content_type_header == NULL) { 314 if (content_type_header == NULL) {
315 choice = URL_ENCODED; 315 choice = URL_ENCODED;
316 } else { 316 } else {
317 const std::string content_type( 317 const std::string content_type(
318 content_type_header->substr(0, content_type_header->find(';'))); 318 content_type_header->substr(0, content_type_header->find(';')));
319 319
320 if (base::EqualsCaseInsensitiveASCII(content_type, 320 if (base::EqualsCaseInsensitiveASCII(content_type,
321 "application/x-www-form-urlencoded")) { 321 "application/x-www-form-urlencoded")) {
322 choice = URL_ENCODED; 322 choice = URL_ENCODED;
323 } else if (base::EqualsCaseInsensitiveASCII(content_type, 323 } else if (base::EqualsCaseInsensitiveASCII(content_type,
324 "multipart/form-data")) { 324 "multipart/form-data")) {
325 static const char kBoundaryString[] = "boundary="; 325 static const char kBoundaryString[] = "boundary=";
326 size_t offset = content_type_header->find(kBoundaryString); 326 size_t offset = content_type_header->find(kBoundaryString);
327 if (offset == std::string::npos) { 327 if (offset == std::string::npos) {
328 // Malformed header. 328 // Malformed header.
329 return scoped_ptr<FormDataParser>(); 329 return std::unique_ptr<FormDataParser>();
330 } 330 }
331 offset += sizeof(kBoundaryString) - 1; 331 offset += sizeof(kBoundaryString) - 1;
332 boundary = content_type_header->substr( 332 boundary = content_type_header->substr(
333 offset, content_type_header->find(';', offset)); 333 offset, content_type_header->find(';', offset));
334 if (!boundary.empty()) 334 if (!boundary.empty())
335 choice = MULTIPART; 335 choice = MULTIPART;
336 } 336 }
337 } 337 }
338 // Other cases are unparseable, including when |content_type| is "text/plain". 338 // Other cases are unparseable, including when |content_type| is "text/plain".
339 339
340 switch (choice) { 340 switch (choice) {
341 case URL_ENCODED: 341 case URL_ENCODED:
342 return scoped_ptr<FormDataParser>(new FormDataParserUrlEncoded()); 342 return std::unique_ptr<FormDataParser>(new FormDataParserUrlEncoded());
343 case MULTIPART: 343 case MULTIPART:
344 return scoped_ptr<FormDataParser>(new FormDataParserMultipart(boundary)); 344 return std::unique_ptr<FormDataParser>(
345 new FormDataParserMultipart(boundary));
345 case ERROR_CHOICE: 346 case ERROR_CHOICE:
346 return scoped_ptr<FormDataParser>(); 347 return std::unique_ptr<FormDataParser>();
347 } 348 }
348 NOTREACHED(); // Some compilers do not believe this is unreachable. 349 NOTREACHED(); // Some compilers do not believe this is unreachable.
349 return scoped_ptr<FormDataParser>(); 350 return std::unique_ptr<FormDataParser>();
350 } 351 }
351 352
352 FormDataParser::FormDataParser() {} 353 FormDataParser::FormDataParser() {}
353 354
354 const net::UnescapeRule::Type FormDataParserUrlEncoded::unescape_rules_ = 355 const net::UnescapeRule::Type FormDataParserUrlEncoded::unescape_rules_ =
355 net::UnescapeRule::PATH_SEPARATORS | 356 net::UnescapeRule::PATH_SEPARATORS |
356 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS | 357 net::UnescapeRule::URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS |
357 net::UnescapeRule::SPOOFING_AND_CONTROL_CHARS | net::UnescapeRule::SPACES | 358 net::UnescapeRule::SPOOFING_AND_CONTROL_CHARS | net::UnescapeRule::SPACES |
358 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE; 359 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE;
359 360
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 if (value_pattern().Match(header, 593 if (value_pattern().Match(header,
593 kContentDispositionLength, header.size(), 594 kContentDispositionLength, header.size(),
594 RE2::UNANCHORED, groups, 2)) { 595 RE2::UNANCHORED, groups, 2)) {
595 value->set(groups[1].data(), groups[1].size()); 596 value->set(groups[1].data(), groups[1].size());
596 *value_assigned = true; 597 *value_assigned = true;
597 } 598 }
598 return true; 599 return true;
599 } 600 }
600 601
601 } // namespace extensions 602 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/form_data_parser.h ('k') | extensions/browser/api/web_request/form_data_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698