Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: chrome/browser/resources/ntp4/md_incognito_tab.js

Issue 2888103002: Speed up the Incognito NTP reload (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Handle the bookmark bar and theme change requests from the C++ side. 5 // Handle the bookmark bar and theme change requests from the C++ side.
6 var ntp = { 6 var ntp = {
7 /** @param {string} attached */ 7 /** @param {string} attached */
8 setBookmarkBarAttached: function(attached) { 8 setBookmarkBarAttached: function(attached) {
9 document.documentElement.setAttribute('bookmarkbarattached', attached); 9 document.documentElement.setAttribute('bookmarkbarattached', attached);
10 }, 10 },
11 11
12 /** @param {!{hasCustomBackground: boolean}} themeData */ 12 /** @param {!{hasCustomBackground: boolean}} themeData */
13 themeChanged: function(themeData) { 13 themeChanged: function(themeData) {
14 document.documentElement.setAttribute('hascustombackground', 14 document.documentElement.setAttribute('hascustombackground',
15 themeData.hasCustomBackground); 15 themeData.hasCustomBackground);
16 $('incognitothemecss').href = 16 $('incognitothemecss').href =
17 'chrome://theme/css/incognito_new_tab_theme.css?' + Date.now(); 17 'chrome://theme/css/incognito_new_tab_theme.css?' + Date.now();
18 }, 18 },
19 }; 19 };
20 20
21 // Let the width of two lists of bulletpoints in a horizontal alignment 21 // Let the width of two lists of bulletpoints in a horizontal alignment
22 // determine the maximum content width. 22 // determine the maximum content width.
23 window.addEventListener('load', function() { 23 window.addEventListener('load', function() {
24 var bulletpoints = document.querySelectorAll('.bulletpoints'); 24 var bulletpoints = document.querySelectorAll('.bulletpoints');
25 var content = document.querySelector('.content'); 25 var content = document.querySelector('.content');
26 26
27 var maxWidth = (bulletpoints[0].offsetWidth + bulletpoints[1].offsetWidth + 27 // Unless this is the first load of the Incognito NTP in this session and
28 40 /* margin */ + 2 /* offsetWidths may be rounded down */); 28 // with this font size, we already have the maximum content width determined.
29 var fontSize =
30 document.defaultView.getComputedStyle(document.body, null)
Dan Beam 2017/05/17 18:09:04 i don't really see a difference between document.d
msramek 2017/05/18 15:16:29 Done. Simplified, thanks.
31 .getPropertyValue("font-size");
Dan Beam 2017/05/17 18:09:04 does zoom affect this value?
msramek 2017/05/18 15:16:28 Good point :) I tested that neither the computed s
32 var savedMaxWidth = window.localStorage.getItem(fontSize);
Dan Beam 2017/05/17 18:09:04 can this all just be: var fontSize = window.getCo
msramek 2017/05/18 15:16:29 Done. Yes, but I'd like to keep the comments to ex
33
34 if (savedMaxWidth) {
35 maxWidth = savedMaxWidth
36 } else {
37 var maxWidth = (bulletpoints[0].offsetWidth + bulletpoints[1].offsetWidth +
38 40 /* margin */ + 2 /* offsetWidths may be rounded down */);
39 }
29 40
30 // Limit the maximum width to 600px. That might force the two lists 41 // Limit the maximum width to 600px. That might force the two lists
31 // of bulletpoints under each other, in which case we must swap the left 42 // of bulletpoints under each other, in which case we must swap the left
32 // and right margin. 43 // and right margin.
33 if (maxWidth > 600) { 44 if (maxWidth > 600) {
34 maxWidth = 600; 45 maxWidth = 600;
35 46
36 bulletpoints[1].classList.add('tooWide'); 47 bulletpoints[1].classList.add('tooWide');
37 } 48 }
38 49
39 content.style.maxWidth = maxWidth + "px"; 50 content.style.maxWidth = maxWidth + "px";
51
52 // Save the data for quicker access when the NTP is reloaded. Note that since
53 // we're in the Incognito mode, the local storage is ephemeral and the data
54 // will be discarded when the session ends.
55 window.localStorage.setItem(fontSize, maxWidth);
Dan Beam 2017/05/17 18:09:04 localStorage[fontSize] = maxWidth;
msramek 2017/05/18 15:16:28 Done.
40 }); 56 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698