Index: chrome/browser/resources/extensions/pack_extension_overlay.js |
diff --git a/chrome/browser/resources/extensions/pack_extension_overlay.js b/chrome/browser/resources/extensions/pack_extension_overlay.js |
index 186f84102e632463ca50099b89a95438d9c8c4b9..5506a6ce06f68d64811c8c0a1f62dbf57ba68de9 100644 |
--- a/chrome/browser/resources/extensions/pack_extension_overlay.js |
+++ b/chrome/browser/resources/extensions/pack_extension_overlay.js |
@@ -48,24 +48,23 @@ cr.define('extensions', function() { |
handleCommit_: function(e) { |
var extensionPath = $('extension-root-dir').value; |
var privateKeyPath = $('extension-private-key').value; |
- chrome.send('pack', [extensionPath, privateKeyPath, 0]); |
+ chrome.developerPrivate.packDirectory( |
+ extensionPath, privateKeyPath, 0, this.onPackResponse_.bind(this)); |
}, |
/** |
* 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. |
+ * select dialog, and set the value property of |node| to the selected path. |
+ * @param {SelectType} selectType The type of selection to use. |
+ * @param {FileType} fileType The type of file to select. |
+ * @param {HTMLInputElement} node The node to set the value of. |
* @private |
*/ |
- showFileDialog_: function(selectType, operation, callback) { |
- window.handleFilePathSelected = function(filePath) { |
- callback(filePath); |
- window.handleFilePathSelected = function() {}; |
- }; |
- |
- chrome.send('packExtensionSelectFilePath', [selectType, operation]); |
+ showFileDialog_: function(selectType, fileType, node) { |
+ chrome.developerPrivate.choosePath(selectType, fileType, function(path) { |
+ if (!chrome.runtime.lastError && path) |
not at google - send to devlin
2015/02/27 17:58:11
Add note, that this will happen if the file choose
Dan Beam
2015/02/27 19:57:51
i find it a little odd that we rely on a global he
Devlin
2015/02/27 21:37:02
Done.
Devlin
2015/02/27 21:37:02
TL;DR: Part of the extensions system. Should be o
Dan Beam
2015/02/27 22:57:17
lame-ish
not at google - send to devlin
2015/02/27 22:58:44
Indeed. It's weighing down my TODO list to fix it,
|
+ node.value = path; |
+ }); |
}, |
/** |
@@ -74,9 +73,10 @@ cr.define('extensions', function() { |
* @private |
*/ |
handleBrowseExtensionDir_: function(e) { |
- this.showFileDialog_('folder', 'load', function(filePath) { |
- $('extension-root-dir').value = filePath; |
- }); |
+ this.showFileDialog_( |
+ 'FOLDER', |
+ 'LOAD', |
+ /** @type {HTMLInputElement} */ ($('extension-root-dir'))); |
}, |
/** |
@@ -85,44 +85,71 @@ cr.define('extensions', function() { |
* @private |
*/ |
handleBrowsePrivateKey_: function(e) { |
- this.showFileDialog_('file', 'pem', function(filePath) { |
- $('extension-private-key').value = filePath; |
- }); |
+ this.showFileDialog_( |
+ 'FILE', |
+ 'PEM', |
+ /** @type {HTMLInputElement} */ ($('extension-private-key'))); |
}, |
- }; |
- /** |
- * 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); |
- }); |
- extensions.ExtensionSettings.showOverlay($('alertOverlay')); |
- }; |
+ /** |
+ * Handles a response from a packDirectory call. |
+ * @param {PackDirectoryResponse} response The response of the pack call. |
+ * @private |
+ */ |
+ onPackResponse_: function(response) { |
not at google - send to devlin
2015/02/27 17:58:11
I will give this a spin when I get to work.
Devlin
2015/02/27 21:37:02
Spun.
|
+ console.log('On pack response'); |
+ console.log(JSON.stringify(response)); |
not at google - send to devlin
2015/02/27 17:58:11
Remove logging?
Dan Beam
2015/02/27 19:57:51
+1
Devlin
2015/02/27 21:37:02
Done.
|
+ /** @type {string} */ |
+ var alertTitle; |
+ /** @type {string} */ |
+ var alertOk; |
+ /** @type {string} */ |
+ var alertCancel; |
+ /** @type {function()} */ |
+ var alertOkCallback; |
+ /** @type {function()} */ |
+ var alertCancelCallback; |
- /** |
- * Post an alert overlay showing |message|, and upon acknowledgement, close |
- * the alert overlay and return to showing the PackExtensionOverlay. |
- * @param {string} message The error message. |
- */ |
- PackExtensionOverlay.showError = function(message) { |
- alertOverlay.setValues( |
- loadTimeData.getString('packExtensionErrorTitle'), |
- message, |
- loadTimeData.getString('ok'), |
- '', |
- function() { |
+ var closeAlert = function() { |
+ extensions.ExtensionSettings.showOverlay(null); |
+ }; |
+ |
+ if (response.status == 'SUCCESS') { |
not at google - send to devlin
2015/02/27 19:23:58
Can you switch?
Dan Beam
2015/02/27 19:57:51
yes, switch (stringValue) {...} works in js, and i
Devlin
2015/02/27 21:37:02
switch done.
Dan, what would it look like to use
Dan Beam
2015/02/27 22:57:17
http://stackoverflow.com/questions/18186309/is-the
Devlin
2015/02/27 23:38:37
I was more curious if there was a way of doing it
Dan Beam
2015/02/28 00:17:57
JavaScript has no enums natively, so using some ex
|
+ alertTitle = loadTimeData.getString('packExtensionOverlay'); |
+ alertOk = loadTimeData.getString('ok'); |
+ alertOkCallback = closeAlert; |
+ // No 'Cancel' option. |
+ } else if (response.status == 'WARNING') { |
+ alertTitle = loadTimeData.getString('packExtensionWarningTitle'), |
+ alertOk = loadTimeData.getString('packExtensionProceedAnyway'), |
+ alertCancel = loadTimeData.getString('cancel'), |
+ alertOkCallback = function() { |
+ chrome.developerPrivate.packDirectory( |
+ response.item_path, |
+ response.pem_path, |
+ response.override_flags, |
+ this.onPackResponse_.bind(this)); |
+ closeAlert(); |
+ }.bind(this); |
+ alertCancelCallback = closeAlert; |
+ } else { |
+ assert(response.status == 'ERROR'); |
not at google - send to devlin
2015/02/27 19:23:58
I'd rather cover this in a switch case then in a d
Devlin
2015/02/27 21:37:02
Done.
|
+ alertTitle = loadTimeData.getString('packExtensionErrorTitle'), |
+ alertOk = loadTimeData.getString('ok'), |
+ alertOkCallback = function() { |
extensions.ExtensionSettings.showOverlay($('pack-extension-overlay')); |
- }); |
- extensions.ExtensionSettings.showOverlay($('alertOverlay')); |
+ }; |
+ // No 'Cancel' option. |
+ } |
+ |
+ alertOverlay.setValues(alertTitle, |
Dan Beam
2015/02/27 19:57:50
where does this variable come from? is alertOverl
Devlin
2015/02/27 21:37:03
Took me forever to find it, to, when I was trying
|
+ response.message, |
+ alertOk, |
+ alertCancel, |
+ alertOkCallback, |
+ alertCancelCallback); |
+ extensions.ExtensionSettings.showOverlay($('alertOverlay')); |
+ }, |
}; |
// Export |