aboutsummaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-11 21:59:38 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-13 23:11:56 -0500
commit573f83b65a8a0f87def6f4200ce503d957464f0d (patch)
tree5b8c3b68a599fbc22e532df0a5fb25dd15550ae8 /ext
parentb7144ed879a59b89ee11aa13702e89a6fdaa0e35 (diff)
Update frontend API receiver handlers
Diffstat (limited to 'ext')
-rw-r--r--ext/fg/js/frontend-api-receiver.js17
-rw-r--r--ext/fg/js/popup-proxy-host.js22
2 files changed, 18 insertions, 21 deletions
diff --git a/ext/fg/js/frontend-api-receiver.js b/ext/fg/js/frontend-api-receiver.js
index 7d38ddd5..8d5e52ee 100644
--- a/ext/fg/js/frontend-api-receiver.js
+++ b/ext/fg/js/frontend-api-receiver.js
@@ -18,9 +18,9 @@
class FrontendApiReceiver {
- constructor(source='', handlers={}) {
- this.source = source;
- this.handlers = handlers;
+ constructor(source='', handlers=new Map()) {
+ this._source = source;
+ this._handlers = handlers;
chrome.runtime.onConnect.addListener(this.onConnect.bind(this));
}
@@ -32,16 +32,13 @@ class FrontendApiReceiver {
}
onMessage(port, {id, action, params, target, senderId}) {
- if (
- target !== this.source ||
- !hasOwn(this.handlers, action)
- ) {
- return;
- }
+ if (target !== this._source) { return; }
+
+ const handler = this._handlers.get(action);
+ if (typeof handler !== 'function') { return; }
this.sendAck(port, id, senderId);
- const handler = this.handlers[action];
handler(params).then(
(result) => {
this.sendResult(port, id, senderId, {result});
diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js
index b2f18b97..de182afe 100644
--- a/ext/fg/js/popup-proxy-host.js
+++ b/ext/fg/js/popup-proxy-host.js
@@ -36,17 +36,17 @@ class PopupProxyHost {
const {frameId} = await this.frameIdPromise;
if (typeof frameId !== 'number') { return; }
- this.apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, {
- createNestedPopup: ({parentId}) => this.createNestedPopup(parentId),
- setOptions: ({id, options}) => this.setOptions(id, options),
- hide: ({id, changeFocus}) => this.hide(id, changeFocus),
- isVisibleAsync: ({id}) => this.isVisibleAsync(id),
- setVisibleOverride: ({id, visible}) => this.setVisibleOverride(id, visible),
- containsPoint: ({id, x, y}) => this.containsPoint(id, x, y),
- showContent: ({id, elementRect, writingMode, type, details}) => this.showContent(id, elementRect, writingMode, type, details),
- setCustomCss: ({id, css}) => this.setCustomCss(id, css),
- clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id)
- });
+ this.apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, new Map([
+ ['createNestedPopup', ({parentId}) => this.createNestedPopup(parentId)],
+ ['setOptions', ({id, options}) => this.setOptions(id, options)],
+ ['hide', ({id, changeFocus}) => this.hide(id, changeFocus)],
+ ['isVisibleAsync', ({id}) => this.isVisibleAsync(id)],
+ ['setVisibleOverride', ({id, visible}) => this.setVisibleOverride(id, visible)],
+ ['containsPoint', ({id, x, y}) => this.containsPoint(id, x, y)],
+ ['showContent', ({id, elementRect, writingMode, type, details}) => this.showContent(id, elementRect, writingMode, type, details)],
+ ['setCustomCss', ({id, css}) => this.setCustomCss(id, css)],
+ ['clearAutoPlayTimer', ({id}) => this.clearAutoPlayTimer(id)]
+ ]));
}
createPopup(parentId, depth) {