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

Side by Side Diff: net/base/mime_util.cc

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.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
« no previous file with comments | « net/base/mime_sniffer.cc ('k') | net/base/net_string_util_icu.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 #include <iterator> 6 #include <iterator>
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 const char* FindMimeType(const MimeInfo* mappings, 111 const char* FindMimeType(const MimeInfo* mappings,
112 size_t mappings_len, 112 size_t mappings_len,
113 const char* ext) { 113 const char* ext) {
114 size_t ext_len = strlen(ext); 114 size_t ext_len = strlen(ext);
115 115
116 for (size_t i = 0; i < mappings_len; ++i) { 116 for (size_t i = 0; i < mappings_len; ++i) {
117 const char* extensions = mappings[i].extensions; 117 const char* extensions = mappings[i].extensions;
118 for (;;) { 118 for (;;) {
119 size_t end_pos = strcspn(extensions, ","); 119 size_t end_pos = strcspn(extensions, ",");
120 if (end_pos == ext_len && 120 if (end_pos == ext_len && strncasecmp(extensions, ext, ext_len) == 0)
121 base::strncasecmp(extensions, ext, ext_len) == 0)
122 return mappings[i].mime_type; 121 return mappings[i].mime_type;
123 extensions += end_pos; 122 extensions += end_pos;
124 if (!*extensions) 123 if (!*extensions)
125 break; 124 break;
126 extensions += 1; // skip over comma 125 extensions += 1; // skip over comma
127 } 126 }
128 } 127 }
129 return NULL; 128 return NULL;
130 } 129 }
131 130
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const std::string base_pattern(mime_type_pattern.substr(0, semicolon)); 263 const std::string base_pattern(mime_type_pattern.substr(0, semicolon));
265 semicolon = mime_type.find(';'); 264 semicolon = mime_type.find(';');
266 const std::string base_type(mime_type.substr(0, semicolon)); 265 const std::string base_type(mime_type.substr(0, semicolon));
267 266
268 if (base_pattern == "*" || base_pattern == "*/*") 267 if (base_pattern == "*" || base_pattern == "*/*")
269 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); 268 return MatchesMimeTypeParameters(mime_type_pattern, mime_type);
270 269
271 const std::string::size_type star = base_pattern.find('*'); 270 const std::string::size_type star = base_pattern.find('*');
272 if (star == std::string::npos) { 271 if (star == std::string::npos) {
273 if (base_pattern.size() == base_type.size() && 272 if (base_pattern.size() == base_type.size() &&
274 base::strncasecmp(base_pattern.c_str(), base_type.c_str(), 273 strncasecmp(base_pattern.c_str(), base_type.c_str(),
275 base_pattern.size()) == 0) { 274 base_pattern.size()) == 0) {
276 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); 275 return MatchesMimeTypeParameters(mime_type_pattern, mime_type);
277 } else { 276 } else {
278 return false; 277 return false;
279 } 278 }
280 } 279 }
281 280
282 // Test length to prevent overlap between |left| and |right|. 281 // Test length to prevent overlap between |left| and |right|.
283 if (base_type.length() < base_pattern.length() - 1) 282 if (base_type.length() < base_pattern.length() - 1)
284 return false; 283 return false;
285 284
286 const std::string left(base_pattern.substr(0, star)); 285 const std::string left(base_pattern.substr(0, star));
287 const std::string right(base_pattern.substr(star + 1)); 286 const std::string right(base_pattern.substr(star + 1));
288 287
289 if (!StartsWithASCII(base_type, left, false)) 288 if (!base::StartsWith(base_type, left, base::CompareCase::INSENSITIVE_ASCII))
290 return false; 289 return false;
291 290
292 if (!right.empty() && !EndsWith(base_type, right, false)) 291 if (!right.empty() &&
292 !base::EndsWith(base_type, right, base::CompareCase::INSENSITIVE_ASCII))
293 return false; 293 return false;
294 294
295 return MatchesMimeTypeParameters(mime_type_pattern, mime_type); 295 return MatchesMimeTypeParameters(mime_type_pattern, mime_type);
296 } 296 }
297 297
298 // See http://www.iana.org/assignments/media-types/media-types.xhtml 298 // See http://www.iana.org/assignments/media-types/media-types.xhtml
299 static const char* const legal_top_level_types[] = { 299 static const char* const legal_top_level_types[] = {
300 "application", 300 "application",
301 "audio", 301 "audio",
302 "example", 302 "example",
(...skipping 23 matching lines...) Expand all
326 return true; 326 return true;
327 } 327 }
328 328
329 bool MimeUtil::IsValidTopLevelMimeType(const std::string& type_string) const { 329 bool MimeUtil::IsValidTopLevelMimeType(const std::string& type_string) const {
330 std::string lower_type = base::StringToLowerASCII(type_string); 330 std::string lower_type = base::StringToLowerASCII(type_string);
331 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) { 331 for (size_t i = 0; i < arraysize(legal_top_level_types); ++i) {
332 if (lower_type.compare(legal_top_level_types[i]) == 0) 332 if (lower_type.compare(legal_top_level_types[i]) == 0)
333 return true; 333 return true;
334 } 334 }
335 335
336 return type_string.size() > 2 && StartsWithASCII(type_string, "x-", false); 336 return type_string.size() > 2 &&
337 base::StartsWith(type_string, "x-",
338 base::CompareCase::INSENSITIVE_ASCII);
337 } 339 }
338 340
339 //---------------------------------------------------------------------------- 341 //----------------------------------------------------------------------------
340 // Wrappers for the singleton 342 // Wrappers for the singleton
341 //---------------------------------------------------------------------------- 343 //----------------------------------------------------------------------------
342 344
343 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext, 345 bool GetMimeTypeFromExtension(const base::FilePath::StringType& ext,
344 std::string* mime_type) { 346 std::string* mime_type) {
345 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type); 347 return g_mime_util.Get().GetMimeTypeFromExtension(ext, mime_type);
346 } 348 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 { "video/", kStandardVideoTypes, arraysize(kStandardVideoTypes) }, 455 { "video/", kStandardVideoTypes, arraysize(kStandardVideoTypes) },
454 { NULL, NULL, 0 } 456 { NULL, NULL, 0 }
455 }; 457 };
456 458
457 void GetExtensionsFromHardCodedMappings( 459 void GetExtensionsFromHardCodedMappings(
458 const MimeInfo* mappings, 460 const MimeInfo* mappings,
459 size_t mappings_len, 461 size_t mappings_len,
460 const std::string& leading_mime_type, 462 const std::string& leading_mime_type,
461 base::hash_set<base::FilePath::StringType>* extensions) { 463 base::hash_set<base::FilePath::StringType>* extensions) {
462 for (size_t i = 0; i < mappings_len; ++i) { 464 for (size_t i = 0; i < mappings_len; ++i) {
463 if (StartsWithASCII(mappings[i].mime_type, leading_mime_type, false)) { 465 if (base::StartsWith(mappings[i].mime_type, leading_mime_type,
466 base::CompareCase::INSENSITIVE_ASCII)) {
464 std::vector<string> this_extensions; 467 std::vector<string> this_extensions;
465 base::SplitString(mappings[i].extensions, ',', &this_extensions); 468 base::SplitString(mappings[i].extensions, ',', &this_extensions);
466 for (size_t j = 0; j < this_extensions.size(); ++j) { 469 for (size_t j = 0; j < this_extensions.size(); ++j) {
467 #if defined(OS_WIN) 470 #if defined(OS_WIN)
468 base::FilePath::StringType extension( 471 base::FilePath::StringType extension(
469 base::UTF8ToWide(this_extensions[j])); 472 base::UTF8ToWide(this_extensions[j]));
470 #else 473 #else
471 base::FilePath::StringType extension(this_extensions[j]); 474 base::FilePath::StringType extension(this_extensions[j]);
472 #endif 475 #endif
473 extensions->insert(extension); 476 extensions->insert(extension);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 518
516 void GetExtensionsForMimeType( 519 void GetExtensionsForMimeType(
517 const std::string& unsafe_mime_type, 520 const std::string& unsafe_mime_type,
518 std::vector<base::FilePath::StringType>* extensions) { 521 std::vector<base::FilePath::StringType>* extensions) {
519 if (unsafe_mime_type == "*/*" || unsafe_mime_type == "*") 522 if (unsafe_mime_type == "*/*" || unsafe_mime_type == "*")
520 return; 523 return;
521 524
522 const std::string mime_type = base::StringToLowerASCII(unsafe_mime_type); 525 const std::string mime_type = base::StringToLowerASCII(unsafe_mime_type);
523 base::hash_set<base::FilePath::StringType> unique_extensions; 526 base::hash_set<base::FilePath::StringType> unique_extensions;
524 527
525 if (EndsWith(mime_type, "/*", false)) { 528 if (base::EndsWith(mime_type, "/*", base::CompareCase::INSENSITIVE_ASCII)) {
526 std::string leading_mime_type = mime_type.substr(0, mime_type.length() - 1); 529 std::string leading_mime_type = mime_type.substr(0, mime_type.length() - 1);
527 530
528 // Find the matching StandardType from within kStandardTypes, or fall 531 // Find the matching StandardType from within kStandardTypes, or fall
529 // through to the last (default) StandardType. 532 // through to the last (default) StandardType.
530 const StandardType* type = NULL; 533 const StandardType* type = NULL;
531 for (size_t i = 0; i < arraysize(kStandardTypes); ++i) { 534 for (size_t i = 0; i < arraysize(kStandardTypes); ++i) {
532 type = &(kStandardTypes[i]); 535 type = &(kStandardTypes[i]);
533 if (type->leading_mime_type && 536 if (type->leading_mime_type &&
534 leading_mime_type == type->leading_mime_type) 537 leading_mime_type == type->leading_mime_type)
535 break; 538 break;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 post_data->append("\r\n" + value + "\r\n"); 581 post_data->append("\r\n" + value + "\r\n");
579 } 582 }
580 583
581 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 584 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
582 std::string* post_data) { 585 std::string* post_data) {
583 DCHECK(post_data); 586 DCHECK(post_data);
584 post_data->append("--" + mime_boundary + "--\r\n"); 587 post_data->append("--" + mime_boundary + "--\r\n");
585 } 588 }
586 589
587 } // namespace net 590 } // namespace net
OLDNEW
« no previous file with comments | « net/base/mime_sniffer.cc ('k') | net/base/net_string_util_icu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698