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 // TODO(devlin): Once we expose enums on extension APIs, we should use |
| 117 // those objects, instead of a string. |
| 118 switch (response.status) { |
| 119 case 'SUCCESS': |
| 120 alertTitle = loadTimeData.getString('packExtensionOverlay'); |
| 121 alertOk = loadTimeData.getString('ok'); |
| 122 alertOkCallback = closeAlert; |
| 123 // No 'Cancel' option. |
| 124 break; |
| 125 case 'WARNING': |
| 126 alertTitle = loadTimeData.getString('packExtensionWarningTitle'); |
| 127 alertOk = loadTimeData.getString('packExtensionProceedAnyway'); |
| 128 alertCancel = loadTimeData.getString('cancel'); |
| 129 alertOkCallback = function() { |
| 130 chrome.developerPrivate.packDirectory( |
| 131 response.item_path, |
| 132 response.pem_path, |
| 133 response.override_flags, |
| 134 this.onPackResponse_.bind(this)); |
| 135 closeAlert(); |
| 136 }.bind(this); |
| 137 alertCancelCallback = closeAlert; |
| 138 break; |
| 139 case 'ERROR': |
| 140 alertTitle = loadTimeData.getString('packExtensionErrorTitle'); |
| 141 alertOk = loadTimeData.getString('ok'); |
| 142 alertOkCallback = function() { |
| 143 extensions.ExtensionSettings.showOverlay( |
| 144 $('pack-extension-overlay')); |
| 145 }; |
| 146 // No 'Cancel' option. |
| 147 break; |
| 148 default: |
| 149 assertNotReached(); |
| 150 return; |
| 151 } |
| 152 |
| 153 alertOverlay.setValues(alertTitle, |
| 154 response.message, |
| 155 alertOk, |
| 156 alertCancel, |
| 157 alertOkCallback, |
| 158 alertCancelCallback); |
| 159 extensions.ExtensionSettings.showOverlay($('alertOverlay')); |
91 }, | 160 }, |
92 }; | 161 }; |
93 | 162 |
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 | 163 // Export |
129 return { | 164 return { |
130 PackExtensionOverlay: PackExtensionOverlay | 165 PackExtensionOverlay: PackExtensionOverlay |
131 }; | 166 }; |
132 }); | 167 }); |
OLD | NEW |