Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.GLOBAL] = (win : CrossDomainWindowType, serializedMessage : string) => {
if (!needsGlobalMessagingForBrowser()) {
throw new Error(`Global messaging not needed for browser`);
}
if (!isSameDomain(win)) {
throw new Error(`Post message through global disabled between different domain windows`);
}
if (isSameTopWindow(window, win) !== false) {
throw new Error(`Can only use global to communicate between two different windows, not between frames`);
}
// $FlowFixMe
const foreignGlobal = getGlobal(win);
if (!foreignGlobal) {
throw new Error(`Can not find postRobot global on foreign window`);
}
foreignGlobal.receiveMessage({
source: window,
origin: getDomain(),
data: serializedMessage
});
};
const data = event.data;
if (origin === 'null') {
origin = `${ PROTOCOL.FILE }//`;
}
if (!source) {
return;
}
if (!origin) {
throw new Error(`Post message did not have origin domain`);
}
if (__TEST__) {
if (needsGlobalMessagingForBrowser() && isSameTopWindow(source, window) === false) {
return;
}
}
receiveMessage({ source, origin, data }, { on, send });
}
checkAllowRender(target : CrossDomainWindowType, domain : string | RegExp, container : string | HTMLElement) {
if (target === window) {
return;
}
if (!isSameTopWindow(window, target)) {
throw new Error(`Can only renderTo an adjacent frame`);
}
const origin = getDomain();
if (!matchDomain(domain, origin) && !isSameDomain(target)) {
throw new Error(`Can not render remotely to ${ domain.toString() } - can only render to ${ origin }`);
}
if (container && typeof container !== 'string') {
throw new Error(`Container passed to renderTo must be a string selector, got ${ typeof container } }`);
}
}
export function emulateIERestrictions(sourceWindow, targetWindow) {
if (!CONFIG.ALLOW_POSTMESSAGE_POPUP) {
if (isSameTopWindow(sourceWindow, targetWindow) === false) {
throw new Error('Can not send and receive post messages between two different windows (disabled to emulate IE)');
}
}
}
SEND_MESSAGE_STRATEGIES[SEND_STRATEGY.POST_MESSAGE] = (win : CrossDomainWindowType, serializedMessage : string, domain : DomainMatcher) => {
if (__TEST__) {
if (needsGlobalMessagingForBrowser() && isSameTopWindow(window, win) === false) {
return;
}
}
let domains;
if (Array.isArray(domain)) {
domains = domain;
} else if (typeof domain === 'string') {
domains = [ domain ];
} else {
domains = [ WILDCARD ];
}
domains = domains.map(dom => {
checkAllowRemoteRender(target : CrossDomainWindowType) {
if (!target) {
throw this.component.createError(`Must pass window to renderTo`);
}
if (!isSameTopWindow(window, target)) {
throw new Error(`Can only renderTo an adjacent frame`);
}
let origin = getDomain();
let domain = this.getDomain();
if (!matchDomain(domain, origin) && !isSameDomain(target)) {
throw new Error(`Can not render remotely to ${ domain.toString() } - can only render to ${ origin }`);
}
}
ParentComponent.prototype.checkAllowRemoteRender = function checkAllowRemoteRender(target) {
if (!target) {
throw this.component.createError('Must pass window to renderTo');
}
if (!isSameTopWindow(window, target)) {
throw new Error('Can only renderTo an adjacent frame');
}
var origin = getDomain();
var domain = this.getDomain();
if (!matchDomain(domain, origin) && !isSameDomain(target)) {
throw new Error('Can not render remotely to ' + domain.toString() + ' - can only render to ' + origin);
}
};
export function needsBridgeForWin(win : CrossDomainWindowType) : boolean {
if (!isSameTopWindow(window, win)) {
return true;
}
return false;
}
export function emulateIERestrictions(sourceWindow : CrossDomainWindowType, targetWindow : CrossDomainWindowType) {
if (!CONFIG.ALLOW_POSTMESSAGE_POPUP) {
if (isSameTopWindow(sourceWindow, targetWindow) === false) {
throw new Error(`Can not send and receive post messages between two different windows (disabled to emulate IE)`);
}
}
}