|
@@ -99,12 +99,11 @@ this.FrameTree = this.FrameTree || (() => {
|
|
|
|
|
|
|
|
function initRequest(message) {
|
|
function initRequest(message) {
|
|
|
FrameTree.windowId = message.windowId;
|
|
FrameTree.windowId = message.windowId;
|
|
|
- FrameTree.index = message.index;
|
|
|
|
|
const frameElements = document.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]");
|
|
const frameElements = document.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]");
|
|
|
if (frameElements.length) {
|
|
if (frameElements.length) {
|
|
|
- setFramesWinId(MESSAGE_PREFIX, frameElements, message.options, FrameTree.index, FrameTree.windowId, window);
|
|
|
|
|
|
|
+ setFramesWinId(MESSAGE_PREFIX, frameElements, message.options, FrameTree.windowId, window);
|
|
|
} else {
|
|
} else {
|
|
|
- top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData: [], windowId: FrameTree.windowId, index: FrameTree.index }), "*");
|
|
|
|
|
|
|
+ top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData: [], windowId: FrameTree.windowId }), "*");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -125,16 +124,15 @@ this.FrameTree = this.FrameTree || (() => {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
FrameTree.windowId = message.windowId;
|
|
FrameTree.windowId = message.windowId;
|
|
|
- FrameTree.index = message.index;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function setFramesWinId(MESSAGE_PREFIX, frameElements, options, index, windowId, win) {
|
|
|
|
|
|
|
+ function setFramesWinId(MESSAGE_PREFIX, frameElements, options, windowId, win) {
|
|
|
const framesData = [];
|
|
const framesData = [];
|
|
|
if (win != top) {
|
|
if (win != top) {
|
|
|
- win.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", windowId, index }), "*");
|
|
|
|
|
|
|
+ win.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", windowId }), "*");
|
|
|
}
|
|
}
|
|
|
- frameElements.forEach((frameElement, index) => {
|
|
|
|
|
|
|
+ frameElements.forEach((frameElement, frameIndex) => {
|
|
|
let src, sameDomain;
|
|
let src, sameDomain;
|
|
|
try {
|
|
try {
|
|
|
sameDomain = Boolean(frameElement.contentDocument && frameElement.contentWindow && top.addEventListener && top);
|
|
sameDomain = Boolean(frameElement.contentDocument && frameElement.contentWindow && top.addEventListener && top);
|
|
@@ -142,11 +140,11 @@ this.FrameTree = this.FrameTree || (() => {
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
/* ignored */
|
|
/* ignored */
|
|
|
}
|
|
}
|
|
|
- framesData.push({ sameDomain, src, index, windowId: windowId + "." + index });
|
|
|
|
|
|
|
+ framesData.push({ sameDomain, src, windowId: windowId + "." + frameIndex });
|
|
|
});
|
|
});
|
|
|
- top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData, windowId, index }), "*");
|
|
|
|
|
- frameElements.forEach((frameElement, index) => {
|
|
|
|
|
- const frameWinId = windowId + "." + index;
|
|
|
|
|
|
|
+ top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData, windowId }), "*");
|
|
|
|
|
+ frameElements.forEach((frameElement, frameIndex) => {
|
|
|
|
|
+ const frameWinId = windowId + "." + frameIndex;
|
|
|
frameElement.setAttribute(docHelper.WIN_ID_ATTRIBUTE_NAME, frameWinId);
|
|
frameElement.setAttribute(docHelper.WIN_ID_ATTRIBUTE_NAME, frameWinId);
|
|
|
let frameDoc, frameWindow, topWindow;
|
|
let frameDoc, frameWindow, topWindow;
|
|
|
let content, emptyStyleRulesText, canvasData;
|
|
let content, emptyStyleRulesText, canvasData;
|
|
@@ -158,7 +156,7 @@ this.FrameTree = this.FrameTree || (() => {
|
|
|
/* ignored */
|
|
/* ignored */
|
|
|
}
|
|
}
|
|
|
if (frameWindow && frameDoc && topWindow) {
|
|
if (frameWindow && frameDoc && topWindow) {
|
|
|
- setFramesWinId(MESSAGE_PREFIX, frameDoc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"), options, index, frameWinId, frameWindow);
|
|
|
|
|
|
|
+ setFramesWinId(MESSAGE_PREFIX, frameDoc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"), options, frameWinId, frameWindow);
|
|
|
topWindow.addEventListener("message", onMessage, false);
|
|
topWindow.addEventListener("message", onMessage, false);
|
|
|
const docData = docHelper.preProcessDoc(frameDoc, frameWindow, options);
|
|
const docData = docHelper.preProcessDoc(frameDoc, frameWindow, options);
|
|
|
content = docHelper.serialize(frameDoc);
|
|
content = docHelper.serialize(frameDoc);
|
|
@@ -166,8 +164,8 @@ this.FrameTree = this.FrameTree || (() => {
|
|
|
canvasData = docData.canvasData;
|
|
canvasData = docData.canvasData;
|
|
|
docHelper.postProcessDoc(frameDoc, options);
|
|
docHelper.postProcessDoc(frameDoc, options);
|
|
|
} else if (frameWindow) {
|
|
} else if (frameWindow) {
|
|
|
- frameWindow.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initRequest", windowId: frameWinId, index, options }), "*");
|
|
|
|
|
- timeout.set(() => top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData: [], windowId: frameWinId, index }), "*"), TIMEOUT_INIT_REQUEST_MESSAGE);
|
|
|
|
|
|
|
+ frameWindow.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initRequest", windowId: frameWinId, frameIndex, options }), "*");
|
|
|
|
|
+ timeout.set(() => top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: "initResponse", framesData: [], windowId: frameWinId, frameIndex }), "*"), TIMEOUT_INIT_REQUEST_MESSAGE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onMessage(event) {
|
|
function onMessage(event) {
|