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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 appAdded(highlightApp, true); | 312 appAdded(highlightApp, true); |
313 | 313 |
314 // Mark the current page. | 314 // Mark the current page. |
315 cardSlider.currentCardValue.navigationDot.classList.add('selected'); | 315 cardSlider.currentCardValue.navigationDot.classList.add('selected'); |
316 logEvent('apps.layout: ' + (Date.now() - startTime)); | 316 logEvent('apps.layout: ' + (Date.now() - startTime)); |
317 | 317 |
318 document.documentElement.classList.remove('starting-up'); | 318 document.documentElement.classList.remove('starting-up'); |
319 } | 319 } |
320 | 320 |
321 /** | 321 /** |
322 * Called by chrome when a new app has been added to chrome. | 322 * Called by chrome when a new app has been added to chrome or has been |
323 * @param {Object} app A data structure full of relevant information for the | 323 * enabled if previously disabled. |
324 * app. | 324 * @param {Object} appData A data structure full of relevant information for |
| 325 * the app. |
325 */ | 326 */ |
326 function appAdded(app, opt_highlight) { | 327 function appAdded(appData, opt_highlight) { |
327 if (app.id == highlightAppId) { | 328 if (appData.id == highlightAppId) { |
328 opt_highlight = true; | 329 opt_highlight = true; |
329 highlightAppId = null; | 330 highlightAppId = null; |
330 } | 331 } |
331 | 332 |
332 var pageIndex = app.page_index || 0; | 333 var pageIndex = appData.page_index || 0; |
333 | 334 |
334 if (pageIndex >= appsPages.length) { | 335 if (pageIndex >= appsPages.length) { |
335 while (pageIndex >= appsPages.length) { | 336 while (pageIndex >= appsPages.length) { |
336 appendAppsPage(new ntp4.AppsPage(), ''); | 337 appendAppsPage(new ntp4.AppsPage(), ''); |
337 } | 338 } |
338 updateSliderCards(); | 339 updateSliderCards(); |
339 } | 340 } |
340 | 341 |
341 var page = appsPages[pageIndex]; | 342 var page = appsPages[pageIndex]; |
342 page.appendApp(app, opt_highlight); | 343 var app = $(appData.id); |
| 344 if (app) |
| 345 app.replaceAppData(appData); |
| 346 else |
| 347 page.appendApp(appData, opt_highlight); |
343 } | 348 } |
344 | 349 |
345 /** | 350 /** |
346 * Sets that an app should be highlighted if it is added. Called right before | 351 * Sets that an app should be highlighted if it is added. Called right before |
347 * appAdded for new installs. | 352 * appAdded for new installs. |
348 */ | 353 */ |
349 function setAppToBeHighlighted(appId) { | 354 function setAppToBeHighlighted(appId) { |
350 highlightAppId = appId; | 355 highlightAppId = appId; |
351 } | 356 } |
352 | 357 |
353 /** | 358 /** |
354 * Called by chrome when an existing app has been removed/uninstalled from | 359 * Called by chrome when an existing app has been disabled or |
355 * chrome. | 360 * removed/uninstalled from chrome. |
356 * @param {Object} appData A data structure full of relevant information for | 361 * @param {Object} appData A data structure full of relevant information for |
357 * the app. | 362 * the app. |
| 363 * @param {boolean} isUninstall True if the app is being uninstalled; |
| 364 * false if the app is being disabled. |
358 */ | 365 */ |
359 function appRemoved(appData) { | 366 function appRemoved(appData, isUninstall) { |
360 var app = $(appData.id); | 367 var app = $(appData.id); |
361 assert(app, 'trying to remove an app that doesn\'t exist'); | 368 assert(app, 'trying to remove an app that doesn\'t exist'); |
362 app.remove(); | 369 |
| 370 if (!isUninstall) |
| 371 app.replaceAppData(appData); |
| 372 else |
| 373 app.remove(); |
363 } | 374 } |
364 | 375 |
365 /** | 376 /** |
366 * Given a theme resource name, construct a URL for it. | 377 * Given a theme resource name, construct a URL for it. |
367 * @param {string} resourceName The name of the resource. | 378 * @param {string} resourceName The name of the resource. |
368 * @return {string} A url which can be used to load the resource. | 379 * @return {string} A url which can be used to load the resource. |
369 */ | 380 */ |
370 function getThemeUrl(resourceName) { | 381 function getThemeUrl(resourceName) { |
371 return 'chrome://theme/' + resourceName; | 382 return 'chrome://theme/' + resourceName; |
372 } | 383 } |
(...skipping 10 matching lines...) Expand all Loading... |
383 // by only calling it for changes across different instances of the NTP | 394 // by only calling it for changes across different instances of the NTP |
384 // (i.e. two separate tabs both showing NTP). | 395 // (i.e. two separate tabs both showing NTP). |
385 for (var j = 0; j < data.apps.length; ++j) { | 396 for (var j = 0; j < data.apps.length; ++j) { |
386 for (var i = 0; i < apps.length; ++i) { | 397 for (var i = 0; i < apps.length; ++i) { |
387 if (data.apps[j]['id'] == apps[i].appId) | 398 if (data.apps[j]['id'] == apps[i].appId) |
388 apps[i].appData = data.apps[j]; | 399 apps[i].appData = data.apps[j]; |
389 } | 400 } |
390 } | 401 } |
391 } | 402 } |
392 | 403 |
| 404 /** |
| 405 * Listener for offline status change events. Updates apps that are |
| 406 * not offline-enabled to be grayscale if the browser is offline. |
| 407 */ |
| 408 function updateOfflineEnabledApps() { |
| 409 var apps = document.querySelectorAll('.app'); |
| 410 for (var i = 0; i < apps.length; ++i) { |
| 411 if (apps[i].appData.enabled && !apps[i].appData.offline_enabled) |
| 412 apps[i].setIcon(); |
| 413 } |
| 414 } |
| 415 |
393 function getCardSlider() { | 416 function getCardSlider() { |
394 return cardSlider; | 417 return cardSlider; |
395 } | 418 } |
396 | 419 |
397 /** | 420 /** |
398 * Invoked whenever the pages in apps-page-list have changed so that | 421 * Invoked whenever the pages in apps-page-list have changed so that |
399 * the Slider knows about the new elements. | 422 * the Slider knows about the new elements. |
400 */ | 423 */ |
401 function updateSliderCards() { | 424 function updateSliderCards() { |
402 var pageNo = cardSlider.currentCard; | 425 var pageNo = cardSlider.currentCard; |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 getCardSlider: getCardSlider, | 811 getCardSlider: getCardSlider, |
789 initialize: initialize, | 812 initialize: initialize, |
790 isRTL: isRTL, | 813 isRTL: isRTL, |
791 leaveRearrangeMode: leaveRearrangeMode, | 814 leaveRearrangeMode: leaveRearrangeMode, |
792 saveAppPageName: saveAppPageName, | 815 saveAppPageName: saveAppPageName, |
793 setAppToBeHighlighted: setAppToBeHighlighted, | 816 setAppToBeHighlighted: setAppToBeHighlighted, |
794 setBookmarksData: setBookmarksData, | 817 setBookmarksData: setBookmarksData, |
795 setMostVisitedPages: setMostVisitedPages, | 818 setMostVisitedPages: setMostVisitedPages, |
796 setRecentlyClosedTabs: setRecentlyClosedTabs, | 819 setRecentlyClosedTabs: setRecentlyClosedTabs, |
797 showNotification: showNotification, | 820 showNotification: showNotification, |
798 themeChanged: themeChanged | 821 themeChanged: themeChanged, |
| 822 updateOfflineEnabledApps: updateOfflineEnabledApps |
799 }; | 823 }; |
800 }); | 824 }); |
801 | 825 |
802 // publish ntp globals | 826 // publish ntp globals |
803 // TODO(estade): update the content handlers to use ntp namespace instead of | 827 // TODO(estade): update the content handlers to use ntp namespace instead of |
804 // making these global. | 828 // making these global. |
805 var assert = ntp4.assert; | 829 var assert = ntp4.assert; |
806 var getAppsCallback = ntp4.getAppsCallback; | 830 var getAppsCallback = ntp4.getAppsCallback; |
807 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; | 831 var appsPrefChangeCallback = ntp4.appsPrefChangeCallback; |
808 var themeChanged = ntp4.themeChanged; | 832 var themeChanged = ntp4.themeChanged; |
809 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; | 833 var recentlyClosedTabs = ntp4.setRecentlyClosedTabs; |
810 var setMostVisitedPages = ntp4.setMostVisitedPages; | 834 var setMostVisitedPages = ntp4.setMostVisitedPages; |
811 | 835 |
812 document.addEventListener('DOMContentLoaded', ntp4.initialize); | 836 document.addEventListener('DOMContentLoaded', ntp4.initialize); |
| 837 window.addEventListener('online', ntp4.updateOfflineEnabledApps); |
| 838 window.addEventListener('offline', ntp4.updateOfflineEnabledApps); |
OLD | NEW |