5

在 Google Chrome 扩展中,我希望能够以编程方式获取Content-Type它可以处理的所有 HTTP 的列表。例如,它处理的一些是text/plain,text/htmlapplication/pdf.

4

1 回答 1

2

查看 chrome 中的 MIME 类型映射

static const MimeInfo primary_mappings[] = {
  { "text/html", "html,htm" },
  { "text/css", "css" },
  { "text/xml", "xml" },
  { "image/gif", "gif" },
  { "image/jpeg", "jpeg,jpg" },
  { "image/webp", "webp" },
  { "image/png", "png" },
  { "video/mp4", "mp4,m4v" },
  { "audio/x-m4a", "m4a" },
  { "audio/mp3", "mp3" },
  { "video/ogg", "ogv,ogm" },
  { "audio/ogg", "ogg,oga,opus" },
  { "video/webm", "webm" },
  { "audio/webm", "webm" },
  { "audio/wav", "wav" },
  { "application/xhtml+xml", "xhtml,xht" },
  { "application/x-chrome-extension", "crx" },
  { "multipart/related", "mhtml,mht" }
};

static const MimeInfo secondary_mappings[] = {
  { "application/octet-stream", "exe,com,bin" },
  { "application/gzip", "gz" },
  { "application/pdf", "pdf" },
  { "application/postscript", "ps,eps,ai" },
  { "application/javascript", "js" },
  { "application/font-woff", "woff" },
  { "image/bmp", "bmp" },
  { "image/x-icon", "ico" },
  { "image/vnd.microsoft.icon", "ico" },
  { "image/jpeg", "jfif,pjpeg,pjp" },
  { "image/tiff", "tiff,tif" },
  { "image/x-xbitmap", "xbm" },
  { "image/svg+xml", "svg,svgz" },
  { "message/rfc822", "eml" },
  { "text/plain", "txt,text" },
  { "text/html", "shtml,ehtml" },
  { "application/rss+xml", "rss" },
  { "application/rdf+xml", "rdf" },
  { "text/xml", "xsl,xbl" },
  { "application/vnd.mozilla.xul+xml", "xul" },
  { "application/x-shockwave-flash", "swf,swl" },
  { "application/pkcs7-mime", "p7m,p7c,p7z" },
  { "application/pkcs7-signature", "p7s" }
};

如需进一步查找,您可以查看参考

https://code.google.com/p/chromium/codesearch#chromium/src/net/base/mime_util.cc


编辑1:

是的,在 chrome 扩展 API 中无法直接访问此数据

但是您可以在 javascript 中构建 MIME 嗅探器类并为其提供支持的 Mime 类型,然后当用户要下载文件时,您可以针对支持的类型测试内容。

这是源代码中的单元测试。

https://code.google.com/p/chromium/codesearch#chromium/src/net/base/mime_sniffer_unittest.cc


通常所有浏览器都支持标准的 MIME 类型

http://webdesign.about.com/od/multimedia/a/mime-types-by-content-type.htm

http://reference.sitepoint.com/html/mime-types-full

http://www.freeformatter.com/mime-types-list.html

于 2013-10-01T19:56:57.253 回答