Measurement of the prompt J/psi and psi(2S) polarizations in pp collisions at sqrt(s) = 7 TeV