Move generateId to core.js (#748)

This commit is contained in:
toasted-nutbread 2020-08-22 15:49:24 -04:00 committed by GitHub
parent 9fa0f2a56a
commit f0c974d319
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 19 additions and 18 deletions

View File

@ -107,6 +107,7 @@
"escapeRegExp": "readonly",
"deferPromise": "readonly",
"clone": "readonly",
"generateId": "readonly",
"EventDispatcher": "readonly",
"EventListenerCollection": "readonly"
}

View File

@ -739,7 +739,7 @@ class Backend {
if (typeof tabId !== 'number') { throw new Error('Sender has invalid tab ID'); }
const frameId = sender.frameId;
const id = yomichan.generateId(16);
const id = generateId(16);
const details = {
name: 'action-port',
id

View File

@ -25,7 +25,7 @@ class SettingsController extends EventDispatcher {
constructor(profileIndex=0) {
super();
this._profileIndex = profileIndex;
this._source = yomichan.generateId(16);
this._source = generateId(16);
this._pageExitPreventions = new Set();
this._pageExitPreventionEventListeners = new EventListenerCollection();
}

View File

@ -42,7 +42,7 @@ class FrameOffsetForwarder {
return [0, 0];
}
const uniqueId = yomichan.generateId(16);
const uniqueId = generateId(16);
const frameOffsetPromise = yomichan.getTemporaryListenerResult(
chrome.runtime.onMessage,

View File

@ -33,7 +33,7 @@ class Frontend {
isSearchPage,
allowRootFramePopupProxy
}) {
this._id = yomichan.generateId(16);
this._id = generateId(16);
this._popup = null;
this._disabledOverride = false;
this._options = null;

View File

@ -86,7 +86,7 @@ class PopupFactory {
if (frameId === this._frameId) {
// New unique id
if (id === null) {
id = yomichan.generateId(16);
id = generateId(16);
}
const popup = new Popup(id, depth, frameId, ownerFrameId);
if (parent !== null) {

View File

@ -197,6 +197,16 @@ if (typeof window === 'object' && window !== null) {
window.clone = clone;
}
function generateId(length) {
const array = new Uint8Array(length);
crypto.getRandomValues(array);
let id = '';
for (const value of array) {
id += value.toString(16).padStart(2, '0');
}
return id;
}
/*
* Async utilities

View File

@ -166,7 +166,7 @@ class DisplayHistory extends EventDispatcher {
}
_generateId() {
return yomichan.generateId(16);
return generateId(16);
}
_clear() {

View File

@ -90,7 +90,7 @@ class FrameClient {
case 'frameEndpointReady':
{
const {secret} = params;
const token = yomichan.generateId(16);
const token = generateId(16);
tokenMap.set(secret, token);
postMessage('frameEndpointConnect', {secret, token, hostFrameId});
}

View File

@ -21,7 +21,7 @@
class FrameEndpoint {
constructor() {
this._secret = yomichan.generateId(16);
this._secret = generateId(16);
this._token = null;
this._eventListeners = new EventListenerCollection();
this._eventListenersSetup = false;

View File

@ -84,16 +84,6 @@ const yomichan = (() => {
this.sendMessage({action: 'yomichanReady'});
}
generateId(length) {
const array = new Uint8Array(length);
crypto.getRandomValues(array);
let id = '';
for (const value of array) {
id += value.toString(16).padStart(2, '0');
}
return id;
}
isExtensionUrl(url) {
try {
return url.startsWith(chrome.runtime.getURL('/'));