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

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

Issue 1631923004: Sync 3rd party wallpaper app name (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address tbarzic@'s comment. Created 4 years, 10 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
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 var WallpaperUtil = { 5 var WallpaperUtil = {
6 strings: null, // Object that contains all the flags 6 strings: null, // Object that contains all the flags
7 syncFs: null, // syncFileSystem handler 7 syncFs: null, // syncFileSystem handler
8 webkitFs: null // webkitFileSystem handler 8 webkitFs: null // webkitFileSystem handler
9 }; 9 };
10 10
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 reader.result, 252 reader.result,
253 wallpaperLayout, 253 wallpaperLayout,
254 true, 254 true,
255 wallpaperFilename, 255 wallpaperFilename,
256 function(thumbnailData) { 256 function(thumbnailData) {
257 // TODO(ranj): Ignore 'canceledWallpaper' error. 257 // TODO(ranj): Ignore 'canceledWallpaper' error.
258 if (chrome.runtime.lastError) { 258 if (chrome.runtime.lastError) {
259 console.error(chrome.runtime.lastError.message); 259 console.error(chrome.runtime.lastError.message);
260 return; 260 return;
261 } 261 }
262 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
263 reader.result, Constants.WallpaperDirNameEnum.ORIGINAL);
264 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
265 thumbnailData, Constants.WallpaperDirNameEnum.THUMBNAIL);
266 if (onSuccess) 262 if (onSuccess)
267 onSuccess(); 263 onSuccess();
268 }); 264 });
269 }; 265 };
270 reader.readAsArrayBuffer(file); 266 reader.readAsArrayBuffer(file);
271 }, WallpaperUtil.onFileSystemError); 267 }, WallpaperUtil.onFileSystemError);
272 }, function(e) {} // fail to read file, expected due to download delay 268 }, function(e) {} // fail to read file, expected due to download delay
273 ); 269 );
274 }; 270 };
275 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback); 271 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback);
(...skipping 27 matching lines...) Expand all
303 }); 299 });
304 }; 300 };
305 301
306 /** 302 /**
307 * Saves user's wallpaper infomation to local and sync storage. Note that local 303 * Saves user's wallpaper infomation to local and sync storage. Note that local
308 * value should be saved first. 304 * value should be saved first.
309 * @param {string} url The url address of wallpaper. For custom wallpaper, it is 305 * @param {string} url The url address of wallpaper. For custom wallpaper, it is
310 * the file name. 306 * the file name.
311 * @param {string} layout The wallpaper layout. 307 * @param {string} layout The wallpaper layout.
312 * @param {string} source The wallpaper source. 308 * @param {string} source The wallpaper source.
309 * @param {string} appName The third party app name. If the current wallpaper is
310 * set by the built-in wallpaper picker, it is set to an empty string.
313 */ 311 */
314 WallpaperUtil.saveWallpaperInfo = function(url, layout, source) { 312 WallpaperUtil.saveWallpaperInfo = function(url, layout, source, appName) {
315 var wallpaperInfo = { 313 var wallpaperInfo = {
316 url: url, 314 url: url,
317 layout: layout, 315 layout: layout,
318 source: source 316 source: source,
317 appName: appName,
319 }; 318 };
320 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalWallpaperInfoKey, 319 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalWallpaperInfoKey,
321 wallpaperInfo, function() { 320 wallpaperInfo, function() {
322 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncWallpaperInfoKey, 321 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncWallpaperInfoKey,
323 wallpaperInfo); 322 wallpaperInfo);
324 }); 323 });
325 }; 324 };
326 325
327 /** 326 /**
328 * Downloads resources from url. Calls onSuccess and opt_onFailure accordingly. 327 * Downloads resources from url. Calls onSuccess and opt_onFailure accordingly.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 chrome.wallpaperPrivate.setWallpaperIfExists(url, layout, function(exists) { 371 chrome.wallpaperPrivate.setWallpaperIfExists(url, layout, function(exists) {
373 if (exists) { 372 if (exists) {
374 onSuccess(); 373 onSuccess();
375 return; 374 return;
376 } 375 }
377 376
378 self.fetchURL(url, 'arraybuffer', function(xhr) { 377 self.fetchURL(url, 'arraybuffer', function(xhr) {
379 if (xhr.response != null) { 378 if (xhr.response != null) {
380 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url, 379 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url,
381 onSuccess); 380 onSuccess);
382 self.saveWallpaperInfo(url, layout, 381 self.saveWallpaperInfo(
383 Constants.WallpaperSourceEnum.Online); 382 url, layout, Constants.WallpaperSourceEnum.Online, '');
384 } else { 383 } else {
385 onFailure(); 384 onFailure();
386 } 385 }
387 }, onFailure); 386 }, onFailure);
388 }); 387 });
389 }; 388 };
390 389
391 /** 390 /**
392 * Runs chrome.test.sendMessage in test environment. Does nothing if running 391 * Runs chrome.test.sendMessage in test environment. Does nothing if running
393 * in production environment. 392 * in production environment.
394 * 393 *
395 * @param {string} message Test message to send. 394 * @param {string} message Test message to send.
396 */ 395 */
397 WallpaperUtil.testSendMessage = function(message) { 396 WallpaperUtil.testSendMessage = function(message) {
398 var test = chrome.test || window.top.chrome.test; 397 var test = chrome.test || window.top.chrome.test;
399 if (test) 398 if (test)
400 test.sendMessage(message); 399 test.sendMessage(message);
401 }; 400 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698