|
|
@@ -18,7 +18,7 @@
|
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
-/* global window, top, document, addEventListener, docHelper, timeout, MessageChannel, superFetch, fetch, TextDecoder, DOMParser, lazyLoader, setTimeout */
|
|
|
+/* global window, top, document, addEventListener, docHelper, timeout, MessageChannel, superFetch, fetch, TextDecoder, DOMParser, lazyLoader, setTimeout, browser */
|
|
|
|
|
|
this.frameTree = this.frameTree || (() => {
|
|
|
|
|
|
@@ -39,6 +39,13 @@ this.frameTree = this.frameTree || (() => {
|
|
|
|
|
|
if (TOP_WINDOW) {
|
|
|
windowId = TOP_WINDOW_ID;
|
|
|
+ if (this.browser && browser.runtime && browser.runtime.onMessage && browser.runtime.onMessage.addListener) {
|
|
|
+ browser.runtime.onMessage.addListener(message => {
|
|
|
+ if (message.method == INIT_RESPONSE_MESSAGE) {
|
|
|
+ initResponse(message);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
addEventListener("message", event => {
|
|
|
if (typeof event.data == "string" && event.data.startsWith(MESSAGE_PREFIX)) {
|
|
|
@@ -232,12 +239,16 @@ this.frameTree = this.frameTree || (() => {
|
|
|
}
|
|
|
|
|
|
function sendMessage(targetWindow, message, useChannel) {
|
|
|
- if (useChannel) {
|
|
|
- const channel = new MessageChannel();
|
|
|
- targetWindow.postMessage(MESSAGE_PREFIX + JSON.stringify({ method: message.method }), TARGET_ORIGIN, [channel.port2]);
|
|
|
- channel.port1.postMessage(message);
|
|
|
+ if (targetWindow == top && this.browser && browser.runtime && browser.runtime.sendMessage) {
|
|
|
+ browser.runtime.sendMessage(message);
|
|
|
} else {
|
|
|
- targetWindow.postMessage(MESSAGE_PREFIX + JSON.stringify(message), TARGET_ORIGIN);
|
|
|
+ if (useChannel) {
|
|
|
+ const channel = new MessageChannel();
|
|
|
+ targetWindow.postMessage(MESSAGE_PREFIX + JSON.stringify({ method: message.method }), TARGET_ORIGIN, [channel.port2]);
|
|
|
+ channel.port1.postMessage(message);
|
|
|
+ } else {
|
|
|
+ targetWindow.postMessage(MESSAGE_PREFIX + JSON.stringify(message), TARGET_ORIGIN);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|