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.
5 cr.define('extensions', function() {
7 * PackExtensionOverlay class
8 * Encapsulated handling of the 'Pack Extension' overlay page.
11 function PackExtensionOverlay() {
14 cr.addSingletonGetter(PackExtensionOverlay);
16 PackExtensionOverlay.prototype = {
18 * Initialize the page.
20 initializePage: function() {
21 var overlay = $('overlay');
22 cr.ui.overlay.setupOverlay(overlay);
23 cr.ui.overlay.globalInitialization();
24 overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this));
26 $('pack-extension-dismiss').addEventListener('click',
27 this.handleDismiss_.bind(this));
28 $('pack-extension-commit').addEventListener('click',
29 this.handleCommit_.bind(this));
30 $('browse-extension-dir').addEventListener('click',
31 this.handleBrowseExtensionDir_.bind(this));
32 $('browse-private-key').addEventListener('click',
33 this.handleBrowsePrivateKey_.bind(this));
37 * Handles a click on the dismiss button.
38 * @param {Event} e The click event.
40 handleDismiss_: function(e) {
41 extensions.ExtensionSettings.showOverlay(null);
45 * Handles a click on the pack button.
46 * @param {Event} e The click event.
48 handleCommit_: function(e) {
49 var extensionPath = $('extension-root-dir').value;
50 var privateKeyPath = $('extension-private-key').value;
51 chrome.send('pack', [extensionPath, privateKeyPath, 0]);
55 * Utility function which asks the C++ to show a platform-specific file
56 * select dialog, and fire |callback| with the |filePath| that resulted.
57 * |selectType| can be either 'file' or 'folder'. |operation| can be 'load'
58 * or 'pem' which are signals to the C++ to do some operation-specific
62 showFileDialog_: function(selectType, operation, callback) {
63 handleFilePathSelected = function(filePath) {
65 handleFilePathSelected = function() {};
68 chrome.send('packExtensionSelectFilePath', [selectType, operation]);
72 * Handles the showing of the extension directory browser.
73 * @param {Event} e Change event.
76 handleBrowseExtensionDir_: function(e) {
77 this.showFileDialog_('folder', 'load', function(filePath) {
78 $('extension-root-dir').value = filePath;
83 * Handles the showing of the extension private key file.
84 * @param {Event} e Change event.
87 handleBrowsePrivateKey_: function(e) {
88 this.showFileDialog_('file', 'pem', function(filePath) {
89 $('extension-private-key').value = filePath;
95 * Wrap up the pack process by showing the success |message| and closing
97 * @param {string} message The message to show to the user.
99 PackExtensionOverlay.showSuccessMessage = function(message) {
100 alertOverlay.setValues(
101 loadTimeData.getString('packExtensionOverlay'),
103 loadTimeData.getString('ok'),
106 extensions.ExtensionSettings.showOverlay(null);
109 extensions.ExtensionSettings.showOverlay($('alertOverlay'));
113 * Post an alert overlay showing |message|, and upon acknowledgement, close
114 * the alert overlay and return to showing the PackExtensionOverlay.
116 PackExtensionOverlay.showError = function(message) {
117 alertOverlay.setValues(
118 loadTimeData.getString('packExtensionErrorTitle'),
120 loadTimeData.getString('ok'),
123 extensions.ExtensionSettings.showOverlay($('pack-extension-overlay'));
126 extensions.ExtensionSettings.showOverlay($('alertOverlay'));
131 PackExtensionOverlay: PackExtensionOverlay