|
|
@@ -18,7 +18,7 @@
|
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
-/* global window, top, document, addEventListener, docHelper, timeout */
|
|
|
+/* global window, top, document, addEventListener, docHelper, timeout, MessageChannel */
|
|
|
|
|
|
this.frameTree = this.frameTree || (() => {
|
|
|
|
|
|
@@ -40,7 +40,8 @@ this.frameTree = this.frameTree || (() => {
|
|
|
if (message.method == INIT_REQUEST_MESSAGE) {
|
|
|
initRequest(message);
|
|
|
} else if (message.method == INIT_RESPONSE_MESSAGE) {
|
|
|
- initResponse(message);
|
|
|
+ const port = event.ports[0];
|
|
|
+ port.onmessage = event => initResponse(event.data);
|
|
|
}
|
|
|
}
|
|
|
}, false);
|
|
|
@@ -72,7 +73,7 @@ this.frameTree = this.frameTree || (() => {
|
|
|
const content = docHelper.serialize(document);
|
|
|
docHelper.postProcessDoc(document, window, message.options);
|
|
|
callTopInitResponse({
|
|
|
- method: INIT_RESPONSE_MESSAGE, framesData: [{
|
|
|
+ framesData: [{
|
|
|
windowId,
|
|
|
content,
|
|
|
baseURI: document.baseURI.split("#")[0],
|
|
|
@@ -127,13 +128,12 @@ this.frameTree = this.frameTree || (() => {
|
|
|
/* ignored */
|
|
|
}
|
|
|
}
|
|
|
- timeout.set(() => top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({
|
|
|
- method: INIT_RESPONSE_MESSAGE,
|
|
|
+ timeout.set(() => callTopInitResponse({
|
|
|
framesData: [{ windowId: frameWindowId, processed: true, timeout: true }],
|
|
|
windowId: frameWindowId, sessionId
|
|
|
- }), "*"), TIMEOUT_INIT_REQUEST_MESSAGE);
|
|
|
+ }, "*"), TIMEOUT_INIT_REQUEST_MESSAGE);
|
|
|
});
|
|
|
- callTopInitResponse({ method: INIT_RESPONSE_MESSAGE, framesData, windowId, sessionId });
|
|
|
+ callTopInitResponse({ framesData, windowId, sessionId });
|
|
|
if (frameElements.length) {
|
|
|
framesData = [];
|
|
|
frameElements.forEach((frameElement, frameIndex) => {
|
|
|
@@ -162,15 +162,19 @@ this.frameTree = this.frameTree || (() => {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- callTopInitResponse({ method: INIT_RESPONSE_MESSAGE, framesData, windowId, sessionId });
|
|
|
+ callTopInitResponse({ framesData, windowId, sessionId });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function callTopInitResponse(message) {
|
|
|
+ message.method = INIT_RESPONSE_MESSAGE;
|
|
|
try {
|
|
|
top.frameTree.initResponse(message);
|
|
|
} catch (error) {
|
|
|
- top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify(message), "*");
|
|
|
+ const channel = new MessageChannel();
|
|
|
+ const port = channel.port1;
|
|
|
+ top.postMessage(MESSAGE_PREFIX + "::" + JSON.stringify({ method: INIT_RESPONSE_MESSAGE }), "*", [channel.port2]);
|
|
|
+ port.postMessage(message);
|
|
|
}
|
|
|
}
|
|
|
|