How to use the cross-domain-utils/src.getDomain function in cross-domain-utils

To help you get started, we’ve selected a few cross-domain-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github krakenjs / zoid / src / component / parent / index.js View on Github external
getPropsForChild(domain : string | RegExp) : (BuiltInPropsType & P) {

        let result = {};

        for (let key of Object.keys(this.props)) {
            let prop = this.component.getProp(key);

            if (prop && prop.sendToChild === false) {
                continue;
            }

            if (prop && prop.sameDomain && !matchDomain(domain, getDomain(window))) {
                continue;
            }

            // $FlowFixMe
            result[key] = this.props[key];
        }

        // $FlowFixMe
        return result;
    }
github krakenjs / zoid / dist / module / component / child / index.js View on Github external
var type = _ref.type,
            value = _ref.value,
            uid = _ref.uid;

        var props = void 0;

        if (type === INITIAL_PROPS.RAW) {
            props = value;
        } else if (type === INITIAL_PROPS.UID) {

            if (!isSameDomain(parentComponentWindow)) {
                if (window.location.protocol === 'file:') {
                    throw new Error('Can not get props from file:// domain');
                }

                throw new Error('Parent component window is on a different domain - expected ' + getDomain() + ' - can not retrieve props');
            }

            var global = globalFor(parentComponentWindow);

            if (!global) {
                throw new Error('Can not find global for parent component - can not retrieve props');
            }

            props = global.props[uid];
        }

        if (!props) {
            throw new Error('Initial props not found');
        }

        return deserializeMessage(parentComponentWindow, domain, props);
github krakenjs / zoid / src / parent / index.js View on Github external
getPropsRef(proxyWin : ProxyWindow, childDomain : string, domain : string | RegExp, uid : string) : PropRef {
        const value = serializeMessage(proxyWin, domain, this.getPropsForChild(domain));

        const propRef = (childDomain === getDomain())
            ? { type: INITIAL_PROPS.UID, uid }
            : { type: INITIAL_PROPS.RAW, value };

        if (propRef.type === INITIAL_PROPS.UID) {
            const global = getGlobal(window);
            global.props = global.props || {};
            global.props[uid] = value;

            this.clean.register(() => {
                delete global.props[uid];
            });
        }

        return propRef;
    }
github krakenjs / zoid / src / parent / index.js View on Github external
buildChildPayload({ proxyWin, childDomain, domain, target = window, context, uid } : { proxyWin : ProxyWindow, childDomain : string, domain : string | RegExp, target : CrossDomainWindowType, context : $Values, uid : string } = {}) : ChildPayload {
        return {
            uid,
            context,
            version:      __ZOID__.__VERSION__,
            childDomain,
            parentDomain: getDomain(window),
            tag:          this.component.tag,
            parent:       this.getWindowRef(target, childDomain, uid, context),
            props:        this.getPropsRef(proxyWin, childDomain, domain, uid),
            exports:      serializeMessage(proxyWin, domain, this.buildParentExports(proxyWin))
        };
    }
github krakenjs / zoid / dist / module / component / parent / index.js View on Github external
ParentComponent.prototype.getWindowRef = function getWindowRef(target, domain, uid, context) {

        if (domain === getDomain(window)) {
            global.windows[uid] = window;
            this.clean.register(function () {
                delete global.windows[uid];
            });

            return { type: WINDOW_REFERENCES.GLOBAL, uid: uid };
        }

        if (target !== window) {
            throw new Error('Can not currently create window reference for different target with a different domain');
        }

        if (context === CONTEXT.POPUP) {
            return { type: WINDOW_REFERENCES.OPENER };
        }
github krakenjs / zoid / src / parent / index.js View on Github external
getWindowRef(target : CrossDomainWindowType, domain : string, uid : string, context : $Values) : WindowRef {
        
        if (domain === getDomain(window)) {
            const global = getGlobal(window);
            global.windows = global.windows || {};
            global.windows[uid] = window;
            this.clean.register(() => {
                delete global.windows[uid];
            });
    
            return { type: WINDOW_REFERENCES.GLOBAL, uid };
        }

        if (context === CONTEXT.POPUP) {
            return { type: WINDOW_REFERENCES.OPENER };
        }

        return { type: WINDOW_REFERENCES.PARENT, distance: getDistanceFromTop(window) };
    }
github krakenjs / zoid / src / component / component.js View on Github external
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 } }`);
        }
    }
github krakenjs / zoid / dist / module / component / parent / index.js View on Github external
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);
        }
    };
github krakenjs / post-robot / src / drivers / send / index.js View on Github external
export function sendMessage(win : CrossDomainWindowType, domain : DomainMatcher, message : Message, { on, send } : { on : OnType, send : SendType }) {
    if (isWindowClosed(win)) {
        throw new Error('Window is closed');
    }
    
    const serializedMessage = serializeMessage(win, domain, {
        [ __POST_ROBOT__.__GLOBAL_KEY__ ]: {
            id:     uniqueID(),
            origin: getDomain(window),
            ...message
        }
    }, { on, send });

    const strategies = Object.keys(SEND_MESSAGE_STRATEGIES);
    const errors = [];

    for (const strategyName of strategies) {
        try {
            SEND_MESSAGE_STRATEGIES[strategyName](win, serializedMessage, domain);
        } catch (err) {
            errors.push(err);
        }
    }

    if (errors.length === strategies.length) {