Kaynağa Gözat

canvasData and empty style sheets data returned by preProcessDoc

Gildas 7 yıl önce
ebeveyn
işleme
aa8586560a

+ 4 - 2
lib/single-file/doc-helper.js

@@ -27,8 +27,6 @@ this.docHelper = this.docHelper || (() => {
 	return {
 		preProcessDoc,
 		postProcessDoc,
-		getCanvasData,
-		getEmptyStyleRulesText,
 		serialize,
 		WIN_ID_ATTRIBUTE_NAME,
 		PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
@@ -60,6 +58,10 @@ this.docHelper = this.docHelper || (() => {
 				}
 			});
 		}
+		return {
+			canvasData: getCanvasData(doc),
+			emptyStyleRulesText: getEmptyStyleRulesText(doc)
+		};
 	}
 
 	function postProcessDoc(doc, options) {

+ 6 - 6
lib/single-file/frame-tree/content/frame-tree.js

@@ -73,14 +73,14 @@ this.FrameTree = this.FrameTree || (() => {
 	}
 	browser.runtime.onMessage.addListener(message => {
 		if (message.method == "FrameTree.getDataRequest" && FrameTree.windowId == message.windowId) {
-			docHelper.preProcessDoc(document, window, message.options);
+			const docData = docHelper.preProcessDoc(document, window, message.options);
 			browser.runtime.sendMessage({
 				method: "FrameTree.getDataResponse",
 				windowId: message.windowId,
 				tabId: message.tabId,
 				content: docHelper.serialize(document),
-				emptyStyleRulesText: docHelper.getEmptyStyleRulesText(document),
-				canvasData: docHelper.getCanvasData(document),
+				emptyStyleRulesText: docData.emptyStyleRulesText,
+				canvasData: docData.canvasData,
 				baseURI: document.baseURI,
 				title: document.title
 			}).catch(() => {/* ignored */ });
@@ -183,10 +183,10 @@ this.FrameTree = this.FrameTree || (() => {
 			if (frameWindow && frameDoc && topWindow) {
 				setFramesWinId(MESSAGE_PREFIX, frameDoc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"), options, index, frameWinId, frameWindow);
 				topWindow.addEventListener("message", onMessage, false);
-				docHelper.preProcessDoc(frameDoc, frameWindow, options);
+				const docData = docHelper.preProcessDoc(frameDoc, frameWindow, options);
 				content = docHelper.serialize(frameDoc);
-				emptyStyleRulesText = docHelper.getEmptyStyleRulesText(frameDoc);
-				canvasData = docHelper.getCanvasData(frameDoc);
+				emptyStyleRulesText = docData.emptyStyleRulesText;
+				canvasData = docData.canvasData;
 				docHelper.postProcessDoc(frameDoc, options);
 			} else if (frameWindow) {
 				frameWindow.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initRequest", windowId: frameWinId, index, options }), "*");

+ 1 - 9
lib/single-file/single-file-browser.js

@@ -135,21 +135,13 @@ this.SingleFile = this.SingleFile || (() => {
 		}
 
 		static preProcessDoc(doc, win, options) {
-			docHelper.preProcessDoc(doc, win, options);
+			return docHelper.preProcessDoc(doc, win, options);
 		}
 
 		static postProcessDoc(doc, options) {
 			docHelper.postProcessDoc(doc, options);
 		}
 
-		static getEmptyStyleRulesText(doc) {
-			return docHelper.getEmptyStyleRulesText(doc);
-		}
-
-		static getCanvasData(doc) {
-			return docHelper.getCanvasData(doc);
-		}
-
 		static winIdAttributeName() {
 			return docHelper.WIN_ID_ATTRIBUTE_NAME;
 		}

+ 3 - 3
lib/single-file/single-file-core.js

@@ -74,9 +74,9 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			this.options.url = this.options.url || this.options.doc.location.href;
 			this.processor = new DOMProcessor(options);
 			if (this.options.doc) {
-				this.options.canvasData = DOM.getCanvasData(this.options.doc);
-				this.options.emptyStyleRulesText = DOM.getEmptyStyleRulesText(this.options.doc);
-				DOM.preProcessDoc(this.options.doc, this.options.win, this.options);
+				const docData = DOM.preProcessDoc(this.options.doc, this.options.win, this.options);
+				this.options.canvasData = docData.canvasData;
+				this.options.emptyStyleRulesText = docData.emptyStyleRulesText;
 			}
 			this.options.content = this.options.content || (this.options.doc ? DOM.serialize(this.options.doc, false) : null);
 			this.onprogress = options.onprogress || (() => { });