Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: chrome/browser/resources/ntp_search/new_tab.js

Issue 11416091: NTP5: Implementing new specification for favicons of Most Visited Pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/resources/ntp_search/thumbnail_page.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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. NewTabView manages page list, 7 * This is the main code for the new tab page. NewTabView manages page list,
8 * dot list and handles apps pages callbacks from backend. It also handles 8 * dot list and handles apps pages callbacks from backend. It also handles
9 * the layout of the Bottom Panel and the global UI states of the New Tab Page. 9 * the layout of the Bottom Panel and the global UI states of the New Tab Page.
10 */ 10 */
(...skipping 19 matching lines...) Expand all
30 * @type {number} 30 * @type {number}
31 * @const 31 * @const
32 */ 32 */
33 var BOTTOM_PANEL_HORIZONTAL_MARGIN = 100; 33 var BOTTOM_PANEL_HORIZONTAL_MARGIN = 100;
34 34
35 /** 35 /**
36 * The height required to show the Bottom Panel. 36 * The height required to show the Bottom Panel.
37 * @type {number} 37 * @type {number}
38 * @const 38 * @const
39 */ 39 */
40 var HEIGHT_FOR_BOTTOM_PANEL = 550; 40 var HEIGHT_FOR_BOTTOM_PANEL = 558;
41 41
42 /** 42 /**
43 * The Bottom Panel width required to show 6 cols of Tiles, which is used 43 * The Bottom Panel width required to show 6 cols of Tiles, which is used
44 * in the width computation. 44 * in the width computation.
45 * @type {number} 45 * @type {number}
46 * @const 46 * @const
47 */ 47 */
48 var MAX_BOTTOM_PANEL_WIDTH = 920; 48 var MAX_BOTTOM_PANEL_WIDTH = 920;
49 49
50 /** 50 /**
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 */ 151 */
152 pageList: undefined, 152 pageList: undefined,
153 153
154 /** 154 /**
155 * A list of all 'tile-page' elements. 155 * A list of all 'tile-page' elements.
156 * @type {!NodeList|undefined} 156 * @type {!NodeList|undefined}
157 */ 157 */
158 tilePages: undefined, 158 tilePages: undefined,
159 159
160 /** 160 /**
161 * The Apps page. 161 * A list of all 'apps-page' elements.
162 * @type {!Element|undefined} 162 * @type {!NodeList|undefined}
163 */ 163 */
164 appsPage: undefined, 164 appsPages: undefined,
165 165
166 /** 166 /**
167 * The Most Visited page. 167 * The Most Visited page.
168 * @type {!Element|undefined} 168 * @type {!Element|undefined}
169 */ 169 */
170 mostVisitedPage: undefined, 170 mostVisitedPage: undefined,
171 171
172 /** 172 /**
173 * The Recently Closed page. 173 * The Recently Closed page.
174 * @type {!Element|undefined} 174 * @type {!Element|undefined}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 this.dotList = dotList; 222 this.dotList = dotList;
223 cr.ui.decorate(this.dotList, ntp.DotList); 223 cr.ui.decorate(this.dotList, ntp.DotList);
224 224
225 this.shownPage = loadTimeData.getInteger('shown_page_type'); 225 this.shownPage = loadTimeData.getInteger('shown_page_type');
226 this.shownPageIndex = loadTimeData.getInteger('shown_page_index'); 226 this.shownPageIndex = loadTimeData.getInteger('shown_page_index');
227 227
228 if (loadTimeData.getBoolean('showApps')) { 228 if (loadTimeData.getBoolean('showApps')) {
229 // Request data on the apps so we can fill them in. 229 // Request data on the apps so we can fill them in.
230 // Note that this is kicked off asynchronously. 'getAppsCallback' will 230 // Note that this is kicked off asynchronously. 'getAppsCallback' will
231 // be invoked at some point after this function returns. 231 // be invoked at some point after this function returns.
232 chrome.send('getApps'); 232 if (!ntp.ntp5)
233 chrome.send('getApps');
233 } else if (this.shownPage == loadTimeData.getInteger('apps_page_id')) { 234 } else if (this.shownPage == loadTimeData.getInteger('apps_page_id')) {
234 // No apps page. 235 // No apps page.
235 this.setShownPage_( 236 this.setShownPage_(
236 loadTimeData.getInteger('most_visited_page_id'), 0); 237 loadTimeData.getInteger('most_visited_page_id'), 0);
237 } 238 }
238 239
239 this.tilePages = this.pageList.getElementsByClassName('tile-page'); 240 this.tilePages = this.pageList.getElementsByClassName('tile-page');
241 this.appsPages = this.pageList.getElementsByClassName('apps-page');
240 242
241 // Initialize the cardSlider without any cards at the moment. 243 // Initialize the cardSlider without any cards at the moment.
242 this.sliderFrame = cardSliderFrame; 244 this.sliderFrame = cardSliderFrame;
243 this.cardSlider = new cr.ui.CardSlider(this.sliderFrame, this.pageList, 245 this.cardSlider = new cr.ui.CardSlider(this.sliderFrame, this.pageList,
244 this.sliderFrame.offsetWidth); 246 this.sliderFrame.offsetWidth);
245 247
246 var cardSlider = this.cardSlider; 248 var cardSlider = this.cardSlider;
247 this.cardSlider.initialize( 249 this.cardSlider.initialize(
248 loadTimeData.getBoolean('isSwipeTrackingFromScrollEventsEnabled')); 250 loadTimeData.getBoolean('isSwipeTrackingFromScrollEventsEnabled'));
249 251
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 298 }
297 299
298 // Remember special MostVisitedPage. 300 // Remember special MostVisitedPage.
299 if (typeof ntp.MostVisitedPage != 'undefined' && 301 if (typeof ntp.MostVisitedPage != 'undefined' &&
300 page instanceof ntp.MostVisitedPage) { 302 page instanceof ntp.MostVisitedPage) {
301 assert(this.tilePages.length == 1, 303 assert(this.tilePages.length == 1,
302 'MostVisitedPage should be added as first tile page'); 304 'MostVisitedPage should be added as first tile page');
303 this.mostVisitedPage = page; 305 this.mostVisitedPage = page;
304 } 306 }
305 307
306 if (typeof ntp.AppsPage != 'undefined' &&
307 page instanceof ntp.AppsPage) {
308 this.appsPage = page;
309 }
310
311 if (typeof ntp.RecentlyClosedPage != 'undefined' && 308 if (typeof ntp.RecentlyClosedPage != 'undefined' &&
312 page instanceof ntp.RecentlyClosedPage) { 309 page instanceof ntp.RecentlyClosedPage) {
313 this.recentlyClosedPage = page; 310 this.recentlyClosedPage = page;
314 } 311 }
315 312
316 // Remember special OtherDevicesPage. 313 // Remember special OtherDevicesPage.
317 if (typeof ntp.OtherDevicesPage != 'undefined' && 314 if (typeof ntp.OtherDevicesPage != 'undefined' &&
318 page instanceof ntp.OtherDevicesPage) { 315 page instanceof ntp.OtherDevicesPage) {
319 this.otherDevicesPage = page; 316 this.otherDevicesPage = page;
320 } 317 }
(...skipping 13 matching lines...) Expand all
334 * @param {Object} appData The data for the app. This contains page and 331 * @param {Object} appData The data for the app. This contains page and
335 * position indices. 332 * position indices.
336 */ 333 */
337 appMoved: function(appData) { 334 appMoved: function(appData) {
338 assert(loadTimeData.getBoolean('showApps')); 335 assert(loadTimeData.getBoolean('showApps'));
339 336
340 var app = $(appData.id); 337 var app = $(appData.id);
341 assert(app, 'trying to move an app that doesn\'t exist'); 338 assert(app, 'trying to move an app that doesn\'t exist');
342 app.remove(false); 339 app.remove(false);
343 340
344 this.appsPage.insertApp(appData, false); 341 this.appsPages[appData.page_index].insertApp(appData, false);
345 }, 342 },
346 343
347 /** 344 /**
348 * Called by chrome when an existing app has been disabled or 345 * Called by chrome when an existing app has been disabled or
349 * removed/uninstalled from chrome. 346 * removed/uninstalled from chrome.
350 * @param {Object} appData A data structure full of relevant information for 347 * @param {Object} appData A data structure full of relevant information for
351 * the app. 348 * the app.
352 * @param {boolean} isUninstall True if the app is being uninstalled; 349 * @param {boolean} isUninstall True if the app is being uninstalled;
353 * false if the app is being disabled. 350 * false if the app is being disabled.
354 * @param {boolean} fromPage True if the removal was from the current page. 351 * @param {boolean} fromPage True if the removal was from the current page.
(...skipping 30 matching lines...) Expand all
385 * 382 *
386 * Note that calls to this function can occur at any time, not just in 383 * Note that calls to this function can occur at any time, not just in
387 * response to a getApps request. For example, when a user 384 * response to a getApps request. For example, when a user
388 * installs/uninstalls an app on another synchronized devices. 385 * installs/uninstalls an app on another synchronized devices.
389 * @param {Object} data An object with all the data on available 386 * @param {Object} data An object with all the data on available
390 * applications. 387 * applications.
391 */ 388 */
392 getAppsCallback: function(data) { 389 getAppsCallback: function(data) {
393 assert(loadTimeData.getBoolean('showApps')); 390 assert(loadTimeData.getBoolean('showApps'));
394 391
395 var page = this.appsPage;
396 var state = page && page.getTileRepositioningState();
397 if (state) {
398 if (state.isRemoving)
399 page.animateTileRemoval(state.index, data);
400 else
401 page.animateTileRestoration(state.index, data);
402
403 page.resetTileRepositioningState();
404 return;
405 }
406
407 var startTime = Date.now(); 392 var startTime = Date.now();
408 393
409 if (page) 394 // Remember this to select the correct card when done rebuilding.
410 page.removeAllTiles(); 395 var prevCurrentCard = this.cardSlider.currentCard;
396
397 // Make removal of pages and dots as quick as possible with less DOM
398 // operations, reflows, or repaints. We set currentCard = 0 and remove
399 // from the end to not encounter any auto-magic card selections in the
400 // process and we hide the card slider throughout.
401 this.cardSlider.currentCard = 0;
402
403 // Clear any existing apps pages and dots.
404 // TODO(rbyers): It might be nice to preserve animation of dots after an
405 // uninstall. Could we re-use the existing page and dot elements? It
406 // seems unfortunate to have Chrome send us the entire apps list after an
407 // uninstall.
408 while (this.appsPages.length > 0)
409 this.removeTilePageAndDot_(this.appsPages[this.appsPages.length - 1]);
411 410
412 // Get the array of apps and add any special synthesized entries 411 // Get the array of apps and add any special synthesized entries
413 var apps = data.apps; 412 var apps = data.apps;
414 413
414 // Get a list of page names
415 var pageNames = data.appPageNames;
416
415 // Sort by launch ordinal 417 // Sort by launch ordinal
416 apps.sort(function(a, b) { 418 apps.sort(function(a, b) {
417 return a.app_launch_ordinal > b.app_launch_ordinal ? 1 : 419 return a.app_launch_ordinal > b.app_launch_ordinal ? 1 :
418 a.app_launch_ordinal < b.app_launch_ordinal ? -1 : 0; 420 a.app_launch_ordinal < b.app_launch_ordinal ? -1 : 0;
419 }); 421 });
420 422
421 // An app to animate (in case it was just installed). 423 // An app to animate (in case it was just installed).
422 var highlightApp; 424 var highlightApp;
423 425
426 // If there are any pages after the apps, add new pages before them.
427 var lastAppsPage = (this.appsPages.length > 0) ?
428 this.appsPages[this.appsPages.length - 1] : null;
429 var lastAppsPageIndex = (lastAppsPage != null) ?
430 Array.prototype.indexOf.call(this.tilePages, lastAppsPage) : -1;
431 var nextPageAfterApps = lastAppsPageIndex != -1 ?
432 this.tilePages[lastAppsPageIndex + 1] : null;
433
424 // Add the apps, creating pages as necessary 434 // Add the apps, creating pages as necessary
425 this.appendTilePage(new ntp.AppsPage(),
426 loadTimeData.getString('appDefaultPageName'));
427 for (var i = 0; i < apps.length; i++) { 435 for (var i = 0; i < apps.length; i++) {
428 var app = apps[i]; 436 var app = apps[i];
437 var pageIndex = app.page_index || 0;
438 while (pageIndex >= this.appsPages.length) {
439 var pageName = loadTimeData.getString('appDefaultPageName');
440 if (this.appsPages.length < pageNames.length)
441 pageName = pageNames[this.appsPages.length];
442
443 var origPageCount = this.appsPages.length;
444 this.appendTilePage(new ntp.AppsPage(), pageName, nextPageAfterApps);
445 // Confirm that appsPages is a live object, updated when a new page is
446 // added (otherwise we'd have an infinite loop)
447 assert(this.appsPages.length == origPageCount + 1,
448 'expected new page');
449 }
450
429 if (app.id == this.highlightAppId) 451 if (app.id == this.highlightAppId)
430 highlightApp = app; 452 highlightApp = app;
431 else 453 else
432 this.appsPage.insertApp(app, false); 454 this.appsPages[pageIndex].insertApp(app, false);
433 } 455 }
434 456
457 this.cardSlider.currentCard = prevCurrentCard;
458
435 if (highlightApp) 459 if (highlightApp)
436 this.appAdded(highlightApp, true); 460 this.appAdded(highlightApp, true);
437 461
438 logEvent('apps.layout: ' + (Date.now() - startTime)); 462 logEvent('apps.layout: ' + (Date.now() - startTime));
439 463
440 // Tell the slider about the pages and mark the current page. 464 // Tell the slider about the pages and mark the current page.
441 this.updateSliderCards(); 465 this.updateSliderCards();
466 this.cardSlider.currentCardValue.navigationDot.classList.add('selected');
442 467
443 if (!this.appsLoaded_) { 468 if (!this.appsLoaded_) {
444 this.appsLoaded_ = true; 469 this.appsLoaded_ = true;
445 cr.dispatchSimpleEvent(document, 'sectionready', true, true); 470 cr.dispatchSimpleEvent(document, 'sectionready', true, true);
446 } 471 }
447 }, 472 },
448 473
449 /** 474 /**
450 * Called by chrome when a new app has been added to chrome or has been 475 * Called by chrome when a new app has been added to chrome or has been
451 * enabled if previously disabled. 476 * enabled if previously disabled.
452 * @param {Object} appData A data structure full of relevant information for 477 * @param {Object} appData A data structure full of relevant information for
453 * the app. 478 * the app.
454 * @param {boolean=} opt_highlight Whether the app about to be added should 479 * @param {boolean=} opt_highlight Whether the app about to be added should
455 * be highlighted. 480 * be highlighted.
456 */ 481 */
457 appAdded: function(appData, opt_highlight) { 482 appAdded: function(appData, opt_highlight) {
458 assert(loadTimeData.getBoolean('showApps')); 483 assert(loadTimeData.getBoolean('showApps'));
459 484
460 if (appData.id == this.highlightAppId) { 485 if (appData.id == this.highlightAppId) {
461 opt_highlight = true; 486 opt_highlight = true;
462 this.highlightAppId = null; 487 this.highlightAppId = null;
463 } 488 }
464 489
465 var pageIndex = appData.page_index || 0; 490 var pageIndex = appData.page_index || 0;
466 491
492 if (pageIndex >= this.appsPages.length) {
493 while (pageIndex >= this.appsPages.length) {
494 this.appendTilePage(new ntp.AppsPage(),
495 loadTimeData.getString('appDefaultPageName'));
496 }
497 this.updateSliderCards();
498 }
499
500 var page = this.appsPages[pageIndex];
467 var app = $(appData.id); 501 var app = $(appData.id);
468 if (app) { 502 if (app) {
469 app.replaceAppData(appData); 503 app.replaceAppData(appData);
470 } else if (opt_highlight) { 504 } else if (opt_highlight) {
471 this.appsPage.insertAndHighlightApp(appData); 505 page.insertAndHighlightApp(appData);
472 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), 506 this.setShownPage_(loadTimeData.getInteger('apps_page_id'),
473 appData.page_index); 507 appData.page_index);
474 } else { 508 } else {
475 this.appsPage.insertApp(appData, false); 509 page.insertApp(appData, false);
476 } 510 }
477 }, 511 },
478 512
479 /** 513 /**
480 * Callback invoked by chrome whenever an app preference changes. 514 * Callback invoked by chrome whenever an app preference changes.
481 * @param {Object} data An object with all the data on available 515 * @param {Object} data An object with all the data on available
482 * applications. 516 * applications.
483 */ 517 */
484 appsPrefChangedCallback: function(data) { 518 appsPrefChangedCallback: function(data) {
485 assert(loadTimeData.getBoolean('showApps')); 519 assert(loadTimeData.getBoolean('showApps'));
486 520
487 for (var i = 0; i < data.apps.length; ++i) { 521 for (var i = 0; i < data.apps.length; ++i) {
488 $(data.apps[i].id).appData = data.apps[i]; 522 $(data.apps[i].id).appData = data.apps[i];
489 } 523 }
490 }, 524 },
491 525
492 /** 526 /**
493 * Invoked whenever the pages in page-list have changed so that the 527 * Invoked whenever the pages in page-list have changed so that the
494 * CardSlider knows about the new elements. 528 * CardSlider knows about the new elements.
495 */ 529 */
496 updateSliderCards: function() { 530 updateSliderCards: function() {
497 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard, 531 var pageNo = Math.max(0, Math.min(this.cardSlider.currentCard,
498 this.tilePages.length - 1)); 532 this.tilePages.length - 1));
499 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages), 533 this.cardSlider.setCards(Array.prototype.slice.call(this.tilePages),
500 pageNo); 534 pageNo);
501 switch (this.shownPage) { 535
502 case loadTimeData.getInteger('apps_page_id'): 536 assert(this.mostVisitedPage, 'Most Visited Page not found');
503 this.cardSlider.selectCardByValue(this.appsPage); 537 // NTP pages are not sticky anymore, so we should always select the Most
504 break; 538 // Visited page when loading the card slider.
505 case loadTimeData.getInteger('most_visited_page_id'): 539 this.cardSlider.selectCardByValue(this.mostVisitedPage);
506 if (this.mostVisitedPage)
507 this.cardSlider.selectCardByValue(this.mostVisitedPage);
508 break;
509 }
510 }, 540 },
511 541
512 /** 542 /**
543 * Returns the index of the given apps page.
544 * @param {AppsPage} page The AppsPage we wish to find.
545 * @return {number} The index of |page| or -1 if it is not in the
546 * collection.
547 */
548 getAppsPageIndex: function(page) {
549 return Array.prototype.indexOf.call(this.appsPages, page);
550 },
551
552 /**
513 * Handler for cardSlider:card_changed events from this.cardSlider. 553 * Handler for cardSlider:card_changed events from this.cardSlider.
514 * @param {Event} e The cardSlider:card_changed event. 554 * @param {Event} e The cardSlider:card_changed event.
515 * @private 555 * @private
516 */ 556 */
517 onCardChanged_: function(e) { 557 onCardChanged_: function(e) {
518 var page = e.cardSlider.currentCardValue; 558 var page = e.cardSlider.currentCardValue;
519 559
520 // Don't change shownPage until startup is done (and page changes actually 560 // Don't change shownPage until startup is done (and page changes actually
521 // reflect user actions). 561 // reflect user actions).
522 if (!this.isStartingUp_()) { 562 if (!this.isStartingUp_()) {
523 if (page.classList.contains('apps-page')) { 563 if (page.classList.contains('apps-page')) {
524 this.setShownPage_(loadTimeData.getInteger('apps_page_id'), 0); 564 this.setShownPage_(loadTimeData.getInteger('apps_page_id'),
565 this.getAppsPageIndex(page));
525 } else if (page.classList.contains('most-visited-page')) { 566 } else if (page.classList.contains('most-visited-page')) {
526 this.setShownPage_( 567 this.setShownPage_(
527 loadTimeData.getInteger('most_visited_page_id'), 0); 568 loadTimeData.getInteger('most_visited_page_id'), 0);
528 } else if (page.classList.contains('recently-closed-page')) { 569 } else if (page.classList.contains('recently-closed-page')) {
529 this.setShownPage_( 570 this.setShownPage_(
530 loadTimeData.getInteger('recently_closed_page_id'), 0); 571 loadTimeData.getInteger('recently_closed_page_id'), 0);
531 } else if (page.classList.contains('other-devices-page')) { 572 } else if (page.classList.contains('other-devices-page')) {
532 this.setShownPage_( 573 this.setShownPage_(
533 loadTimeData.getInteger('other_devices_page_id'), 0); 574 loadTimeData.getInteger('other_devices_page_id'), 0);
534 } else { 575 } else {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 * selected TilePage. Alternatively, you can pass a specific TilePage in 714 * selected TilePage. Alternatively, you can pass a specific TilePage in
674 * the |opt_page| parameter, which is useful for initializing the layout 715 * the |opt_page| parameter, which is useful for initializing the layout
675 * of a recently created TilePage. 716 * of a recently created TilePage.
676 * 717 *
677 * The |NewTabView.layout| deals with the global layout state while the 718 * The |NewTabView.layout| deals with the global layout state while the
678 * |TilePage.layout| deals with the per-page layout state. A general rule 719 * |TilePage.layout| deals with the per-page layout state. A general rule
679 * would be: if you need to resize any element which is outside the 720 * would be: if you need to resize any element which is outside the
680 * card-slider-frame, it should be handled here in NewTabView. Otherwise, 721 * card-slider-frame, it should be handled here in NewTabView. Otherwise,
681 * it should be handled in TilePage. 722 * it should be handled in TilePage.
682 * 723 *
683 * @param {boolean=} opt_animate Whether the layout should be animated. 724 * @param {boolean} opt_animate Whether the layout should be animated.
684 * @param {ntp.TilePage=} opt_page Alternative TilePage to calculate layout. 725 * @param {ntp.TilePage} opt_page Alternative TilePage to calculate layout.
685 */ 726 */
686 layout: function(opt_animate, opt_page) { 727 layout: function(opt_animate, opt_page) {
687 opt_animate = typeof opt_animate == 'undefined' ? false : opt_animate; 728 opt_animate = typeof opt_animate == 'undefined' ? false : opt_animate;
688 729
689 var viewHeight = cr.doc.documentElement.clientHeight; 730 var viewHeight = cr.doc.documentElement.clientHeight;
690 var isBottomPanelVisible = viewHeight >= HEIGHT_FOR_BOTTOM_PANEL; 731 var isBottomPanelVisible = viewHeight >= HEIGHT_FOR_BOTTOM_PANEL;
691 // Toggles the visibility of the Bottom Panel when there is (or there 732 // Toggles the visibility of the Bottom Panel when there is (or there
692 // is not) space to show the entire panel. 733 // is not) space to show the entire panel.
693 this.showBottomPanel_(isBottomPanelVisible); 734 this.showBottomPanel_(isBottomPanelVisible);
694 735
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 803
763 notificationContainer = getRequiredElement('notification-container'); 804 notificationContainer = getRequiredElement('notification-container');
764 notificationContainer.addEventListener( 805 notificationContainer.addEventListener(
765 'webkitTransitionEnd', onNotificationTransitionEnd); 806 'webkitTransitionEnd', onNotificationTransitionEnd);
766 807
767 var mostVisited = new ntp.MostVisitedPage(); 808 var mostVisited = new ntp.MostVisitedPage();
768 newTabView.appendTilePage(mostVisited, 809 newTabView.appendTilePage(mostVisited,
769 loadTimeData.getString('mostvisited')); 810 loadTimeData.getString('mostvisited'));
770 chrome.send('getMostVisited'); 811 chrome.send('getMostVisited');
771 812
813 var recentlyClosed = new ntp.RecentlyClosedPage();
814 newTabView.appendTilePage(recentlyClosed,
815 loadTimeData.getString('recentlyclosed'));
816 chrome.send('getRecentlyClosedTabs');
817
818 var devices = new ntp.OtherDevicesPage();
819 newTabView.appendTilePage(devices, loadTimeData.getString('otherSessions'));
820 chrome.send('getForeignSessions');
821
772 doWhenAllSectionsReady(function() { 822 doWhenAllSectionsReady(function() {
773 // Tell the slider about the pages. 823 // Tell the slider about the pages.
774 newTabView.updateSliderCards(); 824 newTabView.updateSliderCards();
775 newTabView.onReady(); 825 newTabView.onReady();
776
777 // Restore the visibility only after calling updateSliderCards to avoid 826 // Restore the visibility only after calling updateSliderCards to avoid
778 // flickering, otherwise for a small fraction of a second the Page List is 827 // flickering, otherwise for a small fraction of a second the Page List is
779 // partially rendered. 828 // partially rendered.
780 $('bottom-panel').style.visibility = 'visible'; 829 $('bottom-panel').style.visibility = 'visible';
781
782 if (loadTimeData.valueExists('serverpromo')) { 830 if (loadTimeData.valueExists('serverpromo')) {
783 var promo = loadTimeData.getString('serverpromo'); 831 var promo = loadTimeData.getString('serverpromo');
784 var tags = ['IMG']; 832 var tags = ['IMG'];
785 var attrs = { 833 var attrs = {
786 src: function(node, value) { 834 src: function(node, value) {
787 return node.tagName == 'IMG' && 835 return node.tagName == 'IMG' &&
788 /^data\:image\/(?:png|gif|jpe?g)/.test(value); 836 /^data\:image\/(?:png|gif|jpe?g)/.test(value);
789 }, 837 },
790 }; 838 };
791 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() { 839 showNotification(parseHtmlSubset(promo, tags, attrs), [], function() {
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 */ 993 */
946 function onNotificationTransitionEnd(e) { 994 function onNotificationTransitionEnd(e) {
947 if (notificationContainer.classList.contains('inactive')) 995 if (notificationContainer.classList.contains('inactive'))
948 notificationContainer.hidden = true; 996 notificationContainer.hidden = true;
949 } 997 }
950 998
951 function setRecentlyClosedTabs(dataList) { 999 function setRecentlyClosedTabs(dataList) {
952 newTabView.recentlyClosedPage.setDataList(dataList); 1000 newTabView.recentlyClosedPage.setDataList(dataList);
953 } 1001 }
954 1002
955 function setMostVisitedPages(dataList, hasBlacklistedUrls) { 1003 function setMostVisitedPages(data, hasBlacklistedUrls) {
956 var page = newTabView.mostVisitedPage; 1004 var page = newTabView.mostVisitedPage;
957 var state = page.getTileRepositioningState(); 1005 var state = page.getTileRepositioningState();
958 if (state) { 1006 if (state) {
959 if (state.isRemoving) 1007 if (state.isRemoving)
960 page.animateTileRemoval(state.index, dataList); 1008 page.animateTileRemoval(state.index, data);
961 else 1009 else
962 page.animateTileRestoration(state.index, dataList); 1010 page.animateTileRestoration(state.index, data);
963 1011
964 page.resetTileRepositioningState(); 1012 page.resetTileRepositioningState();
965 } else { 1013 } else {
966 page.setDataList(dataList); 1014 page.setDataList(data);
967 cr.dispatchSimpleEvent(document, 'sectionready', true, true); 1015 cr.dispatchSimpleEvent(document, 'sectionready', true, true);
968 } 1016 }
969 } 1017 }
970 1018
971 function setForeignSessions(dataList, isTabSyncEnabled) { 1019 function setForeignSessions(dataList, isTabSyncEnabled) {
972 newTabView.otherDevicesPage.setDataList(dataList); 1020 newTabView.otherDevicesPage.setDataList(dataList);
973 } 1021 }
974 1022
975 function getThumbnailUrl(url) { 1023 function getThumbnailUrl(url) {
976 return 'chrome://thumb/' + url; 1024 return 'chrome://thumb/' + url;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 } 1062 }
1015 1063
1016 function appsPrefChangeCallback() { 1064 function appsPrefChangeCallback() {
1017 return newTabView.appsPrefChangedCallback.apply(newTabView, arguments); 1065 return newTabView.appsPrefChangedCallback.apply(newTabView, arguments);
1018 } 1066 }
1019 1067
1020 function getAppsCallback() { 1068 function getAppsCallback() {
1021 return newTabView.getAppsCallback.apply(newTabView, arguments); 1069 return newTabView.getAppsCallback.apply(newTabView, arguments);
1022 } 1070 }
1023 1071
1072 function getAppsPageIndex() {
1073 return newTabView.getAppsPageIndex.apply(newTabView, arguments);
1074 }
1075
1024 function getCardSlider() { 1076 function getCardSlider() {
1025 return newTabView.cardSlider; 1077 return newTabView.cardSlider;
1026 } 1078 }
1027 1079
1028 function setAppToBeHighlighted(appId) { 1080 function setAppToBeHighlighted(appId) {
1029 newTabView.highlightAppId = appId; 1081 newTabView.highlightAppId = appId;
1030 } 1082 }
1031 1083
1032 function layout(opt_animate) { 1084 function layout(opt_animate) {
1033 newTabView.layout(opt_animate); 1085 newTabView.layout(opt_animate);
1034 } 1086 }
1035 1087
1036 function getContentWidth() { 1088 function getContentWidth() {
1037 return newTabView.contentWidth; 1089 return newTabView.contentWidth;
1038 } 1090 }
1039 1091
1040 // Return an object with all the exports 1092 // Return an object with all the exports
1041 return { 1093 return {
1042 APP_LAUNCH: APP_LAUNCH, 1094 APP_LAUNCH: APP_LAUNCH,
1043 appAdded: appAdded, 1095 appAdded: appAdded,
1044 appMoved: appMoved, 1096 appMoved: appMoved,
1045 appRemoved: appRemoved, 1097 appRemoved: appRemoved,
1046 appsPrefChangeCallback: appsPrefChangeCallback, 1098 appsPrefChangeCallback: appsPrefChangeCallback,
1047 getAppsCallback: getAppsCallback, 1099 getAppsCallback: getAppsCallback,
1100 getAppsPageIndex: getAppsPageIndex,
1048 getCardSlider: getCardSlider, 1101 getCardSlider: getCardSlider,
1049 getContentWidth: getContentWidth, 1102 getContentWidth: getContentWidth,
1050 getThumbnailUrl: getThumbnailUrl, 1103 getThumbnailUrl: getThumbnailUrl,
1051 incrementHoveredThumbnailCount: incrementHoveredThumbnailCount, 1104 incrementHoveredThumbnailCount: incrementHoveredThumbnailCount,
1052 layout: layout, 1105 layout: layout,
1053 logTimeToClickAndHoverCount: logTimeToClickAndHoverCount, 1106 logTimeToClickAndHoverCount: logTimeToClickAndHoverCount,
1107 // This property is being used to disable NTP5 features that are not ready
1108 // yet. Right now this is being used just to disable Apps page.
1109 // TODO(pedrosimonetti): Remove this property after porting Apps Page.
1110 ntp5: true,
1054 NtpFollowAction: NtpFollowAction, 1111 NtpFollowAction: NtpFollowAction,
1055 onLoad: onLoad, 1112 onLoad: onLoad,
1056 setAppToBeHighlighted: setAppToBeHighlighted, 1113 setAppToBeHighlighted: setAppToBeHighlighted,
1057 setBookmarkBarAttached: setBookmarkBarAttached, 1114 setBookmarkBarAttached: setBookmarkBarAttached,
1058 setForeignSessions: setForeignSessions, 1115 setForeignSessions: setForeignSessions,
1059 setMostVisitedPages: setMostVisitedPages, 1116 setMostVisitedPages: setMostVisitedPages,
1060 setRecentlyClosedTabs: setRecentlyClosedTabs, 1117 setRecentlyClosedTabs: setRecentlyClosedTabs,
1061 showNotification: showNotification, 1118 showNotification: showNotification,
1062 themeChanged: themeChanged, 1119 themeChanged: themeChanged,
1063 }; 1120 };
1064 }); 1121 });
1065 1122
1066 document.addEventListener('DOMContentLoaded', ntp.onLoad); 1123 document.addEventListener('DOMContentLoaded', ntp.onLoad);
1067 1124
1068 var toCssPx = cr.ui.toCssPx; 1125 var toCssPx = cr.ui.toCssPx;
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/ntp_search/thumbnail_page.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698