Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('extensions', function() { | 5 cr.define('extensions', function() { |
| 6 /** | 6 /** |
| 7 * PackExtensionOverlay class | 7 * PackExtensionOverlay class |
| 8 * Encapsulated handling of the 'Pack Extension' overlay page. | 8 * Encapsulated handling of the 'Pack Extension' overlay page. |
| 9 * @constructor | 9 * @constructor |
| 10 */ | 10 */ |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 extensions.ExtensionSettings.showOverlay(null); | 41 extensions.ExtensionSettings.showOverlay(null); |
| 42 }, | 42 }, |
| 43 | 43 |
| 44 /** | 44 /** |
| 45 * Handles a click on the pack button. | 45 * Handles a click on the pack button. |
| 46 * @param {Event} e The click event. | 46 * @param {Event} e The click event. |
| 47 */ | 47 */ |
| 48 handleCommit_: function(e) { | 48 handleCommit_: function(e) { |
| 49 var extensionPath = $('extension-root-dir').value; | 49 var extensionPath = $('extension-root-dir').value; |
| 50 var privateKeyPath = $('extension-private-key').value; | 50 var privateKeyPath = $('extension-private-key').value; |
| 51 chrome.send('pack', [extensionPath, privateKeyPath, 0]); | 51 chrome.developerPrivate.packDirectory( |
| 52 extensionPath, privateKeyPath, 0, this.onPackResponse_.bind(this)); | |
| 52 }, | 53 }, |
| 53 | 54 |
| 54 /** | 55 /** |
| 55 * Utility function which asks the C++ to show a platform-specific file | 56 * Utility function which asks the C++ to show a platform-specific file |
| 56 * select dialog, and fire |callback| with the |filePath| that resulted. | 57 * select dialog, and set the value property of |node| to the selected path. |
| 57 * |selectType| can be either 'file' or 'folder'. |operation| can be 'load' | 58 * @param {SelectType} selectType The type of selection to use. |
| 58 * or 'pem' which are signals to the C++ to do some operation-specific | 59 * @param {FileType} fileType The type of file to select. |
| 59 * configuration. | 60 * @param {HTMLInputElement} node The node to set the value of. |
| 60 * @private | 61 * @private |
| 61 */ | 62 */ |
| 62 showFileDialog_: function(selectType, operation, callback) { | 63 showFileDialog_: function(selectType, fileType, node) { |
| 63 window.handleFilePathSelected = function(filePath) { | 64 chrome.developerPrivate.choosePath(selectType, fileType, function(path) { |
| 64 callback(filePath); | 65 // Last error is set if the user canceled the dialog. |
| 65 window.handleFilePathSelected = function() {}; | 66 if (!chrome.runtime.lastError && path) |
| 66 }; | 67 node.value = path; |
| 67 | 68 }); |
| 68 chrome.send('packExtensionSelectFilePath', [selectType, operation]); | |
| 69 }, | 69 }, |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * Handles the showing of the extension directory browser. | 72 * Handles the showing of the extension directory browser. |
| 73 * @param {Event} e Change event. | 73 * @param {Event} e Change event. |
| 74 * @private | 74 * @private |
| 75 */ | 75 */ |
| 76 handleBrowseExtensionDir_: function(e) { | 76 handleBrowseExtensionDir_: function(e) { |
| 77 this.showFileDialog_('folder', 'load', function(filePath) { | 77 this.showFileDialog_( |
| 78 $('extension-root-dir').value = filePath; | 78 'FOLDER', |
| 79 }); | 79 'LOAD', |
| 80 /** @type {HTMLInputElement} */ ($('extension-root-dir'))); | |
| 80 }, | 81 }, |
| 81 | 82 |
| 82 /** | 83 /** |
| 83 * Handles the showing of the extension private key file. | 84 * Handles the showing of the extension private key file. |
| 84 * @param {Event} e Change event. | 85 * @param {Event} e Change event. |
| 85 * @private | 86 * @private |
| 86 */ | 87 */ |
| 87 handleBrowsePrivateKey_: function(e) { | 88 handleBrowsePrivateKey_: function(e) { |
| 88 this.showFileDialog_('file', 'pem', function(filePath) { | 89 this.showFileDialog_( |
| 89 $('extension-private-key').value = filePath; | 90 'FILE', |
| 90 }); | 91 'PEM', |
| 92 /** @type {HTMLInputElement} */ ($('extension-private-key'))); | |
| 93 }, | |
| 94 | |
| 95 /** | |
| 96 * Handles a response from a packDirectory call. | |
| 97 * @param {PackDirectoryResponse} response The response of the pack call. | |
| 98 * @private | |
| 99 */ | |
| 100 onPackResponse_: function(response) { | |
| 101 /** @type {string} */ | |
| 102 var alertTitle; | |
| 103 /** @type {string} */ | |
| 104 var alertOk; | |
| 105 /** @type {string} */ | |
| 106 var alertCancel; | |
| 107 /** @type {function()} */ | |
| 108 var alertOkCallback; | |
| 109 /** @type {function()} */ | |
| 110 var alertCancelCallback; | |
| 111 | |
| 112 var closeAlert = function() { | |
| 113 extensions.ExtensionSettings.showOverlay(null); | |
| 114 }; | |
| 115 | |
| 116 switch (response.status) { | |
| 117 case 'SUCCESS': | |
| 118 alertTitle = loadTimeData.getString('packExtensionOverlay'); | |
| 119 alertOk = loadTimeData.getString('ok'); | |
| 120 alertOkCallback = closeAlert; | |
| 121 // No 'Cancel' option. | |
| 122 break; | |
| 123 case 'WARNING': | |
| 124 alertTitle = loadTimeData.getString('packExtensionWarningTitle'), | |
| 125 alertOk = loadTimeData.getString('packExtensionProceedAnyway'), | |
| 126 alertCancel = loadTimeData.getString('cancel'), | |
|
Dan Beam
2015/02/27 22:57:17
, -> ;
Devlin
2015/02/27 23:38:37
Done.
| |
| 127 alertOkCallback = function() { | |
| 128 chrome.developerPrivate.packDirectory( | |
| 129 response.item_path, | |
| 130 response.pem_path, | |
| 131 response.override_flags, | |
| 132 this.onPackResponse_.bind(this)); | |
| 133 closeAlert(); | |
| 134 }.bind(this); | |
| 135 alertCancelCallback = closeAlert; | |
| 136 break; | |
| 137 case 'ERROR': | |
| 138 alertTitle = loadTimeData.getString('packExtensionErrorTitle'), | |
| 139 alertOk = loadTimeData.getString('ok'), | |
|
Dan Beam
2015/02/27 22:57:17
, -> ;
Devlin
2015/02/27 23:38:38
Done.
| |
| 140 alertOkCallback = function() { | |
| 141 extensions.ExtensionSettings.showOverlay( | |
| 142 $('pack-extension-overlay')); | |
| 143 }; | |
| 144 // No 'Cancel' option. | |
| 145 break; | |
| 146 default: | |
| 147 assert(false); | |
|
Dan Beam
2015/02/27 22:57:17
assertNotReached();
also maybe
return;
?
Devlin
2015/02/27 23:38:38
Done.
| |
| 148 } | |
| 149 | |
| 150 alertOverlay.setValues(alertTitle, | |
| 151 response.message, | |
| 152 alertOk, | |
| 153 alertCancel, | |
| 154 alertOkCallback, | |
| 155 alertCancelCallback); | |
| 156 extensions.ExtensionSettings.showOverlay($('alertOverlay')); | |
| 91 }, | 157 }, |
| 92 }; | 158 }; |
| 93 | 159 |
| 94 /** | |
| 95 * Wrap up the pack process by showing the success |message| and closing | |
| 96 * the overlay. | |
| 97 * @param {string} message The message to show to the user. | |
| 98 */ | |
| 99 PackExtensionOverlay.showSuccessMessage = function(message) { | |
| 100 alertOverlay.setValues( | |
| 101 loadTimeData.getString('packExtensionOverlay'), | |
| 102 message, | |
| 103 loadTimeData.getString('ok'), | |
| 104 '', | |
| 105 function() { | |
| 106 extensions.ExtensionSettings.showOverlay(null); | |
| 107 }); | |
| 108 extensions.ExtensionSettings.showOverlay($('alertOverlay')); | |
| 109 }; | |
| 110 | |
| 111 /** | |
| 112 * Post an alert overlay showing |message|, and upon acknowledgement, close | |
| 113 * the alert overlay and return to showing the PackExtensionOverlay. | |
| 114 * @param {string} message The error message. | |
| 115 */ | |
| 116 PackExtensionOverlay.showError = function(message) { | |
| 117 alertOverlay.setValues( | |
| 118 loadTimeData.getString('packExtensionErrorTitle'), | |
| 119 message, | |
| 120 loadTimeData.getString('ok'), | |
| 121 '', | |
| 122 function() { | |
| 123 extensions.ExtensionSettings.showOverlay($('pack-extension-overlay')); | |
| 124 }); | |
| 125 extensions.ExtensionSettings.showOverlay($('alertOverlay')); | |
| 126 }; | |
| 127 | |
| 128 // Export | 160 // Export |
| 129 return { | 161 return { |
| 130 PackExtensionOverlay: PackExtensionOverlay | 162 PackExtensionOverlay: PackExtensionOverlay |
| 131 }; | 163 }; |
| 132 }); | 164 }); |
| OLD | NEW |