mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
In order to simplify m-c code, move some in pdf.js
* move set/clear|Timeout/Interval and crackURL code in pdf.js * remove the "backdoor" in the proxy (used to dispatch event) and so return the dispatch function in the initializer * remove listeners if an error occured during sandbox initialization * add support for alert and prompt in the sandbox * add a function to eval in the global scope
This commit is contained in:
parent
3447f7c703
commit
8bff4f1ea9
14 changed files with 472 additions and 265 deletions
|
@ -1015,42 +1015,6 @@ function getActiveOrFocusedElement() {
|
|||
return curActiveOrFocused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random string which is not define somewhere in actions.
|
||||
*
|
||||
* @param {Object} objects - The value returned by `getFieldObjects` in the API.
|
||||
* @returns {string} A unique string.
|
||||
*/
|
||||
function generateRandomStringForSandbox(objects) {
|
||||
const allObjects = Object.values(objects).flat(2);
|
||||
const actions = allObjects
|
||||
.filter(obj => !!obj.actions)
|
||||
.map(obj => Object.values(obj.actions))
|
||||
.flat(2);
|
||||
|
||||
while (true) {
|
||||
const name = new Uint8Array(64);
|
||||
if (typeof crypto !== "undefined") {
|
||||
crypto.getRandomValues(name);
|
||||
} else {
|
||||
for (let i = 0, ii = name.length; i < ii; i++) {
|
||||
name[i] = Math.floor(256 * Math.random());
|
||||
}
|
||||
}
|
||||
|
||||
const nameString =
|
||||
"_" +
|
||||
btoa(
|
||||
Array.from(name)
|
||||
.map(x => String.fromCharCode(x))
|
||||
.join("")
|
||||
);
|
||||
if (actions.every(action => !action.includes(nameString))) {
|
||||
return nameString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
AutoPrintRegExp,
|
||||
CSS_UNITS,
|
||||
|
@ -1074,7 +1038,6 @@ export {
|
|||
NullL10n,
|
||||
EventBus,
|
||||
ProgressBar,
|
||||
generateRandomStringForSandbox,
|
||||
getPDFFileNameFromURL,
|
||||
noContextMenuHandler,
|
||||
parseQueryString,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue