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