Fix telemetry from child windows of Data Explorer (#633)

* Fix telemetry from child windows of Data Explorer

* Address feedback
This commit is contained in:
Tanuj Mittal
2021-04-09 00:22:41 -07:00
committed by GitHub
parent 3ab6b2a05d
commit 37e0f50ef2
2 changed files with 31 additions and 24 deletions

View File

@@ -3,7 +3,7 @@ import { applyExplorerBindings } from "../applyExplorerBindings";
import { AuthType } from "../AuthType";
import { AccountKind, DefaultAccountExperience } from "../Common/Constants";
import { normalizeArmEndpoint } from "../Common/EnvironmentUtility";
import { sendReadyMessage } from "../Common/MessageHandler";
import { sendMessage, sendReadyMessage } from "../Common/MessageHandler";
import { configContext, Platform, updateConfigContext } from "../ConfigContext";
import { ActionType, DataExplorerAction } from "../Contracts/ActionContracts";
import { MessageTypes } from "../Contracts/ExplorerContracts";
@@ -266,6 +266,8 @@ async function configurePortal(explorerParams: ExplorerParams): Promise<Explorer
if (openAction) {
handleOpenAction(openAction, explorer.databases(), explorer);
}
} else if (shouldForwardMessage(message, event.origin)) {
sendMessage(message);
}
},
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 {
if (typeof event.data !== "object") {
return false;