WIP; also merge from trunk up to and including bug 1066184.
WIP