瀏覽代碼

updated constants

Gildas 7 年之前
父節點
當前提交
8b69c94346
共有 1 個文件被更改,包括 7 次插入6 次删除
  1. 7 6
      lib/single-file/frame-tree.js

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

@@ -22,10 +22,11 @@
 
 this.frameTree = this.frameTree || (() => {
 
-	const MESSAGE_PREFIX = "__frameTree__";
+	const MESSAGE_PREFIX = "__frameTree__::";
 	const FRAMES_CSS_SELECTOR = "iframe, frame, object[type=\"text/html\"][data]";
 	const INIT_REQUEST_MESSAGE = "initRequest";
 	const INIT_RESPONSE_MESSAGE = "initResponse";
+	const TARGET_ORIGIN = "*";
 	const TIMEOUT_INIT_REQUEST_MESSAGE = 500;
 	const TOP_WINDOW_ID = "0";
 	const TOP_WINDOW = window == top;
@@ -36,8 +37,8 @@ this.frameTree = this.frameTree || (() => {
 		windowId = TOP_WINDOW_ID;
 	}
 	addEventListener("message", event => {
-		if (typeof event.data == "string" && event.data.startsWith(MESSAGE_PREFIX + "::")) {
-			const message = JSON.parse(event.data.substring(MESSAGE_PREFIX.length + 2));
+		if (typeof event.data == "string" && event.data.startsWith(MESSAGE_PREFIX)) {
+			const message = JSON.parse(event.data.substring(MESSAGE_PREFIX.length));
 			if (message.method == INIT_REQUEST_MESSAGE) {
 				initRequest(message);
 			} else if (message.method == INIT_RESPONSE_MESSAGE) {
@@ -130,12 +131,12 @@ this.frameTree = this.frameTree || (() => {
 			framesData.push({ windowId });
 			if (!frameElement.contentDocument) {
 				try {
-					frameElement.contentWindow.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: INIT_REQUEST_MESSAGE, windowId, sessionId, options }), "*");
+					frameElement.contentWindow.postMessage(MESSAGE_PREFIX + JSON.stringify({ method: INIT_REQUEST_MESSAGE, windowId, sessionId, options }), TARGET_ORIGIN);
 				} catch (error) {
 					/* ignored */
 				}
 			}
-			timeout.set(() => sendInitResponse({ framesData: [{ windowId, processed: true, timeout: true }], windowId, sessionId }, "*"), TIMEOUT_INIT_REQUEST_MESSAGE);
+			timeout.set(() => sendInitResponse({ framesData: [{ windowId, processed: true, timeout: true }], windowId, sessionId }), TIMEOUT_INIT_REQUEST_MESSAGE);
 		});
 		sendInitResponse({ framesData, parentWindowId, sessionId });
 	}
@@ -169,7 +170,7 @@ this.frameTree = this.frameTree || (() => {
 		} catch (error) {
 			const channel = new MessageChannel();
 			const port = channel.port1;
-			top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: INIT_RESPONSE_MESSAGE }), "*", [channel.port2]);
+			top.postMessage(MESSAGE_PREFIX + JSON.stringify({ method: INIT_RESPONSE_MESSAGE }), TARGET_ORIGIN, [channel.port2]);
 			port.postMessage(message);
 		}
 	}