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 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,
| |
65 window.handleFilePathSelected = function() {}; | 66 node.value = path; |
66 }; | 67 }); |
67 | |
68 chrome.send('packExtensionSelectFilePath', [selectType, operation]); | |
69 }, | 68 }, |
70 | 69 |
71 /** | 70 /** |
72 * Handles the showing of the extension directory browser. | 71 * Handles the showing of the extension directory browser. |
73 * @param {Event} e Change event. | 72 * @param {Event} e Change event. |
74 * @private | 73 * @private |
75 */ | 74 */ |
76 handleBrowseExtensionDir_: function(e) { | 75 handleBrowseExtensionDir_: function(e) { |
77 this.showFileDialog_('folder', 'load', function(filePath) { | 76 this.showFileDialog_( |
78 $('extension-root-dir').value = filePath; | 77 'FOLDER', |
79 }); | 78 'LOAD', |
79 /** @type {HTMLInputElement} */ ($('extension-root-dir'))); | |
80 }, | 80 }, |
81 | 81 |
82 /** | 82 /** |
83 * Handles the showing of the extension private key file. | 83 * Handles the showing of the extension private key file. |
84 * @param {Event} e Change event. | 84 * @param {Event} e Change event. |
85 * @private | 85 * @private |
86 */ | 86 */ |
87 handleBrowsePrivateKey_: function(e) { | 87 handleBrowsePrivateKey_: function(e) { |
88 this.showFileDialog_('file', 'pem', function(filePath) { | 88 this.showFileDialog_( |
89 $('extension-private-key').value = filePath; | 89 'FILE', |
90 }); | 90 'PEM', |
91 /** @type {HTMLInputElement} */ ($('extension-private-key'))); | |
92 }, | |
93 | |
94 /** | |
95 * Handles a response from a packDirectory call. | |
96 * @param {PackDirectoryResponse} response The response of the pack call. | |
97 * @private | |
98 */ | |
99 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.
| |
100 console.log('On pack response'); | |
101 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.
| |
102 /** @type {string} */ | |
103 var alertTitle; | |
104 /** @type {string} */ | |
105 var alertOk; | |
106 /** @type {string} */ | |
107 var alertCancel; | |
108 /** @type {function()} */ | |
109 var alertOkCallback; | |
110 /** @type {function()} */ | |
111 var alertCancelCallback; | |
112 | |
113 var closeAlert = function() { | |
114 extensions.ExtensionSettings.showOverlay(null); | |
115 }; | |
116 | |
117 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
| |
118 alertTitle = loadTimeData.getString('packExtensionOverlay'); | |
119 alertOk = loadTimeData.getString('ok'); | |
120 alertOkCallback = closeAlert; | |
121 // No 'Cancel' option. | |
122 } else if (response.status == 'WARNING') { | |
123 alertTitle = loadTimeData.getString('packExtensionWarningTitle'), | |
124 alertOk = loadTimeData.getString('packExtensionProceedAnyway'), | |
125 alertCancel = loadTimeData.getString('cancel'), | |
126 alertOkCallback = function() { | |
127 chrome.developerPrivate.packDirectory( | |
128 response.item_path, | |
129 response.pem_path, | |
130 response.override_flags, | |
131 this.onPackResponse_.bind(this)); | |
132 closeAlert(); | |
133 }.bind(this); | |
134 alertCancelCallback = closeAlert; | |
135 } else { | |
136 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.
| |
137 alertTitle = loadTimeData.getString('packExtensionErrorTitle'), | |
138 alertOk = loadTimeData.getString('ok'), | |
139 alertOkCallback = function() { | |
140 extensions.ExtensionSettings.showOverlay($('pack-extension-overlay')); | |
141 }; | |
142 // No 'Cancel' option. | |
143 } | |
144 | |
145 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
| |
146 response.message, | |
147 alertOk, | |
148 alertCancel, | |
149 alertOkCallback, | |
150 alertCancelCallback); | |
151 extensions.ExtensionSettings.showOverlay($('alertOverlay')); | |
91 }, | 152 }, |
92 }; | 153 }; |
93 | 154 |
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 | 155 // Export |
129 return { | 156 return { |
130 PackExtensionOverlay: PackExtensionOverlay | 157 PackExtensionOverlay: PackExtensionOverlay |
131 }; | 158 }; |
132 }); | 159 }); |
OLD | NEW |