mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 23:16:56 +00:00
Fix telemetry from child windows of Data Explorer (#633)
* Fix telemetry from child windows of Data Explorer * Address feedback
This commit is contained in:
parent
3ab6b2a05d
commit
37e0f50ef2
@ -48,32 +48,18 @@ export function sendCachedDataMessage<TResponseDataModel>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function sendMessage(data: any): void {
|
export function sendMessage(data: any): void {
|
||||||
if (canSendMessage()) {
|
_sendMessage({
|
||||||
// We try to find data explorer window first, then fallback to current window
|
|
||||||
const portalChildWindow = getDataExplorerWindow(window) || window;
|
|
||||||
portalChildWindow.parent.postMessage(
|
|
||||||
{
|
|
||||||
signature: "pcIframe",
|
signature: "pcIframe",
|
||||||
data: data,
|
data: data,
|
||||||
},
|
});
|
||||||
portalChildWindow.document.referrer || "*"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendReadyMessage(): void {
|
export function sendReadyMessage(): void {
|
||||||
if (canSendMessage()) {
|
_sendMessage({
|
||||||
// We try to find data explorer window first, then fallback to current window
|
|
||||||
const portalChildWindow = getDataExplorerWindow(window) || window;
|
|
||||||
portalChildWindow.parent.postMessage(
|
|
||||||
{
|
|
||||||
signature: "pcIframe",
|
signature: "pcIframe",
|
||||||
kind: "ready",
|
kind: "ready",
|
||||||
data: "ready",
|
data: "ready",
|
||||||
},
|
});
|
||||||
portalChildWindow.document.referrer || "*"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function canSendMessage(): boolean {
|
export function canSendMessage(): boolean {
|
||||||
@ -89,3 +75,17 @@ export function runGarbageCollector() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const _sendMessage = (message: any): void => {
|
||||||
|
if (canSendMessage()) {
|
||||||
|
// Portal window can receive messages from only child windows
|
||||||
|
const portalChildWindow = getDataExplorerWindow(window) || window;
|
||||||
|
if (portalChildWindow === window) {
|
||||||
|
// Current window is a child of portal, send message to portal window
|
||||||
|
portalChildWindow.parent.postMessage(message, portalChildWindow.document.referrer || "*");
|
||||||
|
} else {
|
||||||
|
// Current window is not a child of portal, send message to the child window instead (which is data explorer)
|
||||||
|
portalChildWindow.postMessage(message, portalChildWindow.location.origin || "*");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
@ -3,7 +3,7 @@ import { applyExplorerBindings } from "../applyExplorerBindings";
|
|||||||
import { AuthType } from "../AuthType";
|
import { AuthType } from "../AuthType";
|
||||||
import { AccountKind, DefaultAccountExperience } from "../Common/Constants";
|
import { AccountKind, DefaultAccountExperience } from "../Common/Constants";
|
||||||
import { normalizeArmEndpoint } from "../Common/EnvironmentUtility";
|
import { normalizeArmEndpoint } from "../Common/EnvironmentUtility";
|
||||||
import { sendReadyMessage } from "../Common/MessageHandler";
|
import { sendMessage, sendReadyMessage } from "../Common/MessageHandler";
|
||||||
import { configContext, Platform, updateConfigContext } from "../ConfigContext";
|
import { configContext, Platform, updateConfigContext } from "../ConfigContext";
|
||||||
import { ActionType, DataExplorerAction } from "../Contracts/ActionContracts";
|
import { ActionType, DataExplorerAction } from "../Contracts/ActionContracts";
|
||||||
import { MessageTypes } from "../Contracts/ExplorerContracts";
|
import { MessageTypes } from "../Contracts/ExplorerContracts";
|
||||||
@ -266,6 +266,8 @@ async function configurePortal(explorerParams: ExplorerParams): Promise<Explorer
|
|||||||
if (openAction) {
|
if (openAction) {
|
||||||
handleOpenAction(openAction, explorer.databases(), explorer);
|
handleOpenAction(openAction, explorer.databases(), explorer);
|
||||||
}
|
}
|
||||||
|
} else if (shouldForwardMessage(message, event.origin)) {
|
||||||
|
sendMessage(message);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
@ -275,6 +277,11 @@ async function configurePortal(explorerParams: ExplorerParams): Promise<Explorer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldForwardMessage(message: PortalMessage, messageOrigin: string) {
|
||||||
|
// Only allow forwarding messages from the same origin
|
||||||
|
return messageOrigin === window.document.location.origin && message.type === MessageTypes.TelemetryInfo;
|
||||||
|
}
|
||||||
|
|
||||||
function shouldProcessMessage(event: MessageEvent): boolean {
|
function shouldProcessMessage(event: MessageEvent): boolean {
|
||||||
if (typeof event.data !== "object") {
|
if (typeof event.data !== "object") {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user