Move generateId to core.js (#748)
This commit is contained in:
parent
9fa0f2a56a
commit
f0c974d319
@ -107,6 +107,7 @@
|
|||||||
"escapeRegExp": "readonly",
|
"escapeRegExp": "readonly",
|
||||||
"deferPromise": "readonly",
|
"deferPromise": "readonly",
|
||||||
"clone": "readonly",
|
"clone": "readonly",
|
||||||
|
"generateId": "readonly",
|
||||||
"EventDispatcher": "readonly",
|
"EventDispatcher": "readonly",
|
||||||
"EventListenerCollection": "readonly"
|
"EventListenerCollection": "readonly"
|
||||||
}
|
}
|
||||||
|
@ -739,7 +739,7 @@ class Backend {
|
|||||||
if (typeof tabId !== 'number') { throw new Error('Sender has invalid tab ID'); }
|
if (typeof tabId !== 'number') { throw new Error('Sender has invalid tab ID'); }
|
||||||
|
|
||||||
const frameId = sender.frameId;
|
const frameId = sender.frameId;
|
||||||
const id = yomichan.generateId(16);
|
const id = generateId(16);
|
||||||
const details = {
|
const details = {
|
||||||
name: 'action-port',
|
name: 'action-port',
|
||||||
id
|
id
|
||||||
|
@ -25,7 +25,7 @@ class SettingsController extends EventDispatcher {
|
|||||||
constructor(profileIndex=0) {
|
constructor(profileIndex=0) {
|
||||||
super();
|
super();
|
||||||
this._profileIndex = profileIndex;
|
this._profileIndex = profileIndex;
|
||||||
this._source = yomichan.generateId(16);
|
this._source = generateId(16);
|
||||||
this._pageExitPreventions = new Set();
|
this._pageExitPreventions = new Set();
|
||||||
this._pageExitPreventionEventListeners = new EventListenerCollection();
|
this._pageExitPreventionEventListeners = new EventListenerCollection();
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class FrameOffsetForwarder {
|
|||||||
return [0, 0];
|
return [0, 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
const uniqueId = yomichan.generateId(16);
|
const uniqueId = generateId(16);
|
||||||
|
|
||||||
const frameOffsetPromise = yomichan.getTemporaryListenerResult(
|
const frameOffsetPromise = yomichan.getTemporaryListenerResult(
|
||||||
chrome.runtime.onMessage,
|
chrome.runtime.onMessage,
|
||||||
|
@ -33,7 +33,7 @@ class Frontend {
|
|||||||
isSearchPage,
|
isSearchPage,
|
||||||
allowRootFramePopupProxy
|
allowRootFramePopupProxy
|
||||||
}) {
|
}) {
|
||||||
this._id = yomichan.generateId(16);
|
this._id = generateId(16);
|
||||||
this._popup = null;
|
this._popup = null;
|
||||||
this._disabledOverride = false;
|
this._disabledOverride = false;
|
||||||
this._options = null;
|
this._options = null;
|
||||||
|
@ -86,7 +86,7 @@ class PopupFactory {
|
|||||||
if (frameId === this._frameId) {
|
if (frameId === this._frameId) {
|
||||||
// New unique id
|
// New unique id
|
||||||
if (id === null) {
|
if (id === null) {
|
||||||
id = yomichan.generateId(16);
|
id = generateId(16);
|
||||||
}
|
}
|
||||||
const popup = new Popup(id, depth, frameId, ownerFrameId);
|
const popup = new Popup(id, depth, frameId, ownerFrameId);
|
||||||
if (parent !== null) {
|
if (parent !== null) {
|
||||||
|
@ -197,6 +197,16 @@ if (typeof window === 'object' && window !== null) {
|
|||||||
window.clone = clone;
|
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
|
* Async utilities
|
||||||
|
@ -166,7 +166,7 @@ class DisplayHistory extends EventDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_generateId() {
|
_generateId() {
|
||||||
return yomichan.generateId(16);
|
return generateId(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
_clear() {
|
_clear() {
|
||||||
|
@ -90,7 +90,7 @@ class FrameClient {
|
|||||||
case 'frameEndpointReady':
|
case 'frameEndpointReady':
|
||||||
{
|
{
|
||||||
const {secret} = params;
|
const {secret} = params;
|
||||||
const token = yomichan.generateId(16);
|
const token = generateId(16);
|
||||||
tokenMap.set(secret, token);
|
tokenMap.set(secret, token);
|
||||||
postMessage('frameEndpointConnect', {secret, token, hostFrameId});
|
postMessage('frameEndpointConnect', {secret, token, hostFrameId});
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
class FrameEndpoint {
|
class FrameEndpoint {
|
||||||
constructor() {
|
constructor() {
|
||||||
this._secret = yomichan.generateId(16);
|
this._secret = generateId(16);
|
||||||
this._token = null;
|
this._token = null;
|
||||||
this._eventListeners = new EventListenerCollection();
|
this._eventListeners = new EventListenerCollection();
|
||||||
this._eventListenersSetup = false;
|
this._eventListenersSetup = false;
|
||||||
|
@ -84,16 +84,6 @@ const yomichan = (() => {
|
|||||||
this.sendMessage({action: 'yomichanReady'});
|
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) {
|
isExtensionUrl(url) {
|
||||||
try {
|
try {
|
||||||
return url.startsWith(chrome.runtime.getURL('/'));
|
return url.startsWith(chrome.runtime.getURL('/'));
|
||||||
|
Loading…
Reference in New Issue
Block a user