diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-29 19:17:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-30 00:17:46 +0000 |
commit | 7303da3991814a0ce220bf2fff3e51b968913b86 (patch) | |
tree | 809c289d824ec2a08c5ff54579766b7f5c5e09e1 /ext/js/app/frontend.js | |
parent | 1b0e0c551d1505ed4242c04ebac224e5fff81f04 (diff) |
Cross frame API safety (#491)
* Require error type
* Add TODOs
* Fix init
* Updates
* More type safety
* Fix incorrect API map
* Update type safety
* Updates
* Add API
* Update types
* Update types
* Updates
* Remove unused
* Restore types
* Update frame ancestry handler
* Simplify names
* Fix
* Remove old message handlers
Diffstat (limited to 'ext/js/app/frontend.js')
-rw-r--r-- | ext/js/app/frontend.js | 42 |
1 files changed, 12 insertions, 30 deletions
diff --git a/ext/js/app/frontend.js b/ext/js/app/frontend.js index e386bf64..9dafde7a 100644 --- a/ext/js/app/frontend.js +++ b/ext/js/app/frontend.js @@ -178,11 +178,11 @@ export class Frontend { /* eslint-disable no-multi-spaces */ yomitan.crossFrame.registerHandlers([ - ['Frontend.closePopup', this._onApiClosePopup.bind(this)], - ['Frontend.copySelection', this._onApiCopySelection.bind(this)], - ['Frontend.getSelectionText', this._onApiGetSelectionText.bind(this)], - ['Frontend.getPopupInfo', this._onApiGetPopupInfo.bind(this)], - ['Frontend.getPageInfo', this._onApiGetPageInfo.bind(this)] + ['frontendClosePopup', this._onApiClosePopup.bind(this)], + ['frontendCopySelection', this._onApiCopySelection.bind(this)], + ['frontendGetSelectionText', this._onApiGetSelectionText.bind(this)], + ['frontendGetPopupInfo', this._onApiGetPopupInfo.bind(this)], + ['frontendGetPageInfo', this._onApiGetPageInfo.bind(this)] ]); /* eslint-enable no-multi-spaces */ @@ -263,48 +263,31 @@ export class Frontend { // API message handlers - /** - * @returns {string} - */ - _onApiGetUrl() { - return window.location.href; - } - - /** - * @returns {void} - */ + /** @type {import('cross-frame-api').ApiHandler<'frontendClosePopup'>} */ _onApiClosePopup() { this._clearSelection(false); } - /** - * @returns {void} - */ + /** @type {import('cross-frame-api').ApiHandler<'frontendCopySelection'>} */ _onApiCopySelection() { // This will not work on Firefox if a popup has focus, which is usually the case when this function is called. document.execCommand('copy'); } - /** - * @returns {string} - */ + /** @type {import('cross-frame-api').ApiHandler<'frontendGetSelectionText'>} */ _onApiGetSelectionText() { const selection = document.getSelection(); return selection !== null ? selection.toString() : ''; } - /** - * @returns {import('frontend').GetPopupInfoResult} - */ + /** @type {import('cross-frame-api').ApiHandler<'frontendGetPopupInfo'>} */ _onApiGetPopupInfo() { return { popupId: (this._popup !== null ? this._popup.id : null) }; } - /** - * @returns {{url: string, documentTitle: string}} - */ + /** @type {import('cross-frame-api').ApiHandler<'frontendGetPageInfo'>} */ _onApiGetPageInfo() { return { url: window.location.href, @@ -620,8 +603,7 @@ export class Frontend { return await this._getDefaultPopup(); } - /** @type {import('frontend').GetPopupInfoResult} */ - const {popupId} = await yomitan.crossFrame.invoke(targetFrameId, 'Frontend.getPopupInfo', {}); + const {popupId} = await yomitan.crossFrame.invoke(targetFrameId, 'frontendGetPopupInfo', void 0); if (popupId === null) { return null; } @@ -905,7 +887,7 @@ export class Frontend { let documentTitle = document.title; if (this._useProxyPopup && this._parentFrameId !== null) { try { - ({url, documentTitle} = await yomitan.crossFrame.invoke(this._parentFrameId, 'Frontend.getPageInfo', {})); + ({url, documentTitle} = await yomitan.crossFrame.invoke(this._parentFrameId, 'frontendGetPageInfo', void 0)); } catch (e) { // NOP } |