save/restore conversation view scroll position

Save scroll position as a fraction of total height to handle
scaled and width-change cases. Restore scroll position fraction
in JavaScript as soon as the document geometry is known.
(This was how it was done in Gmail1, and I can't find a better
non-JS way to detect this signal.)

Does not restore scale upon rotate/re-render.

Bug: 7246054
Bug: 7022509
Change-Id: Ibf811b31ba6d7d79d34c236f6ffe2229d626528f
diff --git a/assets/script.js b/assets/script.js
index 0f25064..39ee3c8 100644
--- a/assets/script.js
+++ b/assets/script.js
@@ -189,6 +189,13 @@
     metaViewport.setAttribute('content', 'width=' + WIDE_VIEWPORT_WIDTH);
 }
 
+function restoreScrollPosition() {
+    var scrollYPercent = window.mail.getScrollYPercent();
+    if (scrollYPercent && document.body.offsetHeight > window.innerHeight) {
+        document.body.scrollTop = Math.floor(scrollYPercent * document.body.offsetHeight);
+    }
+}
+
 // BEGIN Java->JavaScript handlers
 function measurePositions() {
     var overlayBottoms;
@@ -328,5 +335,6 @@
 hideUnsafeImages();
 normalizeAllMessageWidths();
 //setWideViewport();
+restoreScrollPosition();
 measurePositions();