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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 $('wallpaper-grid').classList.add('image-picker-offline'); | 311 $('wallpaper-grid').classList.add('image-picker-offline'); |
312 }); | 312 }); |
313 window.addEventListener('online', function() { | 313 window.addEventListener('online', function() { |
314 self.downloadedListMap_ = null; | 314 self.downloadedListMap_ = null; |
315 $('wallpaper-grid').classList.remove('image-picker-offline'); | 315 $('wallpaper-grid').classList.remove('image-picker-offline'); |
316 }); | 316 }); |
317 } | 317 } |
318 | 318 |
319 this.onResize_(); | 319 this.onResize_(); |
320 this.initContextMenuAndCommand_(); | 320 this.initContextMenuAndCommand_(); |
| 321 WallpaperUtil.testSendMessage('launched'); |
321 }; | 322 }; |
322 | 323 |
323 /** | 324 /** |
324 * One-time initialization of context menu and command. | 325 * One-time initialization of context menu and command. |
325 */ | 326 */ |
326 WallpaperManager.prototype.initContextMenuAndCommand_ = function() { | 327 WallpaperManager.prototype.initContextMenuAndCommand_ = function() { |
327 this.wallpaperContextMenu_ = $('wallpaper-context-menu'); | 328 this.wallpaperContextMenu_ = $('wallpaper-context-menu'); |
328 cr.ui.Menu.decorate(this.wallpaperContextMenu_); | 329 cr.ui.Menu.decorate(this.wallpaperContextMenu_); |
329 cr.ui.contextMenuHandler.setContextMenu(this.wallpaperGrid_, | 330 cr.ui.contextMenuHandler.setContextMenu(this.wallpaperGrid_, |
330 this.wallpaperContextMenu_); | 331 this.wallpaperContextMenu_); |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 reader.addEventListener('load', function(e) { | 518 reader.addEventListener('load', function(e) { |
518 self.setCustomWallpaper(e.target.result, | 519 self.setCustomWallpaper(e.target.result, |
519 selectedItem.layout, | 520 selectedItem.layout, |
520 false, selectedItem.baseURL, | 521 false, selectedItem.baseURL, |
521 self.onWallpaperChanged_.bind(self, | 522 self.onWallpaperChanged_.bind(self, |
522 selectedItem, selectedItem.baseURL), | 523 selectedItem, selectedItem.baseURL), |
523 errorHandler); | 524 errorHandler); |
524 }); | 525 }); |
525 }, errorHandler); | 526 }, errorHandler); |
526 }, errorHandler); | 527 }, errorHandler); |
527 } | 528 }; |
528 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, | 529 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, |
529 success, errorHandler); | 530 success, errorHandler); |
530 break; | 531 break; |
531 case Constants.WallpaperSourceEnum.OEM: | 532 case Constants.WallpaperSourceEnum.OEM: |
532 // Resets back to default wallpaper. | 533 // Resets back to default wallpaper. |
533 chrome.wallpaperPrivate.resetWallpaper(); | 534 chrome.wallpaperPrivate.resetWallpaper(); |
534 this.onWallpaperChanged_(selectedItem, selectedItem.baseURL); | 535 this.onWallpaperChanged_(selectedItem, selectedItem.baseURL); |
535 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, | 536 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, |
536 selectedItem.source); | 537 selectedItem.source); |
537 break; | 538 break; |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 */ | 869 */ |
869 WallpaperManager.prototype.removeCustomWallpaper = function(fileName) { | 870 WallpaperManager.prototype.removeCustomWallpaper = function(fileName) { |
870 var errorHandler = this.onFileSystemError_.bind(this); | 871 var errorHandler = this.onFileSystemError_.bind(this); |
871 var self = this; | 872 var self = this; |
872 var removeFile = function(fileName) { | 873 var removeFile = function(fileName) { |
873 var success = function(dirEntry) { | 874 var success = function(dirEntry) { |
874 dirEntry.getFile(fileName, {create: false}, function(fileEntry) { | 875 dirEntry.getFile(fileName, {create: false}, function(fileEntry) { |
875 fileEntry.remove(function() { | 876 fileEntry.remove(function() { |
876 }, errorHandler); | 877 }, errorHandler); |
877 }, errorHandler); | 878 }, errorHandler); |
878 } | 879 }; |
879 | 880 |
880 // Removes copy of original. | 881 // Removes copy of original. |
881 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, success, | 882 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, success, |
882 errorHandler); | 883 errorHandler); |
883 | 884 |
884 // Removes generated thumbnail. | 885 // Removes generated thumbnail. |
885 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.THUMBNAIL, success, | 886 self.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.THUMBNAIL, success, |
886 errorHandler); | 887 errorHandler); |
887 }; | 888 }; |
888 removeFile(fileName); | 889 removeFile(fileName); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 bar.style.left = selectedListItem.offsetLeft + 'px'; | 961 bar.style.left = selectedListItem.offsetLeft + 'px'; |
961 bar.style.width = selectedListItem.offsetWidth + 'px'; | 962 bar.style.width = selectedListItem.offsetWidth + 'px'; |
962 | 963 |
963 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); | 964 var wallpapersDataModel = new cr.ui.ArrayDataModel([]); |
964 var selectedItem; | 965 var selectedItem; |
965 if (selectedListItem.custom) { | 966 if (selectedListItem.custom) { |
966 this.document_.body.setAttribute('custom', ''); | 967 this.document_.body.setAttribute('custom', ''); |
967 var errorHandler = this.onFileSystemError_.bind(this); | 968 var errorHandler = this.onFileSystemError_.bind(this); |
968 var toArray = function(list) { | 969 var toArray = function(list) { |
969 return Array.prototype.slice.call(list || [], 0); | 970 return Array.prototype.slice.call(list || [], 0); |
970 } | 971 }; |
971 | 972 |
972 var self = this; | 973 var self = this; |
973 var processResults = function(entries) { | 974 var processResults = function(entries) { |
974 for (var i = 0; i < entries.length; i++) { | 975 for (var i = 0; i < entries.length; i++) { |
975 var entry = entries[i]; | 976 var entry = entries[i]; |
976 var wallpaperInfo = { | 977 var wallpaperInfo = { |
977 baseURL: entry.name, | 978 baseURL: entry.name, |
978 // The layout will be replaced by the actual value saved in | 979 // The layout will be replaced by the actual value saved in |
979 // local storage when requested later. Layout is not important | 980 // local storage when requested later. Layout is not important |
980 // for constructing thumbnails grid, we use CENTER_CROPPED here | 981 // for constructing thumbnails grid, we use CENTER_CROPPED here |
(...skipping 21 matching lines...) Expand all Loading... |
1002 var lastElement = { | 1003 var lastElement = { |
1003 baseURL: '', | 1004 baseURL: '', |
1004 layout: '', | 1005 layout: '', |
1005 source: Constants.WallpaperSourceEnum.AddNew, | 1006 source: Constants.WallpaperSourceEnum.AddNew, |
1006 availableOffline: true | 1007 availableOffline: true |
1007 }; | 1008 }; |
1008 wallpapersDataModel.push(lastElement); | 1009 wallpapersDataModel.push(lastElement); |
1009 self.wallpaperGrid_.dataModel = wallpapersDataModel; | 1010 self.wallpaperGrid_.dataModel = wallpapersDataModel; |
1010 self.wallpaperGrid_.selectedItem = selectedItem; | 1011 self.wallpaperGrid_.selectedItem = selectedItem; |
1011 self.wallpaperGrid_.activeItem = selectedItem; | 1012 self.wallpaperGrid_.activeItem = selectedItem; |
1012 } | 1013 }; |
1013 | 1014 |
1014 var success = function(dirEntry) { | 1015 var success = function(dirEntry) { |
1015 var dirReader = dirEntry.createReader(); | 1016 var dirReader = dirEntry.createReader(); |
1016 var entries = []; | 1017 var entries = []; |
1017 // All of a directory's entries are not guaranteed to return in a single | 1018 // All of a directory's entries are not guaranteed to return in a single |
1018 // call. | 1019 // call. |
1019 var readEntries = function() { | 1020 var readEntries = function() { |
1020 dirReader.readEntries(function(results) { | 1021 dirReader.readEntries(function(results) { |
1021 if (!results.length) { | 1022 if (!results.length) { |
1022 processResults(entries.sort()); | 1023 processResults(entries.sort()); |
1023 } else { | 1024 } else { |
1024 entries = entries.concat(toArray(results)); | 1025 entries = entries.concat(toArray(results)); |
1025 readEntries(); | 1026 readEntries(); |
1026 } | 1027 } |
1027 }, errorHandler); | 1028 }, errorHandler); |
1028 }; | 1029 }; |
1029 readEntries(); // Start reading dirs. | 1030 readEntries(); // Start reading dirs. |
1030 } | 1031 }; |
1031 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, | 1032 this.wallpaperDirs_.getDirectory(WallpaperDirNameEnum.ORIGINAL, |
1032 success, errorHandler); | 1033 success, errorHandler); |
1033 } else { | 1034 } else { |
1034 this.document_.body.removeAttribute('custom'); | 1035 this.document_.body.removeAttribute('custom'); |
1035 for (var key in this.manifest_.wallpaper_list) { | 1036 for (var key in this.manifest_.wallpaper_list) { |
1036 if (selectedIndex == AllCategoryIndex || | 1037 if (selectedIndex == AllCategoryIndex || |
1037 this.manifest_.wallpaper_list[key].categories.indexOf( | 1038 this.manifest_.wallpaper_list[key].categories.indexOf( |
1038 selectedIndex - OnlineCategoriesOffset) != -1) { | 1039 selectedIndex - OnlineCategoriesOffset) != -1) { |
1039 var wallpaperInfo = { | 1040 var wallpaperInfo = { |
1040 baseURL: this.manifest_.wallpaper_list[key].base_url, | 1041 baseURL: this.manifest_.wallpaper_list[key].base_url, |
(...skipping 19 matching lines...) Expand all Loading... |
1060 } | 1061 } |
1061 } | 1062 } |
1062 } | 1063 } |
1063 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1064 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
1064 this.wallpaperGrid_.selectedItem = selectedItem; | 1065 this.wallpaperGrid_.selectedItem = selectedItem; |
1065 this.wallpaperGrid_.activeItem = selectedItem; | 1066 this.wallpaperGrid_.activeItem = selectedItem; |
1066 } | 1067 } |
1067 }; | 1068 }; |
1068 | 1069 |
1069 })(); | 1070 })(); |
OLD | NEW |