| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 i18nTemplate.process(this.document_, loadTimeData); | 278 i18nTemplate.process(this.document_, loadTimeData); |
| 279 this.initCategoriesList_(); | 279 this.initCategoriesList_(); |
| 280 this.initThumbnailsGrid_(); | 280 this.initThumbnailsGrid_(); |
| 281 this.presetCategory_(); | 281 this.presetCategory_(); |
| 282 | 282 |
| 283 $('file-selector').addEventListener( | 283 $('file-selector').addEventListener( |
| 284 'change', this.onFileSelectorChanged_.bind(this)); | 284 'change', this.onFileSelectorChanged_.bind(this)); |
| 285 $('set-wallpaper-layout').addEventListener( | 285 $('set-wallpaper-layout').addEventListener( |
| 286 'change', this.onWallpaperLayoutChanged_.bind(this)); | 286 'change', this.onWallpaperLayoutChanged_.bind(this)); |
| 287 | 287 |
| 288 if (loadTimeData.valueExists('wallpaperAppName')) { | 288 // Always prefer the value from local filesystem to avoid the time window |
| 289 $('wallpaper-set-by-message').textContent = loadTimeData.getStringF( | 289 // of setting the third party app name and the third party wallpaper. |
| 290 'currentWallpaperSetByMessage', str('wallpaperAppName')); | 290 var getThirdPartyAppName = function(callback) { |
| 291 $('wallpaper-grid').classList.add('small'); | 291 Constants.WallpaperLocalStorage.get( |
| 292 } else { | 292 Constants.AccessLocalWallpaperInfoKey, function(items) { |
| 293 $('wallpaper-grid').classList.remove('small'); | 293 var localInfo = items[Constants.AccessLocalWallpaperInfoKey]; |
| 294 } | 294 if (localInfo && localInfo.hasOwnProperty('appName')) |
| 295 callback(localInfo.appName); |
| 296 else if (loadTimeData.valueExists('wallpaperAppName')) |
| 297 callback(str('wallpaperAppName')); |
| 298 else |
| 299 callback(''); |
| 300 }); |
| 301 }; |
| 302 |
| 303 getThirdPartyAppName(function(appName) { |
| 304 if (!!appName) { |
| 305 $('wallpaper-set-by-message').textContent = loadTimeData.getStringF( |
| 306 'currentWallpaperSetByMessage', appName); |
| 307 $('wallpaper-grid').classList.add('small'); |
| 308 } else { |
| 309 $('wallpaper-grid').classList.remove('small'); |
| 310 } |
| 311 }); |
| 295 | 312 |
| 296 if (this.enableOnlineWallpaper_) { | 313 if (this.enableOnlineWallpaper_) { |
| 297 var self = this; | 314 var self = this; |
| 298 self.document_.body.setAttribute('surprise-me-disabled', ''); | 315 self.document_.body.setAttribute('surprise-me-disabled', ''); |
| 299 $('surprise-me').hidden = false; | 316 $('surprise-me').hidden = false; |
| 300 $('surprise-me').addEventListener('click', | 317 $('surprise-me').addEventListener('click', |
| 301 this.toggleSurpriseMe_.bind(this)); | 318 this.toggleSurpriseMe_.bind(this)); |
| 302 var onSurpriseMeEnabled = function() { | 319 var onSurpriseMeEnabled = function() { |
| 303 $('surprise-me').querySelector('#checkbox').classList.add('checked'); | 320 $('surprise-me').querySelector('#checkbox').classList.add('checked'); |
| 304 $('categories-list').disabled = true; | 321 $('categories-list').disabled = true; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 this.removeCustomWallpaper(item.baseURL); | 425 this.removeCustomWallpaper(item.baseURL); |
| 409 wallpaperGrid.dataModel.splice(selectedIndex, 1); | 426 wallpaperGrid.dataModel.splice(selectedIndex, 1); |
| 410 // Calculate the number of remaining custom wallpapers. The add new button | 427 // Calculate the number of remaining custom wallpapers. The add new button |
| 411 // in data model needs to be excluded. | 428 // in data model needs to be excluded. |
| 412 var customWallpaperCount = wallpaperGrid.dataModel.length - 1; | 429 var customWallpaperCount = wallpaperGrid.dataModel.length - 1; |
| 413 if (customWallpaperCount == 0) { | 430 if (customWallpaperCount == 0) { |
| 414 // Active custom wallpaper is also copied in chronos data dir. It needs | 431 // Active custom wallpaper is also copied in chronos data dir. It needs |
| 415 // to be deleted. | 432 // to be deleted. |
| 416 chrome.wallpaperPrivate.resetWallpaper(); | 433 chrome.wallpaperPrivate.resetWallpaper(); |
| 417 this.onWallpaperChanged_(null, null); | 434 this.onWallpaperChanged_(null, null); |
| 418 WallpaperUtil.saveWallpaperInfo('', '', | 435 WallpaperUtil.saveWallpaperInfo( |
| 419 Constants.WallpaperSourceEnum.Default); | 436 '', '', Constants.WallpaperSourceEnum.Default, ''); |
| 420 } else { | 437 } else { |
| 421 selectedIndex = Math.min(selectedIndex, customWallpaperCount - 1); | 438 selectedIndex = Math.min(selectedIndex, customWallpaperCount - 1); |
| 422 wallpaperGrid.selectionModel.selectedIndex = selectedIndex; | 439 wallpaperGrid.selectionModel.selectedIndex = selectedIndex; |
| 423 } | 440 } |
| 424 event.cancelBubble = true; | 441 event.cancelBubble = true; |
| 425 } | 442 } |
| 426 }; | 443 }; |
| 427 | 444 |
| 428 /** | 445 /** |
| 429 * Decides if a command can be executed on current target. | 446 * Decides if a command can be executed on current target. |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 }, errorHandler); | 608 }, errorHandler); |
| 592 }, errorHandler); | 609 }, errorHandler); |
| 593 }; | 610 }; |
| 594 this.wallpaperDirs_.getDirectory( | 611 this.wallpaperDirs_.getDirectory( |
| 595 Constants.WallpaperDirNameEnum.ORIGINAL, success, errorHandler); | 612 Constants.WallpaperDirNameEnum.ORIGINAL, success, errorHandler); |
| 596 break; | 613 break; |
| 597 case Constants.WallpaperSourceEnum.OEM: | 614 case Constants.WallpaperSourceEnum.OEM: |
| 598 // Resets back to default wallpaper. | 615 // Resets back to default wallpaper. |
| 599 chrome.wallpaperPrivate.resetWallpaper(); | 616 chrome.wallpaperPrivate.resetWallpaper(); |
| 600 this.onWallpaperChanged_(selectedItem, selectedItem.baseURL); | 617 this.onWallpaperChanged_(selectedItem, selectedItem.baseURL); |
| 601 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, | 618 WallpaperUtil.saveWallpaperInfo( |
| 602 selectedItem.source); | 619 wallpaperURL, selectedItem.layout, selectedItem.source, ''); |
| 603 break; | 620 break; |
| 604 case Constants.WallpaperSourceEnum.Online: | 621 case Constants.WallpaperSourceEnum.Online: |
| 605 var wallpaperURL = selectedItem.baseURL + | 622 var wallpaperURL = selectedItem.baseURL + |
| 606 Constants.HighResolutionSuffix; | 623 Constants.HighResolutionSuffix; |
| 607 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem); | 624 var selectedGridItem = this.wallpaperGrid_.getListItem(selectedItem); |
| 608 | 625 |
| 609 chrome.wallpaperPrivate.setWallpaperIfExists(wallpaperURL, | 626 chrome.wallpaperPrivate.setWallpaperIfExists(wallpaperURL, |
| 610 selectedItem.layout, | 627 selectedItem.layout, |
| 611 function(exists) { | 628 function(exists) { |
| 612 if (exists) { | 629 if (exists) { |
| 613 self.onWallpaperChanged_(selectedItem, wallpaperURL); | 630 self.onWallpaperChanged_(selectedItem, wallpaperURL); |
| 614 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, | 631 WallpaperUtil.saveWallpaperInfo( |
| 615 selectedItem.source); | 632 wallpaperURL, selectedItem.layout, selectedItem.source, ''); |
| 616 return; | 633 return; |
| 617 } | 634 } |
| 618 | 635 |
| 619 // Falls back to request wallpaper from server. | 636 // Falls back to request wallpaper from server. |
| 620 if (self.wallpaperRequest_) | 637 if (self.wallpaperRequest_) |
| 621 self.wallpaperRequest_.abort(); | 638 self.wallpaperRequest_.abort(); |
| 622 | 639 |
| 623 self.wallpaperRequest_ = new XMLHttpRequest(); | 640 self.wallpaperRequest_ = new XMLHttpRequest(); |
| 624 self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem); | 641 self.progressManager_.reset(self.wallpaperRequest_, selectedGridItem); |
| 625 | 642 |
| 626 var onSuccess = function(xhr) { | 643 var onSuccess = function(xhr) { |
| 627 var image = xhr.response; | 644 var image = xhr.response; |
| 628 chrome.wallpaperPrivate.setWallpaper(image, selectedItem.layout, | 645 chrome.wallpaperPrivate.setWallpaper(image, selectedItem.layout, |
| 629 wallpaperURL, | 646 wallpaperURL, |
| 630 function() { | 647 function() { |
| 631 self.progressManager_.hideProgressBar(selectedGridItem); | 648 self.progressManager_.hideProgressBar(selectedGridItem); |
| 632 | 649 |
| 633 if (chrome.runtime.lastError != undefined && | 650 if (chrome.runtime.lastError != undefined && |
| 634 chrome.runtime.lastError.message != | 651 chrome.runtime.lastError.message != |
| 635 str('canceledWallpaper')) { | 652 str('canceledWallpaper')) { |
| 636 self.showError_(chrome.runtime.lastError.message); | 653 self.showError_(chrome.runtime.lastError.message); |
| 637 } else { | 654 } else { |
| 638 self.onWallpaperChanged_(selectedItem, wallpaperURL); | 655 self.onWallpaperChanged_(selectedItem, wallpaperURL); |
| 639 } | 656 } |
| 640 }); | 657 }); |
| 641 WallpaperUtil.saveWallpaperInfo(wallpaperURL, selectedItem.layout, | 658 WallpaperUtil.saveWallpaperInfo( |
| 642 selectedItem.source); | 659 wallpaperURL, selectedItem.layout, selectedItem.source, ''); |
| 643 self.wallpaperRequest_ = null; | 660 self.wallpaperRequest_ = null; |
| 644 }; | 661 }; |
| 645 var onFailure = function(status) { | 662 var onFailure = function(status) { |
| 646 self.progressManager_.hideProgressBar(selectedGridItem); | 663 self.progressManager_.hideProgressBar(selectedGridItem); |
| 647 self.showError_(str('downloadFailed')); | 664 self.showError_(str('downloadFailed')); |
| 648 self.wallpaperRequest_ = null; | 665 self.wallpaperRequest_ = null; |
| 649 }; | 666 }; |
| 650 WallpaperUtil.fetchURL(wallpaperURL, 'arraybuffer', onSuccess, | 667 WallpaperUtil.fetchURL(wallpaperURL, 'arraybuffer', onSuccess, |
| 651 onFailure, self.wallpaperRequest_); | 668 onFailure, self.wallpaperRequest_); |
| 652 }); | 669 }); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 var onFinished = function(opt_thumbnail) { | 977 var onFinished = function(opt_thumbnail) { |
| 961 if (chrome.runtime.lastError != undefined && | 978 if (chrome.runtime.lastError != undefined && |
| 962 chrome.runtime.lastError.message != str('canceledWallpaper')) { | 979 chrome.runtime.lastError.message != str('canceledWallpaper')) { |
| 963 self.showError_(chrome.runtime.lastError.message); | 980 self.showError_(chrome.runtime.lastError.message); |
| 964 $('set-wallpaper-layout').disabled = true; | 981 $('set-wallpaper-layout').disabled = true; |
| 965 failure(); | 982 failure(); |
| 966 } else { | 983 } else { |
| 967 success(opt_thumbnail); | 984 success(opt_thumbnail); |
| 968 // Custom wallpapers are not synced yet. If login on a different | 985 // Custom wallpapers are not synced yet. If login on a different |
| 969 // computer after set a custom wallpaper, wallpaper wont change by sync. | 986 // computer after set a custom wallpaper, wallpaper wont change by sync. |
| 970 WallpaperUtil.saveWallpaperInfo(fileName, layout, | 987 WallpaperUtil.saveWallpaperInfo( |
| 971 Constants.WallpaperSourceEnum.Custom); | 988 fileName, layout, Constants.WallpaperSourceEnum.Custom, ''); |
| 972 } | 989 } |
| 973 }; | 990 }; |
| 974 | 991 |
| 975 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, layout, | 992 chrome.wallpaperPrivate.setCustomWallpaper(wallpaper, layout, |
| 976 generateThumbnail, | 993 generateThumbnail, |
| 977 fileName, onFinished); | 994 fileName, onFinished); |
| 978 }; | 995 }; |
| 979 | 996 |
| 980 /** | 997 /** |
| 981 * Handles the layout setting change of custom wallpaper. | 998 * Handles the layout setting change of custom wallpaper. |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 } | 1142 } |
| 1126 this.wallpaperGrid_.dataModel = wallpapersDataModel; | 1143 this.wallpaperGrid_.dataModel = wallpapersDataModel; |
| 1127 if (selectedItem) { | 1144 if (selectedItem) { |
| 1128 this.wallpaperGrid_.selectedItem = selectedItem; | 1145 this.wallpaperGrid_.selectedItem = selectedItem; |
| 1129 this.wallpaperGrid_.activeItem = selectedItem; | 1146 this.wallpaperGrid_.activeItem = selectedItem; |
| 1130 } | 1147 } |
| 1131 } | 1148 } |
| 1132 }; | 1149 }; |
| 1133 | 1150 |
| 1134 })(); | 1151 })(); |
| OLD | NEW |