From 25b0c2f8cbefd3513327c1a6b335a26af2fb914e Mon Sep 17 00:00:00 2001 From: Westin Wrzesinski Date: Mon, 14 Feb 2022 14:38:20 -0600 Subject: [PATCH] refactor!: move `dist/module` to `lib` and export flow types Moving esm files to `lib/` folder gives us a path to stop importing from `src/` when importing files for treeshaking. We can migrate to importing from `lib/` and still have flow definitions at the ready Tasks Completed: - Remove module folder - Output transpiled code and flow defs to `lib/` --- dist/.gitignore | 0 dist/cross-domain-utils.js.map | 1 - dist/module/index.js.flow | 56 -- dist/module/util.js.flow | 5 - dist/test.htm | 1 - {dist/module => lib}/constants.js | 0 lib/constants.js.flow | 14 + {dist/module => lib}/index.js | 0 lib/index.js.flow | 5 + {dist/module => lib}/types.js | 0 lib/types.js.flow | 40 ++ {dist/module => lib}/util.js | 0 lib/util.js.flow | 11 + {dist/module => lib}/utils.js | 0 lib/utils.js.flow | 1103 +++++++++++++++++++++++++++++ package.json | 13 +- 16 files changed, 1181 insertions(+), 68 deletions(-) delete mode 100644 dist/.gitignore delete mode 100644 dist/cross-domain-utils.js.map delete mode 100644 dist/module/index.js.flow delete mode 100644 dist/module/util.js.flow delete mode 100644 dist/test.htm rename {dist/module => lib}/constants.js (100%) create mode 100644 lib/constants.js.flow rename {dist/module => lib}/index.js (100%) create mode 100644 lib/index.js.flow rename {dist/module => lib}/types.js (100%) create mode 100644 lib/types.js.flow rename {dist/module => lib}/util.js (100%) create mode 100644 lib/util.js.flow rename {dist/module => lib}/utils.js (100%) create mode 100644 lib/utils.js.flow diff --git a/dist/.gitignore b/dist/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/dist/cross-domain-utils.js.map b/dist/cross-domain-utils.js.map deleted file mode 100644 index e5a75b1..0000000 --- a/dist/cross-domain-utils.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap 36ec335e14d702e46b56","webpack:///./src/util.js","webpack:///./src/constants.js","webpack:///./src/utils.js","webpack:///./src/index.js","webpack:///./src/types.js"],"names":["root","factory","exports","module","define","amd","self","this","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","isRegex","item","toString","PROTOCOL","MOCK","FILE","ABOUT","WILDCARD","WINDOW_TYPE","IFRAME","POPUP","IE_WIN_ACCESS_ERROR","isFileProtocol","arguments","length","undefined","window","location","protocol","isAboutProtocol","getParent","win","parent","err","getOpener","opener","canReadFromWindow","href","getActualDomain","Error","host","getDomain","domain","mockDomain","indexOf","isBlankDomain","isActuallySameDomain","desc","getOwnPropertyDescriptor","isSameDomain","assertSameDomain","getParents","result","push","isAncestorParent","child","childParent","getFrames","frames","len","frame","getAllChildFrames","_i3","_getFrames2","_length2","_i5","_getAllChildFrames2","_length4","childFrame","getTop","top","_i7","_getAllChildFrames4","_length6","getNextOpener","getUltimateTop","getAllFramesInWindow","getAllWindows","concat","isTop","isFrameWindowClosed","contentWindow","parentNode","doc","ownerDocument","documentElement","contains","iframeWindows","iframeFrames","isWindowClosed","allowMock","closed","message","mockclosed","iframeIndex","collection","safeIndexOf","linkFrameWindow","splice","cleanIframes","getUserAgent","navigator","mockUserAgent","userAgent","getFrameByName","winFrames","_i9","_length8","findChildFrameByName","_i11","_getFrames4","_length10","namedFrame","findFrameByName","isParent","frameParent","_i13","_getFrames6","_length12","isOpener","getAncestor","getAncestors","results","ancestor","isAncestor","actualParent","_i15","_getFrames8","_length14","isPopup","Boolean","isIframe","isFullpage","anyMatch","collection1","collection2","_i17","_length16","item1","_i19","_length18","getDistanceFromTop","distance","getNthParent","getNthParentFromTop","isSameTopWindow","win1","win2","top1","top2","allFrames1","allFrames2","opener1","opener2","matchDomain","pattern","origin","Array","isArray","match","JSON","stringify","some","subpattern","stringifyDomainPattern","join","getDomainFromUrl","url","split","slice","onCloseWindow","callback","delay","maxtime","Infinity","timeout","check","clearTimeout","setTimeout","cancel","isWindow","obj","Window","__cross_domain_utils_window_check__","isBrowser","isCurrentDomain","isMockDomain","normalizeMockUrl","closeWindow","close","getFrameForWindow","frameElement","_i21","_document$querySelect2","document","querySelectorAll","_length20","__webpack_exports__"],"mappings":"CAAA,SAAAA,MAAAC;IACA,mBAAAC,WAAA,mBAAAC,SACAA,OAAAD,UAAAD,YACA,qBAAAG,iBAAAC,MACAD,OAAA,wBAAAH,WACA,mBAAAC,UACAA,QAAA,mBAAAD,YAEAD,KAAA,mBAAAC;CARA,CASC,sBAAAK,cAAAC,MAAA;IACD;QCTA,IAAAC;QAGA,SAAAC,oBAAAC;YAGA,IAAAF,iBAAAE,WACA,OAAAF,iBAAAE,UAAAR;YAGA,IAAAC,SAAAK,iBAAAE;gBACAC,GAAAD;gBACAE,IAAA;gBACAV;;YAIAW,QAAAH,UAAAI,KAAAX,OAAAD,SAAAC,eAAAD,SAAAO;YAGAN,OAAAS,KAAA;YAGA,OAAAT,OAAAD;;QAKAO,oBAAAM,IAAAF;QAGAJ,oBAAAO,IAAAR;QAGAC,oBAAAQ,IAAA,SAAAf,SAAAgB,MAAAC;YACAV,oBAAAW,EAAAlB,SAAAgB,SACAG,OAAAC,eAAApB,SAAAgB;gBACAK,eAAA;gBACAC,aAAA;gBACAC,KAAAN;;;QAMAV,oBAAAiB,IAAA,SAAAvB;YACA,IAAAgB,SAAAhB,iBAAAwB,aACA;gBAA2B,OAAAxB,OAAA;gBAC3B;gBAAiC,OAAAA;;YACjCM,oBAAAQ,EAAAE,QAAA,KAAAA;YACA,OAAAA;;QAIAV,oBAAAW,IAAA,SAAAQ,QAAAC;YAAsD,OAAAR,OAAAS,UAAAC,eAAAjB,KAAAc,QAAAC;;QAGtDpB,oBAAAuB,IAAA;QAGA,OAAAvB,wCAAAwB,IAAA;;;;;;;YC3DO,SAASC,QAAQC;gBACpB,OAAgD,sBAAzCd,OAAOS,UAAUM,SAAStB,KAAKqB;;YCDnC,IAAME;gBACTC,MAAQ;gBACRC,MAAQ;gBACRC,O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factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"crossDomainUtils\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"crossDomainUtils\"] = factory();\n\telse\n\t\troot[\"crossDomainUtils\"] = factory();\n})(typeof self !== 'undefined' ? self : this, function() {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./src/index.js\");\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 36ec335e14d702e46b56","/* @flow */\n\nexport function isRegex(item : mixed) : boolean {\n return Object.prototype.toString.call(item) === '[object RegExp]';\n}\n\n// eslint-disable-next-line no-unused-vars\nexport function noop(...args : Array) {\n // pass\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/util.js","/* @flow */\n\nexport const PROTOCOL = {\n MOCK: ('mock:' : 'mock:'),\n FILE: ('file:' : 'file:'),\n ABOUT: ('about:' : 'about:')\n};\n\nexport const WILDCARD = '*';\n\nexport const WINDOW_TYPE = {\n IFRAME: ('iframe' : 'iframe'),\n POPUP: ('popup' : 'popup')\n};\n\n\n\n// WEBPACK FOOTER //\n// ./src/constants.js","/* @flow */\n/* eslint max-lines: 0 */\n\nimport { isRegex, noop } from './util';\nimport type { CrossDomainWindowType, SameDomainWindowType, DomainMatcher } from './types';\nimport { PROTOCOL, WILDCARD } from './constants';\n\nlet IE_WIN_ACCESS_ERROR = 'Call was rejected by callee.\\r\\n';\n\nexport function isFileProtocol(win : SameDomainWindowType = window) : boolean {\n return win.location.protocol === PROTOCOL.FILE;\n}\n\nexport function isAboutProtocol(win : SameDomainWindowType = window) : boolean {\n return win.location.protocol === PROTOCOL.ABOUT;\n}\n\nexport function getParent(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType {\n\n if (!win) {\n return;\n }\n\n try {\n if (win.parent && win.parent !== win) {\n return win.parent;\n }\n } catch (err) {\n // pass\n }\n}\n\nexport function getOpener(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType {\n\n if (!win) {\n return;\n }\n\n // Make sure we're not actually an iframe which has had window.open() called on us\n if (getParent(win)) {\n return;\n }\n\n try {\n return win.opener;\n } catch (err) {\n // pass\n }\n}\n\nexport function canReadFromWindow(win : CrossDomainWindowType | SameDomainWindowType) : boolean {\n try {\n // $FlowFixMe\n noop(win && win.location && win.location.href);\n return true;\n } catch (err) {\n // pass\n }\n\n return false;\n}\n\nexport function getActualDomain(win? : SameDomainWindowType = window) : string {\n\n let location = win.location;\n\n if (!location) {\n throw new Error(`Can not read window location`);\n }\n\n let protocol = location.protocol;\n\n if (!protocol) {\n throw new Error(`Can not read window protocol`);\n }\n\n if (protocol === PROTOCOL.FILE) {\n return `${ PROTOCOL.FILE }//`;\n }\n\n if (protocol === PROTOCOL.ABOUT) {\n\n let parent = getParent(win);\n if (parent && canReadFromWindow(parent)) {\n // $FlowFixMe\n return getActualDomain(parent);\n }\n\n return `${ PROTOCOL.ABOUT }//`;\n }\n\n let host = location.host;\n\n if (!host) {\n throw new Error(`Can not read window host`);\n }\n\n return `${ protocol }//${ host }`;\n}\n\nexport function getDomain(win? : SameDomainWindowType = window) : string {\n\n let domain = getActualDomain(win);\n\n if (domain && win.mockDomain && win.mockDomain.indexOf(PROTOCOL.MOCK) === 0) {\n return win.mockDomain;\n }\n\n return domain;\n}\n\nexport function isBlankDomain(win : CrossDomainWindowType) : boolean {\n try {\n // $FlowFixMe\n if (!win.location.href) {\n return true;\n }\n\n if (win.location.href === 'about:blank') {\n return true;\n }\n } catch (err) {\n // pass\n }\n\n return false;\n}\n\nexport function isActuallySameDomain(win : CrossDomainWindowType) : boolean {\n\n try {\n if (win === window) {\n return true;\n }\n\n } catch (err) {\n // pass\n }\n\n try {\n let desc = Object.getOwnPropertyDescriptor(win, 'location');\n\n if (desc && desc.enumerable === false) {\n return false;\n }\n\n } catch (err) {\n // pass\n }\n\n try {\n // $FlowFixMe\n if (isAboutProtocol(win) && canReadFromWindow(win)) {\n return true;\n }\n } catch (err) {\n // pass\n }\n\n try {\n // $FlowFixMe\n if (getActualDomain(win) === getActualDomain(window)) {\n return true;\n }\n\n } catch (err) {\n // pass\n }\n\n return false;\n}\n\nexport function isSameDomain(win : CrossDomainWindowType | SameDomainWindowType) : boolean {\n\n if (!isActuallySameDomain(win)) {\n return false;\n }\n\n try {\n\n if (win === window) {\n return true;\n }\n\n // $FlowFixMe\n if (isAboutProtocol(win) && canReadFromWindow(win)) {\n return true;\n }\n\n // $FlowFixMe\n if (getDomain(window) === getDomain(win)) {\n return true;\n }\n\n } catch (err) {\n // pass\n }\n\n return false;\n}\n\n\nexport function assertSameDomain(win : CrossDomainWindowType | SameDomainWindowType) : SameDomainWindowType {\n if (!isSameDomain(win)) {\n throw new Error(`Expected window to be same domain`);\n }\n\n // $FlowFixMe\n return win;\n}\n\nexport function getParents(win : CrossDomainWindowType) : Array {\n\n let result = [];\n\n try {\n\n while (win.parent !== win) {\n result.push(win.parent);\n win = win.parent;\n }\n\n } catch (err) {\n // pass\n }\n\n return result;\n}\n\nexport function isAncestorParent(parent : CrossDomainWindowType, child : CrossDomainWindowType) : boolean {\n\n if (!parent || !child) {\n return false;\n }\n\n let childParent = getParent(child);\n\n if (childParent) {\n return childParent === parent;\n }\n\n if (getParents(child).indexOf(parent) !== -1) {\n return true;\n }\n\n return false;\n}\n\nexport function getFrames(win : CrossDomainWindowType) : Array {\n\n let result = [];\n\n let frames;\n\n try {\n frames = win.frames;\n } catch (err) {\n frames = win;\n }\n\n let len;\n\n try {\n len = frames.length;\n } catch (err) {\n // pass\n }\n\n if (len === 0) {\n return result;\n }\n\n if (len) {\n for (let i = 0; i < len; i++) {\n\n let frame;\n\n try {\n frame = frames[i];\n } catch (err) {\n continue;\n }\n\n result.push(frame);\n }\n\n return result;\n }\n\n for (let i = 0; i < 100; i++) {\n let frame;\n\n try {\n frame = frames[i];\n } catch (err) {\n return result;\n }\n\n if (!frame) {\n return result;\n }\n\n result.push(frame);\n }\n\n return result;\n}\n\n\nexport function getAllChildFrames(win : CrossDomainWindowType) : Array {\n\n let result = [];\n\n for (let frame of getFrames(win)) {\n result.push(frame);\n\n for (let childFrame of getAllChildFrames(frame)) {\n result.push(childFrame);\n }\n }\n\n return result;\n}\n\nexport function getTop(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType {\n\n try {\n if (win.top) {\n return win.top;\n }\n } catch (err) {\n // pass\n }\n\n if (getParent(win) === win) {\n return win;\n }\n\n try {\n if (isAncestorParent(window, win) && window.top) {\n return window.top;\n }\n } catch (err) {\n // pass\n }\n\n try {\n if (isAncestorParent(win, window) && window.top) {\n return window.top;\n }\n } catch (err) {\n // pass\n }\n\n for (let frame of getAllChildFrames(win)) {\n try {\n if (frame.top) {\n return frame.top;\n }\n } catch (err) {\n // pass\n }\n\n if (getParent(frame) === frame) {\n return frame;\n }\n }\n}\n\nexport function getNextOpener(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType {\n return getOpener(getTop(win) || win);\n}\n\nexport function getUltimateTop(win? : CrossDomainWindowType = window) : CrossDomainWindowType {\n let opener = getNextOpener(win);\n\n if (opener) {\n return getUltimateTop(opener);\n }\n\n return top;\n}\n\nexport function getAllFramesInWindow(win : CrossDomainWindowType) : $ReadOnlyArray {\n let top = getTop(win);\n\n if (!top) {\n throw new Error(`Can not determine top window`);\n }\n\n let result = [ ...getAllChildFrames(top), top ];\n\n // Win may be in shadow dom\n if (result.indexOf(win) === -1) {\n result = [ ...result, win, ...getAllChildFrames(win) ];\n }\n\n return result;\n}\n\nexport function getAllWindows(win? : CrossDomainWindowType = window) : $ReadOnlyArray {\n let frames = getAllFramesInWindow(win);\n let opener = getNextOpener(win);\n\n if (opener) {\n return [ ...getAllWindows(opener), ...frames ];\n } else {\n return frames;\n }\n}\n\nexport function isTop(win : CrossDomainWindowType) : boolean {\n return win === getTop(win);\n}\n\nexport function isFrameWindowClosed(frame : HTMLIFrameElement) : boolean {\n\n if (!frame.contentWindow) {\n return true;\n }\n\n if (!frame.parentNode) {\n return true;\n }\n\n let doc = frame.ownerDocument;\n\n if (doc && doc.documentElement && !doc.documentElement.contains(frame)) {\n let parent = frame;\n\n while (parent.parentNode && parent.parentNode !== parent) {\n parent = parent.parentNode;\n }\n\n // $FlowFixMe\n if (!parent.host || !doc.documentElement.contains(parent.host)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction safeIndexOf(collection : Array, item : T) : number {\n for (let i = 0; i < collection.length; i++) {\n\n try {\n if (collection[i] === item) {\n return i;\n }\n } catch (err) {\n // pass\n }\n }\n\n return -1;\n}\n\nlet iframeWindows = [];\nlet iframeFrames = [];\n\nexport function isWindowClosed(win : CrossDomainWindowType, allowMock : boolean = true) : boolean {\n\n try {\n if (win === window) {\n return false;\n }\n } catch (err) {\n return true;\n }\n\n try {\n if (!win) {\n return true;\n }\n\n } catch (err) {\n return true;\n }\n\n try {\n if (win.closed) {\n return true;\n }\n\n } catch (err) {\n\n // I love you so much IE\n\n if (err && err.message === IE_WIN_ACCESS_ERROR) {\n return false;\n }\n\n return true;\n }\n\n\n if (allowMock && isSameDomain(win)) {\n try {\n // $FlowFixMe\n if (win.mockclosed) {\n return true;\n }\n } catch (err) {\n // pass\n }\n }\n\n // Mobile safari\n\n try {\n if (!win.parent || !win.top) {\n return true;\n }\n } catch (err) {\n // pass\n }\n\n // Yes, this actually happens in IE. win === win errors out when the window\n // is from an iframe, and the iframe was removed from the page.\n\n try {\n noop(win === win); // eslint-disable-line no-self-compare\n } catch (err) {\n return true;\n }\n\n // IE orphaned frame\n\n let iframeIndex = safeIndexOf(iframeWindows, win);\n\n if (iframeIndex !== -1) {\n let frame = iframeFrames[iframeIndex];\n\n if (frame && isFrameWindowClosed(frame)) {\n return true;\n }\n }\n\n return false;\n}\n\nfunction cleanIframes() {\n for (let i = 0; i < iframeWindows.length; i++) {\n let closed = false;\n\n try {\n closed = iframeWindows[i].closed;\n } catch (err) {\n // pass\n }\n\n if (closed) {\n iframeFrames.splice(i, 1);\n iframeWindows.splice(i, 1);\n }\n }\n}\n\nexport function linkFrameWindow(frame : HTMLIFrameElement) {\n\n cleanIframes();\n\n if (frame && frame.contentWindow) {\n try {\n iframeWindows.push(frame.contentWindow);\n iframeFrames.push(frame);\n } catch (err) {\n // pass\n }\n }\n}\n\nexport function getUserAgent(win : ?SameDomainWindowType) : string {\n win = win || window;\n return win.navigator.mockUserAgent || win.navigator.userAgent;\n}\n\n\nexport function getFrameByName(win : CrossDomainWindowType, name : string) : ?CrossDomainWindowType {\n\n let winFrames = getFrames(win);\n\n for (let childFrame of winFrames) {\n try {\n // $FlowFixMe\n if (isSameDomain(childFrame) && childFrame.name === name && winFrames.indexOf(childFrame) !== -1) {\n return childFrame;\n }\n } catch (err) {\n // pass\n }\n }\n\n try {\n // $FlowFixMe\n if (winFrames.indexOf(win.frames[name]) !== -1) {\n // $FlowFixMe\n return win.frames[name];\n }\n } catch (err) {\n // pass\n }\n\n try {\n if (winFrames.indexOf(win[name]) !== -1) {\n return win[name];\n }\n } catch (err) {\n // pass\n }\n}\n\nexport function findChildFrameByName(win : CrossDomainWindowType, name : string) : ?CrossDomainWindowType {\n\n let frame = getFrameByName(win, name);\n\n if (frame) {\n return frame;\n }\n\n for (let childFrame of getFrames(win)) {\n let namedFrame = findChildFrameByName(childFrame, name);\n\n if (namedFrame) {\n return namedFrame;\n }\n }\n}\n\nexport function findFrameByName(win : CrossDomainWindowType, name : string) : ?CrossDomainWindowType {\n\n let frame;\n\n frame = getFrameByName(win, name);\n\n if (frame) {\n return frame;\n }\n\n let top = getTop(win) || win;\n\n return findChildFrameByName(top, name);\n}\n\nexport function isParent(win : CrossDomainWindowType, frame : CrossDomainWindowType) : boolean {\n\n let frameParent = getParent(frame);\n\n if (frameParent) {\n return frameParent === win;\n }\n\n for (let childFrame of getFrames(win)) {\n if (childFrame === frame) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function isOpener(parent : CrossDomainWindowType, child : CrossDomainWindowType) : boolean {\n\n return parent === getOpener(child);\n}\n\nexport function getAncestor(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType {\n win = win || window;\n\n let opener = getOpener(win);\n\n if (opener) {\n return opener;\n }\n\n let parent = getParent(win);\n\n if (parent) {\n return parent;\n }\n}\n\nexport function getAncestors(win : CrossDomainWindowType) : Array {\n\n let results = [];\n\n let ancestor = win;\n\n while (ancestor) {\n ancestor = getAncestor(ancestor);\n if (ancestor) {\n results.push(ancestor);\n }\n }\n\n return results;\n}\n\n\nexport function isAncestor(parent : CrossDomainWindowType, child : CrossDomainWindowType) : boolean {\n\n let actualParent = getAncestor(child);\n\n if (actualParent) {\n if (actualParent === parent) {\n return true;\n }\n\n return false;\n }\n\n if (child === parent) {\n return false;\n }\n\n if (getTop(child) === child) {\n return false;\n }\n\n for (let frame of getFrames(parent)) {\n if (frame === child) {\n return true;\n }\n }\n\n return false;\n}\n\nexport function isPopup(win? : CrossDomainWindowType = window) : boolean {\n return Boolean(getOpener(win));\n}\n\nexport function isIframe(win? : CrossDomainWindowType = window) : boolean {\n return Boolean(getParent(win));\n}\n\nexport function isFullpage(win? : CrossDomainWindowType = window) : boolean {\n return Boolean(!isIframe(win) && !isPopup(win));\n}\n\nfunction anyMatch(collection1, collection2) : boolean {\n\n for (let item1 of collection1) {\n for (let item2 of collection2) {\n if (item1 === item2) {\n return true;\n }\n }\n }\n\n return false;\n}\n\nexport function getDistanceFromTop(win : CrossDomainWindowType = window) : number {\n let distance = 0;\n let parent = win;\n\n while (parent) {\n parent = getParent(parent);\n if (parent) {\n distance += 1;\n }\n }\n\n return distance;\n}\n\nexport function getNthParent(win : CrossDomainWindowType, n : number = 1) : ?CrossDomainWindowType {\n let parent = win;\n\n for (let i = 0; i < n; i++) {\n if (!parent) {\n return;\n }\n\n parent = getParent(parent);\n }\n\n return parent;\n}\n\nexport function getNthParentFromTop(win : CrossDomainWindowType, n : number = 1) : ?CrossDomainWindowType {\n return getNthParent(win, getDistanceFromTop(win) - n);\n}\n\nexport function isSameTopWindow(win1 : CrossDomainWindowType, win2 : CrossDomainWindowType) : boolean {\n\n let top1 = getTop(win1) || win1;\n let top2 = getTop(win2) || win2;\n\n try {\n if (top1 && top2) {\n if (top1 === top2) {\n return true;\n }\n\n return false;\n }\n } catch (err) {\n // pass\n }\n\n let allFrames1 = getAllFramesInWindow(win1);\n let allFrames2 = getAllFramesInWindow(win2);\n\n if (anyMatch(allFrames1, allFrames2)) {\n return true;\n }\n\n let opener1 = getOpener(top1);\n let opener2 = getOpener(top2);\n\n if (opener1 && anyMatch(getAllFramesInWindow(opener1), allFrames2)) {\n return false;\n }\n\n if (opener2 && anyMatch(getAllFramesInWindow(opener2), allFrames1)) {\n return false;\n }\n\n return false;\n}\n\nexport function matchDomain(pattern : DomainMatcher, origin : DomainMatcher) : boolean {\n\n if (typeof pattern === 'string') {\n\n if (typeof origin === 'string') {\n return pattern === WILDCARD || origin === pattern;\n }\n\n if (isRegex(origin)) {\n return false;\n }\n\n if (Array.isArray(origin)) {\n return false;\n }\n }\n\n if (isRegex(pattern)) {\n\n if (isRegex(origin)) {\n return pattern.toString() === origin.toString();\n }\n\n if (Array.isArray(origin)) {\n return false;\n }\n\n // $FlowFixMe\n return Boolean(origin.match(pattern));\n }\n\n if (Array.isArray(pattern)) {\n\n if (Array.isArray(origin)) {\n return JSON.stringify(pattern) === JSON.stringify(origin);\n }\n\n if (isRegex(origin)) {\n return false;\n }\n\n return pattern.some(subpattern => matchDomain(subpattern, origin));\n }\n\n return false;\n}\n\nexport function stringifyDomainPattern(pattern : DomainMatcher) : string {\n if (Array.isArray(pattern)) {\n return `(${ pattern.join(' | ') })`;\n } else if (isRegex(pattern)) {\n return `RegExp(${ pattern.toString() }`;\n } else {\n return pattern.toString();\n }\n}\n\nexport function getDomainFromUrl(url : string) : string {\n\n let domain;\n\n if (url.match(/^(https?|mock|file):\\/\\//)) {\n domain = url;\n } else {\n return getDomain();\n }\n\n domain = domain.split('/').slice(0, 3).join('/');\n\n return domain;\n}\n\nexport function onCloseWindow(win : CrossDomainWindowType, callback : Function, delay : number = 1000, maxtime : number = Infinity) : { cancel : () => void } {\n\n let timeout;\n\n let check = () => {\n\n if (isWindowClosed(win)) {\n\n if (timeout) {\n clearTimeout(timeout);\n }\n\n return callback();\n }\n\n if (maxtime <= 0) {\n clearTimeout(timeout);\n } else {\n maxtime -= delay;\n timeout = setTimeout(check, delay);\n }\n };\n\n check();\n\n return {\n cancel() {\n if (timeout) {\n clearTimeout(timeout);\n }\n }\n };\n}\n\n// eslint-disable-next-line complexity\nexport function isWindow(obj : Object) : boolean {\n\n try {\n if (obj === window) {\n return true;\n }\n } catch (err) {\n if (err && err.message === IE_WIN_ACCESS_ERROR) {\n return true;\n }\n }\n\n try {\n if (Object.prototype.toString.call(obj) === '[object Window]') {\n return true;\n }\n } catch (err) {\n if (err && err.message === IE_WIN_ACCESS_ERROR) {\n return true;\n }\n }\n\n try {\n if (window.Window && obj instanceof window.Window) {\n return true;\n }\n } catch (err) {\n if (err && err.message === IE_WIN_ACCESS_ERROR) {\n return true;\n }\n }\n\n try {\n if (obj && obj.self === obj) {\n return true;\n }\n } catch (err) {\n if (err && err.message === IE_WIN_ACCESS_ERROR) {\n return true;\n }\n }\n\n try {\n if (obj && obj.parent === obj) {\n return true;\n }\n } catch (err) {\n if (err && err.message === IE_WIN_ACCESS_ERROR) {\n return true;\n }\n }\n\n try {\n if (obj && obj.top === obj) {\n return true;\n }\n } catch (err) {\n if (err && err.message === IE_WIN_ACCESS_ERROR) {\n return true;\n }\n }\n\n try {\n if (noop(obj === obj) === '__unlikely_value__') { // eslint-disable-line no-self-compare\n return false;\n }\n\n } catch (err) {\n return true;\n }\n\n try {\n if (obj && obj.__cross_domain_utils_window_check__ === '__unlikely_value__') {\n return false;\n }\n\n } catch (err) {\n return true;\n }\n\n try {\n if ('postMessage' in obj && 'self' in obj && 'location' in obj) {\n return true;\n }\n } catch (err) {\n // pass\n }\n\n return false;\n}\n\nexport function isBrowser() : boolean {\n return (typeof window !== 'undefined' && typeof window.location !== 'undefined');\n}\n\nexport function isCurrentDomain(domain : string) : boolean {\n if (!isBrowser()) {\n return false;\n }\n\n return (getDomain() === domain);\n}\n\nexport function isMockDomain(domain : string) : boolean {\n return domain.indexOf(PROTOCOL.MOCK) === 0;\n}\n\nexport function normalizeMockUrl(url : string) : string {\n if (!isMockDomain(getDomainFromUrl(url))) {\n return url;\n }\n\n if (!__TEST__) {\n throw new Error(`Mock urls not supported out of test mode`);\n }\n\n return url.replace(/^mock:\\/\\/[^/]+/, getActualDomain(window));\n}\n\nexport function closeWindow(win : CrossDomainWindowType) {\n try {\n win.close();\n } catch (err) {\n // pass\n }\n}\n\nexport function getFrameForWindow(win : CrossDomainWindowType) : ?HTMLElement {\n if (isSameDomain(win)) {\n return assertSameDomain(win).frameElement;\n }\n\n for (const frame of document.querySelectorAll('iframe')) {\n if (frame && frame.contentWindow && frame.contentWindow === win) {\n return frame;\n }\n }\n}\n\n\n\n// WEBPACK FOOTER //\n// ./src/utils.js","/* @flow */\n\nexport * from './utils';\nexport * from './types';\nexport * from './constants';\n\n\n\n// WEBPACK FOOTER //\n// ./src/index.js","/* @flow */\n\n// export something to force webpack to see this as an ES module\nexport const TYPES = true;\n\nexport type CrossDomainLocationType = {|\n\n|};\n\nexport type CrossDomainWindowType = {|\n location : string | CrossDomainLocationType,\n self : CrossDomainWindowType,\n closed : boolean,\n open : (string, string, string) => CrossDomainWindowType,\n close : () => void,\n focus : () => void,\n top : CrossDomainWindowType,\n frames : Array,\n opener ? : CrossDomainWindowType,\n parent : CrossDomainWindowType,\n length : number,\n postMessage : (string, string) => void\n|};\n\nexport type SameDomainWindowType = Object & {\n location : string | Object,\n self : CrossDomainWindowType,\n closed : boolean,\n open : (string, string, string) => CrossDomainWindowType,\n close : () => void,\n focus : () => void,\n XMLHttpRequest : typeof XMLHttpRequest,\n document : Document,\n navigator : {\n userAgent : string,\n mockUserAgent? : string\n }\n};\n\nexport type DomainMatcher = string | Array | $ReadOnlyArray | RegExp;\n\n\n\n// WEBPACK FOOTER //\n// ./src/types.js"],"sourceRoot":""} \ No newline at end of file diff --git a/dist/module/index.js.flow b/dist/module/index.js.flow deleted file mode 100644 index ef9b15f..0000000 --- a/dist/module/index.js.flow +++ /dev/null @@ -1,56 +0,0 @@ -// @flow - -import {isRegex, noop} from "./util"; -declare class Class0 extends HTMLElement<> { - - allowFullScreen: boolean; - contentDocument: Document; - contentWindow: any; - frameBorder: string; - height: string; - marginHeight: string; - marginWidth: string; - name: string; - sandbox: DOMTokenList; - scrolling: string; - src: string; - srcDoc: string; - width: string; -} -declare export function findChildFrameByName(win: any, name: string): void; -declare export function findFrameByName(win: any, name: string): void; -declare export function getActualDomain(win: any): string; -declare export function getAllChildFrames(win: any): []; -declare export function getAllFramesInWindow(win: any): Array; -declare export function getAncestor(win: any): void; -declare export function getAncestors(win: any): []; -declare export function getDistanceFromTop(win?: any): number; -declare export function getDomain(win: any): string; -declare export function getDomainFromUrl(url: string): string; -declare export function getFrameByName(win: any, name: string): void; -declare export function getFrames(win: any): []; -declare export function getNthParent(win: any, n?: number): any; -declare export function getNthParentFromTop(win: any, n?: number): any; -declare export function getOpener(win: any): void; -declare export function getParent(win: any): void; -declare export function getParents(win: any): []; -declare export function getTop(win: any): void; -declare export function getUserAgent(win: any): any; -declare export function isActuallySameDomain(win: any): boolean; -declare export function isAncestor(parent: any, child: any): boolean; -declare export function isAncestorParent(parent: any, child: any): boolean; -declare export function isBlankDomain(win: any): boolean; -declare export function isFrameWindowClosed(frame: Class0): boolean; -declare export function isFullpage(): boolean; -declare export function isIframe(): boolean; -declare export function isOpener(parent: any, child: any): boolean; -declare export function isParent(win: any, frame: any): boolean; -declare export function isPopup(): boolean; -declare export function isSameDomain(win: any): boolean; -declare export function isSameTopWindow(win1: any, win2: any): boolean | boolean | boolean | boolean | boolean | void; -declare export function isTop(win: any): boolean; -declare export function isWindow(obj: Object): boolean; -declare export function isWindowClosed(win: any, allowMock?: boolean): boolean; -declare export function linkFrameWindow(frame: Class0): void; -declare export function matchDomain(pattern: any, origin: any): boolean; -declare export function onCloseWindow(win: any, callback: Function, delay?: number, maxtime?: number): {cancel: () => void}; diff --git a/dist/module/util.js.flow b/dist/module/util.js.flow deleted file mode 100644 index dcc6f53..0000000 --- a/dist/module/util.js.flow +++ /dev/null @@ -1,5 +0,0 @@ -// @flow - -export function isRegex(item : any) { - return Object.prototype.toString.call(item) === '[object RegExp]'; -} diff --git a/dist/test.htm b/dist/test.htm deleted file mode 100644 index 902d92d..0000000 --- a/dist/test.htm +++ /dev/null @@ -1 +0,0 @@ - diff --git a/dist/module/constants.js b/lib/constants.js similarity index 100% rename from dist/module/constants.js rename to lib/constants.js diff --git a/lib/constants.js.flow b/lib/constants.js.flow new file mode 100644 index 0000000..daa8038 --- /dev/null +++ b/lib/constants.js.flow @@ -0,0 +1,14 @@ +/* @flow */ + +export const PROTOCOL = { + MOCK: ('mock:' : 'mock:'), + FILE: ('file:' : 'file:'), + ABOUT: ('about:' : 'about:') +}; + +export const WILDCARD = '*'; + +export const WINDOW_TYPE = { + IFRAME: ('iframe' : 'iframe'), + POPUP: ('popup' : 'popup') +}; diff --git a/dist/module/index.js b/lib/index.js similarity index 100% rename from dist/module/index.js rename to lib/index.js diff --git a/lib/index.js.flow b/lib/index.js.flow new file mode 100644 index 0000000..7065a14 --- /dev/null +++ b/lib/index.js.flow @@ -0,0 +1,5 @@ +/* @flow */ + +export * from './utils'; +export * from './types'; +export * from './constants'; diff --git a/dist/module/types.js b/lib/types.js similarity index 100% rename from dist/module/types.js rename to lib/types.js diff --git a/lib/types.js.flow b/lib/types.js.flow new file mode 100644 index 0000000..0275ed2 --- /dev/null +++ b/lib/types.js.flow @@ -0,0 +1,40 @@ +/* @flow */ + +// export something to force webpack to see this as an ES module +export const TYPES = true; + +export type CrossDomainLocationType = {| + +|}; + +export type CrossDomainWindowType = {| + location : string | CrossDomainLocationType, + self : CrossDomainWindowType, + closed : boolean, + open : (string, string, string) => CrossDomainWindowType, + close : () => void, + focus : () => void, + top : CrossDomainWindowType, + frames : $ReadOnlyArray, + opener ? : CrossDomainWindowType, + parent : CrossDomainWindowType, + length : number, + postMessage : (string, string) => void +|}; + +export type SameDomainWindowType = Object & {| + location : string | Object, + self : CrossDomainWindowType, + closed : boolean, + open : (string, string, string) => CrossDomainWindowType, + close : () => void, + focus : () => void, + XMLHttpRequest : typeof XMLHttpRequest, + document : Document, + navigator : {| + userAgent : string, + mockUserAgent? : string + |} +|}; + +export type DomainMatcher = string | $ReadOnlyArray | $ReadOnlyArray | RegExp; diff --git a/dist/module/util.js b/lib/util.js similarity index 100% rename from dist/module/util.js rename to lib/util.js diff --git a/lib/util.js.flow b/lib/util.js.flow new file mode 100644 index 0000000..20fb864 --- /dev/null +++ b/lib/util.js.flow @@ -0,0 +1,11 @@ +/* @flow */ + +export function isRegex(item : mixed) : boolean { + // $FlowFixMe method-unbinding + return Object.prototype.toString.call(item) === '[object RegExp]'; +} + +// eslint-disable-next-line no-unused-vars +export function noop(...args : $ReadOnlyArray) { + // pass +} diff --git a/dist/module/utils.js b/lib/utils.js similarity index 100% rename from dist/module/utils.js rename to lib/utils.js diff --git a/lib/utils.js.flow b/lib/utils.js.flow new file mode 100644 index 0000000..e9cb45e --- /dev/null +++ b/lib/utils.js.flow @@ -0,0 +1,1103 @@ +/* @flow */ +/* eslint max-lines: 0 */ + +import { isRegex, noop } from './util'; +import type { CrossDomainWindowType, SameDomainWindowType, DomainMatcher } from './types'; +import { PROTOCOL, WILDCARD } from './constants'; + +const IE_WIN_ACCESS_ERROR = 'Call was rejected by callee.\r\n'; + +export function getActualProtocol(win : SameDomainWindowType = window) : ?string { + return win.location.protocol; +} + +export function getProtocol(win : SameDomainWindowType = window) : ?string { + if (win.mockDomain) { + const protocol = win.mockDomain.split('//')[0]; + + if (protocol) { + return protocol; + } + } + + return getActualProtocol(win); +} + +export function isFileProtocol(win : SameDomainWindowType = window) : boolean { + return getProtocol(win) === PROTOCOL.FILE; +} + +export function isAboutProtocol(win : SameDomainWindowType = window) : boolean { + return getProtocol(win) === PROTOCOL.ABOUT; +} + +export function isMockProtocol(win : SameDomainWindowType = window) : boolean { + return getProtocol(win) === PROTOCOL.MOCK; +} + +export function getParent(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType { + + if (!win) { + return; + } + + try { + if (win.parent && win.parent !== win) { + return win.parent; + } + } catch (err) { + // pass + } +} + +export function getOpener(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType { + + if (!win) { + return; + } + + // Make sure we're not actually an iframe which has had window.open() called on us + if (getParent(win)) { + return; + } + + try { + return win.opener; + } catch (err) { + // pass + } +} + +export function canReadFromWindow(win : CrossDomainWindowType | SameDomainWindowType) : boolean { + try { + // $FlowFixMe + noop(win && win.location && win.location.href); + return true; + } catch (err) { + // pass + } + + return false; +} + +export function getActualDomain(win? : SameDomainWindowType = window) : string { + + const location = win.location; + + if (!location) { + throw new Error(`Can not read window location`); + } + + const protocol = getActualProtocol(win); + + if (!protocol) { + throw new Error(`Can not read window protocol`); + } + + if (protocol === PROTOCOL.FILE) { + return `${ PROTOCOL.FILE }//`; + } + + if (protocol === PROTOCOL.ABOUT) { + + const parent = getParent(win); + if (parent && canReadFromWindow(parent)) { + // $FlowFixMe + return getActualDomain(parent); + } + + return `${ PROTOCOL.ABOUT }//`; + } + + const host = location.host; + + if (!host) { + throw new Error(`Can not read window host`); + } + + return `${ protocol }//${ host }`; +} + +export function getDomain(win? : SameDomainWindowType = window) : string { + + const domain = getActualDomain(win); + + if (domain && win.mockDomain && win.mockDomain.indexOf(PROTOCOL.MOCK) === 0) { + return win.mockDomain; + } + + return domain; +} + +export function isBlankDomain(win : CrossDomainWindowType) : boolean { + try { + // $FlowFixMe + if (!win.location.href) { + return true; + } + + if (win.location.href === 'about:blank') { + return true; + } + } catch (err) { + // pass + } + + return false; +} + +export function isActuallySameDomain(win : CrossDomainWindowType) : boolean { + + try { + if (win === window) { + return true; + } + + } catch (err) { + // pass + } + + try { + const desc = Object.getOwnPropertyDescriptor(win, 'location'); + + if (desc && desc.enumerable === false) { + return false; + } + + } catch (err) { + // pass + } + + try { + // $FlowFixMe + if (isAboutProtocol(win) && canReadFromWindow(win)) { + return true; + } + } catch (err) { + // pass + } + + try { + // $FlowFixMe + if (isMockProtocol(win) && canReadFromWindow(win)) { + return true; + } + } catch (err) { + // pass + } + + try { + // $FlowFixMe + if (getActualDomain(win) === getActualDomain(window)) { + return true; + } + + } catch (err) { + // pass + } + + return false; +} + +export function isSameDomain(win : CrossDomainWindowType | SameDomainWindowType) : boolean { + + if (!isActuallySameDomain(win)) { + return false; + } + + try { + if (win === window) { + return true; + } + + // $FlowFixMe + if (isAboutProtocol(win) && canReadFromWindow(win)) { + return true; + } + + // $FlowFixMe + if (getDomain(window) === getDomain(win)) { + return true; + } + + } catch (err) { + // pass + } + + return false; +} + + +export function assertSameDomain(win : CrossDomainWindowType | SameDomainWindowType) : SameDomainWindowType { + if (!isSameDomain(win)) { + throw new Error(`Expected window to be same domain`); + } + + // $FlowFixMe + return win; +} + +export function getParents(win : CrossDomainWindowType) : $ReadOnlyArray { + + const result = []; + + try { + + while (win.parent !== win) { + result.push(win.parent); + win = win.parent; + } + + } catch (err) { + // pass + } + + return result; +} + +export function isAncestorParent(parent : CrossDomainWindowType, child : CrossDomainWindowType) : boolean { + + if (!parent || !child) { + return false; + } + + const childParent = getParent(child); + + if (childParent) { + return childParent === parent; + } + + if (getParents(child).indexOf(parent) !== -1) { + return true; + } + + return false; +} + +export function getFrames(win : CrossDomainWindowType) : $ReadOnlyArray { + + const result = []; + + let frames; + + try { + frames = win.frames; + } catch (err) { + frames = win; + } + + let len; + + try { + len = frames.length; + } catch (err) { + // pass + } + + if (len === 0) { + return result; + } + + if (len) { + for (let i = 0; i < len; i++) { + + let frame; + + try { + frame = frames[i]; + } catch (err) { + continue; + } + + result.push(frame); + } + + return result; + } + + for (let i = 0; i < 100; i++) { + let frame; + + try { + frame = frames[i]; + } catch (err) { + return result; + } + + if (!frame) { + return result; + } + + result.push(frame); + } + + return result; +} + + +export function getAllChildFrames(win : CrossDomainWindowType) : $ReadOnlyArray { + + const result = []; + + for (const frame of getFrames(win)) { + result.push(frame); + + for (const childFrame of getAllChildFrames(frame)) { + result.push(childFrame); + } + } + + return result; +} + +export function getTop(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType { + + try { + if (win.top) { + return win.top; + } + } catch (err) { + // pass + } + + if (getParent(win) === win) { + return win; + } + + try { + if (isAncestorParent(window, win) && window.top) { + return window.top; + } + } catch (err) { + // pass + } + + try { + if (isAncestorParent(win, window) && window.top) { + return window.top; + } + } catch (err) { + // pass + } + + for (const frame of getAllChildFrames(win)) { + try { + if (frame.top) { + return frame.top; + } + } catch (err) { + // pass + } + + if (getParent(frame) === frame) { + return frame; + } + } +} + +export function getNextOpener(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType { + return getOpener(getTop(win) || win); +} + +export function getUltimateTop(win? : CrossDomainWindowType = window) : CrossDomainWindowType { + const opener = getNextOpener(win); + + if (opener) { + return getUltimateTop(opener); + } + + return top; +} + +export function getAllFramesInWindow(win : CrossDomainWindowType) : $ReadOnlyArray { + const top = getTop(win); + + if (!top) { + throw new Error(`Can not determine top window`); + } + + let result = [ ...getAllChildFrames(top), top ]; + + // Win may be in shadow dom + if (result.indexOf(win) === -1) { + result = [ ...result, win, ...getAllChildFrames(win) ]; + } + + return result; +} + +export function getAllWindows(win? : CrossDomainWindowType = window) : $ReadOnlyArray { + const frames = getAllFramesInWindow(win); + const opener = getNextOpener(win); + + if (opener) { + return [ ...getAllWindows(opener), ...frames ]; + } else { + return frames; + } +} + +export function isTop(win : CrossDomainWindowType) : boolean { + return win === getTop(win); +} + +export function isFrameWindowClosed(frame : HTMLIFrameElement) : boolean { + + if (!frame.contentWindow) { + return true; + } + + if (!frame.parentNode) { + return true; + } + + const doc = frame.ownerDocument; + + if (doc && doc.documentElement && !doc.documentElement.contains(frame)) { + let parent = frame; + + while (parent.parentNode && parent.parentNode !== parent) { + parent = parent.parentNode; + } + + // $FlowFixMe + if (!parent.host || !doc.documentElement.contains(parent.host)) { + return true; + } + } + + return false; +} + +function safeIndexOf(collection : $ReadOnlyArray, item : T) : number { + for (let i = 0; i < collection.length; i++) { + + try { + if (collection[i] === item) { + return i; + } + } catch (err) { + // pass + } + } + + return -1; +} + +const iframeWindows = []; +const iframeFrames = []; + +export function isWindowClosed(win : CrossDomainWindowType, allowMock : boolean = true) : boolean { + + try { + if (win === window) { + return false; + } + } catch (err) { + return true; + } + + try { + if (!win) { + return true; + } + + } catch (err) { + return true; + } + + try { + if (win.closed) { + return true; + } + + } catch (err) { + + // I love you so much IE + + if (err && err.message === IE_WIN_ACCESS_ERROR) { + return false; + } + + return true; + } + + + if (allowMock && isSameDomain(win)) { + try { + // $FlowFixMe + if (win.mockclosed) { + return true; + } + } catch (err) { + // pass + } + } + + // Mobile safari + + try { + if (!win.parent || !win.top) { + return true; + } + } catch (err) { + // pass + } + + // Yes, this actually happens in IE. win === win errors out when the window + // is from an iframe, and the iframe was removed from the page. + + try { + noop(win === win); // eslint-disable-line no-self-compare + } catch (err) { + return true; + } + + // IE orphaned frame + + const iframeIndex = safeIndexOf(iframeWindows, win); + + if (iframeIndex !== -1) { + const frame = iframeFrames[iframeIndex]; + + if (frame && isFrameWindowClosed(frame)) { + return true; + } + } + + return false; +} + +function cleanIframes() { + for (let i = 0; i < iframeWindows.length; i++) { + let closed = false; + + try { + closed = iframeWindows[i].closed; + } catch (err) { + // pass + } + + if (closed) { + iframeFrames.splice(i, 1); + iframeWindows.splice(i, 1); + } + } +} + +export function linkFrameWindow(frame : HTMLIFrameElement) { + + cleanIframes(); + + if (frame && frame.contentWindow) { + try { + iframeWindows.push(frame.contentWindow); + iframeFrames.push(frame); + } catch (err) { + // pass + } + } +} + +export function getUserAgent(win : ?SameDomainWindowType) : string { + win = win || window; + return win.navigator.mockUserAgent || win.navigator.userAgent; +} + + +export function getFrameByName(win : CrossDomainWindowType, name : string) : ?CrossDomainWindowType { + + const winFrames = getFrames(win); + + for (const childFrame of winFrames) { + try { + // $FlowFixMe + if (isSameDomain(childFrame) && childFrame.name === name && winFrames.indexOf(childFrame) !== -1) { + return childFrame; + } + } catch (err) { + // pass + } + } + + try { + // $FlowFixMe + if (winFrames.indexOf(win.frames[name]) !== -1) { + // $FlowFixMe + return win.frames[name]; + } + } catch (err) { + // pass + } + + try { + if (winFrames.indexOf(win[name]) !== -1) { + return win[name]; + } + } catch (err) { + // pass + } +} + +export function findChildFrameByName(win : CrossDomainWindowType, name : string) : ?CrossDomainWindowType { + + const frame = getFrameByName(win, name); + + if (frame) { + return frame; + } + + for (const childFrame of getFrames(win)) { + const namedFrame = findChildFrameByName(childFrame, name); + + if (namedFrame) { + return namedFrame; + } + } +} + +export function findFrameByName(win : CrossDomainWindowType, name : string) : ?CrossDomainWindowType { + const frame = getFrameByName(win, name); + + if (frame) { + return frame; + } + + const top = getTop(win) || win; + + return findChildFrameByName(top, name); +} + +export function isParent(win : CrossDomainWindowType, frame : CrossDomainWindowType) : boolean { + + const frameParent = getParent(frame); + + if (frameParent) { + return frameParent === win; + } + + for (const childFrame of getFrames(win)) { + if (childFrame === frame) { + return true; + } + } + + return false; +} + +export function isOpener(parent : CrossDomainWindowType, child : CrossDomainWindowType) : boolean { + + return parent === getOpener(child); +} + +export function getAncestor(win? : CrossDomainWindowType = window) : ?CrossDomainWindowType { + win = win || window; + + const opener = getOpener(win); + + if (opener) { + return opener; + } + + const parent = getParent(win); + + if (parent) { + return parent; + } +} + +export function getAncestors(win : CrossDomainWindowType) : $ReadOnlyArray { + + const results = []; + + let ancestor = win; + + while (ancestor) { + ancestor = getAncestor(ancestor); + if (ancestor) { + results.push(ancestor); + } + } + + return results; +} + + +export function isAncestor(parent : CrossDomainWindowType, child : CrossDomainWindowType) : boolean { + + const actualParent = getAncestor(child); + + if (actualParent) { + if (actualParent === parent) { + return true; + } + + return false; + } + + if (child === parent) { + return false; + } + + if (getTop(child) === child) { + return false; + } + + for (const frame of getFrames(parent)) { + if (frame === child) { + return true; + } + } + + return false; +} + +export function isPopup(win? : CrossDomainWindowType = window) : boolean { + return Boolean(getOpener(win)); +} + +export function isIframe(win? : CrossDomainWindowType = window) : boolean { + return Boolean(getParent(win)); +} + +export function isFullpage(win? : CrossDomainWindowType = window) : boolean { + return Boolean(!isIframe(win) && !isPopup(win)); +} + +function anyMatch(collection1, collection2) : boolean { + + for (const item1 of collection1) { + for (const item2 of collection2) { + if (item1 === item2) { + return true; + } + } + } + + return false; +} + +export function getDistanceFromTop(win : CrossDomainWindowType = window) : number { + let distance = 0; + let parent = win; + + while (parent) { + parent = getParent(parent); + if (parent) { + distance += 1; + } + } + + return distance; +} + +export function getNthParent(win : CrossDomainWindowType, n : number = 1) : ?CrossDomainWindowType { + let parent = win; + + for (let i = 0; i < n; i++) { + if (!parent) { + return; + } + + parent = getParent(parent); + } + + return parent; +} + +export function getNthParentFromTop(win : CrossDomainWindowType, n : number = 1) : ?CrossDomainWindowType { + return getNthParent(win, getDistanceFromTop(win) - n); +} + +export function isSameTopWindow(win1 : CrossDomainWindowType, win2 : CrossDomainWindowType) : boolean { + + const top1 = getTop(win1) || win1; + const top2 = getTop(win2) || win2; + + try { + if (top1 && top2) { + if (top1 === top2) { + return true; + } + + return false; + } + } catch (err) { + // pass + } + + const allFrames1 = getAllFramesInWindow(win1); + const allFrames2 = getAllFramesInWindow(win2); + + if (anyMatch(allFrames1, allFrames2)) { + return true; + } + + const opener1 = getOpener(top1); + const opener2 = getOpener(top2); + + if (opener1 && anyMatch(getAllFramesInWindow(opener1), allFrames2)) { + return false; + } + + if (opener2 && anyMatch(getAllFramesInWindow(opener2), allFrames1)) { + return false; + } + + return false; +} + +export function matchDomain(pattern : DomainMatcher, origin : DomainMatcher) : boolean { + + if (typeof pattern === 'string') { + + if (typeof origin === 'string') { + return pattern === WILDCARD || origin === pattern; + } + + if (isRegex(origin)) { + return false; + } + + if (Array.isArray(origin)) { + return false; + } + } + + if (isRegex(pattern)) { + + if (isRegex(origin)) { + return pattern.toString() === origin.toString(); + } + + if (Array.isArray(origin)) { + return false; + } + + // $FlowFixMe + return Boolean(origin.match(pattern)); + } + + if (Array.isArray(pattern)) { + + if (Array.isArray(origin)) { + return JSON.stringify(pattern) === JSON.stringify(origin); + } + + if (isRegex(origin)) { + return false; + } + + return pattern.some(subpattern => matchDomain(subpattern, origin)); + } + + return false; +} + +export function stringifyDomainPattern(pattern : DomainMatcher) : string { + if (Array.isArray(pattern)) { + return `(${ pattern.join(' | ') })`; + } else if (isRegex(pattern)) { + return `RegExp(${ pattern.toString() })`; + } else { + return pattern.toString(); + } +} + +export function getDomainFromUrl(url : string) : string { + + let domain; + + if (url.match(/^(https?|mock|file):\/\//)) { + domain = url; + } else { + return getDomain(); + } + + domain = domain.split('/').slice(0, 3).join('/'); + + return domain; +} + +export function onCloseWindow(win : CrossDomainWindowType, callback : Function, delay : number = 1000, maxtime : number = Infinity) : {| cancel : () => void |} { + + let timeout; + + const check = () => { + + if (isWindowClosed(win)) { + + if (timeout) { + clearTimeout(timeout); + } + + return callback(); + } + + if (maxtime <= 0) { + clearTimeout(timeout); + } else { + maxtime -= delay; + timeout = setTimeout(check, delay); + } + }; + + check(); + + return { + cancel() { + if (timeout) { + clearTimeout(timeout); + } + } + }; +} + +// eslint-disable-next-line complexity +export function isWindow(obj : Object) : boolean { + + try { + if (obj === window) { + return true; + } + } catch (err) { + if (err && err.message === IE_WIN_ACCESS_ERROR) { + return true; + } + } + + try { + // $FlowFixMe method-unbinding + if (Object.prototype.toString.call(obj) === '[object Window]') { + return true; + } + } catch (err) { + if (err && err.message === IE_WIN_ACCESS_ERROR) { + return true; + } + } + + try { + if (window.Window && obj instanceof window.Window) { + return true; + } + } catch (err) { + if (err && err.message === IE_WIN_ACCESS_ERROR) { + return true; + } + } + + try { + if (obj && obj.self === obj) { + return true; + } + } catch (err) { + if (err && err.message === IE_WIN_ACCESS_ERROR) { + return true; + } + } + + try { + if (obj && obj.parent === obj) { + return true; + } + } catch (err) { + if (err && err.message === IE_WIN_ACCESS_ERROR) { + return true; + } + } + + try { + if (obj && obj.top === obj) { + return true; + } + } catch (err) { + if (err && err.message === IE_WIN_ACCESS_ERROR) { + return true; + } + } + + try { + if (noop(obj === obj) === '__unlikely_value__') { // eslint-disable-line no-self-compare + return false; + } + + } catch (err) { + return true; + } + + try { + if (obj && obj.__cross_domain_utils_window_check__ === '__unlikely_value__') { + return false; + } + + } catch (err) { + return true; + } + + try { + if ('postMessage' in obj && 'self' in obj && 'location' in obj) { + return true; + } + } catch (err) { + // pass + } + + return false; +} + +export function isBrowser() : boolean { + return (typeof window !== 'undefined' && typeof window.location !== 'undefined'); +} + +export function isCurrentDomain(domain : string) : boolean { + if (!isBrowser()) { + return false; + } + + return (getDomain() === domain); +} + +export function isMockDomain(domain : string) : boolean { + return domain.indexOf(PROTOCOL.MOCK) === 0; +} + +export function normalizeMockUrl(url : string) : string { + if (!isMockDomain(getDomainFromUrl(url))) { + return url; + } + + if (!__TEST__) { + throw new Error(`Mock urls not supported out of test mode`); + } + + return url.replace(/^mock:\/\/[^/]+/, getActualDomain(window)); +} + +export function getFrameForWindow(win : CrossDomainWindowType) : ?HTMLElement { + if (isSameDomain(win)) { + return assertSameDomain(win).frameElement; + } + + for (const frame of document.querySelectorAll('iframe')) { + if (frame && frame.contentWindow && frame.contentWindow === win) { + return frame; + } + } +} + +export function closeWindow(win : CrossDomainWindowType) { + if (isIframe(win)) { + const frame = getFrameForWindow(win); + if (frame && frame.parentElement) { + frame.parentElement.removeChild(frame); + return; + } + } + + try { + win.close(); + } catch (err) { + // pass + } +} diff --git a/package.json b/package.json index 5830e58..f7aff4c 100644 --- a/package.json +++ b/package.json @@ -3,17 +3,18 @@ "version": "3.0.0", "description": "Javascript module template.", "main": "dist/cross-domain-utils.js", - "module": "dist/module/index.js", + "module": "lib/index.js", "scripts": { - "build": "npm run babel && npm run webpack", + "build": "npm run babel && npm run webpack && npm run gen-flow-files", "webpack": "cross-env NODE_ENV=production babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/webpack --progress --output-path dist", - "babel": "cross-env NODE_ENV=production babel src/ --out-dir dist/module", + "babel": "cross-env NODE_ENV=production babel src/ --out-dir lib/", "karma": "cross-env NODE_ENV=test babel-node --plugins=transform-es2015-modules-commonjs ./node_modules/.bin/karma start", "test": "npm run lint && npm run flow-typed && npm run flow && npm run karma", "lint": "eslint src/ test/", "flow": "flow", "flow-typed": "rm -rf ./flow-typed && flow-typed install", - "clean": "rimraf dist coverage", + "gen-flow-files": "gen-flow-files src --out-dir lib", + "clean": "rimraf dist coverage lib", "reinstall": "rimraf flow-typed && rimraf node_modules && npm install && flow-typed install", "prerelease": "npm run clean && npm run test && npm run build", "release": "standard-version", @@ -33,7 +34,8 @@ "license": "Apache-2.0", "files": [ "src/", - "dist/" + "dist/", + "lib/" ], "readmeFilename": "README.md", "devDependencies": { @@ -41,6 +43,7 @@ "@commitlint/config-conventional": "^16.2.1", "chai": "^4.2.0", "flow-bin": "0.155.0", + "gen-flow-files": "^0.5.0", "grumbler-scripts": "^3", "husky": "^7.0.4", "mocha": "^4",