summaryrefslogtreecommitdiff
path: root/ext/bg/js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-05-06 19:27:21 -0400
committerGitHub <noreply@github.com>2020-05-06 19:27:21 -0400
commit501281e887fb66b490f90e7593639112b058ab97 (patch)
tree06b48bdd813ec6bf743c4bac7ccafa7f832e7182 /ext/bg/js
parentac2f743b76b92c46624cab87cd0f6630256738e4 (diff)
Popup init update (#497)
* Add API function to send a message to a specific frameId in a tab * Update _windowMessageHandlers to support additional info per handler * Remove message token * Add new authorization check * Set up new initialization handler * Update initialization * Remove message token * Replace 'prepare' with 'configure' * Create new prepare function * Change configure guard * Log errors in onMessage * Improve popup initialize function * Clear secret/token in _resetFrame * Remove backend message token * Clear src and srcdoc attributes before loading * Don't treat about:blank unloads as load events
Diffstat (limited to 'ext/bg/js')
-rw-r--r--ext/bg/js/backend.js19
1 files changed, 12 insertions, 7 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 43fa8190..c5173a2e 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -73,8 +73,6 @@ class Backend {
const apiForwarder = new BackendApiForwarder();
apiForwarder.prepare();
- this.messageToken = yomichan.generateId(16);
-
this._defaultBrowserActionTitle = null;
this._isPrepared = false;
this._prepareError = false;
@@ -98,6 +96,7 @@ class Backend {
['commandExec', {handler: this._onApiCommandExec.bind(this), async: false}],
['audioGetUri', {handler: this._onApiAudioGetUri.bind(this), async: true}],
['screenshotGet', {handler: this._onApiScreenshotGet.bind(this), async: true}],
+ ['sendMessageToFrame', {handler: this._onApiSendMessageToFrame.bind(this), async: false}],
['broadcastTab', {handler: this._onApiBroadcastTab.bind(this), async: false}],
['frameInformationGet', {handler: this._onApiFrameInformationGet.bind(this), async: true}],
['injectStylesheet', {handler: this._onApiInjectStylesheet.bind(this), async: true}],
@@ -106,7 +105,6 @@ class Backend {
['getDisplayTemplatesHtml', {handler: this._onApiGetDisplayTemplatesHtml.bind(this), async: true}],
['getQueryParserTemplatesHtml', {handler: this._onApiGetQueryParserTemplatesHtml.bind(this), async: true}],
['getZoom', {handler: this._onApiGetZoom.bind(this), async: true}],
- ['getMessageToken', {handler: this._onApiGetMessageToken.bind(this), async: false}],
['getDefaultAnkiFieldTemplates', {handler: this._onApiGetDefaultAnkiFieldTemplates.bind(this), async: false}],
['getAnkiDeckNames', {handler: this._onApiGetAnkiDeckNames.bind(this), async: true}],
['getAnkiModelNames', {handler: this._onApiGetAnkiModelNames.bind(this), async: true}],
@@ -600,6 +598,17 @@ class Backend {
});
}
+ _onApiSendMessageToFrame({frameId, action, params}, sender) {
+ if (!(sender && sender.tab)) {
+ return false;
+ }
+
+ const tabId = sender.tab.id;
+ const callback = () => this.checkLastError(chrome.runtime.lastError);
+ chrome.tabs.sendMessage(tabId, {action, params}, {frameId}, callback);
+ return true;
+ }
+
_onApiBroadcastTab({action, params}, sender) {
if (!(sender && sender.tab)) {
return false;
@@ -731,10 +740,6 @@ class Backend {
});
}
- _onApiGetMessageToken() {
- return this.messageToken;
- }
-
_onApiGetDefaultAnkiFieldTemplates() {
return this.defaultAnkiFieldTemplates;
}