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

Added referrer policy support to GUI Image to control xhr request header #12664

Merged
merged 5 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions packages/dev/core/src/Engines/ICanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export interface IImage {
* thereby enabling the configuration of the CORS requests for the element's fetched data.
*/
crossOrigin: string | null;

/**
* provides support for referrer policy on xhr load request,
* it is used to control the request header.
*/
referrerPolicy: string;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions packages/dev/core/src/Misc/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ export class Tools {
SetCorsBehavior(url, element);
}

/**
* Sets the referrerPolicy behavior on a dom element.
* @param referrerPolicy define the referrer policy to use
* @param element define the dom element where to configure the referrer policy
* @param element.referrerPolicy
*/
public static SetReferrerPolicyBehavior(referrerPolicy: Nullable<ReferrerPolicy>, element: { referrerPolicy: string | null }): void {
element.referrerPolicy = referrerPolicy;
}

// External files

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/dev/gui/src/2D/controls/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ export class Image extends Control {
*/
public onSVGAttributesComputedObservable = new Observable<Image>();

/**
* Gets or sets the referrer policy to apply on the img element load request.
* You should set referrerPolicy before set the source of the image if you want to ensure the header will be present on the xhr loading request
*/
public referrerPolicy: Nullable<ReferrerPolicy>;

/**
* Gets a boolean indicating that the content is loaded
*/
Expand Down Expand Up @@ -527,6 +533,7 @@ export class Image extends Control {
};
if (value) {
Tools.SetCorsBehavior(value, this._domImage);
Tools.SetReferrerPolicyBehavior(this.referrerPolicy, this._domImage);
this._domImage.src = value;
}
}
Expand Down