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.developerPrivate.packDirectory(
52 extensionPath, privateKeyPath, 0, this.onPackResponse_.bind(this));
56 * Utility function which asks the C++ to show a platform-specific file
57 * select dialog, and set the value property of |node| to the selected path.
58 * @param {SelectType} selectType The type of selection to use.
59 * @param {FileType} fileType The type of file to select.
60 * @param {HTMLInputElement} node The node to set the value of.
63 showFileDialog_: function(selectType, fileType, node) {
64 chrome.developerPrivate.choosePath(selectType, fileType, function(path) {
65 // Last error is set if the user canceled the dialog.
66 if (!chrome.runtime.lastError && path)
72 * Handles the showing of the extension directory browser.
73 * @param {Event} e Change event.
76 handleBrowseExtensionDir_: function(e) {
80 /** @type {HTMLInputElement} */ ($('extension-root-dir')));
84 * Handles the showing of the extension private key file.
85 * @param {Event} e Change event.
88 handleBrowsePrivateKey_: function(e) {
92 /** @type {HTMLInputElement} */ ($('extension-private-key')));
96 * Handles a response from a packDirectory call.
97 * @param {PackDirectoryResponse} response The response of the pack call.
100 onPackResponse_: function(response) {
101 /** @type {string} */
103 /** @type {string} */
105 /** @type {string} */
107 /** @type {function()} */
109 /** @type {function()} */
110 var alertCancelCallback;
112 var closeAlert = function() {
113 extensions.ExtensionSettings.showOverlay(null);
116 // TODO(devlin): Once we expose enums on extension APIs, we should use
117 // those objects, instead of a string.
118 switch (response.status) {
120 alertTitle = loadTimeData.getString('packExtensionOverlay');
121 alertOk = loadTimeData.getString('ok');
122 alertOkCallback = closeAlert;
123 // No 'Cancel' option.
126 alertTitle = loadTimeData.getString('packExtensionWarningTitle');
127 alertOk = loadTimeData.getString('packExtensionProceedAnyway');
128 alertCancel = loadTimeData.getString('cancel');
129 alertOkCallback = function() {
130 chrome.developerPrivate.packDirectory(
133 response.override_flags,
134 this.onPackResponse_.bind(this));
137 alertCancelCallback = closeAlert;
140 alertTitle = loadTimeData.getString('packExtensionErrorTitle');
141 alertOk = loadTimeData.getString('ok');
142 alertOkCallback = function() {
143 extensions.ExtensionSettings.showOverlay(
144 $('pack-extension-overlay'));
146 // No 'Cancel' option.
153 alertOverlay.setValues(alertTitle,
158 alertCancelCallback);
159 extensions.ExtensionSettings.showOverlay($('alertOverlay'));
165 PackExtensionOverlay: PackExtensionOverlay