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