Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ChildComponent.prototype.getWindowByRef = function getWindowByRef(ref) {
var type = ref.type;
var result = void 0;
if (type === WINDOW_REFERENCES.OPENER) {
result = getOpener(window);
} else if (type === WINDOW_REFERENCES.TOP) {
result = getTop(window);
} else if (type === WINDOW_REFERENCES.PARENT) {
// $FlowFixMe
var distance = ref.distance;
if (distance) {
result = getNthParentFromTop(window, distance);
} else {
result = getParent(window);
}
}
if (type === WINDOW_REFERENCES.GLOBAL) {
// $FlowFixMe
getParentComponentWindow(ref : WindowRef) : CrossDomainWindowType {
const { type } = ref;
if (type === WINDOW_REFERENCES.OPENER) {
return assertExists('opener', getOpener(window));
} else if (type === WINDOW_REFERENCES.PARENT && typeof ref.distance === 'number') {
return assertExists('parent', getNthParentFromTop(window, ref.distance));
} else if (type === WINDOW_REFERENCES.GLOBAL && ref.uid && typeof ref.uid === 'string') {
const { uid } = ref;
const ancestor = getAncestor(window);
if (!ancestor) {
throw new Error(`Can not find ancestor window`);
}
for (const frame of getAllFramesInWindow(ancestor)) {
if (isSameDomain(frame)) {
const global = getGlobal(frame);
return ZalgoPromise.try(() => {
const opener = getOpener(window);
if (!opener || !needsBridge({ win: opener })) {
return;
}
registerRemoteWindow(opener);
return awaitRemoteBridgeForWindow(opener).then(bridge => {
if (!bridge) {
return rejectRemoteSendMessage(opener, new Error(`Can not register with opener: no bridge found in opener`));
}
if (!window.name) {
return rejectRemoteSendMessage(opener, new Error(`Can not register with opener: window does not have a name`));
}
getType: () => winPromise.then(win => {
return getOpener(win) ? WINDOW_TYPE.POPUP : WINDOW_TYPE.IFRAME;
}),
getInstanceID: memoizePromise(() => winPromise.then(win => getWindowInstanceID(win, { send }))),