Skip to content

Commit

Permalink
Add __GLOBAL_MESSAGE_SUPPORT__ flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Brain committed Jul 9, 2018
1 parent 53d698c commit a1da00d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
3 changes: 2 additions & 1 deletion globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
module.exports = {
'__POST_ROBOT__': {
__IE_POPUP_SUPPORT__: true,
__ALLOW_POSTMESSAGE_POPUP__: true
__ALLOW_POSTMESSAGE_POPUP__: true,
__GLOBAL_MESSAGE_SUPPORT__: true
},
'__POST_ROBOT__.__IE_POPUP_SUPPORT__': true
};
3 changes: 2 additions & 1 deletion src/declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

declare var __POST_ROBOT__ : {
__IE_POPUP_SUPPORT__ : boolean,
__ALLOW_POSTMESSAGE_POPUP__ : boolean
__ALLOW_POSTMESSAGE_POPUP__ : boolean,
__GLOBAL_MESSAGE_SUPPORT__ : boolean
};

declare var __TEST__ : boolean;
6 changes: 5 additions & 1 deletion src/drivers/send/strategies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { isSameDomain, isSameTopWindow, isActuallySameDomain, getActualDomain, getDomain, type CrossDomainWindowType } from 'cross-domain-utils/src';

import { CONSTANTS } from '../../conf';
import { needsGlobalMessagingForBrowser } from '../../lib';

export let SEND_MESSAGE_STRATEGIES = {};

Expand Down Expand Up @@ -75,10 +76,13 @@ if (__POST_ROBOT__.__IE_POPUP_SUPPORT__) {

return sendBridgeMessage(win, serializedMessage, domain);
};
}

if (__POST_ROBOT__.__IE_POPUP_SUPPORT__ || __POST_ROBOT__.__GLOBAL_MESSAGE_SUPPORT__) {

SEND_MESSAGE_STRATEGIES[CONSTANTS.SEND_STRATEGIES.GLOBAL] = (win : CrossDomainWindowType, serializedMessage : string) => {

if (!needsBridgeForBrowser()) {
if (!needsGlobalMessagingForBrowser()) {
return;
}

Expand Down
17 changes: 15 additions & 2 deletions src/lib/util.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* @flow */

import { WeakMap } from 'cross-domain-safe-weakmap/src';
import { isPopup, isIframe } from 'cross-domain-utils/src';
import { isPopup, isIframe, getUserAgent } from 'cross-domain-utils/src';

import { CONSTANTS } from '../conf';
import { CONFIG, CONSTANTS } from '../conf';


export function stringifyError(err : mixed, level : number = 1) : string {
Expand Down Expand Up @@ -268,3 +268,16 @@ export function jsonStringify<T : mixed>(obj : T, replacer : ?Function, indent :
export function jsonParse(item : string) : mixed {
return JSON.parse(item);
}

export function needsGlobalMessagingForBrowser() : boolean {

if (getUserAgent(window).match(/MSIE|trident|edge\/12|edge\/13/i)) {
return true;
}

if (!CONFIG.ALLOW_POSTMESSAGE_POPUP) {
return true;
}

return false;
}
6 changes: 4 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export let WEBPACK_CONFIG = getWebpackConfig({

__POST_ROBOT__: {
...globals.__POST_ROBOT__,
__IE_POPUP_SUPPORT__: false
__IE_POPUP_SUPPORT__: false,
__GLOBAL_MESSAGE_SUPPORT__: false
}
}
});
Expand All @@ -30,7 +31,8 @@ export let WEBPACK_CONFIG_MIN = getWebpackConfig({

__POST_ROBOT__: {
...globals.__POST_ROBOT__,
__IE_POPUP_SUPPORT__: false
__IE_POPUP_SUPPORT__: false,
__GLOBAL_MESSAGE_SUPPORT__: false
}
}
});
Expand Down

0 comments on commit a1da00d

Please # to comment.