Explorar el Código

disable blocking of localStorage and indexedDB when lazy-loading resources

Former-commit-id: e092c5ed077ab290f0b233065796d9ca7507ff66
Gildas hace 6 años
padre
commit
46c24f0773

+ 1 - 0
extension/core/bg/config.js

@@ -42,6 +42,7 @@ singlefile.extension.core.bg.config = (() => {
 		loadDeferredImages: true,
 		loadDeferredImagesMaxIdleTime: 1500,
 		loadDeferredImagesBlockCookies: true,
+		loadDeferredImagesBlockStorage: false,
 		filenameTemplate: "{page-title} ({date-iso} {time-locale}).html",
 		infobarTemplate: "",
 		confirmInfobarContent: false,

+ 10 - 2
lib/hooks/content/content-hooks-frames-web.js

@@ -29,6 +29,8 @@
 	const LOAD_DEFERRED_IMAGES_END_EVENT = "single-file-load-deferred-images-end";
 	const BLOCK_COOKIES_START_EVENT = "single-file-block-cookies-start";
 	const BLOCK_COOKIES_END_EVENT = "single-file-block-cookies-end";
+	const BLOCK_STORAGE_START_EVENT = "single-file-block-storage-start";
+	const BLOCK_STORAGE_END_EVENT = "single-file-block-storage-end";
 	const LOAD_IMAGE_EVENT = "single-file-load-image";
 	const IMAGE_LOADED_EVENT = "single-file-image-loaded";
 	const NEW_FONT_FACE_EVENT = "single-file-new-font-face";
@@ -179,6 +181,13 @@
 		} catch (error) {
 			// ignored
 		}
+	});
+
+	addEventListener(BLOCK_COOKIES_END_EVENT, () => {
+		delete document.cookie;
+	});
+
+	addEventListener(BLOCK_STORAGE_START_EVENT, () => {
 		if (!window._singleFile_localStorage) {
 			window._singleFile_localStorage = window.localStorage;
 			window.__defineGetter__("localStorage", () => { throw new Error("localStorage temporary blocked by SingleFile"); });
@@ -189,8 +198,7 @@
 		}
 	});
 
-	addEventListener(BLOCK_COOKIES_END_EVENT, () => {
-		delete document.cookie;
+	addEventListener(BLOCK_STORAGE_END_EVENT, () => {
 		if (window._singleFile_localStorage) {
 			delete window.localStorage;
 			window.localStorage = window._singleFile_localStorage;

+ 8 - 0
lib/hooks/content/content-hooks-frames.js

@@ -29,6 +29,8 @@ this.singlefile.lib.hooks.content.frames = this.singlefile.lib.hooks.content.fra
 	const LOAD_DEFERRED_IMAGES_END_EVENT = "single-file-load-deferred-images-end";
 	const BLOCK_COOKIES_START_EVENT = "single-file-block-cookies-start";
 	const BLOCK_COOKIES_END_EVENT = "single-file-block-cookies-end";
+	const BLOCK_STORAGE_START_EVENT = "single-file-block-storage-start";
+	const BLOCK_STORAGE_END_EVENT = "single-file-block-storage-end";
 	const LOAD_IMAGE_EVENT = "single-file-load-image";
 	const IMAGE_LOADED_EVENT = "single-file-image-loaded";
 	const NEW_FONT_FACE_EVENT = "single-file-new-font-face";
@@ -53,12 +55,18 @@ this.singlefile.lib.hooks.content.frames = this.singlefile.lib.hooks.content.fra
 			if (options.loadDeferredImagesBlockCookies) {
 				dispatchEvent(new CustomEvent(BLOCK_COOKIES_START_EVENT));
 			}
+			if (options.loadDeferredImagesBlockStorage) {
+				dispatchEvent(new CustomEvent(BLOCK_STORAGE_START_EVENT));
+			}
 			dispatchEvent(new CustomEvent(LOAD_DEFERRED_IMAGES_START_EVENT));
 		},
 		loadDeferredImagesEnd: options => {
 			if (options.loadDeferredImagesBlockCookies) {
 				dispatchEvent(new CustomEvent(BLOCK_COOKIES_END_EVENT));
 			}
+			if (options.loadDeferredImagesBlockStorage) {
+				dispatchEvent(new CustomEvent(BLOCK_STORAGE_END_EVENT));
+			}
 			dispatchEvent(new CustomEvent(LOAD_DEFERRED_IMAGES_END_EVENT));
 		},
 		LOAD_IMAGE_EVENT,