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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 | 90 |
| 91 if (infoBubble) | 91 if (infoBubble) |
| 92 window.setTimeout(infoBubble.reposition.bind(infoBubble), 0); | 92 window.setTimeout(infoBubble.reposition.bind(infoBubble), 0); |
| 93 } | 93 } |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * Invoked at startup once the DOM is available to initialize the app. | 97 * Invoked at startup once the DOM is available to initialize the app. |
| 98 */ | 98 */ |
| 99 function onLoad() { | 99 function onLoad() { |
| 100 var isUserSignedIn = Boolean( | |
| 101 localStrings.getString('login_status_message')); | |
|
Dan Beam
2012/03/23 21:12:47
Casting to Boolean() is a little different than ju
Patrick Dubroy
2012/03/26 15:16:46
What's the difference? According to the spec it sh
Dan Beam
2012/03/26 17:08:33
tl;dr casting or comparing to different types in J
| |
| 100 cr.enablePlatformSpecificCSSRules(); | 102 cr.enablePlatformSpecificCSSRules(); |
| 101 | 103 |
| 102 sectionsToWaitFor = templateData.showApps ? 2 : 1; | 104 sectionsToWaitFor = templateData.showApps ? 2 : 1; |
| 103 measureNavDots(); | 105 measureNavDots(); |
| 104 | 106 |
| 105 // Load the current theme colors. | 107 // Load the current theme colors. |
| 106 themeChanged(); | 108 themeChanged(); |
| 107 | 109 |
| 108 newTabView = new NewTabView(); | 110 newTabView = new NewTabView(); |
| 109 | 111 |
| 110 notificationContainer = getRequiredElement('notification-container'); | 112 notificationContainer = getRequiredElement('notification-container'); |
| 111 notificationContainer.addEventListener( | 113 notificationContainer.addEventListener( |
| 112 'webkitTransitionEnd', onNotificationTransitionEnd); | 114 'webkitTransitionEnd', onNotificationTransitionEnd); |
| 113 | 115 |
| 114 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); | 116 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); |
| 115 chrome.send('getRecentlyClosedTabs'); | 117 chrome.send('getRecentlyClosedTabs'); |
| 116 | 118 |
| 117 if (templateData.showOtherSessionsMenu) { | 119 if (templateData.showOtherSessionsMenu) { |
| 118 cr.ui.decorate($('other-sessions-menu-button'), | 120 cr.ui.decorate($('other-sessions-menu-button'), |
| 119 ntp.OtherSessionsMenuButton); | 121 ntp.OtherSessionsMenuButton); |
| 122 $('other-sessions-menu-button').initialize( | |
| 123 isUserSignedIn, showSyncLoginUI); | |
| 120 } | 124 } |
| 121 | 125 |
| 122 var mostVisited = new ntp.MostVisitedPage(); | 126 var mostVisited = new ntp.MostVisitedPage(); |
| 123 // Move the footer into the most visited page if we are in "bare minimum" | 127 // Move the footer into the most visited page if we are in "bare minimum" |
| 124 // mode. | 128 // mode. |
| 125 if (document.body.classList.contains('bare-minimum')) | 129 if (document.body.classList.contains('bare-minimum')) |
| 126 mostVisited.appendFooter(getRequiredElement('footer')); | 130 mostVisited.appendFooter(getRequiredElement('footer')); |
| 127 newTabView.appendTilePage(mostVisited, | 131 newTabView.appendTilePage(mostVisited, |
| 128 localStrings.getString('mostvisited'), | 132 localStrings.getString('mostvisited'), |
| 129 false); | 133 false); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 150 $('chrome-web-store-href').addEventListener('click', | 154 $('chrome-web-store-href').addEventListener('click', |
| 151 onChromeWebStoreButtonClick); | 155 onChromeWebStoreButtonClick); |
| 152 | 156 |
| 153 $('footer-content').classList.add('enable-cws-experiment'); | 157 $('footer-content').classList.add('enable-cws-experiment'); |
| 154 } | 158 } |
| 155 | 159 |
| 156 if (templateData.appInstallHintEnabled) { | 160 if (templateData.appInstallHintEnabled) { |
| 157 var url = appendParam(webstoreLink, 'utm_source', 'chrome-ntp-plus-icon'); | 161 var url = appendParam(webstoreLink, 'utm_source', 'chrome-ntp-plus-icon'); |
| 158 $('app-install-hint-template').href = url; | 162 $('app-install-hint-template').href = url; |
| 159 } | 163 } |
| 160 | 164 if (isUserSignedIn) { |
|
Dan Beam
2012/03/23 21:12:47
I'd undo this.
Patrick Dubroy
2012/03/26 15:16:46
Done.
| |
| 161 if (localStrings.getString('login_status_message')) { | |
| 162 loginBubble = new cr.ui.Bubble; | 165 loginBubble = new cr.ui.Bubble; |
| 163 loginBubble.anchorNode = $('login-container'); | 166 loginBubble.anchorNode = $('login-container'); |
| 164 loginBubble.setArrowLocation(cr.ui.ArrowLocation.TOP_END); | 167 loginBubble.setArrowLocation(cr.ui.ArrowLocation.TOP_END); |
| 165 loginBubble.bubbleAlignment = | 168 loginBubble.bubbleAlignment = |
| 166 cr.ui.BubbleAlignment.BUBBLE_EDGE_TO_ANCHOR_EDGE; | 169 cr.ui.BubbleAlignment.BUBBLE_EDGE_TO_ANCHOR_EDGE; |
| 167 loginBubble.deactivateToDismissDelay = 2000; | 170 loginBubble.deactivateToDismissDelay = 2000; |
| 168 loginBubble.setCloseButtonVisible(false); | 171 loginBubble.setCloseButtonVisible(false); |
| 169 | 172 |
| 170 $('login-status-learn-more').href = | 173 $('login-status-learn-more').href = |
| 171 localStrings.getString('login_status_url'); | 174 localStrings.getString('login_status_url'); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 /^data\:image\/(?:png|gif|jpe?g)/.test(value); | 212 /^data\:image\/(?:png|gif|jpe?g)/.test(value); |
| 210 }, | 213 }, |
| 211 }; | 214 }; |
| 212 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() { | 215 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() { |
| 213 chrome.send('closeNotificationPromo'); | 216 chrome.send('closeNotificationPromo'); |
| 214 }, 60000); | 217 }, 60000); |
| 215 chrome.send('notificationPromoViewed'); | 218 chrome.send('notificationPromoViewed'); |
| 216 } | 219 } |
| 217 | 220 |
| 218 var loginContainer = getRequiredElement('login-container'); | 221 var loginContainer = getRequiredElement('login-container'); |
| 219 loginContainer.addEventListener('click', function() { | 222 loginContainer.addEventListener('click', function(e) { |
| 220 var rect = loginContainer.getBoundingClientRect(); | 223 showSyncLoginUI(this); |
|
Dan Beam
2012/03/23 21:12:47
can you change this to
loginContainer.addEventL
Patrick Dubroy
2012/03/26 19:36:46
Done.
| |
| 221 chrome.send('showSyncLoginUI', | |
| 222 [rect.left, rect.top, rect.width, rect.height]); | |
| 223 }); | 224 }); |
| 224 chrome.send('initializeSyncLogin'); | 225 chrome.send('initializeSyncLogin'); |
| 225 | 226 |
| 226 doWhenAllSectionsReady(function() { | 227 doWhenAllSectionsReady(function() { |
| 227 // Tell the slider about the pages. | 228 // Tell the slider about the pages. |
| 228 newTabView.updateSliderCards(); | 229 newTabView.updateSliderCards(); |
| 229 // Mark the current page. | 230 // Mark the current page. |
| 230 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( | 231 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( |
| 231 'selected'); | 232 'selected'); |
| 232 | 233 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 */ | 487 */ |
| 487 function setStripeColor(id, color) { | 488 function setStripeColor(id, color) { |
| 488 var node = $(id); | 489 var node = $(id); |
| 489 if (node) | 490 if (node) |
| 490 node.stripeColor = color; | 491 node.stripeColor = color; |
| 491 } | 492 } |
| 492 | 493 |
| 493 /** | 494 /** |
| 494 * Updates the text displayed in the login container. If there is no text then | 495 * Updates the text displayed in the login container. If there is no text then |
| 495 * the login container is hidden. | 496 * the login container is hidden. |
| 497 * @param {Boolean} isUserSignedIn Indicates if the user is signed in or not. | |
| 496 * @param {string} loginHeader The first line of text. | 498 * @param {string} loginHeader The first line of text. |
| 497 * @param {string} loginSubHeader The second line of text. | 499 * @param {string} loginSubHeader The second line of text. |
| 498 * @param {string} iconURL The url for the login status icon. If this is null | 500 * @param {string} iconURL The url for the login status icon. If this is null |
| 499 then the login status icon is hidden. | 501 then the login status icon is hidden. |
| 500 */ | 502 */ |
| 501 function updateLogin(loginHeader, loginSubHeader, iconURL) { | 503 function updateLogin(isUserSignedIn, loginHeader, loginSubHeader, iconURL) { |
| 502 if (loginHeader || loginSubHeader) { | 504 if (loginHeader || loginSubHeader) { |
| 503 $('login-container').hidden = false; | 505 $('login-container').hidden = false; |
| 504 $('login-status-header').innerHTML = loginHeader; | 506 $('login-status-header').innerHTML = loginHeader; |
| 505 $('login-status-sub-header').innerHTML = loginSubHeader; | 507 $('login-status-sub-header').innerHTML = loginSubHeader; |
| 506 $('card-slider-frame').classList.add('showing-login-area'); | 508 $('card-slider-frame').classList.add('showing-login-area'); |
| 507 | 509 |
| 508 if (iconURL) { | 510 if (iconURL) { |
| 509 $('login-status-header-container').style.backgroundImage = url(iconURL); | 511 $('login-status-header-container').style.backgroundImage = url(iconURL); |
| 510 $('login-status-header-container').classList.add('login-status-icon'); | 512 $('login-status-header-container').classList.add('login-status-icon'); |
| 511 } else { | 513 } else { |
| 512 $('login-status-header-container').style.backgroundImage = 'none'; | 514 $('login-status-header-container').style.backgroundImage = 'none'; |
| 513 $('login-status-header-container').classList.remove( | 515 $('login-status-header-container').classList.remove( |
| 514 'login-status-icon'); | 516 'login-status-icon'); |
| 515 } | 517 } |
| 516 } else { | 518 } else { |
| 517 $('login-container').hidden = true; | 519 $('login-container').hidden = true; |
| 518 $('card-slider-frame').classList.remove('showing-login-area'); | 520 $('card-slider-frame').classList.remove('showing-login-area'); |
| 519 } | 521 } |
| 520 if (shouldShowLoginBubble) { | 522 if (shouldShowLoginBubble) { |
| 521 window.setTimeout(loginBubble.show.bind(loginBubble), 0); | 523 window.setTimeout(loginBubble.show.bind(loginBubble), 0); |
| 522 chrome.send('loginMessageSeen'); | 524 chrome.send('loginMessageSeen'); |
| 523 shouldShowLoginBubble = false; | 525 shouldShowLoginBubble = false; |
| 524 } else if (loginBubble) { | 526 } else if (loginBubble) { |
| 525 loginBubble.reposition(); | 527 loginBubble.reposition(); |
| 526 } | 528 } |
| 529 $('other-sessions-menu-button').updateSignInState(isUserSignedIn); | |
| 527 } | 530 } |
| 528 | 531 |
| 529 /** | 532 /** |
| 533 * Show the sync login UI. |element| is the element that triggered the login. | |
|
Dan Beam
2012/03/23 21:12:47
doc param
Patrick Dubroy
2012/03/26 15:16:46
Done.
| |
| 534 */ | |
| 535 function showSyncLoginUI(element) { | |
|
Dan Beam
2012/03/23 21:12:47
s/element/e/
var element = e.currentTarget;
Patrick Dubroy
2012/03/26 15:16:46
Done.
| |
| 536 var rect = element.getBoundingClientRect(); | |
| 537 chrome.send('showSyncLoginUI', | |
| 538 [rect.left, rect.top, rect.width, rect.height]); | |
| 539 } | |
| 540 | |
| 541 /** | |
| 530 * Wrappers to forward the callback to corresponding PageListView member. | 542 * Wrappers to forward the callback to corresponding PageListView member. |
| 531 */ | 543 */ |
| 532 function appAdded() { | 544 function appAdded() { |
| 533 return newTabView.appAdded.apply(newTabView, arguments); | 545 return newTabView.appAdded.apply(newTabView, arguments); |
| 534 } | 546 } |
| 535 | 547 |
| 536 function appMoved() { | 548 function appMoved() { |
| 537 return newTabView.appMoved.apply(newTabView, arguments); | 549 return newTabView.appMoved.apply(newTabView, arguments); |
| 538 } | 550 } |
| 539 | 551 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 setSuggestionsPages: setSuggestionsPages, | 613 setSuggestionsPages: setSuggestionsPages, |
| 602 setRecentlyClosedTabs: setRecentlyClosedTabs, | 614 setRecentlyClosedTabs: setRecentlyClosedTabs, |
| 603 setStripeColor: setStripeColor, | 615 setStripeColor: setStripeColor, |
| 604 showNotification: showNotification, | 616 showNotification: showNotification, |
| 605 themeChanged: themeChanged, | 617 themeChanged: themeChanged, |
| 606 updateLogin: updateLogin | 618 updateLogin: updateLogin |
| 607 }; | 619 }; |
| 608 }); | 620 }); |
| 609 | 621 |
| 610 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 622 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
| OLD | NEW |