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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 /** | 47 /** |
48 * Index offset of categories parsed from manifest. The All category is added | 48 * Index offset of categories parsed from manifest. The All category is added |
49 * before them. So the offset is 1. | 49 * before them. So the offset is 1. |
50 */ | 50 */ |
51 /** @const */ var OnlineCategoriesOffset = 1; | 51 /** @const */ var OnlineCategoriesOffset = 1; |
52 | 52 |
53 /** | 53 /** |
54 * Returns a translated string. | 54 * Returns a translated string. |
55 * | 55 * |
56 * Wrapper function to make dealing with translated strings more concise. | 56 * Wrapper function to make dealing with translated strings more concise. |
57 * Equivilant to localStrings.getString(id). | |
58 * | 57 * |
59 * @param {string} id The id of the string to return. | 58 * @param {string} id The id of the string to return. |
60 * @return {string} The translated string. | 59 * @return {string} The translated string. |
61 */ | 60 */ |
62 function str(id) { | 61 function str(id) { |
63 return loadTimeData.getString(id); | 62 return loadTimeData.getString(id); |
64 } | 63 } |
65 | 64 |
66 /** | 65 /** |
67 * Retruns the current selected layout. | 66 * Retruns the current selected layout. |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 reader.addEventListener('load', function(e) { | 516 reader.addEventListener('load', function(e) { |
518 self.setCustomWallpaper(e.target.result, | 517 self.setCustomWallpaper(e.target.result, |
519 selectedItem.layout, | 518 selectedItem.layout, |
520 false, selectedItem.baseURL, | 519 false, selectedItem.baseURL, |
521 self.onWallpaperChanged_.bind(self, | 520 self.onWallpaperChanged_.bind(self, |
522 selectedItem, selectedItem.baseURL), | 521 selectedItem, selectedItem.baseURL), |
523 errorHandler); | 522 errorHandler); |
524 }); | 523 }); |
525 }, errorHandler); | 524 }, errorHandler); |
526 }, errorHandler); | 525 }, errorHandler); |
527 } | 526 }; |
528 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, | 527 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, |
529 success, errorHandler); | 528 success, errorHandler); |
530 break; | 529 break; |
531 case Constants.WallpaperSourceEnum.OEM: | 530 case Constants.WallpaperSourceEnum.OEM: |
532 // Resets back to default wallpaper. | 531 // Resets back to default wallpaper. |
533 chrome.wallpaperPrivate.resetWallpaper(); | 532 chrome.wallpaperPrivate.resetWallpaper(); |
534 this.onWallpaperChanged_(selectedItem, selectedItem.baseURL); | 533 this.onWallpaperChanged_(selectedItem, selectedItem.baseURL); |
535 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, | 534 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, |
536 selectedItem.source); | 535 selectedItem.source); |
537 break; | 536 break; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 */ | 867 */ |
869 WallpaperManager.prototype.removeCustomWallpaper = function(fileName) { | 868 WallpaperManager.prototype.removeCustomWallpaper = function(fileName) { |
870 var errorHandler = this.onFileSystemError_.bind(this); | 869 var errorHandler = this.onFileSystemError_.bind(this); |
871 var self = this; | 870 var self = this; |
872 var removeFile = function(fileName) { | 871 var removeFile = function(fileName) { |
873 var success = function(dirEntry) { | 872 var success = function(dirEntry) { |
874 dirEntry.getFile(fileName, {create: false}, function(fileEntry) { | 873 dirEntry.getFile(fileName, {create: false}, function(fileEntry) { |
875 fileEntry.remove(function() { | 874 fileEntry.remove(function() { |
876 }, errorHandler); | 875 }, errorHandler); |
877 }, errorHandler); | 876 }, errorHandler); |
878 } | 877 }; |
879 | 878 |
880 // Removes copy of original. | 879 // Removes copy of original. |
881 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, success, | 880 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, success, |
882 errorHandler); | 881 errorHandler); |
883 | 882 |
884 // Removes generated thumbnail. | 883 // Removes generated thumbnail. |
885 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.THUMBNAIL, success, | 884 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.THUMBNAIL, success, |
886 errorHandler); | 885 errorHandler); |
887 }; | 886 }; |
888 removeFile(fileName); | 887 removeFile(fileName); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 bar.style.left = selectedListItem.offsetLeft + 'px'; | 959 bar.style.left = selectedListItem.offsetLeft + 'px'; |
961 bar.style.width = selectedListItem.offsetWidth + 'px'; | 960 bar.style.width = selectedListItem.offsetWidth + 'px'; |
962 | 961 |
963 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); | 962 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); |
964 var selectedItem; | 963 var selectedItem; |
965 if (selectedListItem.custom) { | 964 if (selectedListItem.custom) { |
966 this.document_.body.setAttribute('custom', ''); | 965 this.document_.body.setAttribute('custom', ''); |
967 var errorHandler = this.onFileSystemError_.bind(this); | 966 var errorHandler = this.onFileSystemError_.bind(this); |
968 var toArray = function(list) { | 967 var toArray = function(list) { |
969 return Array.prototype.slice.call(list || [], 0); | 968 return Array.prototype.slice.call(list || [], 0); |
970 } | 969 }; |
971 | 970 |
972 var self = this; | 971 var self = this; |
973 var processResults = function(entries) { | 972 var processResults = function(entries) { |
974 for (var i = 0; i < entries.length; i++) { | 973 for (var i = 0; i < entries.length; i++) { |
975 var entry = entries[i]; | 974 var entry = entries[i]; |
976 var wallpaperInfo = { | 975 var wallpaperInfo = { |
977 baseURL: entry.name, | 976 baseURL: entry.name, |
978 // The layout will be replaced by the actual value saved in | 977 // The layout will be replaced by the actual value saved in |
979 // local storage when requested later. Layout is not important | 978 // local storage when requested later. Layout is not important |
980 // for constructing thumbnails grid, we use CENTER_CROPPED here | 979 // for constructing thumbnails grid, we use CENTER_CROPPED here |
(...skipping 21 matching lines...) Expand all Loading... |
1002 var lastElement = { | 1001 var lastElement = { |
1003 baseURL: '', | 1002 baseURL: '', |
1004 layout: '', | 1003 layout: '', |
1005 source: Constants.WallpaperSourceEnum.AddNew, | 1004 source: Constants.WallpaperSourceEnum.AddNew, |
1006 availableOffline: true | 1005 availableOffline: true |
1007 }; | 1006 }; |
1008 wallpapersDataModel.push(lastElement); | 1007 wallpapersDataModel.push(lastElement); |
1009 self.wallpaperGrid_.dataModel = wallpapersDataModel; | 1008 self.wallpaperGrid_.dataModel = wallpapersDataModel; |
1010 self.wallpaperGrid_.selectedItem = selectedItem; | 1009 self.wallpaperGrid_.selectedItem = selectedItem; |
1011 self.wallpaperGrid_.activeItem = selectedItem; | 1010 self.wallpaperGrid_.activeItem = selectedItem; |
1012 } | 1011 }; |
1013 | 1012 |
1014 var success = function(dirEntry) { | 1013 var success = function(dirEntry) { |
1015 var dirReader = dirEntry.createReader(); | 1014 var dirReader = dirEntry.createReader(); |
1016 var entries = []; | 1015 var entries = []; |
1017 // All of a directory's entries are not guaranteed to return in a single | 1016 // All of a directory's entries are not guaranteed to return in a single |
1018 // call. | 1017 // call. |
1019 var readEntries = function() { | 1018 var readEntries = function() { |
1020 dirReader.readEntries(function(results) { | 1019 dirReader.readEntries(function(results) { |
1021 if (!results.length) { | 1020 if (!results.length) { |
1022 processResults(entries.sort()); | 1021 processResults(entries.sort()); |
1023 } else { | 1022 } else { |
1024 entries = entries.concat(toArray(results)); | 1023 entries = entries.concat(toArray(results)); |
1025 readEntries(); | 1024 readEntries(); |
1026 } | 1025 } |
1027 }, errorHandler); | 1026 }, errorHandler); |
1028 }; | 1027 }; |
1029 readEntries(); // Start reading dirs. | 1028 readEntries(); // Start reading dirs. |
1030 } | 1029 }; |
1031 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, | 1030 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, |
1032 success, errorHandler); | 1031 success, errorHandler); |
1033 } else { | 1032 } else { |
1034 this.document_.body.removeAttribute('custom'); | 1033 this.document_.body.removeAttribute('custom'); |
1035 for (var key in this.manifest_.wallpaper_list) { | 1034 for (var key in this.manifest_.wallpaper_list) { |
1036 if (selectedIndex == AllCategoryIndex || | 1035 if (selectedIndex == AllCategoryIndex || |
1037 this.manifest_.wallpaper_list[key].categories.indexOf( | 1036 this.manifest_.wallpaper_list[key].categories.indexOf( |
1038 selectedIndex - OnlineCategoriesOffset) != -1) { | 1037 selectedIndex - OnlineCategoriesOffset) != -1) { |
1039 var wallpaperInfo = { | 1038 var wallpaperInfo = { |
1040 baseURL: this.manifest_.wallpaper_list[key].base_url, | 1039 baseURL: this.manifest_.wallpaper_list[key].base_url, |
(...skipping 19 matching lines...) Expand all Loading... |
1060 } | 1059 } |
1061 } | 1060 } |
1062 } | 1061 } |
1063 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1062 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
1064 this.wallpaperGrid_.selectedItem = selectedItem; | 1063 this.wallpaperGrid_.selectedItem = selectedItem; |
1065 this.wallpaperGrid_.activeItem = selectedItem; | 1064 this.wallpaperGrid_.activeItem = selectedItem; |
1066 } | 1065 } |
1067 }; | 1066 }; |
1068 | 1067 |
1069 })(); | 1068 })(); |
OLD | NEW |