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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 */ | 46 */ |
47 var loginBubble; | 47 var loginBubble; |
48 | 48 |
49 /** | 49 /** |
50 * true if |loginBubble| should be shown. | 50 * true if |loginBubble| should be shown. |
51 * @type {Boolean} | 51 * @type {Boolean} |
52 */ | 52 */ |
53 var shouldShowLoginBubble = false; | 53 var shouldShowLoginBubble = false; |
54 | 54 |
55 /** | 55 /** |
| 56 * The 'other-sessions-menu-button' element. |
| 57 * @type {!Element|undefined} |
| 58 */ |
| 59 var otherSessionsButton; |
| 60 |
| 61 /** |
56 * The time in milliseconds for most transitions. This should match what's | 62 * The time in milliseconds for most transitions. This should match what's |
57 * in new_tab.css. Unfortunately there's no better way to try to time | 63 * in new_tab.css. Unfortunately there's no better way to try to time |
58 * something to occur until after a transition has completed. | 64 * something to occur until after a transition has completed. |
59 * @type {number} | 65 * @type {number} |
60 * @const | 66 * @const |
61 */ | 67 */ |
62 var DEFAULT_TRANSITION_TIME = 500; | 68 var DEFAULT_TRANSITION_TIME = 500; |
63 | 69 |
64 /** | 70 /** |
65 * Creates a NewTabView object. NewTabView extends PageListView with | 71 * Creates a NewTabView object. NewTabView extends PageListView with |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 newTabView = new NewTabView(); | 112 newTabView = new NewTabView(); |
107 | 113 |
108 notificationContainer = getRequiredElement('notification-container'); | 114 notificationContainer = getRequiredElement('notification-container'); |
109 notificationContainer.addEventListener( | 115 notificationContainer.addEventListener( |
110 'webkitTransitionEnd', onNotificationTransitionEnd); | 116 'webkitTransitionEnd', onNotificationTransitionEnd); |
111 | 117 |
112 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); | 118 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); |
113 chrome.send('getRecentlyClosedTabs'); | 119 chrome.send('getRecentlyClosedTabs'); |
114 | 120 |
115 if (templateData.showOtherSessionsMenu) { | 121 if (templateData.showOtherSessionsMenu) { |
116 cr.ui.decorate($('other-sessions-menu-button'), | 122 otherSessionsButton = getRequiredElement('other-sessions-menu-button'); |
117 ntp.OtherSessionsMenuButton); | 123 cr.ui.decorate(otherSessionsButton, ntp.OtherSessionsMenuButton); |
| 124 otherSessionsButton.initialize(templateData.isUserSignedIn); |
118 } | 125 } |
119 | 126 |
120 var mostVisited = new ntp.MostVisitedPage(); | 127 var mostVisited = new ntp.MostVisitedPage(); |
121 // Move the footer into the most visited page if we are in "bare minimum" | 128 // Move the footer into the most visited page if we are in "bare minimum" |
122 // mode. | 129 // mode. |
123 if (document.body.classList.contains('bare-minimum')) | 130 if (document.body.classList.contains('bare-minimum')) |
124 mostVisited.appendFooter(getRequiredElement('footer')); | 131 mostVisited.appendFooter(getRequiredElement('footer')); |
125 newTabView.appendTilePage(mostVisited, | 132 newTabView.appendTilePage(mostVisited, |
126 localStrings.getString('mostvisited'), | 133 localStrings.getString('mostvisited'), |
127 false); | 134 false); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 199 |
193 var learnMoreLink = infoBubble.querySelector('a'); | 200 var learnMoreLink = infoBubble.querySelector('a'); |
194 learnMoreLink.href = localStrings.getString('ntp4_intro_url'); | 201 learnMoreLink.href = localStrings.getString('ntp4_intro_url'); |
195 learnMoreLink.onclick = infoBubble.hide.bind(infoBubble); | 202 learnMoreLink.onclick = infoBubble.hide.bind(infoBubble); |
196 | 203 |
197 infoBubble.show(); | 204 infoBubble.show(); |
198 chrome.send('introMessageSeen'); | 205 chrome.send('introMessageSeen'); |
199 } | 206 } |
200 | 207 |
201 var loginContainer = getRequiredElement('login-container'); | 208 var loginContainer = getRequiredElement('login-container'); |
202 loginContainer.addEventListener('click', function() { | 209 loginContainer.addEventListener('click', showSyncLoginUI); |
203 var rect = loginContainer.getBoundingClientRect(); | |
204 chrome.send('showSyncLoginUI', | |
205 [rect.left, rect.top, rect.width, rect.height]); | |
206 }); | |
207 chrome.send('initializeSyncLogin'); | 210 chrome.send('initializeSyncLogin'); |
208 | 211 |
209 doWhenAllSectionsReady(function() { | 212 doWhenAllSectionsReady(function() { |
210 // Tell the slider about the pages. | 213 // Tell the slider about the pages. |
211 newTabView.updateSliderCards(); | 214 newTabView.updateSliderCards(); |
212 // Mark the current page. | 215 // Mark the current page. |
213 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( | 216 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( |
214 'selected'); | 217 'selected'); |
215 | 218 |
216 var promo = localStrings.getString('serverpromo'); | 219 var promo = localStrings.getString('serverpromo'); |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 node.stripeColor = color; | 491 node.stripeColor = color; |
489 } | 492 } |
490 | 493 |
491 /** | 494 /** |
492 * 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 |
493 * the login container is hidden. | 496 * the login container is hidden. |
494 * @param {string} loginHeader The first line of text. | 497 * @param {string} loginHeader The first line of text. |
495 * @param {string} loginSubHeader The second line of text. | 498 * @param {string} loginSubHeader The second line of text. |
496 * @param {string} iconURL The url for the login status icon. If this is null | 499 * @param {string} iconURL The url for the login status icon. If this is null |
497 then the login status icon is hidden. | 500 then the login status icon is hidden. |
| 501 * @param {boolean} isUserSignedIn Indicates if the user is signed in or not. |
498 */ | 502 */ |
499 function updateLogin(loginHeader, loginSubHeader, iconURL) { | 503 function updateLogin(loginHeader, loginSubHeader, iconURL, isUserSignedIn) { |
500 if (loginHeader || loginSubHeader) { | 504 if (loginHeader || loginSubHeader) { |
501 $('login-container').hidden = false; | 505 $('login-container').hidden = false; |
502 $('login-status-header').innerHTML = loginHeader; | 506 $('login-status-header').innerHTML = loginHeader; |
503 $('login-status-sub-header').innerHTML = loginSubHeader; | 507 $('login-status-sub-header').innerHTML = loginSubHeader; |
504 $('card-slider-frame').classList.add('showing-login-area'); | 508 $('card-slider-frame').classList.add('showing-login-area'); |
505 | 509 |
506 if (iconURL) { | 510 if (iconURL) { |
507 $('login-status-header-container').style.backgroundImage = url(iconURL); | 511 $('login-status-header-container').style.backgroundImage = url(iconURL); |
508 $('login-status-header-container').classList.add('login-status-icon'); | 512 $('login-status-header-container').classList.add('login-status-icon'); |
509 } else { | 513 } else { |
510 $('login-status-header-container').style.backgroundImage = 'none'; | 514 $('login-status-header-container').style.backgroundImage = 'none'; |
511 $('login-status-header-container').classList.remove( | 515 $('login-status-header-container').classList.remove( |
512 'login-status-icon'); | 516 'login-status-icon'); |
513 } | 517 } |
514 } else { | 518 } else { |
515 $('login-container').hidden = true; | 519 $('login-container').hidden = true; |
516 $('card-slider-frame').classList.remove('showing-login-area'); | 520 $('card-slider-frame').classList.remove('showing-login-area'); |
517 } | 521 } |
518 if (shouldShowLoginBubble) { | 522 if (shouldShowLoginBubble) { |
519 window.setTimeout(loginBubble.show.bind(loginBubble), 0); | 523 window.setTimeout(loginBubble.show.bind(loginBubble), 0); |
520 chrome.send('loginMessageSeen'); | 524 chrome.send('loginMessageSeen'); |
521 shouldShowLoginBubble = false; | 525 shouldShowLoginBubble = false; |
522 } else if (loginBubble) { | 526 } else if (loginBubble) { |
523 loginBubble.reposition(); | 527 loginBubble.reposition(); |
524 } | 528 } |
| 529 if (otherSessionsButton) |
| 530 otherSessionsButton.updateSignInState(isUserSignedIn); |
525 } | 531 } |
526 | 532 |
527 /** | 533 /** |
| 534 * Show the sync login UI. |
| 535 * @param {Event} e The click event. |
| 536 */ |
| 537 function showSyncLoginUI(e) { |
| 538 var rect = e.currentTarget.getBoundingClientRect(); |
| 539 chrome.send('showSyncLoginUI', |
| 540 [rect.left, rect.top, rect.width, rect.height]); |
| 541 } |
| 542 |
| 543 /** |
528 * Wrappers to forward the callback to corresponding PageListView member. | 544 * Wrappers to forward the callback to corresponding PageListView member. |
529 */ | 545 */ |
530 function appAdded() { | 546 function appAdded() { |
531 return newTabView.appAdded.apply(newTabView, arguments); | 547 return newTabView.appAdded.apply(newTabView, arguments); |
532 } | 548 } |
533 | 549 |
534 function appMoved() { | 550 function appMoved() { |
535 return newTabView.appMoved.apply(newTabView, arguments); | 551 return newTabView.appMoved.apply(newTabView, arguments); |
536 } | 552 } |
537 | 553 |
538 function appRemoved() { | 554 function appRemoved() { |
539 return newTabView.appRemoved.apply(newTabView, arguments); | 555 return newTabView.appRemoved.apply(newTabView, arguments); |
540 } | 556 } |
541 | 557 |
542 function appsPrefChangeCallback() { | 558 function appsPrefChangeCallback() { |
543 return newTabView.appsPrefChangedCallback.apply(newTabView, arguments); | 559 return newTabView.appsPrefChangedCallback.apply(newTabView, arguments); |
544 } | 560 } |
545 | 561 |
546 function appsReordered() { | 562 function appsReordered() { |
547 return newTabView.appsReordered.apply(newTabView, arguments); | 563 return newTabView.appsReordered.apply(newTabView, arguments); |
548 } | 564 } |
549 | 565 |
550 function enterRearrangeMode() { | 566 function enterRearrangeMode() { |
551 return newTabView.enterRearrangeMode.apply(newTabView, arguments); | 567 return newTabView.enterRearrangeMode.apply(newTabView, arguments); |
552 } | 568 } |
553 | 569 |
554 function foreignSessions(sessionList) { | 570 function setForeignSessions(sessionList, isTabSyncEnabled) { |
555 $('other-sessions-menu-button').sessions = sessionList; | 571 if (otherSessionsButton) |
| 572 otherSessionsButton.setForeignSessions(sessionList, isTabSyncEnabled); |
556 } | 573 } |
557 | 574 |
558 function getAppsCallback() { | 575 function getAppsCallback() { |
559 return newTabView.getAppsCallback.apply(newTabView, arguments); | 576 return newTabView.getAppsCallback.apply(newTabView, arguments); |
560 } | 577 } |
561 | 578 |
562 function getAppsPageIndex() { | 579 function getAppsPageIndex() { |
563 return newTabView.getAppsPageIndex.apply(newTabView, arguments); | 580 return newTabView.getAppsPageIndex.apply(newTabView, arguments); |
564 } | 581 } |
565 | 582 |
(...skipping 13 matching lines...) Expand all Loading... |
579 newTabView.highlightAppId = appId; | 596 newTabView.highlightAppId = appId; |
580 } | 597 } |
581 | 598 |
582 // Return an object with all the exports | 599 // Return an object with all the exports |
583 return { | 600 return { |
584 appAdded: appAdded, | 601 appAdded: appAdded, |
585 appMoved: appMoved, | 602 appMoved: appMoved, |
586 appRemoved: appRemoved, | 603 appRemoved: appRemoved, |
587 appsPrefChangeCallback: appsPrefChangeCallback, | 604 appsPrefChangeCallback: appsPrefChangeCallback, |
588 enterRearrangeMode: enterRearrangeMode, | 605 enterRearrangeMode: enterRearrangeMode, |
589 foreignSessions: foreignSessions, | |
590 getAppsCallback: getAppsCallback, | 606 getAppsCallback: getAppsCallback, |
591 getAppsPageIndex: getAppsPageIndex, | 607 getAppsPageIndex: getAppsPageIndex, |
592 getCardSlider: getCardSlider, | 608 getCardSlider: getCardSlider, |
593 onLoad: onLoad, | 609 onLoad: onLoad, |
594 leaveRearrangeMode: leaveRearrangeMode, | 610 leaveRearrangeMode: leaveRearrangeMode, |
595 saveAppPageName: saveAppPageName, | 611 saveAppPageName: saveAppPageName, |
596 setAppToBeHighlighted: setAppToBeHighlighted, | 612 setAppToBeHighlighted: setAppToBeHighlighted, |
597 setBookmarkBarAttached: setBookmarkBarAttached, | 613 setBookmarkBarAttached: setBookmarkBarAttached, |
| 614 setForeignSessions: setForeignSessions, |
598 setMostVisitedPages: setMostVisitedPages, | 615 setMostVisitedPages: setMostVisitedPages, |
599 setSuggestionsPages: setSuggestionsPages, | 616 setSuggestionsPages: setSuggestionsPages, |
600 setRecentlyClosedTabs: setRecentlyClosedTabs, | 617 setRecentlyClosedTabs: setRecentlyClosedTabs, |
601 setStripeColor: setStripeColor, | 618 setStripeColor: setStripeColor, |
602 showNotification: showNotification, | 619 showNotification: showNotification, |
603 themeChanged: themeChanged, | 620 themeChanged: themeChanged, |
604 updateLogin: updateLogin | 621 updateLogin: updateLogin |
605 }; | 622 }; |
606 }); | 623 }); |
607 | 624 |
608 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 625 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
OLD | NEW |