| OLD | NEW |
| 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 4 | 6 * @fileoverview New tab page 4 |
| 7 * This is the main code for a previous version of the Chrome NTP ("NTP4"). | 7 * This is the main code for a previous version of the Chrome NTP ("NTP4"). |
| 8 * Some parts of this are still used for the chrome://apps page. | 8 * Some parts of this are still used for the chrome://apps page. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 /** | 51 /** |
| 52 * Creates a NewTabView object. NewTabView extends PageListView with | 52 * Creates a NewTabView object. NewTabView extends PageListView with |
| 53 * new tab UI specific logics. | 53 * new tab UI specific logics. |
| 54 * @constructor | 54 * @constructor |
| 55 * @extends {ntp.PageListView} | 55 * @extends {ntp.PageListView} |
| 56 */ | 56 */ |
| 57 function NewTabView() { | 57 function NewTabView() { |
| 58 var pageSwitcherStart; | 58 var pageSwitcherStart; |
| 59 var pageSwitcherEnd; | 59 var pageSwitcherEnd; |
| 60 if (loadTimeData.getValue('showApps')) { | 60 if (loadTimeData.getValue('showApps')) { |
| 61 pageSwitcherStart = /** @type {!ntp.PageSwitcher} */( | 61 pageSwitcherStart = /** @type {!ntp.PageSwitcher} */ ( |
| 62 getRequiredElement('page-switcher-start')); | 62 getRequiredElement('page-switcher-start')); |
| 63 pageSwitcherEnd = /** @type {!ntp.PageSwitcher} */( | 63 pageSwitcherEnd = /** @type {!ntp.PageSwitcher} */ ( |
| 64 getRequiredElement('page-switcher-end')); | 64 getRequiredElement('page-switcher-end')); |
| 65 } | 65 } |
| 66 this.initialize(getRequiredElement('page-list'), | 66 this.initialize( |
| 67 getRequiredElement('dot-list'), | 67 getRequiredElement('page-list'), getRequiredElement('dot-list'), |
| 68 getRequiredElement('card-slider-frame'), | 68 getRequiredElement('card-slider-frame'), getRequiredElement('trash'), |
| 69 getRequiredElement('trash'), | 69 pageSwitcherStart, pageSwitcherEnd); |
| 70 pageSwitcherStart, pageSwitcherEnd); | |
| 71 } | 70 } |
| 72 | 71 |
| 73 // TODO(dbeam): NewTabView is now the only extender of PageListView; these | 72 // TODO(dbeam): NewTabView is now the only extender of PageListView; these |
| 74 // classes should be merged. | 73 // classes should be merged. |
| 75 NewTabView.prototype = {__proto__: ntp.PageListView.prototype}; | 74 NewTabView.prototype = {__proto__: ntp.PageListView.prototype}; |
| 76 | 75 |
| 77 /** | 76 /** |
| 78 * Invoked at startup once the DOM is available to initialize the app. | 77 * Invoked at startup once the DOM is available to initialize the app. |
| 79 */ | 78 */ |
| 80 function onLoad() { | 79 function onLoad() { |
| 81 sectionsToWaitFor = 0; | 80 sectionsToWaitFor = 0; |
| 82 if (loadTimeData.getBoolean('showApps')) { | 81 if (loadTimeData.getBoolean('showApps')) { |
| 83 sectionsToWaitFor++; | 82 sectionsToWaitFor++; |
| 84 if (loadTimeData.getBoolean('showAppLauncherPromo')) { | 83 if (loadTimeData.getBoolean('showAppLauncherPromo')) { |
| 85 $('app-launcher-promo-close-button').addEventListener('click', | 84 $('app-launcher-promo-close-button') |
| 86 function() { chrome.send('stopShowingAppLauncherPromo'); }); | 85 .addEventListener('click', function() { |
| 87 $('apps-promo-learn-more').addEventListener('click', | 86 chrome.send('stopShowingAppLauncherPromo'); |
| 88 function() { chrome.send('onLearnMore'); }); | 87 }); |
| 88 $('apps-promo-learn-more').addEventListener('click', function() { |
| 89 chrome.send('onLearnMore'); |
| 90 }); |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 measureNavDots(); | 93 measureNavDots(); |
| 92 | 94 |
| 93 newTabView = new NewTabView(); | 95 newTabView = new NewTabView(); |
| 94 | 96 |
| 95 if (!loadTimeData.getBoolean('showWebStoreIcon')) { | 97 if (!loadTimeData.getBoolean('showWebStoreIcon')) { |
| 96 var webStoreIcon = $('chrome-web-store-link'); | 98 var webStoreIcon = $('chrome-web-store-link'); |
| 97 // Not all versions of the NTP have a footer, so this may not exist. | 99 // Not all versions of the NTP have a footer, so this may not exist. |
| 98 if (webStoreIcon) | 100 if (webStoreIcon) |
| 99 webStoreIcon.hidden = true; | 101 webStoreIcon.hidden = true; |
| 100 } else { | 102 } else { |
| 101 var webStoreLink = loadTimeData.getString('webStoreLink'); | 103 var webStoreLink = loadTimeData.getString('webStoreLink'); |
| 102 var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-launcher'); | 104 var url = appendParam(webStoreLink, 'utm_source', 'chrome-ntp-launcher'); |
| 103 $('chrome-web-store-link').href = url; | 105 $('chrome-web-store-link').href = url; |
| 104 $('chrome-web-store-link').addEventListener('auxclick', | 106 $('chrome-web-store-link') |
| 105 onChromeWebStoreButtonClick); | 107 .addEventListener('auxclick', onChromeWebStoreButtonClick); |
| 106 $('chrome-web-store-link').addEventListener('click', | 108 $('chrome-web-store-link') |
| 107 onChromeWebStoreButtonClick); | 109 .addEventListener('click', onChromeWebStoreButtonClick); |
| 108 } | 110 } |
| 109 | 111 |
| 110 // We need to wait for all the footer menu setup to be completed before | 112 // We need to wait for all the footer menu setup to be completed before |
| 111 // we can compute its layout. | 113 // we can compute its layout. |
| 112 layoutFooter(); | 114 layoutFooter(); |
| 113 | 115 |
| 114 if (loadTimeData.getString('login_status_message')) { | 116 if (loadTimeData.getString('login_status_message')) { |
| 115 loginBubble = new cr.ui.Bubble; | 117 loginBubble = new cr.ui.Bubble; |
| 116 loginBubble.anchorNode = $('login-container'); | 118 loginBubble.anchorNode = $('login-container'); |
| 117 loginBubble.arrowLocation = cr.ui.ArrowLocation.TOP_END; | 119 loginBubble.arrowLocation = cr.ui.ArrowLocation.TOP_END; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 }); | 153 }); |
| 152 } | 154 } |
| 153 | 155 |
| 154 /** | 156 /** |
| 155 * Launches the chrome web store app with the chrome-ntp-launcher | 157 * Launches the chrome web store app with the chrome-ntp-launcher |
| 156 * source. | 158 * source. |
| 157 * @param {Event} e The click/auxclick event. | 159 * @param {Event} e The click/auxclick event. |
| 158 */ | 160 */ |
| 159 function onChromeWebStoreButtonClick(e) { | 161 function onChromeWebStoreButtonClick(e) { |
| 160 if (e.button > 1) | 162 if (e.button > 1) |
| 161 return; // Ignore buttons other than left and middle. | 163 return; // Ignore buttons other than left and middle. |
| 162 chrome.send('recordAppLaunchByURL', | 164 chrome.send( |
| 163 [encodeURIComponent(this.href), | 165 'recordAppLaunchByURL', |
| 164 ntp.APP_LAUNCH.NTP_WEBSTORE_FOOTER]); | 166 [encodeURIComponent(this.href), ntp.APP_LAUNCH.NTP_WEBSTORE_FOOTER]); |
| 165 } | 167 } |
| 166 | 168 |
| 167 /** | 169 /** |
| 168 * The number of sections to wait on. | 170 * The number of sections to wait on. |
| 169 * @type {number} | 171 * @type {number} |
| 170 */ | 172 */ |
| 171 var sectionsToWaitFor = -1; | 173 var sectionsToWaitFor = -1; |
| 172 | 174 |
| 173 /** | 175 /** |
| 174 * Queued callbacks which lie in wait for all sections to be ready. | 176 * Queued callbacks which lie in wait for all sections to be ready. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 loginBubble.reposition(); | 297 loginBubble.reposition(); |
| 296 } | 298 } |
| 297 } | 299 } |
| 298 | 300 |
| 299 /** | 301 /** |
| 300 * Show the sync login UI. | 302 * Show the sync login UI. |
| 301 * @param {Event} e The click event. | 303 * @param {Event} e The click event. |
| 302 */ | 304 */ |
| 303 function showSyncLoginUI(e) { | 305 function showSyncLoginUI(e) { |
| 304 var rect = e.currentTarget.getBoundingClientRect(); | 306 var rect = e.currentTarget.getBoundingClientRect(); |
| 305 chrome.send('showSyncLoginUI', | 307 chrome.send( |
| 306 [rect.left, rect.top, rect.width, rect.height]); | 308 'showSyncLoginUI', [rect.left, rect.top, rect.width, rect.height]); |
| 307 } | 309 } |
| 308 | 310 |
| 309 /** | 311 /** |
| 310 * Wrappers to forward the callback to corresponding PageListView member. | 312 * Wrappers to forward the callback to corresponding PageListView member. |
| 311 */ | 313 */ |
| 312 | 314 |
| 313 /** | 315 /** |
| 314 * Called by chrome when a new app has been added to chrome or has been | 316 * Called by chrome when a new app has been added to chrome or has been |
| 315 * enabled if previously disabled. | 317 * enabled if previously disabled. |
| 316 * @param {Object} appData A data structure full of relevant information for | 318 * @param {Object} appData A data structure full of relevant information for |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 setAppToBeHighlighted: setAppToBeHighlighted, | 435 setAppToBeHighlighted: setAppToBeHighlighted, |
| 434 setBookmarkBarAttached: setBookmarkBarAttached, | 436 setBookmarkBarAttached: setBookmarkBarAttached, |
| 435 themeChanged: themeChanged, | 437 themeChanged: themeChanged, |
| 436 updateLogin: updateLogin | 438 updateLogin: updateLogin |
| 437 }; | 439 }; |
| 438 }); | 440 }); |
| 439 | 441 |
| 440 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 442 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| 441 | 443 |
| 442 var toCssPx = cr.ui.toCssPx; | 444 var toCssPx = cr.ui.toCssPx; |
| OLD | NEW |