forked from credential-handler/credential-handler-polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCredentialStoreEvent.js
53 lines (47 loc) · 1.6 KB
/
CredentialStoreEvent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*!
* A CredentialStoreEvent is emitted when a request has been made to
* store a credential.
*
* Copyright (c) 2017 Digital Bazaar, Inc. All rights reserved.
*/
/* global Event */
'use strict';
import {WebAppWindow} from 'web-request-rpc';
// can't use "ExtendableEvent"; only accessible from Workers
// TODO: may not be able to even extend `Event` here; could produce "incorrect"
// core attributes
export class CredentialStoreEvent /*extends Event*/ {
constructor({
credentialHandler,
credentialRequestOrigin,
credential,
hintKey
}) {
//super('credentialstore');
this.type = 'credentialstore';
this._credentialHandler = credentialHandler;
this.credentialRequestOrigin = credentialRequestOrigin;
this.credential = credential;
this.hintKey = hintKey;
}
async openWindow(url) {
// TODO: disallow more than one call
// TODO: ensure `url` is to the same origin
await this._credentialHandler.show();
const appWindow = new WebAppWindow(url);
appWindow.ready();
appWindow.show();
// TODO: note that `appWindow.handle` is not a ServiceWorker
// `WindowClient` polyfill... could be confusing here, should we
// implement one to wrap it? -- there is, for example, a
// `navigate` call on `WindowClient` that enforces same origin, would
// need to attempt to add or approximate that
appWindow.handle._dialog = appWindow.dialog;
return appWindow.handle;
}
respondWith(handlerResponse) {
// TODO: throw exception if `_promise` is already set
// TODO: validate handlerResponse
this._promise = handlerResponse;
}
}