Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically find the content types handled by Chrome?

Within a Google Chrome extension, I would like to be able to programmatically obtain a list of all of the HTTP Content-Types that it can handle. For example, some of the ones it handles are text/plain, text/html and application/pdf.

like image 402
Sam Avatar asked Nov 03 '22 23:11

Sam


1 Answers

Looking at the MIME Types mapping in chrome

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" }
};

For further lookup and you can see the reference

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


EDIT 1:

Yes there is no direct access for this data in chrome extension API

But you can build MIME sniffer class in javascript and feed it with supported Mime Types then when user about to download file you can test the content against the supported types.

This is Unit test of in the source code.

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


Generally All the browsers has support for the standard MIME types

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

like image 114
Meabed Avatar answered Nov 09 '22 07:11

Meabed