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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 newTabView = new NewTabView(); | 114 newTabView = new NewTabView(); |
109 | 115 |
110 notificationContainer = getRequiredElement('notification-container'); | 116 notificationContainer = getRequiredElement('notification-container'); |
111 notificationContainer.addEventListener( | 117 notificationContainer.addEventListener( |
112 'webkitTransitionEnd', onNotificationTransitionEnd); | 118 'webkitTransitionEnd', onNotificationTransitionEnd); |
113 | 119 |
114 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); | 120 cr.ui.decorate($('recently-closed-menu-button'), ntp.RecentMenuButton); |
115 chrome.send('getRecentlyClosedTabs'); | 121 chrome.send('getRecentlyClosedTabs'); |
116 | 122 |
117 if (templateData.showOtherSessionsMenu) { | 123 if (templateData.showOtherSessionsMenu) { |
118 cr.ui.decorate($('other-sessions-menu-button'), | 124 otherSessionsButton = getRequiredElement('other-sessions-menu-button'); |
119 ntp.OtherSessionsMenuButton); | 125 cr.ui.decorate(otherSessionsButton, ntp.OtherSessionsMenuButton); |
126 otherSessionsButton.initialize(templateData.isUserSignedIn); | |
120 } | 127 } |
121 | 128 |
122 var mostVisited = new ntp.MostVisitedPage(); | 129 var mostVisited = new ntp.MostVisitedPage(); |
123 // Move the footer into the most visited page if we are in "bare minimum" | 130 // Move the footer into the most visited page if we are in "bare minimum" |
124 // mode. | 131 // mode. |
125 if (document.body.classList.contains('bare-minimum')) | 132 if (document.body.classList.contains('bare-minimum')) |
126 mostVisited.appendFooter(getRequiredElement('footer')); | 133 mostVisited.appendFooter(getRequiredElement('footer')); |
127 newTabView.appendTilePage(mostVisited, | 134 newTabView.appendTilePage(mostVisited, |
128 localStrings.getString('mostvisited'), | 135 localStrings.getString('mostvisited'), |
129 false); | 136 false); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 /^data\:image\/(?:png|gif|jpe?g)/.test(value); | 216 /^data\:image\/(?:png|gif|jpe?g)/.test(value); |
210 }, | 217 }, |
211 }; | 218 }; |
212 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() { | 219 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() { |
213 chrome.send('closeNotificationPromo'); | 220 chrome.send('closeNotificationPromo'); |
214 }, 60000); | 221 }, 60000); |
215 chrome.send('notificationPromoViewed'); | 222 chrome.send('notificationPromoViewed'); |
216 } | 223 } |
217 | 224 |
218 var loginContainer = getRequiredElement('login-container'); | 225 var loginContainer = getRequiredElement('login-container'); |
219 loginContainer.addEventListener('click', function() { | 226 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'); | 227 chrome.send('initializeSyncLogin'); |
225 | 228 |
226 doWhenAllSectionsReady(function() { | 229 doWhenAllSectionsReady(function() { |
227 // Tell the slider about the pages. | 230 // Tell the slider about the pages. |
228 newTabView.updateSliderCards(); | 231 newTabView.updateSliderCards(); |
229 // Mark the current page. | 232 // Mark the current page. |
230 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( | 233 newTabView.cardSlider.currentCardValue.navigationDot.classList.add( |
231 'selected'); | 234 'selected'); |
232 | 235 |
233 document.documentElement.classList.remove('starting-up'); | 236 document.documentElement.classList.remove('starting-up'); |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 node.stripeColor = color; | 493 node.stripeColor = color; |
491 } | 494 } |
492 | 495 |
493 /** | 496 /** |
494 * Updates the text displayed in the login container. If there is no text then | 497 * Updates the text displayed in the login container. If there is no text then |
495 * the login container is hidden. | 498 * the login container is hidden. |
496 * @param {string} loginHeader The first line of text. | 499 * @param {string} loginHeader The first line of text. |
497 * @param {string} loginSubHeader The second line of text. | 500 * @param {string} loginSubHeader The second line of text. |
498 * @param {string} iconURL The url for the login status icon. If this is null | 501 * @param {string} iconURL The url for the login status icon. If this is null |
499 then the login status icon is hidden. | 502 then the login status icon is hidden. |
503 * @param {boolean} isUserSignedIn Indicates if the user is signed in or not. | |
500 */ | 504 */ |
501 function updateLogin(loginHeader, loginSubHeader, iconURL) { | 505 function updateLogin(loginHeader, loginSubHeader, iconURL, isUserSignedIn) { |
502 if (loginHeader || loginSubHeader) { | 506 if (loginHeader || loginSubHeader) { |
503 $('login-container').hidden = false; | 507 $('login-container').hidden = false; |
504 $('login-status-header').innerHTML = loginHeader; | 508 $('login-status-header').innerHTML = loginHeader; |
505 $('login-status-sub-header').innerHTML = loginSubHeader; | 509 $('login-status-sub-header').innerHTML = loginSubHeader; |
506 $('card-slider-frame').classList.add('showing-login-area'); | 510 $('card-slider-frame').classList.add('showing-login-area'); |
507 | 511 |
508 if (iconURL) { | 512 if (iconURL) { |
509 $('login-status-header-container').style.backgroundImage = url(iconURL); | 513 $('login-status-header-container').style.backgroundImage = url(iconURL); |
510 $('login-status-header-container').classList.add('login-status-icon'); | 514 $('login-status-header-container').classList.add('login-status-icon'); |
511 } else { | 515 } else { |
512 $('login-status-header-container').style.backgroundImage = 'none'; | 516 $('login-status-header-container').style.backgroundImage = 'none'; |
513 $('login-status-header-container').classList.remove( | 517 $('login-status-header-container').classList.remove( |
514 'login-status-icon'); | 518 'login-status-icon'); |
515 } | 519 } |
516 } else { | 520 } else { |
517 $('login-container').hidden = true; | 521 $('login-container').hidden = true; |
518 $('card-slider-frame').classList.remove('showing-login-area'); | 522 $('card-slider-frame').classList.remove('showing-login-area'); |
519 } | 523 } |
520 if (shouldShowLoginBubble) { | 524 if (shouldShowLoginBubble) { |
521 window.setTimeout(loginBubble.show.bind(loginBubble), 0); | 525 window.setTimeout(loginBubble.show.bind(loginBubble), 0); |
522 chrome.send('loginMessageSeen'); | 526 chrome.send('loginMessageSeen'); |
523 shouldShowLoginBubble = false; | 527 shouldShowLoginBubble = false; |
524 } else if (loginBubble) { | 528 } else if (loginBubble) { |
525 loginBubble.reposition(); | 529 loginBubble.reposition(); |
526 } | 530 } |
531 if (otherSessionsButton) | |
532 otherSessionsButton.updateSignInState(isUserSignedIn); | |
527 } | 533 } |
528 | 534 |
529 /** | 535 /** |
536 * Show the sync login UI. | |
537 * @param {Event} e The click event. | |
538 */ | |
539 function showSyncLoginUI(e) { | |
540 var rect = e.currentTarget.getBoundingClientRect(); | |
541 chrome.send('showSyncLoginUI', | |
542 [rect.left, rect.top, rect.width, rect.height]); | |
543 } | |
544 | |
545 /** | |
530 * Wrappers to forward the callback to corresponding PageListView member. | 546 * Wrappers to forward the callback to corresponding PageListView member. |
531 */ | 547 */ |
532 function appAdded() { | 548 function appAdded() { |
533 return newTabView.appAdded.apply(newTabView, arguments); | 549 return newTabView.appAdded.apply(newTabView, arguments); |
534 } | 550 } |
535 | 551 |
536 function appMoved() { | 552 function appMoved() { |
537 return newTabView.appMoved.apply(newTabView, arguments); | 553 return newTabView.appMoved.apply(newTabView, arguments); |
538 } | 554 } |
539 | 555 |
540 function appRemoved() { | 556 function appRemoved() { |
541 return newTabView.appRemoved.apply(newTabView, arguments); | 557 return newTabView.appRemoved.apply(newTabView, arguments); |
542 } | 558 } |
543 | 559 |
544 function appsPrefChangeCallback() { | 560 function appsPrefChangeCallback() { |
545 return newTabView.appsPrefChangedCallback.apply(newTabView, arguments); | 561 return newTabView.appsPrefChangedCallback.apply(newTabView, arguments); |
546 } | 562 } |
547 | 563 |
548 function appsReordered() { | 564 function appsReordered() { |
549 return newTabView.appsReordered.apply(newTabView, arguments); | 565 return newTabView.appsReordered.apply(newTabView, arguments); |
550 } | 566 } |
551 | 567 |
552 function enterRearrangeMode() { | 568 function enterRearrangeMode() { |
553 return newTabView.enterRearrangeMode.apply(newTabView, arguments); | 569 return newTabView.enterRearrangeMode.apply(newTabView, arguments); |
554 } | 570 } |
555 | 571 |
556 function foreignSessions(sessionList) { | 572 function setForeignSessions(sessionList, isTabSyncEnabled) { |
557 $('other-sessions-menu-button').sessions = sessionList; | 573 if (otherSessionsButton) |
Dan Beam
2012/03/27 01:21:06
nit: curlies
Patrick Dubroy
2012/03/27 13:44:21
Done.
| |
574 return otherSessionsButton.setForeignSessions(sessionList, | |
575 isTabSyncEnabled); | |
558 } | 576 } |
559 | 577 |
560 function getAppsCallback() { | 578 function getAppsCallback() { |
561 return newTabView.getAppsCallback.apply(newTabView, arguments); | 579 return newTabView.getAppsCallback.apply(newTabView, arguments); |
562 } | 580 } |
563 | 581 |
564 function getAppsPageIndex() { | 582 function getAppsPageIndex() { |
565 return newTabView.getAppsPageIndex.apply(newTabView, arguments); | 583 return newTabView.getAppsPageIndex.apply(newTabView, arguments); |
566 } | 584 } |
567 | 585 |
(...skipping 13 matching lines...) Expand all Loading... | |
581 newTabView.highlightAppId = appId; | 599 newTabView.highlightAppId = appId; |
582 } | 600 } |
583 | 601 |
584 // Return an object with all the exports | 602 // Return an object with all the exports |
585 return { | 603 return { |
586 appAdded: appAdded, | 604 appAdded: appAdded, |
587 appMoved: appMoved, | 605 appMoved: appMoved, |
588 appRemoved: appRemoved, | 606 appRemoved: appRemoved, |
589 appsPrefChangeCallback: appsPrefChangeCallback, | 607 appsPrefChangeCallback: appsPrefChangeCallback, |
590 enterRearrangeMode: enterRearrangeMode, | 608 enterRearrangeMode: enterRearrangeMode, |
591 foreignSessions: foreignSessions, | |
592 getAppsCallback: getAppsCallback, | 609 getAppsCallback: getAppsCallback, |
593 getAppsPageIndex: getAppsPageIndex, | 610 getAppsPageIndex: getAppsPageIndex, |
594 getCardSlider: getCardSlider, | 611 getCardSlider: getCardSlider, |
595 onLoad: onLoad, | 612 onLoad: onLoad, |
596 leaveRearrangeMode: leaveRearrangeMode, | 613 leaveRearrangeMode: leaveRearrangeMode, |
597 saveAppPageName: saveAppPageName, | 614 saveAppPageName: saveAppPageName, |
598 setAppToBeHighlighted: setAppToBeHighlighted, | 615 setAppToBeHighlighted: setAppToBeHighlighted, |
599 setBookmarkBarAttached: setBookmarkBarAttached, | 616 setBookmarkBarAttached: setBookmarkBarAttached, |
617 setForeignSessions: setForeignSessions, | |
Dan Beam
2012/03/27 01:21:06
I mentioned getForeignSessions, but I guess this i
Patrick Dubroy
2012/03/27 13:44:21
Yeah, I saw what you wrote but getForeignSessions
| |
600 setMostVisitedPages: setMostVisitedPages, | 618 setMostVisitedPages: setMostVisitedPages, |
601 setSuggestionsPages: setSuggestionsPages, | 619 setSuggestionsPages: setSuggestionsPages, |
602 setRecentlyClosedTabs: setRecentlyClosedTabs, | 620 setRecentlyClosedTabs: setRecentlyClosedTabs, |
603 setStripeColor: setStripeColor, | 621 setStripeColor: setStripeColor, |
604 showNotification: showNotification, | 622 showNotification: showNotification, |
605 themeChanged: themeChanged, | 623 themeChanged: themeChanged, |
606 updateLogin: updateLogin | 624 updateLogin: updateLogin |
607 }; | 625 }; |
608 }); | 626 }); |
609 | 627 |
610 document.addEventListener('DOMContentLoaded', ntp.onLoad); | 628 document.addEventListener('DOMContentLoaded', ntp.onLoad); |
OLD | NEW |