bug 927080 - land upstream fixes from bug 777402 and bug 913350 to github;r=jgriffin