| 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 var WALLPAPER_PICKER_WIDTH = 574; | 5 var WALLPAPER_PICKER_WIDTH = 574; |
| 6 var WALLPAPER_PICKER_HEIGHT = 420; | 6 var WALLPAPER_PICKER_HEIGHT = 420; |
| 7 | 7 |
| 8 var wallpaperPickerWindow; | 8 var wallpaperPickerWindow; |
| 9 | 9 |
| 10 var surpriseWallpaper = null; | 10 var surpriseWallpaper = null; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 chrome.wallpaperPrivate.restoreMinimizedWindows(); | 265 chrome.wallpaperPrivate.restoreMinimizedWindows(); |
| 266 }); | 266 }); |
| 267 WallpaperUtil.testSendMessage('wallpaper-window-created'); | 267 WallpaperUtil.testSendMessage('wallpaper-window-created'); |
| 268 }); | 268 }); |
| 269 }); | 269 }); |
| 270 | 270 |
| 271 chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) { | 271 chrome.syncFileSystem.onFileStatusChanged.addListener(function(detail) { |
| 272 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { | 272 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { |
| 273 if (!syncEnabled) | 273 if (!syncEnabled) |
| 274 return; | 274 return; |
| 275 if (detail.status == 'synced') { | 275 if (detail.status != 'synced' || detail.direction != 'remote_to_local') |
| 276 if (detail.direction == 'remote_to_local') { | 276 return; |
| 277 if (detail.action == 'added') { | 277 if (detail.action == 'added') { |
| 278 Constants.WallpaperLocalStorage.get( | 278 // TODO(xdai): Get rid of this setCustomWallpaperFromSyncFS logic. |
| 279 Constants.AccessLocalWallpaperInfoKey, | 279 // WallpaperInfo might have been saved in the sync filesystem before the |
| 280 function(items) { | 280 // corresonding custom wallpaper and thumbnail are saved, thus the |
| 281 var localData = items[Constants.AccessLocalWallpaperInfoKey]; | 281 // onChanged() might not set the custom wallpaper correctly. So we need |
| 282 if (localData && localData.url == detail.fileEntry.name && | 282 // setCustomWallpaperFromSyncFS() to be called here again to make sure |
| 283 localData.source == Constants.WallpaperSourceEnum.Custom) { | 283 // custom wallpaper is set. |
| 284 WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url, | 284 Constants.WallpaperLocalStorage.get( |
| 285 localData.layout); | 285 Constants.AccessLocalWallpaperInfoKey, function(items) { |
| 286 } else if (!localData || localData.url != | 286 var localData = items[Constants.AccessLocalWallpaperInfoKey]; |
| 287 detail.fileEntry.name.replace( | 287 if (localData && |
| 288 Constants.CustomWallpaperThumbnailSuffix, '')) { | 288 localData.url == detail.fileEntry.name && |
| 289 // localData might be null on a powerwashed device. | 289 localData.source == Constants.WallpaperSourceEnum.Custom) { |
| 290 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS( | 290 WallpaperUtil.setCustomWallpaperFromSyncFS(localData.url, |
| 291 detail.fileEntry); | 291 localData.layout); |
| 292 } | |
| 293 }); | |
| 294 } else if (detail.action == 'deleted') { | |
| 295 var fileName = detail.fileEntry.name.replace( | |
| 296 Constants.CustomWallpaperThumbnailSuffix, ''); | |
| 297 WallpaperUtil.deleteWallpaperFromLocalFS(fileName); | |
| 298 } | 292 } |
| 293 }); |
| 294 // We only need to store the custom wallpaper if it was set by the |
| 295 // built-in wallpaper picker. |
| 296 if (detail.fileEntry.name.indexOf( |
| 297 Constants.ThirdPartyWallpaperPrefix) != 0) { |
| 298 WallpaperUtil.storeWallpaperFromSyncFSToLocalFS(detail.fileEntry); |
| 299 } | 299 } |
| 300 } else if (detail.action == 'deleted') { |
| 301 var fileName = detail.fileEntry.name.replace( |
| 302 Constants.CustomWallpaperThumbnailSuffix, ''); |
| 303 WallpaperUtil.deleteWallpaperFromLocalFS(fileName); |
| 300 } | 304 } |
| 301 }); | 305 }); |
| 302 }); | 306 }); |
| 303 | 307 |
| 304 chrome.storage.onChanged.addListener(function(changes, namespace) { | 308 chrome.storage.onChanged.addListener(function(changes, namespace) { |
| 305 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { | 309 WallpaperUtil.enabledSyncThemesCallback(function(syncEnabled) { |
| 306 if (syncEnabled) { | 310 if (syncEnabled) { |
| 307 // If sync theme is enabled, use values from chrome.storage.sync to sync | 311 // If sync theme is enabled, use values from chrome.storage.sync to sync |
| 308 // wallpaper changes. | 312 // wallpaper changes. |
| 309 WallpaperUtil.requestSyncFS(function() {}); | 313 WallpaperUtil.requestSyncFS(function() {}); |
| 310 if (changes[Constants.AccessSyncSurpriseMeEnabledKey]) { | 314 if (changes[Constants.AccessSyncSurpriseMeEnabledKey]) { |
| 311 if (changes[Constants.AccessSyncSurpriseMeEnabledKey].newValue) { | 315 if (changes[Constants.AccessSyncSurpriseMeEnabledKey].newValue) { |
| 312 SurpriseWallpaper.getInstance().next(); | 316 SurpriseWallpaper.getInstance().next(); |
| 313 } else { | 317 } else { |
| 314 SurpriseWallpaper.getInstance().disable(); | 318 SurpriseWallpaper.getInstance().disable(); |
| 315 } | 319 } |
| 316 } | 320 } |
| 317 | 321 |
| 318 if (changes[Constants.AccessLocalWallpaperInfoKey]) { | 322 if (changes[Constants.AccessLocalWallpaperInfoKey]) { |
| 319 // If the old wallpaper is a third party wallpaper we should remove it | 323 // If the old wallpaper is a third party wallpaper we should remove it |
| 320 // from the local & sync file system to free space. | 324 // from the local & sync file system to free space. |
| 321 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue; | 325 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue; |
| 322 if (oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) { | 326 if (oldInfo && |
| 327 oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) { |
| 323 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url); | 328 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url); |
| 324 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url); | 329 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url); |
| 325 } | 330 } |
| 326 } | 331 } |
| 327 | 332 |
| 328 if (changes[Constants.AccessSyncWallpaperInfoKey]) { | 333 if (changes[Constants.AccessSyncWallpaperInfoKey]) { |
| 329 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue; | 334 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue; |
| 330 | 335 |
| 331 Constants.WallpaperSyncStorage.get( | 336 Constants.WallpaperSyncStorage.get( |
| 332 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) { | 337 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 347 (syncSurpriseMeEnabled && | 352 (syncSurpriseMeEnabled && |
| 348 syncLastSurpriseMeChangedDate == today)) { | 353 syncLastSurpriseMeChangedDate == today)) { |
| 349 Constants.WallpaperLocalStorage.get( | 354 Constants.WallpaperLocalStorage.get( |
| 350 Constants.AccessLocalWallpaperInfoKey, function(infoItems) { | 355 Constants.AccessLocalWallpaperInfoKey, function(infoItems) { |
| 351 var localInfo = | 356 var localInfo = |
| 352 infoItems[Constants.AccessLocalWallpaperInfoKey]; | 357 infoItems[Constants.AccessLocalWallpaperInfoKey]; |
| 353 // Normally, the wallpaper info saved in local storage and sync | 358 // Normally, the wallpaper info saved in local storage and sync |
| 354 // storage are the same. If the synced value changed by sync | 359 // storage are the same. If the synced value changed by sync |
| 355 // service, they may different. In that case, change wallpaper | 360 // service, they may different. In that case, change wallpaper |
| 356 // to the one saved in sync storage and update the local value. | 361 // to the one saved in sync storage and update the local value. |
| 357 if (localInfo == undefined || | 362 if (!localInfo || |
| 358 localInfo.url != syncInfo.url || | 363 localInfo.url != syncInfo.url || |
| 359 localInfo.layout != syncInfo.layout || | 364 localInfo.layout != syncInfo.layout || |
| 360 localInfo.source != syncInfo.source) { | 365 localInfo.source != syncInfo.source) { |
| 361 if (syncInfo.source == Constants.WallpaperSourceEnum.Online) { | 366 if (syncInfo.source == Constants.WallpaperSourceEnum.Online) { |
| 362 // TODO(bshe): Consider schedule an alarm to set online | 367 // TODO(bshe): Consider schedule an alarm to set online |
| 363 // wallpaper later when failed. Note that we need to cancel | 368 // wallpaper later when failed. Note that we need to cancel |
| 364 // the retry if user set another wallpaper before retry | 369 // the retry if user set another wallpaper before retry |
| 365 // alarm invoked. | 370 // alarm invoked. |
| 366 WallpaperUtil.setOnlineWallpaper(syncInfo.url, | 371 WallpaperUtil.setOnlineWallpaper(syncInfo.url, |
| 367 syncInfo.layout, function() {}, function() {}); | 372 syncInfo.layout, function() {}, function() {}); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 } | 407 } |
| 403 } | 408 } |
| 404 }); | 409 }); |
| 405 }); | 410 }); |
| 406 | 411 |
| 407 chrome.alarms.onAlarm.addListener(function() { | 412 chrome.alarms.onAlarm.addListener(function() { |
| 408 SurpriseWallpaper.getInstance().next(); | 413 SurpriseWallpaper.getInstance().next(); |
| 409 }); | 414 }); |
| 410 | 415 |
| 411 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( | 416 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( |
| 412 wallpaper, thumbnail, layout) { | 417 wallpaper, thumbnail, layout, appName) { |
| 413 WallpaperUtil.saveToLocalStorage( | 418 WallpaperUtil.saveToLocalStorage( |
| 414 Constants.AccessLocalSurpriseMeEnabledKey, false, function() { | 419 Constants.AccessLocalSurpriseMeEnabledKey, false, function() { |
| 415 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey, | 420 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey, |
| 416 false); | 421 false); |
| 417 }); | 422 }); |
| 418 SurpriseWallpaper.getInstance().disable(); | 423 SurpriseWallpaper.getInstance().disable(); |
| 419 | 424 |
| 420 // Make third party wallpaper syncable through different devices. | 425 // Make third party wallpaper syncable through different devices. |
| 421 // TODO(xdai): also sync the third party app name. | |
| 422 var filename = Constants.ThirdPartyWallpaperPrefix + new Date().getTime(); | 426 var filename = Constants.ThirdPartyWallpaperPrefix + new Date().getTime(); |
| 423 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix; | 427 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix; |
| 424 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper); | 428 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper); |
| 425 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail); | 429 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail); |
| 426 WallpaperUtil.saveWallpaperInfo(filename, layout, | 430 WallpaperUtil.saveWallpaperInfo( |
| 427 Constants.WallpaperSourceEnum.Custom); | 431 filename, layout, Constants.WallpaperSourceEnum.Custom, appName); |
| 428 }); | 432 }); |
| OLD | NEW |