Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
| 6 * Sets 'hidden' property of a cr.ui.Command instance and dispatches | 6 * Sets 'hidden' property of a cr.ui.Command instance and dispatches |
| 7 * 'hiddenChange' event manually so that associated cr.ui.MenuItem can handle | 7 * 'hiddenChange' event manually so that associated cr.ui.MenuItem can handle |
| 8 * the event. | 8 * the event. |
| 9 * TODO(fukino): Remove this workaround when crbug.com/481941 is fixed. | 9 * TODO(fukino): Remove this workaround when crbug.com/481941 is fixed. |
| 10 * | 10 * |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1500 }, | 1500 }, |
| 1501 canExecute: function(event, fileManager) { | 1501 canExecute: function(event, fileManager) { |
| 1502 var currentDirEntry = fileManager.directoryModel.getCurrentDirEntry(); | 1502 var currentDirEntry = fileManager.directoryModel.getCurrentDirEntry(); |
| 1503 var volumeInfo = currentDirEntry && | 1503 var volumeInfo = currentDirEntry && |
| 1504 fileManager.volumeManager.getVolumeInfo(currentDirEntry); | 1504 fileManager.volumeManager.getVolumeInfo(currentDirEntry); |
| 1505 event.canExecute = volumeInfo && !volumeInfo.watchable; | 1505 event.canExecute = volumeInfo && !volumeInfo.watchable; |
| 1506 event.command.setHidden(!event.canExecute || | 1506 event.command.setHidden(!event.canExecute || |
| 1507 fileManager.directoryModel.getFileListSelection().getCheckSelectMode()); | 1507 fileManager.directoryModel.getFileListSelection().getCheckSelectMode()); |
| 1508 } | 1508 } |
| 1509 }); | 1509 }); |
| 1510 | |
| 1511 /** | |
| 1512 * Refreshes the currently selected directory. | |
| 1513 */ | |
| 1514 CommandHandler.COMMANDS_['set-wallpaper'] = /** @type {Command} */ ({ | |
| 1515 /** | |
| 1516 * @param {!Event} event Command event. | |
| 1517 * @param {!FileManager} fileManager FileManager to use. | |
| 1518 */ | |
| 1519 execute: function(event, fileManager) { | |
| 1520 var entry = fileManager.getSelection().entries[0]; | |
| 1521 new Promise(function(resolve, reject) { | |
| 1522 entry.file(resolve, reject); | |
| 1523 }).then(function(blob) { | |
| 1524 var fileReader = new FileReader(); | |
| 1525 return new Promise(function(resolve, reject) { | |
| 1526 fileReader.onload = function() { | |
| 1527 resolve(fileReader.result); | |
| 1528 }; | |
| 1529 fileReader.onerror = function() { | |
| 1530 reject(fileReader.error); | |
| 1531 }; | |
| 1532 fileReader.readAsArrayBuffer(blob); | |
| 1533 }) | |
| 1534 }).then(function(/** @type {!ArrayBuffer} */ arrayBuffer) { | |
| 1535 return new Promise(function(resolve, reject) { | |
| 1536 chrome.wallpaper.setWallpaper({ | |
| 1537 data: arrayBuffer, | |
| 1538 layout: 'CENTER_CROPPED', | |
|
Dan Beam
2016/02/25 17:08:55
using the enum even if the @param is a {string} sh
ryoh
2016/02/26 02:30:03
Done.
| |
| 1539 filename: 'wallpaper' | |
| 1540 }, function() { | |
| 1541 if (chrome.runtime.lastError) { | |
| 1542 reject(chrome.runtime.lastError); | |
| 1543 }else{ | |
| 1544 resolve(null); | |
| 1545 } | |
| 1546 }); | |
| 1547 }); | |
| 1548 }).catch(function() { | |
| 1549 fileManager.ui.alertDialog.showHtml( | |
| 1550 '', str('ERROR_INVALID_WALLPAPER'), null, null, null); | |
| 1551 }); | |
| 1552 }, | |
| 1553 canExecute: function(event, fileManager) { | |
| 1554 var entries = CommandUtil.getCommandEntries(event.target); | |
| 1555 if (entries.length === 0) { | |
| 1556 event.canExecute = false; | |
| 1557 event.command.setHidden(true); | |
| 1558 return; | |
| 1559 } | |
| 1560 var type = FileType.getType(entries[0]); | |
| 1561 if (entries.length !== 1 || type.type !== 'image') { | |
| 1562 event.canExecute = false; | |
| 1563 event.command.setHidden(true); | |
| 1564 return; | |
| 1565 } | |
| 1566 | |
| 1567 event.canExecute = type.subtype === 'JPEG' || type.subtype === 'PNG'; | |
| 1568 event.command.setHidden(false); | |
| 1569 } | |
| 1570 }); | |
| OLD | NEW |