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

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

Issue 1134393002: Implement ChromeOS mime type extension mappings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move to platform_mime_util_chromeos.cc Created 5 years, 7 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 <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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 bool allow_proprietary_codecs_; 157 bool allow_proprietary_codecs_;
158 158
159 // Lookup table for string compare based string -> Codec mappings. 159 // Lookup table for string compare based string -> Codec mappings.
160 StringToCodecMappings string_to_codec_map_; 160 StringToCodecMappings string_to_codec_map_;
161 }; // class MimeUtil 161 }; // class MimeUtil
162 162
163 // This variable is Leaky because we need to access it from WorkerPool threads. 163 // This variable is Leaky because we need to access it from WorkerPool threads.
164 static base::LazyInstance<MimeUtil>::Leaky g_mime_util = 164 static base::LazyInstance<MimeUtil>::Leaky g_mime_util =
165 LAZY_INSTANCE_INITIALIZER; 165 LAZY_INSTANCE_INITIALIZER;
166 166
167 struct MimeInfo {
168 const char* const mime_type;
169 const char* const extensions; // comma separated list
170 };
171
172 static const MimeInfo primary_mappings[] = { 167 static const MimeInfo primary_mappings[] = {
173 { "text/html", "html,htm,shtml,shtm" }, 168 { "text/html", "html,htm,shtml,shtm" },
174 { "text/css", "css" }, 169 { "text/css", "css" },
175 { "text/xml", "xml" }, 170 { "text/xml", "xml" },
176 { "image/gif", "gif" }, 171 { "image/gif", "gif" },
177 { "image/jpeg", "jpeg,jpg" }, 172 { "image/jpeg", "jpeg,jpg" },
178 { "image/webp", "webp" }, 173 { "image/webp", "webp" },
179 { "image/png", "png" }, 174 { "image/png", "png" },
180 { "video/mp4", "mp4,m4v" }, 175 { "video/mp4", "mp4,m4v" },
181 { "audio/x-m4a", "m4a" }, 176 { "audio/x-m4a", "m4a" },
(...skipping 27 matching lines...) Expand all
209 { "text/plain", "txt,text" }, 204 { "text/plain", "txt,text" },
210 { "text/html", "ehtml" }, 205 { "text/html", "ehtml" },
211 { "application/rss+xml", "rss" }, 206 { "application/rss+xml", "rss" },
212 { "application/rdf+xml", "rdf" }, 207 { "application/rdf+xml", "rdf" },
213 { "text/xml", "xsl,xbl,xslt" }, 208 { "text/xml", "xsl,xbl,xslt" },
214 { "application/vnd.mozilla.xul+xml", "xul" }, 209 { "application/vnd.mozilla.xul+xml", "xul" },
215 { "application/x-shockwave-flash", "swf,swl" }, 210 { "application/x-shockwave-flash", "swf,swl" },
216 { "application/pkcs7-mime", "p7m,p7c,p7z" }, 211 { "application/pkcs7-mime", "p7m,p7c,p7z" },
217 { "application/pkcs7-signature", "p7s" }, 212 { "application/pkcs7-signature", "p7s" },
218 { "application/x-mpegurl", "m3u8" }, 213 { "application/x-mpegurl", "m3u8" },
219 { "application/epub+zip", "epub" },
yawano 2015/05/15 08:11:51 Since epub mime type is added for same reason (htt
220 }; 214 };
221 215
222 static const char* FindMimeType(const MimeInfo* mappings, 216 const char* FindMimeType(const MimeInfo* mappings,
223 size_t mappings_len, 217 size_t mappings_len,
224 const char* ext) { 218 const char* ext) {
225 size_t ext_len = strlen(ext); 219 size_t ext_len = strlen(ext);
226 220
227 for (size_t i = 0; i < mappings_len; ++i) { 221 for (size_t i = 0; i < mappings_len; ++i) {
228 const char* extensions = mappings[i].extensions; 222 const char* extensions = mappings[i].extensions;
229 for (;;) { 223 for (;;) {
230 size_t end_pos = strcspn(extensions, ","); 224 size_t end_pos = strcspn(extensions, ",");
231 if (end_pos == ext_len && 225 if (end_pos == ext_len &&
232 base::strncasecmp(extensions, ext, ext_len) == 0) 226 base::strncasecmp(extensions, ext, ext_len) == 0)
233 return mappings[i].mime_type; 227 return mappings[i].mime_type;
234 extensions += end_pos; 228 extensions += end_pos;
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1208 post_data->append("\r\n" + value + "\r\n"); 1202 post_data->append("\r\n" + value + "\r\n");
1209 } 1203 }
1210 1204
1211 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary, 1205 void AddMultipartFinalDelimiterForUpload(const std::string& mime_boundary,
1212 std::string* post_data) { 1206 std::string* post_data) {
1213 DCHECK(post_data); 1207 DCHECK(post_data);
1214 post_data->append("--" + mime_boundary + "--\r\n"); 1208 post_data->append("--" + mime_boundary + "--\r\n");
1215 } 1209 }
1216 1210
1217 } // namespace net 1211 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698