1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('extensions', function() {
/**
* PackExtensionOverlay class
* Encapsulated handling of the 'Pack Extension' overlay page.
* @constructor
*/
function PackExtensionOverlay() {
}
cr.addSingletonGetter(PackExtensionOverlay);
PackExtensionOverlay.prototype = {
/**
* Initialize the page.
*/
initializePage: function() {
var overlay = $('overlay');
cr.ui.overlay.setupOverlay(overlay);
cr.ui.overlay.globalInitialization();
overlay.addEventListener('cancelOverlay', this.handleDismiss_.bind(this));
$('pack-extension-dismiss').addEventListener('click',
this.handleDismiss_.bind(this));
$('pack-extension-commit').addEventListener('click',
this.handleCommit_.bind(this));
$('browse-extension-dir').addEventListener('click',
this.handleBrowseExtensionDir_.bind(this));
$('browse-private-key').addEventListener('click',
this.handleBrowsePrivateKey_.bind(this));
},
/**
* Handles a click on the dismiss button.
* @param {Event} e The click event.
*/
handleDismiss_: function(e) {
extensions.ExtensionSettings.showOverlay(null);
},
/**
* Handles a click on the pack button.
* @param {Event} e The click event.
*/
handleCommit_: function(e) {
var extensionPath = $('extension-root-dir').value;
var privateKeyPath = $('extension-private-key').value;
chrome.send('pack', [extensionPath, privateKeyPath, 0]);
},
/**
* Utility function which asks the C++ to show a platform-specific file
* select dialog, and fire |callback| with the |filePath| that resulted.
* |selectType| can be either 'file' or 'folder'. |operation| can be 'load'
* or 'pem' which are signals to the C++ to do some operation-specific
* configuration.
* @private
*/
showFileDialog_: function(selectType, operation, callback) {
handleFilePathSelected = function(filePath) {
callback(filePath);
handleFilePathSelected = function() {};
};
chrome.send('packExtensionSelectFilePath', [selectType, operation]);
},
/**
* Handles the showing of the extension directory browser.
* @param {Event} e Change event.
* @private
*/
handleBrowseExtensionDir_: function(e) {
this.showFileDialog_('folder', 'load', function(filePath) {
$('extension-root-dir').value = filePath;
});
},
/**
* Handles the showing of the extension private key file.
* @param {Event} e Change event.
* @private
*/
handleBrowsePrivateKey_: function(e) {
this.showFileDialog_('file', 'pem', function(filePath) {
$('extension-private-key').value = filePath;
});
},
};
/**
* Wrap up the pack process by showing the success |message| and closing
* the overlay.
* @param {string} message The message to show to the user.
*/
PackExtensionOverlay.showSuccessMessage = function(message) {
alertOverlay.setValues(
loadTimeData.getString('packExtensionOverlay'),
message,
loadTimeData.getString('ok'),
'',
function() {
extensions.ExtensionSettings.showOverlay(null);
},
null);
extensions.ExtensionSettings.showOverlay($('alertOverlay'));
};
/**
* Post an alert overlay showing |message|, and upon acknowledgement, close
* the alert overlay and return to showing the PackExtensionOverlay.
*/
PackExtensionOverlay.showError = function(message) {
alertOverlay.setValues(
loadTimeData.getString('packExtensionErrorTitle'),
message,
loadTimeData.getString('ok'),
'',
function() {
extensions.ExtensionSettings.showOverlay($('pack-extension-overlay'));
},
null);
extensions.ExtensionSettings.showOverlay($('alertOverlay'));
};
// Export
return {
PackExtensionOverlay: PackExtensionOverlay
};
});
|