OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 * WallpaperManager constructor. | 6 * WallpaperManager constructor. |
7 * | 7 * |
8 * WallpaperManager objects encapsulate the functionality of the wallpaper | 8 * WallpaperManager objects encapsulate the functionality of the wallpaper |
9 * manager extension. | 9 * manager extension. |
10 * | 10 * |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 i18nTemplate.process(this.document_, loadTimeData); | 246 i18nTemplate.process(this.document_, loadTimeData); |
247 this.initCategoriesList_(); | 247 this.initCategoriesList_(); |
248 this.initThumbnailsGrid_(); | 248 this.initThumbnailsGrid_(); |
249 this.presetCategory_(); | 249 this.presetCategory_(); |
250 | 250 |
251 $('file-selector').addEventListener( | 251 $('file-selector').addEventListener( |
252 'change', this.onFileSelectorChanged_.bind(this)); | 252 'change', this.onFileSelectorChanged_.bind(this)); |
253 $('set-wallpaper-layout').addEventListener( | 253 $('set-wallpaper-layout').addEventListener( |
254 'change', this.onWallpaperLayoutChanged_.bind(this)); | 254 'change', this.onWallpaperLayoutChanged_.bind(this)); |
255 | 255 |
256 if (loadTimeData.valueExists('wallpaperAppName')) { | |
257 $('wallpaper-set-by-message').hidden = false; | |
flackr
2014/06/17 15:20:34
Use the :empty CSS selector to automatically hide
bshe
2014/06/17 19:01:44
Done.
| |
258 $('wallpaper-set-by-message').innerText = loadTimeData.getStringF( | |
flackr
2014/06/17 15:20:34
s/innerText/textContent
bshe
2014/06/17 19:01:44
Done.
| |
259 'currentWallpaperSetByMessage', str('wallpaperAppName')); | |
260 } | |
261 | |
256 if (this.enableOnlineWallpaper_) { | 262 if (this.enableOnlineWallpaper_) { |
257 var self = this; | 263 var self = this; |
258 $('surprise-me').hidden = false; | 264 $('surprise-me').hidden = false; |
259 $('surprise-me').addEventListener('click', | 265 $('surprise-me').addEventListener('click', |
260 this.toggleSurpriseMe_.bind(this)); | 266 this.toggleSurpriseMe_.bind(this)); |
261 Constants.WallpaperSyncStorage.get(Constants.AccessSurpriseMeEnabledKey, | 267 Constants.WallpaperSyncStorage.get(Constants.AccessSurpriseMeEnabledKey, |
262 function(items) { | 268 function(items) { |
263 // Surprise me has been moved from local to sync storage, prefer | 269 // Surprise me has been moved from local to sync storage, prefer |
264 // values from sync, but if unset check local and update synced pref | 270 // values from sync, but if unset check local and update synced pref |
265 // if applicable. | 271 // if applicable. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 return; | 351 return; |
346 this.removeCustomWallpaper(item.baseURL); | 352 this.removeCustomWallpaper(item.baseURL); |
347 wallpaperGrid.dataModel.splice(selectedIndex, 1); | 353 wallpaperGrid.dataModel.splice(selectedIndex, 1); |
348 // Calculate the number of remaining custom wallpapers. The add new button | 354 // Calculate the number of remaining custom wallpapers. The add new button |
349 // in data model needs to be excluded. | 355 // in data model needs to be excluded. |
350 var customWallpaperCount = wallpaperGrid.dataModel.length - 1; | 356 var customWallpaperCount = wallpaperGrid.dataModel.length - 1; |
351 if (customWallpaperCount == 0) { | 357 if (customWallpaperCount == 0) { |
352 // Active custom wallpaper is also copied in chronos data dir. It needs | 358 // Active custom wallpaper is also copied in chronos data dir. It needs |
353 // to be deleted. | 359 // to be deleted. |
354 chrome.wallpaperPrivate.resetWallpaper(); | 360 chrome.wallpaperPrivate.resetWallpaper(); |
361 this.hideWallpaperSetByMessage_(); | |
flackr
2014/06/17 15:20:34
Rather than sprinkling this throughout the code, c
bshe
2014/06/17 19:01:44
Unfortunately, there are a few private APIs(setWal
flackr
2014/06/18 00:59:48
Even if the only thing "onWallpaperChanged" does i
bshe
2014/06/18 21:07:42
make sense. Added a onWallpaperChanged function an
| |
355 } else { | 362 } else { |
356 selectedIndex = Math.min(selectedIndex, customWallpaperCount - 1); | 363 selectedIndex = Math.min(selectedIndex, customWallpaperCount - 1); |
357 wallpaperGrid.selectionModel.selectedIndex = selectedIndex; | 364 wallpaperGrid.selectionModel.selectedIndex = selectedIndex; |
358 } | 365 } |
359 event.cancelBubble = true; | 366 event.cancelBubble = true; |
360 } | 367 } |
361 }; | 368 }; |
362 | 369 |
363 /** | 370 /** |
364 * Decides if a command can be executed on current target. | 371 * Decides if a command can be executed on current target. |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 this.wallpaperRequest_.addEventListener('loadend', function() { | 473 this.wallpaperRequest_.addEventListener('loadend', function() { |
467 // Close window on wallpaper loading finished. | 474 // Close window on wallpaper loading finished. |
468 window.close(); | 475 window.close(); |
469 }); | 476 }); |
470 } else { | 477 } else { |
471 window.close(); | 478 window.close(); |
472 } | 479 } |
473 }; | 480 }; |
474 | 481 |
475 /** | 482 /** |
483 * Hides the wallpaper set by message. It should be called after user changed | |
484 * wallpaper through wallpaper picker. | |
485 */ | |
486 WallpaperManager.prototype.hideWallpaperSetByMessage_ = function() { | |
487 $('wallpaper-set-by-message').hidden = true; | |
488 $('wallpaper-set-by-message').innerText = ''; | |
flackr
2014/06/17 15:20:34
s/innerText/textContent
bshe
2014/06/17 19:01:44
Done. There is only one line left in this function
| |
489 } | |
490 | |
491 /** | |
476 * Sets wallpaper to the corresponding wallpaper of selected thumbnail. | 492 * Sets wallpaper to the corresponding wallpaper of selected thumbnail. |
477 * @param {{baseURL: string, layout: string, source: string, | 493 * @param {{baseURL: string, layout: string, source: string, |
478 * availableOffline: boolean, opt_dynamicURL: string, | 494 * availableOffline: boolean, opt_dynamicURL: string, |
479 * opt_author: string, opt_authorWebsite: string}} | 495 * opt_author: string, opt_authorWebsite: string}} |
480 * selectedItem the selected item in WallpaperThumbnailsGrid's data | 496 * selectedItem the selected item in WallpaperThumbnailsGrid's data |
481 * model. | 497 * model. |
482 */ | 498 */ |
483 WallpaperManager.prototype.setSelectedWallpaper_ = function(selectedItem) { | 499 WallpaperManager.prototype.setSelectedWallpaper_ = function(selectedItem) { |
484 var self = this; | 500 var self = this; |
485 switch (selectedItem.source) { | 501 switch (selectedItem.source) { |
486 case Constants.WallpaperSourceEnum.Custom: | 502 case Constants.WallpaperSourceEnum.Custom: |
487 var errorHandler = this.onFileSystemError_.bind(this); | 503 var errorHandler = this.onFileSystemError_.bind(this); |
488 var setActive = function() { | 504 var setActive = function() { |
489 self.wallpaperGrid_.activeItem = selectedItem; | 505 self.wallpaperGrid_.activeItem = selectedItem; |
490 self.currentWallpaper_ = selectedItem.baseURL; | 506 self.currentWallpaper_ = selectedItem.baseURL; |
507 self.hideWallpaperSetByMessage_(); | |
491 }; | 508 }; |
492 var success = function(dirEntry) { | 509 var success = function(dirEntry) { |
493 dirEntry.getFile(selectedItem.baseURL, {create: false}, | 510 dirEntry.getFile(selectedItem.baseURL, {create: false}, |
494 function(fileEntry) { | 511 function(fileEntry) { |
495 fileEntry.file(function(file) { | 512 fileEntry.file(function(file) { |
496 var reader = new FileReader(); | 513 var reader = new FileReader(); |
497 reader.readAsArrayBuffer(file); | 514 reader.readAsArrayBuffer(file); |
498 reader.addEventListener('error', errorHandler); | 515 reader.addEventListener('error', errorHandler); |
499 reader.addEventListener('load', function(e) { | 516 reader.addEventListener('load', function(e) { |
500 self.setCustomWallpaper(e.target.result, | 517 self.setCustomWallpaper(e.target.result, |
501 selectedItem.layout, | 518 selectedItem.layout, |
502 false, selectedItem.baseURL, | 519 false, selectedItem.baseURL, |
503 setActive, errorHandler); | 520 setActive, errorHandler); |
504 }); | 521 }); |
505 }, errorHandler); | 522 }, errorHandler); |
506 }, errorHandler); | 523 }, errorHandler); |
507 } | 524 } |
508 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, | 525 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, |
509 success, errorHandler); | 526 success, errorHandler); |
510 break; | 527 break; |
511 case Constants.WallpaperSourceEnum.OEM: | 528 case Constants.WallpaperSourceEnum.OEM: |
512 // Resets back to default wallpaper. | 529 // Resets back to default wallpaper. |
513 chrome.wallpaperPrivate.resetWallpaper(); | 530 chrome.wallpaperPrivate.resetWallpaper(); |
531 this.hideWallpaperSetByMessage_(); | |
514 this.currentWallpaper_ = selectedItem.baseURL; | 532 this.currentWallpaper_ = selectedItem.baseURL; |
515 this.wallpaperGrid_.activeItem = selectedItem; | 533 this.wallpaperGrid_.activeItem = selectedItem; |
516 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, | 534 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, |
517 selectedItem.source); | 535 selectedItem.source); |
518 break; | 536 break; |
519 case Constants.WallpaperSourceEnum.Online: | 537 case Constants.WallpaperSourceEnum.Online: |
520 var wallpaperURL = selectedItem.baseURL + | 538 var wallpaperURL = selectedItem.baseURL + |
521 Constants.HighResolutionSuffix; | 539 Constants.HighResolutionSuffix; |
522 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem); | 540 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem); |
523 | 541 |
524 chrome.wallpaperPrivate.setWallpaperIfExists(wallpaperURL, | 542 chrome.wallpaperPrivate.setWallpaperIfExists(wallpaperURL, |
525 selectedItem.layout, | 543 selectedItem.layout, |
526 function(exists) { | 544 function(exists) { |
527 if (exists) { | 545 if (exists) { |
528 self.currentWallpaper_ = wallpaperURL; | 546 self.currentWallpaper_ = wallpaperURL; |
529 self.wallpaperGrid_.activeItem = selectedItem; | 547 self.wallpaperGrid_.activeItem = selectedItem; |
548 self.hideWallpaperSetByMessage_(); | |
530 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, | 549 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, |
531 selectedItem.source); | 550 selectedItem.source); |
532 return; | 551 return; |
533 } | 552 } |
534 | 553 |
535 // Falls back to request wallpaper from server. | 554 // Falls back to request wallpaper from server. |
536 if (self.wallpaperRequest_) | 555 if (self.wallpaperRequest_) |
537 self.wallpaperRequest_.abort(); | 556 self.wallpaperRequest_.abort(); |
538 | 557 |
539 self.wallpaperRequest_ = new XMLHttpRequest(); | 558 self.wallpaperRequest_ = new XMLHttpRequest(); |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
886 chrome.runtime.lastError.message != str('canceledWallpaper')) { | 905 chrome.runtime.lastError.message != str('canceledWallpaper')) { |
887 self.showError_(chrome.runtime.lastError.message); | 906 self.showError_(chrome.runtime.lastError.message); |
888 $('set-wallpaper-layout').disabled = true; | 907 $('set-wallpaper-layout').disabled = true; |
889 failure(); | 908 failure(); |
890 } else { | 909 } else { |
891 success(opt_thumbnail); | 910 success(opt_thumbnail); |
892 // Custom wallpapers are not synced yet. If login on a different | 911 // Custom wallpapers are not synced yet. If login on a different |
893 // computer after set a custom wallpaper, wallpaper wont change by sync. | 912 // computer after set a custom wallpaper, wallpaper wont change by sync. |
894 WallpaperUtil.saveWallpaperInfo(fileName, layout, | 913 WallpaperUtil.saveWallpaperInfo(fileName, layout, |
895 Constants.WallpaperSourceEnum.Custom); | 914 Constants.WallpaperSourceEnum.Custom); |
915 self.hideWallpaperSetByMessage_(); | |
896 } | 916 } |
897 }; | 917 }; |
898 | 918 |
899 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, layout, | 919 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, layout, |
900 generateThumbnail, | 920 generateThumbnail, |
901 fileName, onFinished); | 921 fileName, onFinished); |
902 }; | 922 }; |
903 | 923 |
904 /** | 924 /** |
905 * Sets wallpaper finished. Displays error message if any. | 925 * Sets wallpaper finished. Displays error message if any. |
906 * @param {WallpaperThumbnailsGridItem=} opt_selectedGridItem The wallpaper | 926 * @param {WallpaperThumbnailsGridItem=} opt_selectedGridItem The wallpaper |
907 * thumbnail grid item. It extends from cr.ui.ListItem. | 927 * thumbnail grid item. It extends from cr.ui.ListItem. |
908 * @param {{baseURL: string, layout: string, source: string, | 928 * @param {{baseURL: string, layout: string, source: string, |
909 * availableOffline: boolean, opt_dynamicURL: string, | 929 * availableOffline: boolean, opt_dynamicURL: string, |
910 * opt_author: string, opt_authorWebsite: string}=} | 930 * opt_author: string, opt_authorWebsite: string}=} |
911 * opt_selectedItem the selected item in WallpaperThumbnailsGrid's data | 931 * opt_selectedItem the selected item in WallpaperThumbnailsGrid's data |
912 * model. | 932 * model. |
913 */ | 933 */ |
914 WallpaperManager.prototype.onFinished_ = function(opt_selectedGridItem, | 934 WallpaperManager.prototype.onFinished_ = function(opt_selectedGridItem, |
915 opt_selectedItem) { | 935 opt_selectedItem) { |
916 if (opt_selectedGridItem) | 936 if (opt_selectedGridItem) |
917 this.progressManager_.hideProgressBar(opt_selectedGridItem); | 937 this.progressManager_.hideProgressBar(opt_selectedGridItem); |
918 | 938 |
919 if (chrome.runtime.lastError != undefined && | 939 if (chrome.runtime.lastError != undefined && |
920 chrome.runtime.lastError.message != str('canceledWallpaper')) { | 940 chrome.runtime.lastError.message != str('canceledWallpaper')) { |
921 this.showError_(chrome.runtime.lastError.message); | 941 this.showError_(chrome.runtime.lastError.message); |
922 } else if (opt_selectedItem) { | 942 } else if (opt_selectedItem) { |
923 this.wallpaperGrid_.activeItem = opt_selectedItem; | 943 this.wallpaperGrid_.activeItem = opt_selectedItem; |
944 this.hideWallpaperSetByMessage_(); | |
924 } | 945 } |
925 }; | 946 }; |
926 | 947 |
927 /** | 948 /** |
928 * Handles the layout setting change of custom wallpaper. | 949 * Handles the layout setting change of custom wallpaper. |
929 */ | 950 */ |
930 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { | 951 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { |
931 var layout = getSelectedLayout(); | 952 var layout = getSelectedLayout(); |
932 var self = this; | 953 var self = this; |
933 chrome.wallpaperPrivate.setCustomWallpaperLayout(layout, function() { | 954 chrome.wallpaperPrivate.setCustomWallpaperLayout(layout, function() { |
934 if (chrome.runtime.lastError != undefined && | 955 if (chrome.runtime.lastError != undefined && |
935 chrome.runtime.lastError.message != str('canceledWallpaper')) { | 956 chrome.runtime.lastError.message != str('canceledWallpaper')) { |
936 self.showError_(chrome.runtime.lastError.message); | 957 self.showError_(chrome.runtime.lastError.message); |
937 self.removeCustomWallpaper(fileName); | 958 self.removeCustomWallpaper(fileName); |
938 $('set-wallpaper-layout').disabled = true; | 959 $('set-wallpaper-layout').disabled = true; |
939 } else { | 960 } else { |
940 WallpaperUtil.saveToStorage(self.currentWallpaper_, layout, false); | 961 WallpaperUtil.saveToStorage(self.currentWallpaper_, layout, false); |
962 self.hideWallpaperSetByMessage_(); | |
941 } | 963 } |
942 }); | 964 }); |
943 }; | 965 }; |
944 | 966 |
945 /** | 967 /** |
946 * Handles user clicking on a different category. | 968 * Handles user clicking on a different category. |
947 */ | 969 */ |
948 WallpaperManager.prototype.onCategoriesChange_ = function() { | 970 WallpaperManager.prototype.onCategoriesChange_ = function() { |
949 var categoriesList = this.categoriesList_; | 971 var categoriesList = this.categoriesList_; |
950 var selectedIndex = categoriesList.selectionModel.selectedIndex; | 972 var selectedIndex = categoriesList.selectionModel.selectedIndex; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1055 } | 1077 } |
1056 } | 1078 } |
1057 } | 1079 } |
1058 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1080 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
1059 this.wallpaperGrid_.selectedItem = selectedItem; | 1081 this.wallpaperGrid_.selectedItem = selectedItem; |
1060 this.wallpaperGrid_.activeItem = selectedItem; | 1082 this.wallpaperGrid_.activeItem = selectedItem; |
1061 } | 1083 } |
1062 }; | 1084 }; |
1063 | 1085 |
1064 })(); | 1086 })(); |
OLD | NEW |