OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 appAdded(highlightApp, true); | 335 appAdded(highlightApp, true); |
336 | 336 |
337 // Mark the current page. | 337 // Mark the current page. |
338 cardSlider.currentCardValue.navigationDot.classList.add('selected'); | 338 cardSlider.currentCardValue.navigationDot.classList.add('selected'); |
339 logEvent('apps.layout: ' + (Date.now() - startTime)); | 339 logEvent('apps.layout: ' + (Date.now() - startTime)); |
340 | 340 |
341 document.documentElement.classList.remove('starting-up'); | 341 document.documentElement.classList.remove('starting-up'); |
342 } | 342 } |
343 | 343 |
344 /** | 344 /** |
345 * Called by chrome when a new app has been added to chrome. | 345 * Called by chrome when a new app has been added to chrome or has been |
346 * @param {Object} app A data structure full of relevant information for the | 346 * enabled if previously disabled. |
347 * app. | 347 * @param {Object} appData A data structure full of relevant information for |
348 * the app. | |
348 */ | 349 */ |
349 function appAdded(app, opt_highlight) { | 350 function appAdded(app, opt_highlight) { |
350 // If the page is already open when a new app is installed, the hash will | 351 // If the page is already open when a new app is installed, the hash will |
351 // be set once again. | 352 // be set once again. |
352 var appID = getAndClearAppIDHash(); | 353 var appID = getAndClearAppIDHash(); |
353 if (appID == app.id) | 354 if (appID == app.id) |
354 opt_highlight = true; | 355 opt_highlight = true; |
355 | 356 |
356 var pageIndex = app.page_index || 0; | 357 var pageIndex = app.page_index || 0; |
357 | 358 |
358 if (pageIndex >= appsPages.length) { | 359 if (pageIndex >= appsPages.length) { |
359 while (pageIndex >= appsPages.length) { | 360 while (pageIndex >= appsPages.length) { |
360 appendAppsPage(new ntp4.AppsPage(), ''); | 361 appendAppsPage(new ntp4.AppsPage(), ''); |
361 } | 362 } |
362 updateSliderCards(); | 363 updateSliderCards(); |
363 } | 364 } |
364 | 365 |
365 var page = appsPages[pageIndex]; | 366 var page = appsPages[pageIndex]; |
366 if (opt_highlight) | 367 if (opt_highlight) |
367 cardSlider.selectCardByValue(page); | 368 cardSlider.selectCardByValue(page); |
368 page.appendApp(app, true); | 369 var app = $(appData.id); |
370 if (app) { | |
Evan Stade
2011/08/30 03:34:14
no curlies
Yoyo Zhou
2011/08/30 17:37:10
Done.
| |
371 app.replaceAppData(appData); | |
372 } else { | |
373 page.appendApp(appData, true); | |
374 } | |
369 } | 375 } |
370 | 376 |
371 /** | 377 /** |
372 * Called by chrome when an existing app has been removed/uninstalled from | 378 * Called by chrome when an existing app has been disabled or |
373 * chrome. | 379 * removed/uninstalled from chrome. |
374 * @param {Object} appData A data structure full of relevant information for | 380 * @param {Object} appData A data structure full of relevant information for |
375 * the app. | 381 * the app. |
376 */ | 382 */ |
377 function appRemoved(appData) { | 383 function appRemoved(appData, is_uninstall) { |
Evan Stade
2011/08/30 03:34:14
isUninstall
also, doc the param
Yoyo Zhou
2011/08/30 17:37:10
Done.
| |
378 var app = $(appData.id); | 384 var app = $(appData.id); |
379 assert(app, 'trying to remove an app that doesn\'t exist'); | 385 assert(app, 'trying to remove an app that doesn\'t exist'); |
380 | 386 |
381 var tile = findAncestorByClass(app, 'tile'); | 387 if (!is_uninstall) { |
382 tile.doRemove(); | 388 app.replaceAppData(appData); |
389 } else { | |
390 var tile = findAncestorByClass(app, 'tile'); | |
391 tile.doRemove(); | |
392 } | |
383 } | 393 } |
384 | 394 |
385 /** | 395 /** |
386 * Given a theme resource name, construct a URL for it. | 396 * Given a theme resource name, construct a URL for it. |
387 * @param {string} resourceName The name of the resource. | 397 * @param {string} resourceName The name of the resource. |
388 * @return {string} A url which can be used to load the resource. | 398 * @return {string} A url which can be used to load the resource. |
389 */ | 399 */ |
390 function getThemeUrl(resourceName) { | 400 function getThemeUrl(resourceName) { |
391 return 'chrome://theme/' + resourceName; | 401 return 'chrome://theme/' + resourceName; |
392 } | 402 } |
(...skipping 10 matching lines...) Expand all Loading... | |
403 // by only calling it for changes across different instances of the NTP | 413 // by only calling it for changes across different instances of the NTP |
404 // (i.e. two separate tabs both showing NTP). | 414 // (i.e. two separate tabs both showing NTP). |
405 for (var j = 0; j < data.apps.length; ++j) { | 415 for (var j = 0; j < data.apps.length; ++j) { |
406 for (var i = 0; i < apps.length; ++i) { | 416 for (var i = 0; i < apps.length; ++i) { |
407 if (data.apps[j]['id'] == apps[i].appId) | 417 if (data.apps[j]['id'] == apps[i].appId) |
408 apps[i].appData = data.apps[j]; | 418 apps[i].appData = data.apps[j]; |
409 } | 419 } |
410 } | 420 } |
411 } | 421 } |
412 | 422 |
423 /** | |
424 * Listener for offline status change events. Updates apps that are | |
425 * not offline-enabled to be grayscale if the browser is offline. | |
426 */ | |
427 function updateOfflineEnabledApps() { | |
428 for (var i = 0; i < apps.length; ++i) { | |
429 if (apps[i].appData.enabled && !apps[i].appData.offline_enabled) | |
430 apps[i].setIcon(); | |
431 } | |
432 } | |
433 | |
413 function getCardSlider() { | 434 function getCardSlider() { |
414 return cardSlider; | 435 return cardSlider; |
415 } | 436 } |
416 | 437 |
417 /** | 438 /** |
418 * Invoked whenever the pages in apps-page-list have changed so that | 439 * Invoked whenever the pages in apps-page-list have changed so that |
419 * the Slider knows about the new elements. | 440 * the Slider knows about the new elements. |
420 */ | 441 */ |
421 function updateSliderCards() { | 442 function updateSliderCards() { |
422 var pageNo = cardSlider.currentCard; | 443 var pageNo = cardSlider.currentCard; |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
772 getAppsPageIndex: getAppsPageIndex, | 793 getAppsPageIndex: getAppsPageIndex, |
773 getCardSlider: getCardSlider, | 794 getCardSlider: getCardSlider, |
774 initialize: initialize, | 795 initialize: initialize, |
775 isRTL: isRTL, | 796 isRTL: isRTL, |
776 leaveRearrangeMode: leaveRearrangeMode, | 797 leaveRearrangeMode: leaveRearrangeMode, |
777 saveAppPageName: saveAppPageName, | 798 saveAppPageName: saveAppPageName, |
778 setBookmarksData: setBookmarksData, | 799 setBookmarksData: setBookmarksData, |
779 setMostVisitedPages: setMostVisitedPages, | 800 setMostVisitedPages: setMostVisitedPages, |
780 setRecentlyClosedTabs: setRecentlyClosedTabs, | 801 setRecentlyClosedTabs: setRecentlyClosedTabs, |
781 showNotification: showNotification, | 802 showNotification: showNotification, |
782 themeChanged: themeChanged | 803 themeChanged: themeChanged, |
804 updateOfflineEnabledApps: updateOfflineEnabledApps | |
783 }; | 805 }; |
784 }); | 806 }); |
785 | 807 |
786 // publish ntp globals | 808 // publish ntp globals |
787 // TODO(estade): update the content handlers to use ntp namespace instead of | 809 // TODO(estade): update the content handlers to use ntp namespace instead of |
788 // making these global. | 810 // making these global. |
789 var assert = ntp4.assert; | 811 var assert = ntp4.assert; |
790 var getAppsCallback = ntp4.getAppsCallback; | 812 var getAppsCallback = ntp4.getAppsCallback; |
791 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 813 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
792 var themeChanged = ntp4.themeChanged; | 814 var themeChanged = ntp4.themeChanged; |
793 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 815 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
794 var setMostVisitedPages = ntp4.setMostVisitedPages; | 816 var setMostVisitedPages = ntp4.setMostVisitedPages; |
795 | 817 |
796 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 818 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
819 document.addEventListener('online', ntp4.updateOfflineEnabledApps); | |
820 document.addEventListener('offline', ntp4.updateOfflineEnabledApps); | |
OLD | NEW |