Skip to content

Commit

Permalink
Merge remote-tracking branch 'yomitan/master' into yezichak-chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanVukovic99 committed Dec 27, 2023
2 parents 1b25828 + 60cd218 commit 9d403e5
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 428 deletions.
17 changes: 5 additions & 12 deletions ext/js/accessibility/accessibility-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {isContentScriptRegistered, registerContentScript, unregisterContentScript} from '../background/script-manager.js';
import {log} from '../core.js';

/**
* This class controls the registration of accessibility handlers.
*/
export class AccessibilityController {
/**
* Creates a new instance.
* @param {import('../background/script-manager.js').ScriptManager} scriptManager An instance of the `ScriptManager` class.
*/
constructor(scriptManager) {
/** @type {import('../background/script-manager.js').ScriptManager} */
this._scriptManager = scriptManager;
constructor() {
/** @type {?import('core').TokenObject} */
this._updateGoogleDocsAccessibilityToken = null;
/** @type {?Promise<void>} */
Expand Down Expand Up @@ -90,19 +85,17 @@ export class AccessibilityController {
const id = 'googleDocsAccessibility';
try {
if (forceGoogleDocsHtmlRenderingAny) {
if (await this._scriptManager.isContentScriptRegistered(id)) { return; }
if (await isContentScriptRegistered(id)) { return; }
/** @type {import('script-manager').RegistrationDetails} */
const details = {
allFrames: true,
matchAboutBlank: true,
matches: ['*://docs.google.com/*'],
urlMatches: '^[^:]*://docs\\.google\\.com/[\\w\\W]*$',
runAt: 'document_start',
js: ['js/accessibility/google-docs.js']
};
await this._scriptManager.registerContentScript(id, details);
await registerContentScript(id, details);
} else {
await this._scriptManager.unregisterContentScript(id);
await unregisterContentScript(id);
}
} catch (e) {
log.error(e);
Expand Down
8 changes: 3 additions & 5 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {MediaUtil} from '../media/media-util.js';
import {ClipboardReaderProxy, DictionaryDatabaseProxy, OffscreenProxy, TranslatorProxy} from './offscreen-proxy.js';
import {ProfileConditionsUtil} from './profile-conditions-util.js';
import {RequestBuilder} from './request-builder.js';
import {ScriptManager} from './script-manager.js';
import {injectStylesheet} from './script-manager.js';

/**
* This class controls the core logic of the extension, including API calls
Expand Down Expand Up @@ -110,10 +110,8 @@ export class Backend {
});
/** @type {OptionsUtil} */
this._optionsUtil = new OptionsUtil();
/** @type {ScriptManager} */
this._scriptManager = new ScriptManager();
/** @type {AccessibilityController} */
this._accessibilityController = new AccessibilityController(this._scriptManager);
this._accessibilityController = new AccessibilityController();

/** @type {?number} */
this._searchPopupTabId = null;
Expand Down Expand Up @@ -650,7 +648,7 @@ export class Backend {
async _onApiInjectStylesheet({type, value}, sender) {
const {frameId, tab} = sender;
if (typeof tab !== 'object' || tab === null || typeof tab.id !== 'number') { throw new Error('Invalid tab'); }
return await this._scriptManager.injectStylesheet(type, value, tab.id, frameId, false);
return await injectStylesheet(type, value, tab.id, frameId, false);
}

/** @type {import('api').ApiHandler<'getStylesheetContent'>} */
Expand Down
Loading

0 comments on commit 9d403e5

Please sign in to comment.