| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 SurpriseWallpaper.getInstance().next(); | 312 SurpriseWallpaper.getInstance().next(); |
| 313 } else { | 313 } else { |
| 314 SurpriseWallpaper.getInstance().disable(); | 314 SurpriseWallpaper.getInstance().disable(); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 if (changes[Constants.AccessLocalWallpaperInfoKey]) { | 318 if (changes[Constants.AccessLocalWallpaperInfoKey]) { |
| 319 // If the old wallpaper is a third party wallpaper we should remove it | 319 // If the old wallpaper is a third party wallpaper we should remove it |
| 320 // from the local & sync file system to free space. | 320 // from the local & sync file system to free space. |
| 321 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue; | 321 var oldInfo = changes[Constants.AccessLocalWallpaperInfoKey].oldValue; |
| 322 if (oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) { | 322 if (oldInfo && |
| 323 oldInfo.url.indexOf(Constants.ThirdPartyWallpaperPrefix) != -1) { |
| 323 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url); | 324 WallpaperUtil.deleteWallpaperFromLocalFS(oldInfo.url); |
| 324 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url); | 325 WallpaperUtil.deleteWallpaperFromSyncFS(oldInfo.url); |
| 325 } | 326 } |
| 326 } | 327 } |
| 327 | 328 |
| 329 if (changes[Constants.AccessSyncThirdPartyAppName]) { |
| 330 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalThirdPartyAppName, |
| 331 changes[Constants.AccessSyncThirdPartyAppName].newValue); |
| 332 } |
| 333 |
| 328 if (changes[Constants.AccessSyncWallpaperInfoKey]) { | 334 if (changes[Constants.AccessSyncWallpaperInfoKey]) { |
| 329 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue; | 335 var syncInfo = changes[Constants.AccessSyncWallpaperInfoKey].newValue; |
| 330 | 336 |
| 331 Constants.WallpaperSyncStorage.get( | 337 Constants.WallpaperSyncStorage.get( |
| 332 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) { | 338 Constants.AccessSyncSurpriseMeEnabledKey, function(enabledItems) { |
| 333 var syncSurpriseMeEnabled = | 339 var syncSurpriseMeEnabled = |
| 334 enabledItems[Constants.AccessSyncSurpriseMeEnabledKey]; | 340 enabledItems[Constants.AccessSyncSurpriseMeEnabledKey]; |
| 335 | 341 |
| 336 Constants.WallpaperSyncStorage.get( | 342 Constants.WallpaperSyncStorage.get( |
| 337 Constants.AccessLastSurpriseWallpaperChangedDate, | 343 Constants.AccessLastSurpriseWallpaperChangedDate, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 365 // alarm invoked. | 371 // alarm invoked. |
| 366 WallpaperUtil.setOnlineWallpaper(syncInfo.url, | 372 WallpaperUtil.setOnlineWallpaper(syncInfo.url, |
| 367 syncInfo.layout, function() {}, function() {}); | 373 syncInfo.layout, function() {}, function() {}); |
| 368 } else if (syncInfo.source == | 374 } else if (syncInfo.source == |
| 369 Constants.WallpaperSourceEnum.Custom) { | 375 Constants.WallpaperSourceEnum.Custom) { |
| 370 WallpaperUtil.setCustomWallpaperFromSyncFS(syncInfo.url, | 376 WallpaperUtil.setCustomWallpaperFromSyncFS(syncInfo.url, |
| 371 syncInfo.layout); | 377 syncInfo.layout); |
| 372 } else if (syncInfo.source == | 378 } else if (syncInfo.source == |
| 373 Constants.WallpaperSourceEnum.Default) { | 379 Constants.WallpaperSourceEnum.Default) { |
| 374 chrome.wallpaperPrivate.resetWallpaper(); | 380 chrome.wallpaperPrivate.resetWallpaper(); |
| 381 WallpaperUtil.clearThirdPartyAppName(); |
| 375 } | 382 } |
| 376 | 383 |
| 377 // If the old wallpaper is a third party wallpaper we should | 384 // If the old wallpaper is a third party wallpaper we should |
| 378 // remove it from the local & sync file system to free space. | 385 // remove it from the local & sync file system to free space. |
| 379 if (localInfo && localInfo.url.indexOf( | 386 if (localInfo && localInfo.url.indexOf( |
| 380 Constants.ThirdPartyWallpaperPrefix) != -1) { | 387 Constants.ThirdPartyWallpaperPrefix) != -1) { |
| 381 WallpaperUtil.deleteWallpaperFromLocalFS(localInfo.url); | 388 WallpaperUtil.deleteWallpaperFromLocalFS(localInfo.url); |
| 382 WallpaperUtil.deleteWallpaperFromSyncFS(localInfo.url); | 389 WallpaperUtil.deleteWallpaperFromSyncFS(localInfo.url); |
| 383 } | 390 } |
| 384 | 391 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 402 } | 409 } |
| 403 } | 410 } |
| 404 }); | 411 }); |
| 405 }); | 412 }); |
| 406 | 413 |
| 407 chrome.alarms.onAlarm.addListener(function() { | 414 chrome.alarms.onAlarm.addListener(function() { |
| 408 SurpriseWallpaper.getInstance().next(); | 415 SurpriseWallpaper.getInstance().next(); |
| 409 }); | 416 }); |
| 410 | 417 |
| 411 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( | 418 chrome.wallpaperPrivate.onWallpaperChangedBy3rdParty.addListener(function( |
| 412 wallpaper, thumbnail, layout) { | 419 wallpaper, thumbnail, layout, appname) { |
| 413 WallpaperUtil.saveToLocalStorage( | 420 WallpaperUtil.saveToLocalStorage( |
| 414 Constants.AccessLocalSurpriseMeEnabledKey, false, function() { | 421 Constants.AccessLocalSurpriseMeEnabledKey, false, function() { |
| 415 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey, | 422 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncSurpriseMeEnabledKey, |
| 416 false); | 423 false); |
| 417 }); | 424 }); |
| 418 SurpriseWallpaper.getInstance().disable(); | 425 SurpriseWallpaper.getInstance().disable(); |
| 419 | 426 |
| 420 // Make third party wallpaper syncable through different devices. | 427 // 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(); | 428 var filename = Constants.ThirdPartyWallpaperPrefix + new Date().getTime(); |
| 423 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix; | 429 var thumbnailFilename = filename + Constants.CustomWallpaperThumbnailSuffix; |
| 424 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper); | 430 WallpaperUtil.storeWallpaperToSyncFS(filename, wallpaper); |
| 425 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail); | 431 WallpaperUtil.storeWallpaperToSyncFS(thumbnailFilename, thumbnail); |
| 426 WallpaperUtil.saveWallpaperInfo(filename, layout, | 432 WallpaperUtil.saveWallpaperInfo(filename, layout, |
| 427 Constants.WallpaperSourceEnum.Custom); | 433 Constants.WallpaperSourceEnum.Custom); |
| 434 WallpaperUtil.saveThirdPartyAppName(appname); |
| 428 }); | 435 }); |
| OLD | NEW |