Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: chrome/browser/resources/chromeos/wallpaper_manager/js/wallpaper_manager.js

Issue 14416017: Sync online wallpaper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync wallpaper Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 $('error-container').hidden = false; 165 $('error-container').hidden = false;
166 }; 166 };
167 167
168 /** 168 /**
169 * Sets manifest loaded from server. Called after manifest is successfully 169 * Sets manifest loaded from server. Called after manifest is successfully
170 * loaded. 170 * loaded.
171 * @param {object} manifest The parsed manifest file. 171 * @param {object} manifest The parsed manifest file.
172 */ 172 */
173 WallpaperManager.prototype.onLoadManifestSuccess_ = function(manifest) { 173 WallpaperManager.prototype.onLoadManifestSuccess_ = function(manifest) {
174 this.manifest_ = manifest; 174 this.manifest_ = manifest;
175 WallpaperUtil.saveToLocalStorage(Constants.AccessManifestKey, manifest); 175 WallpaperUtil.saveToStorage(Constants.AccessManifestKey, manifest, false);
176 this.initDom_(); 176 this.initDom_();
177 }; 177 };
178 178
179 // Sets manifest to previously saved object if any and shows connection error. 179 // Sets manifest to previously saved object if any and shows connection error.
180 // Called after manifest failed to load. 180 // Called after manifest failed to load.
181 WallpaperManager.prototype.onLoadManifestFailed_ = function() { 181 WallpaperManager.prototype.onLoadManifestFailed_ = function() {
182 var accessManifestKey = Constants.AccessManifestKey; 182 var accessManifestKey = Constants.AccessManifestKey;
183 var self = this; 183 var self = this;
184 Constants.WallpaperLocalStorage.get(accessManifestKey, function(items) { 184 Constants.WallpaperLocalStorage.get(accessManifestKey, function(items) {
185 self.manifest_ = items[accessManifestKey] ? items[accessManifestKey] : {}; 185 self.manifest_ = items[accessManifestKey] ? items[accessManifestKey] : {};
186 self.showError_(str('connectionFailed')); 186 self.showError_(str('connectionFailed'));
187 self.initDom_(); 187 self.initDom_();
188 $('wallpaper-grid').classList.add('image-picker-offline'); 188 $('wallpaper-grid').classList.add('image-picker-offline');
189 }); 189 });
190 }; 190 };
191 191
192 /** 192 /**
193 * Toggle surprise me feature of wallpaper picker. It fires an storage 193 * Toggle surprise me feature of wallpaper picker. It fires an storage
194 * onChanged event. Event handler for that event is in event_page.js. 194 * onChanged event. Event handler for that event is in event_page.js.
195 * @private 195 * @private
196 */ 196 */
197 WallpaperManager.prototype.toggleSurpriseMe_ = function() { 197 WallpaperManager.prototype.toggleSurpriseMe_ = function() {
198 var checkbox = $('surprise-me').querySelector('#checkbox'); 198 var checkbox = $('surprise-me').querySelector('#checkbox');
199 var shouldEnable = !checkbox.classList.contains('checked'); 199 var shouldEnable = !checkbox.classList.contains('checked');
200 WallpaperUtil.saveToLocalStorage(Constants.AccessSurpriseMeEnabledKey, 200 WallpaperUtil.saveToStorage(Constants.AccessSurpriseMeEnabledKey,
201 shouldEnable, 201 shouldEnable, false, function() {
202 function() {
203 if (chrome.runtime.lastError == null) { 202 if (chrome.runtime.lastError == null) {
204 if (shouldEnable) { 203 if (shouldEnable) {
205 checkbox.classList.add('checked'); 204 checkbox.classList.add('checked');
206 } else { 205 } else {
207 checkbox.classList.remove('checked'); 206 checkbox.classList.remove('checked');
208 } 207 }
209 $('categories-list').disabled = shouldEnable; 208 $('categories-list').disabled = shouldEnable;
210 $('wallpaper-grid').disabled = shouldEnable; 209 $('wallpaper-grid').disabled = shouldEnable;
211 } else { 210 } else {
212 // TODO(bshe): show error message to user. 211 // TODO(bshe): show error message to user.
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 break; 480 break;
482 case Constants.WallpaperSourceEnum.Online: 481 case Constants.WallpaperSourceEnum.Online:
483 var wallpaperURL = selectedItem.baseURL + 482 var wallpaperURL = selectedItem.baseURL +
484 Constants.HighResolutionSuffix; 483 Constants.HighResolutionSuffix;
485 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem); 484 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem);
486 485
487 chrome.wallpaperPrivate.setWallpaperIfExists(wallpaperURL, 486 chrome.wallpaperPrivate.setWallpaperIfExists(wallpaperURL,
488 selectedItem.layout, 487 selectedItem.layout,
489 selectedItem.source, 488 selectedItem.source,
490 function(exists) { 489 function(exists) {
490 var wallpaperInfo = {
491 url: wallpaperURL,
492 layout: selectedItem.layout,
493 source: selectedItem.source
494 };
495
491 if (exists) { 496 if (exists) {
492 self.currentWallpaper_ = wallpaperURL; 497 self.currentWallpaper_ = wallpaperURL;
493 self.wallpaperGrid_.activeItem = selectedItem; 498 self.wallpaperGrid_.activeItem = selectedItem;
499 WallpaperUtil.saveToStorage(Constants.AccessWallpaperInfoKey,
500 wallpaperInfo, true);
494 return; 501 return;
495 } 502 }
496 503
497 // Falls back to request wallpaper from server. 504 // Falls back to request wallpaper from server.
498 if (self.wallpaperRequest_) 505 if (self.wallpaperRequest_)
499 self.wallpaperRequest_.abort(); 506 self.wallpaperRequest_.abort();
500 507
501 self.wallpaperRequest_ = new XMLHttpRequest(); 508 self.wallpaperRequest_ = new XMLHttpRequest();
502 self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem); 509 self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem);
503 510
504 var onSuccess = function(xhr) { 511 var onSuccess = function(xhr) {
505 var image = xhr.response; 512 var image = xhr.response;
506 chrome.wallpaperPrivate.setWallpaper(image, selectedItem.layout, 513 chrome.wallpaperPrivate.setWallpaper(image, selectedItem.layout,
507 wallpaperURL, 514 wallpaperURL,
508 self.onFinished_.bind(self, selectedGridItem, selectedItem)); 515 self.onFinished_.bind(self, selectedGridItem, selectedItem));
509 self.currentWallpaper_ = wallpaperURL; 516 self.currentWallpaper_ = wallpaperURL;
517 WallpaperUtil.saveToStorage(Constants.AccessWallpaperInfoKey,
518 wallpaperInfo, true);
510 self.wallpaperRequest_ = null; 519 self.wallpaperRequest_ = null;
511 }; 520 };
512 var onFailure = function() { 521 var onFailure = function() {
513 self.progressManager_.hideProgressBar(selectedGridItem); 522 self.progressManager_.hideProgressBar(selectedGridItem);
514 self.showError_(str('downloadFailed')); 523 self.showError_(str('downloadFailed'));
515 self.wallpaperRequest_ = null; 524 self.wallpaperRequest_ = null;
516 }; 525 };
517 WallpaperUtil.fetchURL(wallpaperURL, 'arraybuffer', onSuccess, 526 WallpaperUtil.fetchURL(wallpaperURL, 'arraybuffer', onSuccess,
518 onFailure, self.wallpaperRequest_); 527 onFailure, self.wallpaperRequest_);
519 }); 528 });
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 var wallpaperInfo = { 731 var wallpaperInfo = {
723 baseURL: fileName, 732 baseURL: fileName,
724 layout: layout, 733 layout: layout,
725 source: Constants.WallpaperSourceEnum.Custom, 734 source: Constants.WallpaperSourceEnum.Custom,
726 availableOffline: true 735 availableOffline: true
727 }; 736 };
728 self.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo); 737 self.wallpaperGrid_.dataModel.splice(0, 0, wallpaperInfo);
729 self.wallpaperGrid_.selectedItem = wallpaperInfo; 738 self.wallpaperGrid_.selectedItem = wallpaperInfo;
730 self.wallpaperGrid_.activeItem = wallpaperInfo; 739 self.wallpaperGrid_.activeItem = wallpaperInfo;
731 self.currentWallpaper_ = fileName; 740 self.currentWallpaper_ = fileName;
732 WallpaperUtil.saveToLocalStorage(self.currentWallpaper_, 741 WallpaperUtil.saveToStorage(self.currentWallpaper_, layout,
733 layout); 742 false);
734 }; 743 };
735 744
736 fileWriter.onerror = errorHandler; 745 fileWriter.onerror = errorHandler;
737 746
738 var blob = new Blob([new Int8Array(thumbnail)], 747 var blob = new Blob([new Int8Array(thumbnail)],
739 {'type' : 'image\/jpeg'}); 748 {'type' : 'image\/jpeg'});
740 fileWriter.write(blob); 749 fileWriter.write(blob);
741 }, errorHandler); 750 }, errorHandler);
742 }, errorHandler); 751 }, errorHandler);
743 }; 752 };
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 success, 827 success,
819 failure) { 828 failure) {
820 var self = this; 829 var self = this;
821 var onFinished = function(opt_thumbnail) { 830 var onFinished = function(opt_thumbnail) {
822 if (chrome.runtime.lastError != undefined) { 831 if (chrome.runtime.lastError != undefined) {
823 self.showError_(chrome.runtime.lastError.message); 832 self.showError_(chrome.runtime.lastError.message);
824 $('set-wallpaper-layout').disabled = true; 833 $('set-wallpaper-layout').disabled = true;
825 failure(); 834 failure();
826 } else { 835 } else {
827 success(opt_thumbnail); 836 success(opt_thumbnail);
837 var wallpaperInfo = {
838 url: wallpaper,
839 layout: layout,
840 source: Constants.WallpaperSourceEnum.Custom
841 };
842 WallpaperUtil.saveToStorage(Constants.AccessWallpaperInfoKey,
843 wallpaperInfo, true);
828 } 844 }
829 }; 845 };
830 846
831 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, layout, 847 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, layout,
832 generateThumbnail, 848 generateThumbnail,
833 fileName, onFinished); 849 fileName, onFinished);
834 }; 850 };
835 851
836 /** 852 /**
837 * Sets wallpaper finished. Displays error message if any. 853 * Sets wallpaper finished. Displays error message if any.
(...skipping 22 matching lines...) Expand all
860 */ 876 */
861 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() { 877 WallpaperManager.prototype.onWallpaperLayoutChanged_ = function() {
862 var layout = getSelectedLayout(); 878 var layout = getSelectedLayout();
863 var self = this; 879 var self = this;
864 chrome.wallpaperPrivate.setCustomWallpaperLayout(layout, function() { 880 chrome.wallpaperPrivate.setCustomWallpaperLayout(layout, function() {
865 if (chrome.runtime.lastError != undefined) { 881 if (chrome.runtime.lastError != undefined) {
866 self.showError_(chrome.runtime.lastError.message); 882 self.showError_(chrome.runtime.lastError.message);
867 self.removeCustomWallpaper(fileName); 883 self.removeCustomWallpaper(fileName);
868 $('set-wallpaper-layout').disabled = true; 884 $('set-wallpaper-layout').disabled = true;
869 } else { 885 } else {
870 WallpaperUtil.saveToLocalStorage(self.currentWallpaper_, layout); 886 WallpaperUtil.saveToStorage(self.currentWallpaper_, layout, false);
871 } 887 }
872 }); 888 });
873 }; 889 };
874 890
875 /** 891 /**
876 * Handles user clicking on a different category. 892 * Handles user clicking on a different category.
877 */ 893 */
878 WallpaperManager.prototype.onCategoriesChange_ = function() { 894 WallpaperManager.prototype.onCategoriesChange_ = function() {
879 var categoriesList = this.categoriesList_; 895 var categoriesList = this.categoriesList_;
880 var selectedIndex = categoriesList.selectionModel.selectedIndex; 896 var selectedIndex = categoriesList.selectionModel.selectedIndex;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 } 990 }
975 } 991 }
976 } 992 }
977 this.wallpaperGrid_.dataModel = wallpapersDataModel; 993 this.wallpaperGrid_.dataModel = wallpapersDataModel;
978 this.wallpaperGrid_.selectedItem = selectedItem; 994 this.wallpaperGrid_.selectedItem = selectedItem;
979 this.wallpaperGrid_.activeItem = selectedItem; 995 this.wallpaperGrid_.activeItem = selectedItem;
980 } 996 }
981 }; 997 };
982 998
983 })(); 999 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698