Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web: On pages with restrictive CSP show open in new tab option for SWF #17152

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 38 additions & 26 deletions web/packages/core/src/ruffle-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,14 @@ export class RufflePlayer extends HTMLElement {
) {
// Firefox: Don't display the panic screen if the user leaves the page while something is still loading
return;
} else if (error instanceof LoadRuffleWasmError) {
const openInNewTab = this.loadedConfig?.openInNewTab;
const swfUrl = this.loadedConfig && "url" in this.loadedConfig ? new URL(this.loadedConfig.url, document.baseURI) : undefined;
if (openInNewTab && swfUrl) {
// If it is possible to open the SWF in a new tab offer that option if the WASM failed to load
this.addOpenInNewTabMessage(openInNewTab, swfUrl);
return;
}
}

const errorArray: Array<string | null> & {
Expand Down Expand Up @@ -2017,39 +2025,43 @@ export class RufflePlayer extends HTMLElement {
this.destroy();
}

private addOpenInNewTabMessage(openInNewTab: (swf: URL) => void, swfUrl: URL) {
const url = new URL(swfUrl);
if (this.loadedConfig?.parameters) {
const parameters = sanitizeParameters(
this.loadedConfig?.parameters,
);
Object.entries(parameters).forEach(([key, value]) => {
url.searchParams.set(key, value);
});
}
this.hideSplashScreen();

const div = document.createElement("div");
div.id = "message-overlay";
const innerDiv = document.createElement("div");
innerDiv.className = "message";
innerDiv.appendChild(textAsParagraphs("message-cant-embed"));

const buttonDiv = document.createElement("div");
const link = document.createElement("a");
link.innerText = text("open-in-new-tab");
link.onclick = () => openInNewTab(url);
buttonDiv.appendChild(link);

innerDiv.appendChild(buttonDiv);
div.appendChild(innerDiv);
this.container.prepend(div);
}

protected displayRootMovieDownloadFailedMessage(invalidSwf: boolean): void {
const openInNewTab = this.loadedConfig?.openInNewTab;
if (
openInNewTab &&
this.swfUrl &&
window.location.origin !== this.swfUrl.origin
) {
const url = new URL(this.swfUrl);
if (this.loadedConfig?.parameters) {
const parameters = sanitizeParameters(
this.loadedConfig?.parameters,
);
Object.entries(parameters).forEach(([key, value]) => {
url.searchParams.set(key, value);
});
}
this.hideSplashScreen();

const div = document.createElement("div");
div.id = "message-overlay";
const innerDiv = document.createElement("div");
innerDiv.className = "message";
innerDiv.appendChild(textAsParagraphs("message-cant-embed"));

const buttonDiv = document.createElement("div");
const link = document.createElement("a");
link.innerText = text("open-in-new-tab");
link.onclick = () => openInNewTab(url);
buttonDiv.appendChild(link);

innerDiv.appendChild(buttonDiv);
div.appendChild(innerDiv);
this.container.prepend(div);
this.addOpenInNewTabMessage(openInNewTab, this.swfUrl);
} else {
const error = invalidSwf
? new InvalidSwfError(this.swfUrl)
Expand Down