bitwarden-estensione-browser/libs/common/src/models/view/loginUriView.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 lines
2.9 KiB
TypeScript
Raw Normal View History

import { UriMatchType } from "../../enums/uriMatchType";
2022-02-22 15:39:11 +01:00
import { Utils } from "../../misc/utils";
import { LoginUri } from "../domain/loginUri";
2022-02-22 15:39:11 +01:00
import { View } from "./view";
2018-04-19 20:40:42 +02:00
2018-11-02 13:39:09 +01:00
const CanLaunchWhitelist = [
"https://",
"http://",
"ssh://",
"ftp://",
"sftp://",
"irc://",
2019-02-14 15:07:20 +01:00
"vnc://",
// https://docs.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/remote-desktop-uri
"rdp://", // Legacy RDP URI scheme
"ms-rd:", // Preferred RDP URI scheme
2018-11-02 13:39:09 +01:00
"chrome://",
2019-04-17 05:32:02 +02:00
"iosapp://",
"androidapp://",
2018-11-02 13:39:09 +01:00
];
export class LoginUriView implements View {
match: UriMatchType = null;
2021-12-16 13:36:21 +01:00
2019-01-25 15:30:21 +01:00
private _uri: string = null;
private _domain: string = null;
private _hostname: string = null;
private _host: string = null;
2019-01-25 15:30:21 +01:00
private _canLaunch: boolean = null;
2021-12-16 13:36:21 +01:00
constructor(u?: LoginUri) {
if (!u) {
return;
}
this.match = u.match;
2021-12-16 13:36:21 +01:00
}
get uri(): string {
return this._uri;
}
set uri(value: string) {
this._uri = value;
this._domain = null;
2018-11-02 18:03:00 +01:00
this._canLaunch = null;
2021-12-16 13:36:21 +01:00
}
get domain(): string {
if (this._domain == null && this.uri != null) {
2018-10-14 04:21:54 +02:00
this._domain = Utils.getDomain(this.uri);
if (this._domain === "") {
this._domain = null;
2021-12-16 13:36:21 +01:00
}
}
2018-10-14 04:21:54 +02:00
return this._domain;
}
get hostname(): string {
if (this.match === UriMatchType.RegularExpression) {
return null;
}
2018-04-19 20:40:42 +02:00
if (this._hostname == null && this.uri != null) {
this._hostname = Utils.getHostname(this.uri);
2018-04-19 20:40:42 +02:00
if (this._hostname === "") {
this._hostname = null;
}
}
return this._hostname;
}
2018-04-19 20:40:42 +02:00
get host(): string {
if (this.match === UriMatchType.RegularExpression) {
return null;
}
if (this._host == null && this.uri != null) {
this._host = Utils.getHost(this.uri);
if (this._host === "") {
this._host = null;
2021-12-16 13:36:21 +01:00
}
}
return this._host;
2021-12-16 13:36:21 +01:00
}
get hostnameOrUri(): string {
return this.hostname != null ? this.hostname : this.uri;
2021-12-16 13:36:21 +01:00
}
get hostOrUri(): string {
return this.host != null ? this.host : this.uri;
2021-12-16 13:36:21 +01:00
}
get isWebsite(): boolean {
2021-12-16 13:36:21 +01:00
return (
this.uri != null &&
(this.uri.indexOf("http://") === 0 ||
this.uri.indexOf("https://") === 0 ||
(this.uri.indexOf("://") < 0 && Utils.tldEndingRegex.test(this.uri)))
);
2021-12-16 13:36:21 +01:00
}
get canLaunch(): boolean {
2018-11-02 18:03:00 +01:00
if (this._canLaunch != null) {
return this._canLaunch;
}
2019-02-08 14:03:12 +01:00
if (this.uri != null && this.match !== UriMatchType.RegularExpression) {
const uri = this.launchUri;
2018-11-02 18:03:00 +01:00
for (let i = 0; i < CanLaunchWhitelist.length; i++) {
if (uri.indexOf(CanLaunchWhitelist[i]) === 0) {
2018-11-02 18:03:00 +01:00
this._canLaunch = true;
return this._canLaunch;
2018-11-02 13:39:09 +01:00
}
}
}
2018-11-02 18:03:00 +01:00
this._canLaunch = false;
return this._canLaunch;
2021-12-16 13:36:21 +01:00
}
get launchUri(): string {
return this.uri.indexOf("://") < 0 && Utils.tldEndingRegex.test(this.uri)
? "http://" + this.uri
: this.uri;
2021-12-16 13:36:21 +01:00
}
}