ntListener( "ipprotection-status-card:user-toggled-on", this.#statusCardListener ); this.removeEventListener( "ipprotection-status-card:user-toggled-off", this.#statusCardListener ); this.removeEventListener( "ipprotection-site-settings-control:click", this.#statusCardListener ); this.removeEventListener( "ipprotection-message-bar:user-dismissed", this.#messageBarListener ); } get canEnableConnection() { return this.state && this.state.isProtectionEnabled && !this.state.error; } get #hasErrors() { return !this.state || this.state.error !== ""; } handleClickSupportLink(event) { const win = event.target.ownerGlobal; if (event.target === this.supportLinkEl) { event.preventDefault(); win.openWebLinkIn(LINKS.PRODUCT_URL, "tab"); this.dispatchEvent( new CustomEvent("IPProtection:Close", { bubbles: true }) ); } } handleUpgrade(event) { const win = event.target.ownerGlobal; win.openWebLinkIn(LINKS.PRODUCT_URL + "#pricing", "tab"); // Close the panel this.dispatchEvent( new CustomEvent("IPProtection:ClickUpgrade", { bubbles: true }) ); Glean.ipprotection.clickUpgradeButton.record(); } focus() { if (this.state.isSignedOut) { this.signedOutEl?.focus(); } else { this.statusCardEl?.focus(); } } #keyListener(event) { let keyCode = event.code; switch (keyCode) { case "Tab": case "ArrowUp": // Intentional fall-through case "ArrowDown": { event.stopPropagation(); event.preventDefault(); let isForward = (keyCode == "Tab" && !event.shiftKey) || keyCode == "ArrowDown"; let direction = isForward ? Services.focus.MOVEFOCUS_FORWARD : Services.focus.MOVEFOCUS_BACKWARD; Services.focus.moveFocus( window, null, direction, Services.focus.FLAG_BYKEY ); break; } } } #statusCardListener(event) { if (event.type === "ipprotection-status-card:user-toggled-on") { this.dispatchEvent( new CustomEvent("IPProtection:UserEnable", { bubbles: true }) ); } else if (event.type === "ipprotection-status-card:user-toggled-off") { this.dispatchEvent( new CustomEvent("IPProtection:UserDisable", { bubbles: true }) ); } else if (event.type === "ipprotection-site-settings-control:click") { this.dispatchEvent( new CustomEvent("IPProtection:UserShowSiteSettings", { bubbles: true }) ); } } #messageBarListener(event) { if (event.type === "ipprotection-message-bar:user-dismissed") { this._showMessageBar = false; this._messageDismissed = true; this.state.error = ""; this.state.bandwidthWarning = false; } } updated(changedProperties) { super.updated(changedProperties); // Clear messages when there is an error. if (this.state.error) { this._messageDismissed = false; } } messageBarTemplate() { let messageId; let messageLink; let messageLinkl10nId; let messageType = "info"; // If there are errors, the error message should take precedence if (this.#hasErrors) { messageId = "ipprotection-message-generic-error"; messageType = ERRORS.GENERIC; } else if (this.state.bandwidthWarning) { messageId = "ipprotection-message-bandwidth-warning"; messageType = "warning"; } else if (this.state.onboardingMessage) { messageId = this.state.onboardingMessage; messageType = "info"; switch (this.state.onboardingMessage) { case "ipprotection-message-continuous-onboarding-intro": break; case "ipprotection-message-continuous-onboarding-autostart": messageLink = "about:settings#privacy"; messageLinkl10nId = "setting-link"; break; case "ipprotection-message-continuous-onboarding-site-settings": messageLink = "about:settings#privacy"; messageLinkl10nId = "setting-link"; break; } } return html` `; } statusCardTemplate() { // TODO: Pass site information to status-card to conditionally // render the site settings control. (Bug 1997412) return html` `; } pausedTemplate() { return html`

`; } mainContentTemplate() { // TODO: Update support-page with new SUMO link for Mozilla VPN - Bug 1975474 if (this.state.isSignedOut) { return html` `; } if (this.state.paused) { return html` ${this.pausedTemplate()} `; } return html` ${this.statusCardTemplate()} `; } render() { if ( (this.#hasErrors || this.state.onboardingMessage || this.state.bandwidthWarning) && !this._messageDismissed ) { this._showMessageBar = true; } const messageBar = this._showMessageBar ? this.messageBarTemplate() : null; let content = html`${messageBar}${this.mainContentTemplate()}`; // TODO: Conditionally render post-upgrade subview within #ipprotection-content-wrapper - Bug 1973813 return html`
${content}
`; } } customElements.define("ipprotection-content", IPProtectionContentElement); PK