diff options
Diffstat (limited to 'browser/components/contentanalysis')
-rw-r--r-- | browser/components/contentanalysis/content/ContentAnalysis.sys.mjs | 129 |
1 files changed, 108 insertions, 21 deletions
diff --git a/browser/components/contentanalysis/content/ContentAnalysis.sys.mjs b/browser/components/contentanalysis/content/ContentAnalysis.sys.mjs index c710f098cb..901059906a 100644 --- a/browser/components/contentanalysis/content/ContentAnalysis.sys.mjs +++ b/browser/components/contentanalysis/content/ContentAnalysis.sys.mjs @@ -25,6 +25,7 @@ XPCOMUtils.defineLazyServiceGetter( ChromeUtils.defineESModuleGetters(lazy, { clearTimeout: "resource://gre/modules/Timer.sys.mjs", + PanelMultiView: "resource:///modules/PanelMultiView.sys.mjs", setTimeout: "resource://gre/modules/Timer.sys.mjs", }); @@ -211,7 +212,7 @@ export const ContentAnalysis = { * Registers for various messages/events that will indicate the * need for communicating something to the user. */ - initialize() { + initialize(doc) { if (!this.isInitialized) { this.isInitialized = true; this.initializeDownloadCA(); @@ -223,6 +224,17 @@ export const ContentAnalysis = { ); }); } + + // Do this even if initialized so the icon shows up on new windows, not just the + // first one. + if (lazy.gContentAnalysis.isActive) { + doc.l10n.setAttributes( + doc.getElementById("content-analysis-indicator"), + "content-analysis-indicator-tooltip", + { agentName: lazy.agentName } + ); + doc.documentElement.setAttribute("contentanalysisactive", "true"); + } }, async uninitialize() { @@ -390,6 +402,18 @@ export const ContentAnalysis = { } }, + async showPanel(element, panelUI) { + element.ownerDocument.l10n.setAttributes( + lazy.PanelMultiView.getViewNode( + element.ownerDocument, + "content-analysis-panel-description" + ), + "content-analysis-panel-text", + { agentName: lazy.agentName } + ); + panelUI.showSubView("content-analysis-panel", element); + }, + _showAnotherPendingDialog(aBrowsingContext) { const otherBrowsingContext = this.dlpBusyViewsByTopBrowsingContext.getBrowsingContextWithPendingNotification( @@ -618,6 +642,36 @@ export const ContentAnalysis = { }); }, + _getErrorDialogMessage(aResourceNameOrOperationType) { + if (aResourceNameOrOperationType.name) { + return this.l10n.formatValueSync( + "contentanalysis-error-message-upload-file", + { + filename: aResourceNameOrOperationType.name, + } + ); + } + let l10nId = undefined; + switch (aResourceNameOrOperationType.operationType) { + case Ci.nsIContentAnalysisRequest.eClipboard: + l10nId = "contentanalysis-error-message-clipboard"; + break; + case Ci.nsIContentAnalysisRequest.eDroppedText: + l10nId = "contentanalysis-error-message-dropped-text"; + break; + case Ci.nsIContentAnalysisRequest.eOperationPrint: + l10nId = "contentanalysis-error-message-print"; + break; + } + if (!l10nId) { + console.error( + "Unknown operationTypeForDisplay: ", + aResourceNameOrOperationType + ); + return ""; + } + return this.l10n.formatValueSync(l10nId); + }, _showSlowCABlockingMessage( aBrowsingContext, aRequestToken, @@ -710,7 +764,7 @@ export const ContentAnalysis = { Ci.nsIPromptService.BUTTON_TITLE_IS_STRING + Ci.nsIPromptService.BUTTON_POS_1 * Ci.nsIPromptService.BUTTON_TITLE_IS_STRING + - Ci.nsIPromptService.BUTTON_POS_1_DEFAULT, + Ci.nsIPromptService.BUTTON_POS_2_DEFAULT, await this.l10n.formatValue( "contentanalysis-warndialog-response-allow" ), @@ -725,26 +779,60 @@ export const ContentAnalysis = { lazy.gContentAnalysis.respondToWarnDialog(aRequestToken, allow); return null; } - case Ci.nsIContentAnalysisResponse.eBlock: + case Ci.nsIContentAnalysisResponse.eBlock: { if (!lazy.showBlockedResult) { // Don't show anything return null; } - message = await this.l10n.formatValue("contentanalysis-block-message", { - content: this._getResourceNameFromNameOrOperationType( - aResourceNameOrOperationType - ), - }); - timeoutMs = this._RESULT_NOTIFICATION_TIMEOUT_MS; - break; + let titleId = undefined; + let body = undefined; + if (aResourceNameOrOperationType.name) { + titleId = "contentanalysis-block-dialog-title-upload-file"; + body = this.l10n.formatValueSync( + "contentanalysis-block-dialog-body-upload-file", + { + filename: aResourceNameOrOperationType.name, + } + ); + } else { + let bodyId = undefined; + switch (aResourceNameOrOperationType.operationType) { + case Ci.nsIContentAnalysisRequest.eClipboard: + titleId = "contentanalysis-block-dialog-title-clipboard"; + bodyId = "contentanalysis-block-dialog-body-clipboard"; + break; + case Ci.nsIContentAnalysisRequest.eDroppedText: + titleId = "contentanalysis-block-dialog-title-dropped-text"; + bodyId = "contentanalysis-block-dialog-body-dropped-text"; + break; + case Ci.nsIContentAnalysisRequest.eOperationPrint: + titleId = "contentanalysis-block-dialog-title-print"; + bodyId = "contentanalysis-block-dialog-body-print"; + break; + } + if (!titleId || !bodyId) { + console.error( + "Unknown operationTypeForDisplay: ", + aResourceNameOrOperationType + ); + return null; + } + body = this.l10n.formatValueSync(bodyId); + } + Services.prompt.alertBC( + aBrowsingContext, + Ci.nsIPromptService.MODAL_TYPE_TAB, + this.l10n.formatValueSync(titleId), + body + ); + return null; + } case Ci.nsIContentAnalysisResponse.eUnspecified: message = await this.l10n.formatValue( - "contentanalysis-unspecified-error-message", + "contentanalysis-unspecified-error-message-content", { agent: lazy.agentName, - content: this._getResourceNameFromNameOrOperationType( - aResourceNameOrOperationType - ), + content: this._getErrorDialogMessage(aResourceNameOrOperationType), } ); timeoutMs = this._RESULT_NOTIFICATION_TIMEOUT_MS; @@ -759,26 +847,25 @@ export const ContentAnalysis = { ); return null; case Ci.nsIContentAnalysisResponse.eNoAgent: - messageId = "contentanalysis-no-agent-connected-message"; + messageId = "contentanalysis-no-agent-connected-message-content"; break; case Ci.nsIContentAnalysisResponse.eInvalidAgentSignature: - messageId = "contentanalysis-invalid-agent-signature-message"; + messageId = + "contentanalysis-invalid-agent-signature-message-content"; break; case Ci.nsIContentAnalysisResponse.eErrorOther: - messageId = "contentanalysis-unspecified-error-message"; + messageId = "contentanalysis-unspecified-error-message-content"; break; default: console.error( "Unexpected CA cancelError value: " + aRequestCancelError ); - messageId = "contentanalysis-unspecified-error-message"; + messageId = "contentanalysis-unspecified-error-message-content"; break; } message = await this.l10n.formatValue(messageId, { agent: lazy.agentName, - content: this._getResourceNameFromNameOrOperationType( - aResourceNameOrOperationType - ), + content: this._getErrorDialogMessage(aResourceNameOrOperationType), }); timeoutMs = this._RESULT_NOTIFICATION_TIMEOUT_MS; } |