From owner-freebsd-hackers@FreeBSD.ORG Sat Apr 28 14:35:33 2012 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 89729106564A; Sat, 28 Apr 2012 14:35:33 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 4C26F8FC08; Sat, 28 Apr 2012 14:35:33 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id A94987300A; Sat, 28 Apr 2012 16:47:45 +0200 (CEST) Date: Sat, 28 Apr 2012 16:47:45 +0200 From: Luigi Rizzo To: chromium@freebsd.org Message-ID: <20120428144745.GA40844@onelab2.iet.unipi.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.3i Cc: hackers@freebsd.org Subject: how to display C sources in Chromium (file:/// only) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Apr 2012 14:35:33 -0000 (hoping this is of interest for hackers- too) One of the most annoying features of chromium is that it downloads instead of displaying various types of files (.c, .h and so on). After a bit of investigation i found that at least for local files you can override this by defining your preferred mime types in ~/.local/share/mime/globs2 as follows: > cat ~/.local/share/mime/globs2 10:text/plain:*.c 10:text/plain:*.cc 10:text/plain:*.c++ 10:text/plain:*.cpp 10:text/plain:*.h The first field is the priority (smaller number means more important), then follows the mime type, then the pattern that you are matching. The default rules (/usr/local/share/ ...) have a priority of 50 for .c, .h and so on. For remotely-served files, the browser relies on the MIME Type supplied by the server and the trick above does not work. Looking at the Chromium sources chromium-courgette-redacted-18.0.1025.162/net/base/mime_util.cc it seems that a partial fix can be achieved by arring the list of types we want to display to the array static const char* const supported_non_image_types[] = { ... + "text/x-csrc", + "text/x-chdr", ... } Maybe we can have some optional patch to the FreeBSD port, although i'd rather find a way to override the server-supplied mime type in a way that does not require rebuilding Chrome. Anyways, at least for local browsing, this seems a significant improvement. cheers luigi