Ubuntu – How to automatically apply the same theme to Chromium for all new users

chromiumgnomegoogle-chromethemes

Note: when I say Chromium, I mean both Google Chrome and Chromium.

What I do know about applying the same settings for applications to all new users is either defining an schema/override file in /usr/share/glib-2.0/schemas or copying the folder/file to /etc/skel.

When a new user is created, that user is automatically given the gsettings/config file.

So my question is – how do I apply a theme to Chromium and get this to apply to all users? Does Chromium use gsettings type settings? If so, which ones?

Does Chromium use config files (e.g. in ~/.config)? If so, which ones?

I happen to be using either Gnome or Unity – but I suspect any answer will apply to any desktop environment.


I've found this link for a similar Q for Chrome – but for Windows.

Does this apply somehow to Ubuntu … and also to Chromium?


Having had a quick chat in the general room … /etc/chromium-browser/customizations was mentioned – so this may give a clue on what may need to be done for themes.

Best Answer

User config directory

Chromium does use a ~/.config directory (~/.config/chromium - ~/.config/google-chrome for Google Chrome), customisable using a command line flag:

~ man google-chrome | perl -00 -ne 'print if /\.config/'
       --user-data-dir=DIR
              Specifies  the directory that user data (your "profile") is kept
              in.  Defaults to ~/.config/google-chrome .   Separate  instances
              of  Google  Chrome  must  use  separate  user  data directories;
              repeated invocations of google-chrome  will  reuse  an  existing
              process for a given user data directory.

So, the simplest way to create a new configuration is to run either of these with --user-dir=newconfig, customize as needed, then copy over the newconfig directory to /etc/skel/.config/chromium and /etc/skel/.config/google-chrome.


Administrative policies

The last, but perhaps the most flexible, way would be to use /etc/chromium-browser/policies (or /etc/opt/chrome/policies for Google Chrome). The Chromium Documentation for Administrators has pages for Windows, Mac and Linux.

Essentially, on Linux, you make use of JSON files in policies/managed and policies/recommended. The managed directory is for settings that are enforced - the user can't change them.

I'll just adapt the example given for Linux:

$ cat /etc/chromium/policies/managed/test_policy.json
{
  "HomepageLocation": "www.chromium.org",
  "HomepageIsNewTabPage": false
}

Now, on Chromium, the homepage is locked to www.chromium.org. Correspondingly, if the file had been in recommended, the user can change their home page.

The current list of policies is available here. It lists policies, their descriptions and example values.

To install a theme or an extension, the ExtensionInstallForcelist policy can be used. It can't be recommended, only managed:

$ cat /etc/chromium/policies/managed/test_policy.json
{
    "ExtensionInstallForcelist": [
        "gighmmpiobklfepjocnamgkkbiglidom;https://clients2.google.com/service/update2/crx",
        "jeonacmfdmkgfmmdejlinolgjomhcbmh;https://clients2.google.com/service/update2/crx",
    ],
}

This will install the Adblock Extension and the GData Centers 1 Council Bluffs, Iowa theme.


/etc/chromium-browser/customizations

/etc/chromium-browser/customizations/00-example seems to indicate it can only be used for detecting plugins and adding command line flags:

$ cat etc/chromium-browser/customizations/00-example
##   Register plugins this way.  The two parameters are yours to fill.

#discover_registration /path/to/plugin/plugin.info library-name

##   A way to influence the running. This is read-write for you. Please
##   Append only.

#CHROMIUM_FLAGS="${CHROMIUM_FLAGS} --option=value"

##   Read-only variables guaranteed to be set, with example values.

#APPNAME='chromium-browser'
#BUILD_DIST='Ubuntu 14.04'
#DESKTOP_SESSION='ubuntu'
#LIBDIR='/usr/lib/chromium-browser'
#UPSTREAM_VERSION='34.0.1847.131'

(That's from 48.0.2564.116-0ubuntu0.14.04.1.1111, by the way, despite what the UPSTREAM_VERSION might indicate. And for some reason, only the 32-bit package on Ubuntu 14.04 has it, not the 64-bit one.)

The list of command line flags for Chromium can be found at http://peter.sh/experiments/chromium-command-line-switches/, according to
the Chromium website.

discover_registration doesn't seem to be an executable command - it might be a shell function, but I'm inclined to suspect these files are not parsed by our normal shells. In any case, I think this method is not sufficiently versatile, and it's difficult to override if all you want is for users to start off with some settings while letting them change those later. And the flags don't seem to provide a way of installing a theme or an extension.


GSettings

A quick scan of dconf-editor on my system indicates Google Chrome doesn't use it. Neither, apparently (thanks @Serg), does Chromium.


Conclusion

All told, either of the first two methods can be used, and Google Chrome supports whatever Chromium does, but with different paths. Where Chromium has /etc/chromium-browser and ~/.config/chromium, Google Chrome has /etc/opt/chrome and ~/.config/google-chrome, respectively. The first method is OK for one-time initialization, anything more would require the second method.

Since not all settings can be configured using policies, you might have to use both of them.