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<include src="extension_command_list.js"> 6 7cr.define('extensions', function() { 8 'use strict'; 9 10 // The Extension Commands list object that will be used to show the commands 11 // on the page. 12 var ExtensionCommandList = options.ExtensionCommandList; 13 14 /** 15 * ExtensionCommandsOverlay class 16 * Encapsulated handling of the 'Extension Commands' overlay page. 17 * @constructor 18 */ 19 function ExtensionCommandsOverlay() { 20 } 21 22 cr.addSingletonGetter(ExtensionCommandsOverlay); 23 24 ExtensionCommandsOverlay.prototype = { 25 /** 26 * Initialize the page. 27 */ 28 initializePage: function() { 29 var overlay = $('overlay'); 30 cr.ui.overlay.setupOverlay(overlay); 31 cr.ui.overlay.globalInitialization(); 32 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this)); 33 34 $('extension-commands-dismiss').addEventListener('click', 35 this.handleDismiss_.bind(this)); 36 37 // This will request the data to show on the page and will get a response 38 // back in returnExtensionsData. 39 chrome.send('extensionCommandsRequestExtensionsData'); 40 }, 41 42 /** 43 * Handles a click on the dismiss button. 44 * @param {Event} e The click event. 45 */ 46 handleDismiss_: function(e) { 47 extensions.ExtensionSettings.showOverlay(null); 48 }, 49 }; 50 51 /** 52 * Called by the dom_ui_ to re-populate the page with data representing 53 * the current state of extension commands. 54 * @param {!{commands: Array.<{name: string, id: string, commands: ?Array}>}} 55 * extensionsData 56 */ 57 ExtensionCommandsOverlay.returnExtensionsData = function(extensionsData) { 58 ExtensionCommandList.prototype.data_ = extensionsData; 59 var extensionCommandList = $('extension-command-list'); 60 ExtensionCommandList.decorate(extensionCommandList); 61 62 // Make sure the config link is visible, since there are commands to show 63 // and potentially configure. 64 document.querySelector('.extension-commands-config').hidden = 65 extensionsData.commands.length == 0; 66 67 $('no-commands').hidden = extensionsData.commands.length > 0; 68 var list = $('extension-command-list'); 69 if (extensionsData.commands.length == 0) 70 list.classList.add('empty-extension-commands-list'); 71 else 72 list.classList.remove('empty-extension-commands-list'); 73 }; 74 75 // Export 76 return { 77 ExtensionCommandsOverlay: ExtensionCommandsOverlay 78 }; 79}); 80