Speed up the Incognito NTP reload

As described in crbug.com/715042, the new Incognito NTP sometimes
flickers on reload. This is likely caused by the fact that it uses
JavaScript when computing layout, including two relatively heavy
offsetWidth operations which cause a reflow.

However, offsetWidth is constant for a given default font size, and only
needs to be computed once. It can be then stored in localStorage for
the duration of the Incognito session.

Testing on my local debug build shows that the JavaScript execution is
now sped up from ~22ms to ~5ms.

BUG=715042
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2888103002
Cr-Commit-Position: refs/heads/master@{#473176}
diff --git a/chrome/browser/resources/ntp4/md_incognito_tab.js b/chrome/browser/resources/ntp4/md_incognito_tab.js
index 3918f70..a48c9a0 100644
--- a/chrome/browser/resources/ntp4/md_incognito_tab.js
+++ b/chrome/browser/resources/ntp4/md_incognito_tab.js
@@ -24,8 +24,17 @@
   var bulletpoints = document.querySelectorAll('.bulletpoints');
   var content = document.querySelector('.content');
 
-  var maxWidth = (bulletpoints[0].offsetWidth + bulletpoints[1].offsetWidth +
-      40 /* margin */ + 2 /* offsetWidths may be rounded down */);
+  // Unless this is the first load of the Incognito NTP in this session and
+  // with this font size, we already have the maximum content width determined.
+  var fontSize = window.getComputedStyle(document.body).fontSize;
+  var maxWidth = localStorage[fontSize] ||
+      (bulletpoints[0].offsetWidth + bulletpoints[1].offsetWidth +
+           40 /* margin */ + 2 /* offsetWidths may be rounded down */);
+
+  // Save the data for quicker access when the NTP is reloaded. Note that since
+  // we're in the Incognito mode, the local storage is ephemeral and the data
+  // will be discarded when the session ends.
+  localStorage[fontSize] = maxWidth;
 
   // Limit the maximum width to 600px. That might force the two lists
   // of bulletpoints under each other, in which case we must swap the left