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

最佳答案

查看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

关于google-chrome - 如何以编程方式找到Chrome处理的内容类型?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16130668/

10-13 09:22