OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium OS Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * @constructor | |
7 * @param {?string} initPassphrase Initial passphrase for the first passphrase | |
8 * request or NULL if not available. In such case, call to getPassphrase() | |
9 * will invoke a dialog. | |
10 */ | |
11 unpacker.PassphraseManager = function(initPassphrase) { | |
12 /** | |
13 * @private {?string} | |
14 */ | |
15 this.initPassphrase_ = initPassphrase; | |
16 | |
17 /** | |
18 * @public {?string} | |
19 */ | |
20 this.rememberedPassphrase = initPassphrase; | |
21 }; | |
22 | |
23 /** | |
24 * Requests a passphrase from the user. If a passphrase was previously | |
25 * remembered, then tries it first. Otherwise shows a passphrase dialog. | |
26 * @return {!Promise.<string>} | |
27 */ | |
28 unpacker.PassphraseManager.prototype.getPassphrase = function() { | |
29 return new Promise(function(fulfill, reject) { | |
30 // For the first passphrase request try the init passphrase (which may be | |
31 // incorrect though, so do it only once). | |
32 if (this.initPassphrase_) { | |
33 fulfill(this.initPassphrase_); | |
34 this.initPassphrase_ = null; | |
35 return; | |
36 } | |
37 | |
38 // Ask user for a passphrase. | |
39 chrome.app.window.create( | |
40 '../html/passphrase.html', | |
41 /** @type {!chrome.app.window.CreateWindowOptions} */ ({ | |
42 innerBounds: {width: 320, height: 160}, | |
43 alwaysOnTop: true, | |
44 resizable: false, | |
45 frame: 'none', | |
46 hidden: true | |
47 }), | |
48 function(passphraseWindow) { | |
49 var passphraseSucceeded = false; | |
50 | |
51 passphraseWindow.onClosed.addListener(function() { | |
52 if (passphraseSucceeded) | |
53 return; | |
54 reject('FAILED'); | |
55 }.bind(this)); | |
56 | |
57 passphraseWindow.contentWindow.onPassphraseSuccess = | |
58 function(passphrase, remember) { | |
59 passphraseSucceeded = true; | |
60 this.rememberedPassphrase = remember ? passphrase : null; | |
61 fulfill(passphrase); | |
62 }.bind(this); | |
63 }.bind(this)); | |
64 }.bind(this)); | |
65 } | |
OLD | NEW |