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

Side by Side Diff: chrome/browser/intents/web_intents_registry.cc

Issue 10448109: Move function for classifying a string as a mime type into MimeUtil (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/mime_util.h » ('j') | net/base/mime_util.cc » ('J')
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 "chrome/browser/intents/web_intents_registry.h" 5 #include "chrome/browser/intents/web_intents_registry.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 23 matching lines...) Expand all
34 if (net::MatchesMimeType(UTF16ToUTF8(type1), UTF16ToUTF8(type2))) 34 if (net::MatchesMimeType(UTF16ToUTF8(type1), UTF16ToUTF8(type2)))
35 return true; 35 return true;
36 return net::MatchesMimeType(UTF16ToUTF8(type2), UTF16ToUTF8(type1)); 36 return net::MatchesMimeType(UTF16ToUTF8(type2), UTF16ToUTF8(type1));
37 } 37 }
38 38
39 // Returns true if the passed string is a MIME type. Works by comparing string 39 // Returns true if the passed string is a MIME type. Works by comparing string
40 // prefix to the valid MIME top-level types (and the wildcard type */). 40 // prefix to the valid MIME top-level types (and the wildcard type */).
41 // "*" is also accepted as a valid MIME type. 41 // "*" is also accepted as a valid MIME type.
42 // The passed |type_str| should have no leading or trailing whitespace. 42 // The passed |type_str| should have no leading or trailing whitespace.
43 bool IsMimeType(const string16& type_str) { 43 bool IsMimeType(const string16& type_str) {
44 // MIME types are always ASCII and case-insensitive (at least, the top-level 44 return net::MatchesMimeType(UTF16ToUTF8(type_str));
rvargas (doing something else) 2012/06/01 01:51:14 IsStringMimeType?
45 // and secondary types we care about).
46 if (!IsStringASCII(type_str))
47 return false;
48 std::string raw_type = UTF16ToASCII(type_str);
49 StringToLowerASCII(&raw_type);
50
51 // See http://www.iana.org/assignments/media-types/index.html
52 if (StartsWithASCII(raw_type, "application/", false) ||
53 StartsWithASCII(raw_type, "audio/", false) ||
54 StartsWithASCII(raw_type, "example/", false) ||
55 StartsWithASCII(raw_type, "image/", false) ||
56 StartsWithASCII(raw_type, "message/", false) ||
57 StartsWithASCII(raw_type, "model/", false) ||
58 StartsWithASCII(raw_type, "multipart/", false) ||
59 StartsWithASCII(raw_type, "text/", false) ||
60 StartsWithASCII(raw_type, "video/", false) ||
61 raw_type == "*/*" || raw_type == "*") {
62 return true;
63 }
64
65 // If there's a "/" separator character, and the token before it is
66 // "x-" + (ascii characters), it is also a MIME type.
67 size_t slash = raw_type.find('/');
68 if (slash < 3 || slash == std::string::npos || slash == raw_type.length() - 1)
69 return false;
70
71 if (StartsWithASCII(raw_type, "x-", false))
72 return true;
73
74 return false;
75 } 45 }
76 46
77 // Compares two web intents type specifiers to see if there is a match. 47 // Compares two web intents type specifiers to see if there is a match.
78 // First checks if both are MIME types. If so, uses MatchesMimeType. 48 // First checks if both are MIME types. If so, uses MatchesMimeType.
79 // If not, uses exact string equality. 49 // If not, uses exact string equality.
80 bool WebIntentsTypesMatch(const string16& type1, const string16& type2) { 50 bool WebIntentsTypesMatch(const string16& type1, const string16& type2) {
81 if (IsMimeType(type1) && IsMimeType(type2)) 51 if (IsMimeType(type1) && IsMimeType(type2))
82 return MimeTypesAreEqual(type1, type2); 52 return MimeTypesAreEqual(type1, type2);
83 53
84 return type1 == type2; 54 return type1 == type2;
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 if (write_iter != read_iter) 419 if (write_iter != read_iter)
450 *write_iter = *read_iter; 420 *write_iter = *read_iter;
451 } 421 }
452 ++read_iter; 422 ++read_iter;
453 } 423 }
454 424
455 // Cut off everything after the last intent copied to the list. 425 // Cut off everything after the last intent copied to the list.
456 if (++write_iter != services->end()) 426 if (++write_iter != services->end())
457 services->erase(write_iter, services->end()); 427 services->erase(write_iter, services->end());
458 } 428 }
OLDNEW
« no previous file with comments | « no previous file | net/base/mime_util.h » ('j') | net/base/mime_util.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698