Path: blob/main/src/vs/workbench/contrib/browserView/electron-browser/siteInfoWidget.ts
13401 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { localize } from '../../../../nls.js';6import { $, addDisposableListener, EventType } from '../../../../base/browser/dom.js';7import { renderIcon } from '../../../../base/browser/ui/iconLabel/iconLabels.js';8import { Codicon } from '../../../../base/common/codicons.js';9import { Disposable } from '../../../../base/common/lifecycle.js';10import { IBrowserViewCertificateError } from '../../../../platform/browserView/common/browserView.js';11import { IHoverService } from '../../../../platform/hover/browser/hover.js';12import { HoverPosition } from '../../../../base/browser/ui/hover/hoverWidget.js';13import type { BrowserEditor } from './browserEditor.js';1415/**16* Widget that displays site security information (e.g. certificate errors)17* as an indicator button inside the URL bar, with a hover popover for details.18*/19export class SiteInfoWidget extends Disposable {2021private readonly _container: HTMLElement;22private readonly _indicator: HTMLElement;2324constructor(25parent: HTMLElement,26private readonly editor: BrowserEditor,27@IHoverService private readonly hoverService: IHoverService28) {29super();3031this._container = $('.browser-site-info-container');32this._container.style.display = 'none';3334this._indicator = $('.browser-site-info-indicator');35this._indicator.tabIndex = 0;36this._indicator.role = 'button';37this._indicator.ariaLabel = localize('browser.notSecure', "Not Secure");38this._indicator.appendChild(renderIcon(Codicon.workspaceUntrusted));39this._container.appendChild(this._indicator);4041parent.appendChild(this._container);4243this._register(addDisposableListener(this._indicator, EventType.CLICK, () => this._showHover()));44this._register(addDisposableListener(this._indicator, EventType.KEY_DOWN, (e: KeyboardEvent) => {45if (e.key === 'Enter' || e.key === ' ') {46e.preventDefault();47this._showHover();48}49}));50}5152/**53* Update visibility and state from a certificate error (or lack thereof).54*/55setCertificateError(certError: IBrowserViewCertificateError | undefined): void {56this._container.style.display = certError ? '' : 'none';57}5859private _showHover(): void {60const certError = this.editor.getCertificateError();61if (!certError) {62return;63}6465const content = document.createElement('div');66content.classList.add('browser-site-info-hover-content');6768const heading = document.createElement('div');69heading.classList.add('browser-site-info-hover-heading');70heading.textContent = localize('browser.certHoverHeading', "Certificate Not Trusted");71content.appendChild(heading);7273const detail1 = document.createElement('div');74detail1.classList.add('browser-site-info-hover-detail');75detail1.textContent = localize(76'browser.certHoverDetail1',77"Your connection to this site is not secure."78);79content.appendChild(detail1);8081if (certError.hasTrustedException) {82const detail2 = document.createElement('div');83detail2.classList.add('browser-site-info-hover-detail');84detail2.textContent = localize(85'browser.certHoverDetail2',86"You previously chose to proceed to '{0}' despite a certificate error ({1}).",87certError.host,88certError.error89);90content.appendChild(detail2);9192const revokeLink = document.createElement('a');93revokeLink.classList.add('browser-site-info-hover-revoke');94revokeLink.textContent = localize('browser.certRevoke', "Revoke and Close");95revokeLink.role = 'button';96revokeLink.tabIndex = 0;97revokeLink.addEventListener('click', () => {98hover?.dispose();99this.editor.revokeAndClose(certError);100});101revokeLink.addEventListener('keydown', (e) => {102if (e.key === 'Enter' || e.key === ' ') {103e.preventDefault();104hover?.dispose();105this.editor.revokeAndClose(certError);106}107});108content.appendChild(revokeLink);109}110111const hover = this.hoverService.showInstantHover({112content,113target: this._indicator,114container: this._container,115position: { hoverPosition: HoverPosition.BELOW },116persistence: { sticky: true }117}, true);118}119}120121122