Skip to content

Commit 34cd6d6

Browse files
committed
initial
1 parent 63cc17d commit 34cd6d6

File tree

36 files changed

+835
-485
lines changed

36 files changed

+835
-485
lines changed

components/dashboard/src/service/service.tsx

+15-14
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ export function getGitpodService(): GitpodService {
5959
let ideFrontendService: IDEFrontendService | undefined;
6060
export function getIDEFrontendService(workspaceID: string, sessionId: string, service: GitpodService) {
6161
if (!ideFrontendService) {
62-
ideFrontendService = new IDEFrontendService(workspaceID, sessionId, service, window.parent);
62+
const parentOrigin = new URLSearchParams(window.location.search).get("parentOrigin") || undefined;
63+
ideFrontendService = new IDEFrontendService(workspaceID, sessionId, service, window.parent, parentOrigin);
6364
}
6465
return ideFrontendService;
6566
}
6667

6768
export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
6869
private instanceID: string | undefined;
69-
private ideUrl: URL | undefined;
7070
private user: User | undefined;
7171

7272
private latestStatus?: IDEFrontendDashboardService.Status;
@@ -75,14 +75,15 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
7575
readonly onSetState = this.onDidChangeEmitter.event;
7676

7777
constructor(
78-
private workspaceID: string,
79-
private sessionId: string,
80-
private service: GitpodService,
81-
private clientWindow: Window,
78+
private readonly workspaceID: string,
79+
private readonly sessionId: string,
80+
private readonly service: GitpodService,
81+
private readonly clientWindow: Window,
82+
private parentOrigin: string | undefined,
8283
) {
8384
this.processServerInfo();
8485
window.addEventListener("message", (event: MessageEvent) => {
85-
if (event.origin !== this.ideUrl?.origin) {
86+
if (event.origin !== this.parentOrigin) {
8687
return;
8788
}
8889

@@ -119,9 +120,9 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
119120

120121
const listener = await this.service.listenToInstance(this.workspaceID);
121122
listener.onDidChange(() => {
122-
this.ideUrl = listener.info.latestInstance?.ideUrl
123-
? new URL(listener.info.latestInstance?.ideUrl)
124-
: undefined;
123+
if (!this.parentOrigin && listener.info.latestInstance?.ideUrl) {
124+
this.parentOrigin = new URL(listener.info.latestInstance?.ideUrl).origin;
125+
}
125126
const status = this.getWorkspaceStatus(listener.info);
126127
this.latestStatus = status;
127128
this.sendStatusUpdate(this.latestStatus);
@@ -174,25 +175,25 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
174175
}
175176

176177
sendStatusUpdate(status: IDEFrontendDashboardService.Status): void {
177-
if (!this.ideUrl) {
178+
if (!this.parentOrigin) {
178179
return;
179180
}
180181
this.clientWindow.postMessage(
181182
{
182183
type: "ide-status-update",
183184
status,
184185
} as IDEFrontendDashboardService.StatusUpdateEventData,
185-
this.ideUrl.origin,
186+
this.parentOrigin,
186187
);
187188
}
188189

189190
relocate(url: string): void {
190-
if (!this.ideUrl) {
191+
if (!this.parentOrigin) {
191192
return;
192193
}
193194
this.clientWindow.postMessage(
194195
{ type: "ide-relocate", url } as IDEFrontendDashboardService.RelocateEventData,
195-
this.ideUrl.origin,
196+
this.parentOrigin,
196197
);
197198
}
198199
}

0 commit comments

Comments
 (0)