Chromium Code Reviews| 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 | 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 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 notificationContainer = getRequiredElement('notification-container'); | 110 notificationContainer = getRequiredElement('notification-container'); |
| 111 notificationContainer.addEventListener( | 111 notificationContainer.addEventListener( |
| 112 'webkitTransitionEnd', onNotificationTransitionEnd); | 112 'webkitTransitionEnd', onNotificationTransitionEnd); |
| 113 | 113 |
| 114 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); | 114 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); |
| 115 chrome.send('getRecentlyClosedTabs'); | 115 chrome.send('getRecentlyClosedTabs'); |
| 116 | 116 |
| 117 if (templateData.showOtherSessionsMenu) { | 117 if (templateData.showOtherSessionsMenu) { |
| 118 cr.ui.decorate($('other-sessions-menu-button'), | 118 cr.ui.decorate($('other-sessions-menu-button'), |
| 119 ntp.OtherSessionsMenuButton); | 119 ntp.OtherSessionsMenuButton); |
| 120 $('other-sessions-menu-button').initialize( | |
| 121 templateData.isUserSignedIn, showSyncLoginUI); | |
| 120 } | 122 } |
| 121 | 123 |
| 122 var mostVisited = new ntp.MostVisitedPage(); | 124 var mostVisited = new ntp.MostVisitedPage(); |
| 123 // Move the footer into the most visited page if we are in "bare minimum" | 125 // Move the footer into the most visited page if we are in "bare minimum" |
| 124 // mode. | 126 // mode. |
| 125 if (document.body.classList.contains('bare-minimum')) | 127 if (document.body.classList.contains('bare-minimum')) |
| 126 mostVisited.appendFooter(getRequiredElement('footer')); | 128 mostVisited.appendFooter(getRequiredElement('footer')); |
| 127 newTabView.appendTilePage(mostVisited, | 129 newTabView.appendTilePage(mostVisited, |
| 128 localStrings.getString('mostvisited'), | 130 localStrings.getString('mostvisited'), |
| 129 false); | 131 false); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 150 $('chrome-web-store-href').addEventListener('click', | 152 $('chrome-web-store-href').addEventListener('click', |
| 151 onChromeWebStoreButtonClick); | 153 onChromeWebStoreButtonClick); |
| 152 | 154 |
| 153 $('footer-content').classList.add('enable-cws-experiment'); | 155 $('footer-content').classList.add('enable-cws-experiment'); |
| 154 } | 156 } |
| 155 | 157 |
| 156 if (templateData.appInstallHintEnabled) { | 158 if (templateData.appInstallHintEnabled) { |
| 157 var url = appendParam(webstoreLink, 'utm_source', 'chrome-ntp-plus-icon'); | 159 var url = appendParam(webstoreLink, 'utm_source', 'chrome-ntp-plus-icon'); |
| 158 $('app-install-hint-template').href = url; | 160 $('app-install-hint-template').href = url; |
| 159 } | 161 } |
| 160 | |
| 161 if (localStrings.getString('login_status_message')) { | 162 if (localStrings.getString('login_status_message')) { |
| 162 loginBubble = new cr.ui.Bubble; | 163 loginBubble = new cr.ui.Bubble; |
| 163 loginBubble.anchorNode = $('login-container'); | 164 loginBubble.anchorNode = $('login-container'); |
| 164 loginBubble.setArrowLocation(cr.ui.ArrowLocation.TOP_END); | 165 loginBubble.setArrowLocation(cr.ui.ArrowLocation.TOP_END); |
| 165 loginBubble.bubbleAlignment = | 166 loginBubble.bubbleAlignment = |
| 166 cr.ui.BubbleAlignment.BUBBLE_EDGE_TO_ANCHOR_EDGE; | 167 cr.ui.BubbleAlignment.BUBBLE_EDGE_TO_ANCHOR_EDGE; |
| 167 loginBubble.deactivateToDismissDelay = 2000; | 168 loginBubble.deactivateToDismissDelay = 2000; |
| 168 loginBubble.setCloseButtonVisible(false); | 169 loginBubble.setCloseButtonVisible(false); |
| 169 | 170 |
| 170 $('login-status-learn-more').href = | 171 $('login-status-learn-more').href = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 /^data\:image\/(?:png|gif|jpe?g)/.test(value); | 210 /^data\:image\/(?:png|gif|jpe?g)/.test(value); |
| 210 }, | 211 }, |
| 211 }; | 212 }; |
| 212 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() { | 213 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() { |
| 213 chrome.send('closeNotificationPromo'); | 214 chrome.send('closeNotificationPromo'); |
| 214 }, 60000); | 215 }, 60000); |
| 215 chrome.send('notificationPromoViewed'); | 216 chrome.send('notificationPromoViewed'); |
| 216 } | 217 } |
| 217 | 218 |
| 218 var loginContainer = getRequiredElement('login-container'); | 219 var loginContainer = getRequiredElement('login-container'); |
| 219 loginContainer.addEventListener('click', function() { | 220 loginContainer.addEventListener('click', showSyncLoginUI); |
| 220 var rect = loginContainer.getBoundingClientRect(); | |
| 221 chrome.send('showSyncLoginUI', | |
| 222 [rect.left, rect.top, rect.width, rect.height]); | |
| 223 }); | |
| 224 chrome.send('initializeSyncLogin'); | 221 chrome.send('initializeSyncLogin'); |
| 225 | 222 |
| 226 doWhenAllSectionsReady(function() { | 223 doWhenAllSectionsReady(function() { |
| 227 // Tell the slider about the pages. | 224 // Tell the slider about the pages. |
| 228 newTabView.updateSliderCards(); | 225 newTabView.updateSliderCards(); |
| 229 // Mark the current page. | 226 // Mark the current page. |
| 230 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( | 227 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( |
| 231 'selected'); | 228 'selected'); |
| 232 | 229 |
| 233 document.documentElement.classList.remove('starting-up'); | 230 document.documentElement.classList.remove('starting-up'); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 490 node.stripeColor = color; | 487 node.stripeColor = color; |
| 491 } | 488 } |
| 492 | 489 |
| 493 /** | 490 /** |
| 494 * Updates the text displayed in the login container. If there is no text then | 491 * Updates the text displayed in the login container. If there is no text then |
| 495 * the login container is hidden. | 492 * the login container is hidden. |
| 496 * @param {string} loginHeader The first line of text. | 493 * @param {string} loginHeader The first line of text. |
| 497 * @param {string} loginSubHeader The second line of text. | 494 * @param {string} loginSubHeader The second line of text. |
| 498 * @param {string} iconURL The url for the login status icon. If this is null | 495 * @param {string} iconURL The url for the login status icon. If this is null |
| 499 then the login status icon is hidden. | 496 then the login status icon is hidden. |
| 497 * @param {Boolean} isUserSignedIn Indicates if the user is signed in or not. | |
|
Dan Beam
2012/03/26 17:08:34
nit: s/Boolean/boolean/ (as it's not a wrapper cla
Patrick Dubroy
2012/03/26 19:36:46
Done.
| |
| 500 */ | 498 */ |
| 501 function updateLogin(loginHeader, loginSubHeader, iconURL) { | 499 function updateLogin(loginHeader, loginSubHeader, iconURL, isUserSignedIn) { |
| 502 if (loginHeader || loginSubHeader) { | 500 if (loginHeader || loginSubHeader) { |
| 503 $('login-container').hidden = false; | 501 $('login-container').hidden = false; |
| 504 $('login-status-header').innerHTML = loginHeader; | 502 $('login-status-header').innerHTML = loginHeader; |
| 505 $('login-status-sub-header').innerHTML = loginSubHeader; | 503 $('login-status-sub-header').innerHTML = loginSubHeader; |
| 506 $('card-slider-frame').classList.add('showing-login-area'); | 504 $('card-slider-frame').classList.add('showing-login-area'); |
| 507 | 505 |
| 508 if (iconURL) { | 506 if (iconURL) { |
| 509 $('login-status-header-container').style.backgroundImage = url(iconURL); | 507 $('login-status-header-container').style.backgroundImage = url(iconURL); |
| 510 $('login-status-header-container').classList.add('login-status-icon'); | 508 $('login-status-header-container').classList.add('login-status-icon'); |
| 511 } else { | 509 } else { |
| 512 $('login-status-header-container').style.backgroundImage = 'none'; | 510 $('login-status-header-container').style.backgroundImage = 'none'; |
| 513 $('login-status-header-container').classList.remove( | 511 $('login-status-header-container').classList.remove( |
| 514 'login-status-icon'); | 512 'login-status-icon'); |
| 515 } | 513 } |
| 516 } else { | 514 } else { |
| 517 $('login-container').hidden = true; | 515 $('login-container').hidden = true; |
| 518 $('card-slider-frame').classList.remove('showing-login-area'); | 516 $('card-slider-frame').classList.remove('showing-login-area'); |
| 519 } | 517 } |
| 520 if (shouldShowLoginBubble) { | 518 if (shouldShowLoginBubble) { |
| 521 window.setTimeout(loginBubble.show.bind(loginBubble), 0); | 519 window.setTimeout(loginBubble.show.bind(loginBubble), 0); |
| 522 chrome.send('loginMessageSeen'); | 520 chrome.send('loginMessageSeen'); |
| 523 shouldShowLoginBubble = false; | 521 shouldShowLoginBubble = false; |
| 524 } else if (loginBubble) { | 522 } else if (loginBubble) { |
| 525 loginBubble.reposition(); | 523 loginBubble.reposition(); |
| 526 } | 524 } |
| 525 $('other-sessions-menu-button').updateSignInState(isUserSignedIn); | |
| 527 } | 526 } |
| 528 | 527 |
| 529 /** | 528 /** |
| 529 * Show the sync login UI. | |
| 530 * @param {Element} element The element that triggered the login. | |
|
Dan Beam
2012/03/26 17:08:34
isn't this an {Event}, not element... you're calli
Patrick Dubroy
2012/03/26 19:36:46
Done.
| |
| 531 */ | |
| 532 function showSyncLoginUI(e) { | |
| 533 var rect = e.currentTarget.getBoundingClientRect(); | |
| 534 chrome.send('showSyncLoginUI', | |
| 535 [rect.left, rect.top, rect.width, rect.height]); | |
| 536 } | |
| 537 | |
| 538 /** | |
| 530 * Wrappers to forward the callback to corresponding PageListView member. | 539 * Wrappers to forward the callback to corresponding PageListView member. |
| 531 */ | 540 */ |
| 532 function appAdded() { | 541 function appAdded() { |
| 533 return newTabView.appAdded.apply(newTabView, arguments); | 542 return newTabView.appAdded.apply(newTabView, arguments); |
| 534 } | 543 } |
| 535 | 544 |
| 536 function appMoved() { | 545 function appMoved() { |
| 537 return newTabView.appMoved.apply(newTabView, arguments); | 546 return newTabView.appMoved.apply(newTabView, arguments); |
| 538 } | 547 } |
| 539 | 548 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 setSuggestionsPages: setSuggestionsPages, | 610 setSuggestionsPages: setSuggestionsPages, |
| 602 setRecentlyClosedTabs: setRecentlyClosedTabs, | 611 setRecentlyClosedTabs: setRecentlyClosedTabs, |
| 603 setStripeColor: setStripeColor, | 612 setStripeColor: setStripeColor, |
| 604 showNotification: showNotification, | 613 showNotification: showNotification, |
| 605 themeChanged: themeChanged, | 614 themeChanged: themeChanged, |
| 606 updateLogin: updateLogin | 615 updateLogin: updateLogin |
| 607 }; | 616 }; |
| 608 }); | 617 }); |
| 609 | 618 |
| 610 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 619 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| OLD | NEW |