contents.js wrapper for contents service

This is PR #6671, rebased because it's a blocker for the text editor components, and @fperez asked me to make that high priority. So far, I've just rebased, I intend to test it and fix things I see.
Having gone through this code, I'm happy to stick with callbacks instead of events.

One change I would like to see is not using AJAX responses as the interface.  First, other backends may have non-trivial client side logic, which can generate its own errors.  Second, the Contents class knows about the kind of AJAX errors it can receive, and so can decode them and create more informative error messages.

I would define an error class, along with a canonical way to display errors as a dialog.  AJAX errors then get wrapped as these errors.  Similarly on success, then return value should be well defined as a JS object, and documented (e.g. as in list_contents).