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

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

Issue 1151563005: Revert of NTP Zombie Code Slayer Part IV: Most Visited (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 /** 5 /**
6 * @fileoverview New tab page 6 * @fileoverview New tab page
7 * This is the main code for the new tab page used by touch-enabled Chrome 7 * This is the main code for the new tab page used by touch-enabled Chrome
8 * browsers. For now this is still a prototype. 8 * browsers. For now this is still a prototype.
9 */ 9 */
10 10
11 /**
12 * @typedef {{direction: string,
13 * filler: (boolean|undefined),
14 * title: string,
15 * url: string}}
16 * @see chrome/browser/ui/webui/ntp/most_visited_handler.cc
17 */
18 var PageData;
19
11 // Use an anonymous function to enable strict mode just for this file (which 20 // Use an anonymous function to enable strict mode just for this file (which
12 // will be concatenated with other files when embedded in Chrome 21 // will be concatenated with other files when embedded in Chrome
13 cr.define('ntp', function() { 22 cr.define('ntp', function() {
14 'use strict'; 23 'use strict';
15 24
16 /** 25 /**
17 * NewTabView instance. 26 * NewTabView instance.
18 * @type {!Object|undefined} 27 * @type {!Object|undefined}
19 */ 28 */
20 var newTabView; 29 var newTabView;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (promoBubble) 113 if (promoBubble)
105 window.setTimeout(promoBubble.reposition.bind(promoBubble), 0); 114 window.setTimeout(promoBubble.reposition.bind(promoBubble), 0);
106 } 115 }
107 }; 116 };
108 117
109 /** 118 /**
110 * Invoked at startup once the DOM is available to initialize the app. 119 * Invoked at startup once the DOM is available to initialize the app.
111 */ 120 */
112 function onLoad() { 121 function onLoad() {
113 sectionsToWaitFor = 0; 122 sectionsToWaitFor = 0;
123 if (loadTimeData.getBoolean('showMostvisited'))
124 sectionsToWaitFor++;
114 if (loadTimeData.getBoolean('showApps')) { 125 if (loadTimeData.getBoolean('showApps')) {
115 sectionsToWaitFor++; 126 sectionsToWaitFor++;
116 if (loadTimeData.getBoolean('showAppLauncherPromo')) { 127 if (loadTimeData.getBoolean('showAppLauncherPromo')) {
117 $('app-launcher-promo-close-button').addEventListener('click', 128 $('app-launcher-promo-close-button').addEventListener('click',
118 function() { chrome.send('stopShowingAppLauncherPromo'); }); 129 function() { chrome.send('stopShowingAppLauncherPromo'); });
119 $('apps-promo-learn-more').addEventListener('click', 130 $('apps-promo-learn-more').addEventListener('click',
120 function() { chrome.send('onLearnMore'); }); 131 function() { chrome.send('onLearnMore'); });
121 } 132 }
122 } 133 }
123 measureNavDots(); 134 measureNavDots();
124 135
125 // Load the current theme colors. 136 // Load the current theme colors.
126 themeChanged(); 137 themeChanged();
127 138
128 newTabView = new NewTabView(); 139 newTabView = new NewTabView();
129 140
130 notificationContainer = getRequiredElement('notification-container'); 141 notificationContainer = getRequiredElement('notification-container');
131 notificationContainer.addEventListener( 142 notificationContainer.addEventListener(
132 'webkitTransitionEnd', onNotificationTransitionEnd); 143 'webkitTransitionEnd', onNotificationTransitionEnd);
133 144
145 if (loadTimeData.getBoolean('showMostvisited')) {
146 var mostVisited = new ntp.MostVisitedPage();
147 // Move the footer into the most visited page if we are in "bare minimum"
148 // mode.
149 if (document.body.classList.contains('bare-minimum'))
150 mostVisited.appendFooter(getRequiredElement('footer'));
151 newTabView.appendTilePage(mostVisited,
152 loadTimeData.getString('mostvisited'),
153 false);
154 chrome.send('getMostVisited');
155 }
156
134 if (!loadTimeData.getBoolean('showWebStoreIcon')) { 157 if (!loadTimeData.getBoolean('showWebStoreIcon')) {
135 var webStoreIcon = $('chrome-web-store-link'); 158 var webStoreIcon = $('chrome-web-store-link');
136 // Not all versions of the NTP have a footer, so this may not exist. 159 // Not all versions of the NTP have a footer, so this may not exist.
137 if (webStoreIcon) 160 if (webStoreIcon)
138 webStoreIcon.hidden = true; 161 webStoreIcon.hidden = true;
139 } else { 162 } else {
140 var webStoreLink = loadTimeData.getString('webStoreLink'); 163 var webStoreLink = loadTimeData.getString('webStoreLink');
141 var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-launcher'); 164 var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-launcher');
142 $('chrome-web-store-link').href = url; 165 $('chrome-web-store-link').href = url;
143 $('chrome-web-store-link').addEventListener('click', 166 $('chrome-web-store-link').addEventListener('click',
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 measuringDiv.textContent = loadTimeData.getString(id); 319 measuringDiv.textContent = loadTimeData.getString(id);
297 // The 4 is for border and padding. 320 // The 4 is for border and padding.
298 return Math.max(measuringDiv.clientWidth * 1.15 + 4, 80); 321 return Math.max(measuringDiv.clientWidth * 1.15 + 4, 80);
299 } 322 }
300 323
301 /** 324 /**
302 * Fills in an invisible div with the longest dot title string so that 325 * Fills in an invisible div with the longest dot title string so that
303 * its length may be measured and the nav dots sized accordingly. 326 * its length may be measured and the nav dots sized accordingly.
304 */ 327 */
305 function measureNavDots() { 328 function measureNavDots() {
329 var pxWidth = measureNavDot('appDefaultPageName');
330 if (loadTimeData.getBoolean('showMostvisited'))
331 pxWidth = Math.max(measureNavDot('mostvisited'), pxWidth);
332
306 var styleElement = document.createElement('style'); 333 var styleElement = document.createElement('style');
307 styleElement.type = 'text/css'; 334 styleElement.type = 'text/css';
308 // max-width is used because if we run out of space, the nav dots will be 335 // max-width is used because if we run out of space, the nav dots will be
309 // shrunk. 336 // shrunk.
310 var pxWidth = measureNavDot('appDefaultPageName');
311 styleElement.textContent = '.dot { max-width: ' + pxWidth + 'px; }'; 337 styleElement.textContent = '.dot { max-width: ' + pxWidth + 'px; }';
312 document.querySelector('head').appendChild(styleElement); 338 document.querySelector('head').appendChild(styleElement);
313 } 339 }
314 340
315 /** 341 /**
316 * Layout the footer so that the nav dots stay centered. 342 * Layout the footer so that the nav dots stay centered.
317 */ 343 */
318 function layoutFooter() { 344 function layoutFooter() {
319 // We need the image to be loaded. 345 // We need the image to be loaded.
320 var logo = $('logo-img'); 346 var logo = $('logo-img');
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 * When done fading out, set hidden to true so the notification can't be 500 * When done fading out, set hidden to true so the notification can't be
475 * tabbed to or clicked. 501 * tabbed to or clicked.
476 * @param {Event} e The webkitTransitionEnd event. 502 * @param {Event} e The webkitTransitionEnd event.
477 */ 503 */
478 function onNotificationTransitionEnd(e) { 504 function onNotificationTransitionEnd(e) {
479 if (notificationContainer.classList.contains('inactive')) 505 if (notificationContainer.classList.contains('inactive'))
480 notificationContainer.hidden = true; 506 notificationContainer.hidden = true;
481 } 507 }
482 508
483 /** 509 /**
510 * @param {Array<PageData>} data
511 * @param {boolean} hasBlacklistedUrls
512 */
513 function setMostVisitedPages(data, hasBlacklistedUrls) {
514 newTabView.mostVisitedPage.data = data;
515 cr.dispatchSimpleEvent(document, 'sectionready', true, true);
516 }
517
518 /**
484 * Set the dominant color for a node. This will be called in response to 519 * Set the dominant color for a node. This will be called in response to
485 * getFaviconDominantColor. The node represented by |id| better have a setter 520 * getFaviconDominantColor. The node represented by |id| better have a setter
486 * for stripeColor. 521 * for stripeColor.
487 * @param {string} id The ID of a node. 522 * @param {string} id The ID of a node.
488 * @param {string} color The color represented as a CSS string. 523 * @param {string} color The color represented as a CSS string.
489 */ 524 */
490 function setFaviconDominantColor(id, color) { 525 function setFaviconDominantColor(id, color) {
491 var node = $(id); 526 var node = $(id);
492 if (node) 527 if (node)
493 node.stripeColor = color; 528 node.stripeColor = color;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 * Show the sync login UI. 567 * Show the sync login UI.
533 * @param {Event} e The click event. 568 * @param {Event} e The click event.
534 */ 569 */
535 function showSyncLoginUI(e) { 570 function showSyncLoginUI(e) {
536 var rect = e.currentTarget.getBoundingClientRect(); 571 var rect = e.currentTarget.getBoundingClientRect();
537 chrome.send('showSyncLoginUI', 572 chrome.send('showSyncLoginUI',
538 [rect.left, rect.top, rect.width, rect.height]); 573 [rect.left, rect.top, rect.width, rect.height]);
539 } 574 }
540 575
541 /** 576 /**
577 * Logs the time to click for the specified item.
578 * @param {string} item The item to log the time-to-click.
579 */
580 function logTimeToClick(item) {
581 var timeToClick = Date.now() - startTime;
582 chrome.send('logTimeToClick',
583 ['NewTabPage.TimeToClick' + item, timeToClick]);
584 }
585
586 /**
542 * Wrappers to forward the callback to corresponding PageListView member. 587 * Wrappers to forward the callback to corresponding PageListView member.
543 */ 588 */
544 589
545 /** 590 /**
546 * Called by chrome when a new app has been added to chrome or has been 591 * Called by chrome when a new app has been added to chrome or has been
547 * enabled if previously disabled. 592 * enabled if previously disabled.
548 * @param {Object} appData A data structure full of relevant information for 593 * @param {Object} appData A data structure full of relevant information for
549 * the app. 594 * the app.
550 * @param {boolean=} opt_highlight Whether the app about to be added should 595 * @param {boolean=} opt_highlight Whether the app about to be added should
551 * be highlighted. 596 * be highlighted.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 appMoved: appMoved, 699 appMoved: appMoved,
655 appRemoved: appRemoved, 700 appRemoved: appRemoved,
656 appsPrefChangeCallback: appsPrefChangeCallback, 701 appsPrefChangeCallback: appsPrefChangeCallback,
657 appLauncherPromoPrefChangeCallback: appLauncherPromoPrefChangeCallback, 702 appLauncherPromoPrefChangeCallback: appLauncherPromoPrefChangeCallback,
658 enterRearrangeMode: enterRearrangeMode, 703 enterRearrangeMode: enterRearrangeMode,
659 getAppsCallback: getAppsCallback, 704 getAppsCallback: getAppsCallback,
660 getAppsPageIndex: getAppsPageIndex, 705 getAppsPageIndex: getAppsPageIndex,
661 getCardSlider: getCardSlider, 706 getCardSlider: getCardSlider,
662 onLoad: onLoad, 707 onLoad: onLoad,
663 leaveRearrangeMode: leaveRearrangeMode, 708 leaveRearrangeMode: leaveRearrangeMode,
709 logTimeToClick: logTimeToClick,
664 NtpFollowAction: NtpFollowAction, 710 NtpFollowAction: NtpFollowAction,
665 saveAppPageName: saveAppPageName, 711 saveAppPageName: saveAppPageName,
666 setAppToBeHighlighted: setAppToBeHighlighted, 712 setAppToBeHighlighted: setAppToBeHighlighted,
667 setBookmarkBarAttached: setBookmarkBarAttached, 713 setBookmarkBarAttached: setBookmarkBarAttached,
714 setMostVisitedPages: setMostVisitedPages,
668 setFaviconDominantColor: setFaviconDominantColor, 715 setFaviconDominantColor: setFaviconDominantColor,
669 showNotification: showNotification, 716 showNotification: showNotification,
670 themeChanged: themeChanged, 717 themeChanged: themeChanged,
671 updateLogin: updateLogin 718 updateLogin: updateLogin
672 }; 719 };
673 }); 720 });
674 721
675 document.addEventListener('DOMContentLoaded', ntp.onLoad); 722 document.addEventListener('DOMContentLoaded', ntp.onLoad);
676 723
677 var toCssPx = cr.ui.toCssPx; 724 var toCssPx = cr.ui.toCssPx;
OLDNEW
« no previous file with comments | « chrome/browser/resources/ntp4/new_tab.html ('k') | chrome/browser/resources/ntp4/new_tab_theme.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698