aboutsummaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/data/manifest-variants.json4
-rw-r--r--dev/database-vm.js15
-rw-r--r--dev/vm.js22
3 files changed, 35 insertions, 6 deletions
diff --git a/dev/data/manifest-variants.json b/dev/data/manifest-variants.json
index 14050241..14dd02e2 100644
--- a/dev/data/manifest-variants.json
+++ b/dev/data/manifest-variants.json
@@ -114,7 +114,7 @@
"popup.html",
"template-renderer.html"
],
- "content_security_policy": "default-src 'self'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *"
+ "content_security_policy": "default-src 'self'; img-src blob: 'self'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *"
},
"variants": [
{
@@ -194,7 +194,7 @@
{
"action": "set",
"path": ["content_security_policy"],
- "value": "default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *"
+ "value": "default-src 'self'; script-src 'self' 'unsafe-eval'; img-src blob: 'self'; style-src 'self' 'unsafe-inline'; media-src *; connect-src *"
},
{
"action": "set",
diff --git a/dev/database-vm.js b/dev/database-vm.js
index e43daf2f..b682bca3 100644
--- a/dev/database-vm.js
+++ b/dev/database-vm.js
@@ -76,6 +76,13 @@ class Image {
}
}
+class Blob {
+ constructor(array, options) {
+ this._array = array;
+ this._options = options;
+ }
+}
+
async function fetch(url2) {
const filePath = url.fileURLToPath(url2);
await Promise.resolve();
@@ -89,15 +96,21 @@ async function fetch(url2) {
};
}
+function atob(data) {
+ return Buffer.from(data, 'base64').toString('ascii');
+}
+
class DatabaseVM extends VM {
constructor() {
super({
chrome,
Image,
+ Blob,
fetch,
indexedDB: global.indexedDB,
IDBKeyRange: global.IDBKeyRange,
- JSZip
+ JSZip,
+ atob
});
this.context.window = this.context;
this.indexedDB = global.indexedDB;
diff --git a/dev/vm.js b/dev/vm.js
index b3fc63e7..98a1f7bf 100644
--- a/dev/vm.js
+++ b/dev/vm.js
@@ -19,6 +19,7 @@ const fs = require('fs');
const vm = require('vm');
const path = require('path');
const assert = require('assert');
+const crypto = require('crypto');
function getContextEnvironmentRecords(context, names) {
@@ -115,9 +116,9 @@ function deepStrictEqual(actual, expected) {
}
-function createURLClass() {
+function createURLClass(urlMap) {
const BaseURL = URL;
- return function URL(url) {
+ const result = function URL(url) {
const u = new BaseURL(url);
this.hash = u.hash;
this.host = u.host;
@@ -132,12 +133,23 @@ function createURLClass() {
this.searchParams = u.searchParams;
this.username = u.username;
};
+ result.createObjectURL = (object) => {
+ const id = crypto.randomBytes(16).toString('hex');
+ const url = `blob:${id}`;
+ urlMap.set(url, object);
+ return url;
+ };
+ result.revokeObjectURL = (url) => {
+ urlMap.delete(url);
+ };
+ return result;
}
class VM {
constructor(context={}) {
- context.URL = createURLClass();
+ this._urlMap = new Map();
+ context.URL = createURLClass(this._urlMap);
this._context = vm.createContext(context);
this._assert = {
deepStrictEqual
@@ -186,6 +198,10 @@ class VM {
return single ? results[0] : results;
}
+
+ getUrlObject(url) {
+ return this._urlMap.get(url);
+ }
}