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', function() {
27 cr
.dispatchSimpleEvent(overlay
, 'cancelOverlay');
29 $('pack-extension-commit').addEventListener('click',
30 this.handleCommit_
.bind(this));
31 $('browse-extension-dir').addEventListener('click',
32 this.handleBrowseExtensionDir_
.bind(this));
33 $('browse-private-key').addEventListener('click',
34 this.handleBrowsePrivateKey_
.bind(this));
38 * Handles a click on the dismiss button.
39 * @param {Event} e The click event.
41 handleDismiss_: function(e
) {
42 extensions
.ExtensionSettings
.showOverlay(null);
46 * Handles a click on the pack button.
47 * @param {Event} e The click event.
49 handleCommit_: function(e
) {
50 var extensionPath
= $('extension-root-dir').value
;
51 var privateKeyPath
= $('extension-private-key').value
;
52 chrome
.developerPrivate
.packDirectory(
53 extensionPath
, privateKeyPath
, 0, this.onPackResponse_
.bind(this));
57 * Utility function which asks the C++ to show a platform-specific file
58 * select dialog, and set the value property of |node| to the selected path.
59 * @param {chrome.developerPrivate.SelectType} selectType
60 * The type of selection to use.
61 * @param {chrome.developerPrivate.FileType} fileType
62 * The type of file to select.
63 * @param {HTMLInputElement} node The node to set the value of.
66 showFileDialog_: function(selectType
, fileType
, node
) {
67 chrome
.developerPrivate
.choosePath(selectType
, fileType
, function(path
) {
68 // Last error is set if the user canceled the dialog.
69 if (!chrome
.runtime
.lastError
&& path
)
75 * Handles the showing of the extension directory browser.
76 * @param {Event} e Change event.
79 handleBrowseExtensionDir_: function(e
) {
81 chrome
.developerPrivate
.SelectType
.FOLDER
,
82 chrome
.developerPrivate
.FileType
.LOAD
,
83 /** @type {HTMLInputElement} */ ($('extension-root-dir')));
87 * Handles the showing of the extension private key file.
88 * @param {Event} e Change event.
91 handleBrowsePrivateKey_: function(e
) {
93 chrome
.developerPrivate
.SelectType
.FILE
,
94 chrome
.developerPrivate
.FileType
.PEM
,
95 /** @type {HTMLInputElement} */ ($('extension-private-key')));
99 * Handles a response from a packDirectory call.
100 * @param {PackDirectoryResponse} response The response of the pack call.
103 onPackResponse_: function(response
) {
104 /** @type {string} */
106 /** @type {string} */
108 /** @type {string} */
110 /** @type {function()} */
112 /** @type {function()} */
113 var alertCancelCallback
;
115 var closeAlert = function() {
116 extensions
.ExtensionSettings
.showOverlay(null);
119 switch (response
.status
) {
120 case chrome
.developerPrivate
.PackStatus
.SUCCESS
:
121 alertTitle
= loadTimeData
.getString('packExtensionOverlay');
122 alertOk
= loadTimeData
.getString('ok');
123 alertOkCallback
= closeAlert
;
124 // No 'Cancel' option.
126 case chrome
.developerPrivate
.PackStatus
.WARNING
:
127 alertTitle
= loadTimeData
.getString('packExtensionWarningTitle');
128 alertOk
= loadTimeData
.getString('packExtensionProceedAnyway');
129 alertCancel
= loadTimeData
.getString('cancel');
130 alertOkCallback = function() {
131 chrome
.developerPrivate
.packDirectory(
134 response
.override_flags
,
135 this.onPackResponse_
.bind(this));
138 alertCancelCallback
= closeAlert
;
140 case chrome
.developerPrivate
.PackStatus
.ERROR
:
141 alertTitle
= loadTimeData
.getString('packExtensionErrorTitle');
142 alertOk
= loadTimeData
.getString('ok');
143 alertOkCallback = function() {
144 extensions
.ExtensionSettings
.showOverlay(
145 $('pack-extension-overlay'));
147 // No 'Cancel' option.
154 alertOverlay
.setValues(alertTitle
,
159 alertCancelCallback
);
160 extensions
.ExtensionSettings
.showOverlay($('alertOverlay'));
166 PackExtensionOverlay
: PackExtensionOverlay