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

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 comments. 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 WallpaperUtil.storeWallpaperToLocalFS = function(wallpaperFilename, 207 WallpaperUtil.storeWallpaperToLocalFS = function(wallpaperFilename,
208 wallpaperData, saveDir) { 208 wallpaperData, saveDir) {
209 if (!wallpaperData) { 209 if (!wallpaperData) {
210 console.error('wallpaperData is null'); 210 console.error('wallpaperData is null');
211 return; 211 return;
212 } 212 }
213 var getDirSuccess = function(dirEntry) { 213 var getDirSuccess = function(dirEntry) {
214 dirEntry.getFile(wallpaperFilename, 214 dirEntry.getFile(wallpaperFilename,
215 {create: false}, 215 {create: false},
216 function() {}, // already exists 216 function() {}, // already exists
217 function(e) { // not exists, create 217 function(e) { // not exists, create
tbarzic 2016/02/04 21:31:24 Not really related to this cl, so feel to ignore f
xdai1 2016/02/05 01:09:52 Yes, every wallpaper has its unique file path. The
218 dirEntry.getFile(wallpaperFilename, {create: true}, 218 dirEntry.getFile(wallpaperFilename, {create: true},
219 function(fe) { 219 function(fe) {
220 WallpaperUtil.writeFile(fe, 220 WallpaperUtil.writeFile(fe,
221 wallpaperData); 221 wallpaperData);
222 }, 222 },
223 WallpaperUtil.onFileSystemError); 223 WallpaperUtil.onFileSystemError);
224 }); 224 });
225 }; 225 };
226 WallpaperUtil.requestLocalFS(function(fs) { 226 WallpaperUtil.requestLocalFS(function(fs) {
227 fs.root.getDirectory(saveDir, {create: true}, getDirSuccess, 227 fs.root.getDirectory(saveDir, {create: true}, getDirSuccess,
228 WallpaperUtil.onFileSystemError); 228 WallpaperUtil.onFileSystemError);
229 }); 229 });
230 }; 230 };
231 231
232 /** 232 /**
233 * Sets wallpaper from synced file system. 233 * Sets wallpaper from synced file system.
234 * @param {string} wallpaperFilename File name used to set wallpaper. 234 * @param {string} wallpaperFilename File name used to set wallpaper.
235 * @param {string} wallpaperLayout Layout used to set wallpaper. 235 * @param {string} wallpaperLayout Layout used to set wallpaper.
236 * @param {string} appName If non-empty, the current wallpaper is set by a third
tbarzic 2016/02/04 21:31:24 wdyt about changing method signature to (possibly
237 * party wallpaper. Otherwise, it is set by the built-in wallpaper picker.
236 * @param {function=} onSuccess Callback if set successfully. 238 * @param {function=} onSuccess Callback if set successfully.
237 */ 239 */
238 WallpaperUtil.setCustomWallpaperFromSyncFS = function( 240 WallpaperUtil.setCustomWallpaperFromSyncFS = function(
239 wallpaperFilename, wallpaperLayout, onSuccess) { 241 wallpaperFilename, wallpaperLayout, appName, onSuccess) {
240 var setWallpaperFromSyncCallback = function(fs) { 242 var setWallpaperFromSyncCallback = function(fs) {
241 if (!wallpaperFilename) { 243 if (!wallpaperFilename) {
242 console.error('wallpaperFilename is not provided.'); 244 console.error('wallpaperFilename is not provided.');
243 return; 245 return;
244 } 246 }
245 if (!wallpaperLayout) 247 if (!wallpaperLayout)
246 wallpaperLayout = 'CENTER_CROPPED'; 248 wallpaperLayout = 'CENTER_CROPPED';
247 fs.root.getFile(wallpaperFilename, {create: false}, function(fileEntry) { 249 fs.root.getFile(wallpaperFilename, {create: false}, function(fileEntry) {
248 fileEntry.file(function(file) { 250 fileEntry.file(function(file) {
249 var reader = new FileReader(); 251 var reader = new FileReader();
250 reader.onloadend = function() { 252 reader.onloadend = function() {
251 chrome.wallpaperPrivate.setCustomWallpaper( 253 chrome.wallpaperPrivate.setCustomWallpaper(
252 reader.result, 254 reader.result,
253 wallpaperLayout, 255 wallpaperLayout,
254 true, 256 true,
255 wallpaperFilename, 257 wallpaperFilename,
256 function(thumbnailData) { 258 function(thumbnailData) {
257 // TODO(ranj): Ignore 'canceledWallpaper' error. 259 // TODO(ranj): Ignore 'canceledWallpaper' error.
258 if (chrome.runtime.lastError) { 260 if (chrome.runtime.lastError) {
259 console.error(chrome.runtime.lastError.message); 261 console.error(chrome.runtime.lastError.message);
260 return; 262 return;
261 } 263 }
262 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename, 264
263 reader.result, Constants.WallpaperDirNameEnum.ORIGINAL); 265 // We only need to store the custom wallpaper that is set by the
264 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename, 266 // built-in wallpaper picker.
265 thumbnailData, Constants.WallpaperDirNameEnum.THUMBNAIL); 267 if (!appName) {
tbarzic 2016/02/04 21:31:24 This can give false positives if the wallpaper was
xdai1 2016/02/05 01:09:52 You're right. Actually on a second thought I thin
268 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
269 reader.result, Constants.WallpaperDirNameEnum.ORIGINAL);
270 WallpaperUtil.storeWallpaperToLocalFS(wallpaperFilename,
271 thumbnailData, Constants.WallpaperDirNameEnum.THUMBNAIL);
272 }
266 if (onSuccess) 273 if (onSuccess)
267 onSuccess(); 274 onSuccess();
268 }); 275 });
269 }; 276 };
270 reader.readAsArrayBuffer(file); 277 reader.readAsArrayBuffer(file);
271 }, WallpaperUtil.onFileSystemError); 278 }, WallpaperUtil.onFileSystemError);
272 }, function(e) {} // fail to read file, expected due to download delay 279 }, function(e) {} // fail to read file, expected due to download delay
273 ); 280 );
274 }; 281 };
275 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback); 282 WallpaperUtil.requestSyncFS(setWallpaperFromSyncCallback);
(...skipping 27 matching lines...) Expand all
303 }); 310 });
304 }; 311 };
305 312
306 /** 313 /**
307 * Saves user's wallpaper infomation to local and sync storage. Note that local 314 * Saves user's wallpaper infomation to local and sync storage. Note that local
308 * value should be saved first. 315 * value should be saved first.
309 * @param {string} url The url address of wallpaper. For custom wallpaper, it is 316 * @param {string} url The url address of wallpaper. For custom wallpaper, it is
310 * the file name. 317 * the file name.
311 * @param {string} layout The wallpaper layout. 318 * @param {string} layout The wallpaper layout.
312 * @param {string} source The wallpaper source. 319 * @param {string} source The wallpaper source.
320 * @param {string} appName The third party app name. If the current wallpaper is
321 * set by the built-in wallpaper picker, it is set to an empty string.
313 */ 322 */
314 WallpaperUtil.saveWallpaperInfo = function(url, layout, source) { 323 WallpaperUtil.saveWallpaperInfo = function(url, layout, source, appName) {
315 var wallpaperInfo = { 324 var wallpaperInfo = {
316 url: url, 325 url: url,
317 layout: layout, 326 layout: layout,
318 source: source 327 source: source,
328 appName: appName,
319 }; 329 };
320 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalWallpaperInfoKey, 330 WallpaperUtil.saveToLocalStorage(Constants.AccessLocalWallpaperInfoKey,
321 wallpaperInfo, function() { 331 wallpaperInfo, function() {
322 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncWallpaperInfoKey, 332 WallpaperUtil.saveToSyncStorage(Constants.AccessSyncWallpaperInfoKey,
323 wallpaperInfo); 333 wallpaperInfo);
324 }); 334 });
325 }; 335 };
326 336
327 /** 337 /**
328 * Downloads resources from url. Calls onSuccess and opt_onFailure accordingly. 338 * 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) { 382 chrome.wallpaperPrivate.setWallpaperIfExists(url, layout, function(exists) {
373 if (exists) { 383 if (exists) {
374 onSuccess(); 384 onSuccess();
375 return; 385 return;
376 } 386 }
377 387
378 self.fetchURL(url, 'arraybuffer', function(xhr) { 388 self.fetchURL(url, 'arraybuffer', function(xhr) {
379 if (xhr.response != null) { 389 if (xhr.response != null) {
380 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url, 390 chrome.wallpaperPrivate.setWallpaper(xhr.response, layout, url,
381 onSuccess); 391 onSuccess);
382 self.saveWallpaperInfo(url, layout, 392 self.saveWallpaperInfo(
383 Constants.WallpaperSourceEnum.Online); 393 url, layout, Constants.WallpaperSourceEnum.Online, '');
384 } else { 394 } else {
385 onFailure(); 395 onFailure();
386 } 396 }
387 }, onFailure); 397 }, onFailure);
388 }); 398 });
389 }; 399 };
390 400
391 /** 401 /**
392 * Runs chrome.test.sendMessage in test environment. Does nothing if running 402 * Runs chrome.test.sendMessage in test environment. Does nothing if running
393 * in production environment. 403 * in production environment.
394 * 404 *
395 * @param {string} message Test message to send. 405 * @param {string} message Test message to send.
396 */ 406 */
397 WallpaperUtil.testSendMessage = function(message) { 407 WallpaperUtil.testSendMessage = function(message) {
398 var test = chrome.test || window.top.chrome.test; 408 var test = chrome.test || window.top.chrome.test;
399 if (test) 409 if (test)
400 test.sendMessage(message); 410 test.sendMessage(message);
401 }; 411 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698