src/vs/base/browser/iframe.ts/getParentWindowIfSameOrigin
function getParentWindowIfSameOrigin(w: Window): Window | null {
	if (!w.parent || w.parent === w) {
		return null;
	}

	// Cannot really tell if we have access to the parent window unless we try to access something in it
	try {
		let location = w.location;
		let parentLocation = w.parent.location;
		if (location.origin !== 'null' && parentLocation.origin !== 'null') {
			if (location.protocol !== parentLocation.protocol || location.hostname !== parentLocation.hostname || location.port !== parentLocation.port) {
				hasDifferentOriginAncestorFlag = true;
				return null;
			}
		}
	} catch (e) {
		hasDifferentOriginAncestorFlag = true;
		return null;
	}

	return w.parent;
}