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 3 // found in the LICENSE file. 4 5 'use strict'; 6 7 // Namespace object for the utilities. 8 var ActionChoiceUtil = {}; 9 10 /** 11 * Gets list of defined actions. 12 * @param {Object} loadTimeData Load time data for i18n. 13 * @param {function(Array.<Object>)} callback Callback with list of defined 14 * actions. 15 */ 16 ActionChoiceUtil.getDefinedActions = function(loadTimeData, callback) { 17 // Fill out predefined actions first. 18 var result = [{ 19 id: 'view-files', 20 title: loadTimeData.getString('ACTION_CHOICE_VIEW_FILES'), 21 class: 'view-files-icon' 22 }, { 23 id: 'import-photos-to-drive', 24 title: loadTimeData.getString('ACTION_CHOICE_PHOTOS_DRIVE'), 25 class: 'import-photos-to-drive-icon', 26 disabled: true, 27 disabledTitle: loadTimeData.getString('ACTION_CHOICE_DRIVE_NOT_REACHED') 28 }, { 29 id: 'watch-single-video', 30 class: 'watch-single-video-icon', 31 hidden: true, 32 disabled: true 33 }]; 34 chrome.mediaGalleriesPrivate.getHandlers(function(handlers) { 35 for (var i = 0; i < handlers.length; i++) { 36 var action = { 37 id: handlers[i].extensionId + ':' + handlers[i].id, 38 title: handlers[i].title, 39 // TODO(mtomasz): Get the passed icon instead of the extension icon. 40 icon100: 41 'chrome://extension-icon/' + handlers[i].extensionId + '/32/1', 42 icon200: 43 'chrome://extension-icon/' + handlers[i].extensionId + '/64/1', 44 extensionId: handlers[i].extensionId, 45 actionId: handlers[i].id 46 }; 47 result.push(action); 48 } 49 callback(result); 50 }.bind(this)); 51 }; 52 53 /** 54 * Gets the remembered action's identifier. 55 * @param {function(string=)} callback Callback with the identifier. 56 */ 57 ActionChoiceUtil.getRememberedActionId = function(callback) { 58 chrome.storage.local.get(['action-choice'], function(result) { 59 callback(result['action-choice']); 60 }); 61 }; 62 63 /** 64 * Sets the remembered action's identifier. 65 * @param {string=} opt_actionId Action's identifier. If undefined, then forgets 66 * the remembered choice. 67 */ 68 ActionChoiceUtil.setRememberedActionId = function(opt_actionId) { 69 chrome.storage.local.set({'action-choice': opt_actionId}); 70 }; 71