Bug 1878701 - Part 3: Use UX-suggested text for the DLP agent busy dialog r=handyman,fluent-reviewers,bolsson

Differential Revision: https://phabricator.services.mozilla.com/D200729
This commit is contained in:
Greg Stoll 2024-02-21 22:59:53 +00:00
parent bae05be326
commit aff7a2dacd
3 changed files with 109 additions and 58 deletions

View file

@ -35,6 +35,13 @@ XPCOMUtils.defineLazyPreferenceGetter(
false
);
XPCOMUtils.defineLazyPreferenceGetter(
lazy,
"agentName",
"browser.contentanalysis.agent_name",
"A DLP agent"
);
/**
* A class that groups browsing contexts by their top-level one.
* This is necessary because if there may be a subframe that
@ -251,11 +258,11 @@ export const ContentAnalysis = {
"Got dlp-request-made message for a browsingContext that already has a busy view!"
);
}
let resourceNameOrL10NId =
this._getResourceNameOrL10NIdFromRequest(request);
let resourceNameOrOperationType =
this._getResourceNameOrOperationTypeFromRequest(request);
this.requestTokenToRequestInfo.set(request.requestToken, {
browsingContext,
resourceNameOrL10NId,
resourceNameOrOperationType,
});
this.dlpBusyViewsByTopBrowsingContext.setEntry(browsingContext, {
timer: lazy.setTimeout(() => {
@ -263,7 +270,7 @@ export const ContentAnalysis = {
notification: this._showSlowCAMessage(
operation,
request,
resourceNameOrL10NId,
resourceNameOrOperationType,
browsingContext
),
});
@ -279,10 +286,9 @@ export const ContentAnalysis = {
throw new Error("Got dlp-response message but no request was passed");
}
let windowAndResourceNameOrL10NId = this.requestTokenToRequestInfo.get(
request.requestToken
);
if (!windowAndResourceNameOrL10NId) {
let windowAndResourceNameOrOperationType =
this.requestTokenToRequestInfo.get(request.requestToken);
if (!windowAndResourceNameOrOperationType) {
// Perhaps this was cancelled just before the response came in from the
// DLP agent.
console.warn(
@ -292,24 +298,24 @@ export const ContentAnalysis = {
}
this.requestTokenToRequestInfo.delete(request.requestToken);
let dlpBusyView = this.dlpBusyViewsByTopBrowsingContext.getEntry(
windowAndResourceNameOrL10NId.browsingContext
windowAndResourceNameOrOperationType.browsingContext
);
if (dlpBusyView) {
this._disconnectFromView(dlpBusyView);
this.dlpBusyViewsByTopBrowsingContext.deleteEntry(
windowAndResourceNameOrL10NId.browsingContext
windowAndResourceNameOrOperationType.browsingContext
);
}
const responseResult =
request?.action ?? Ci.nsIContentAnalysisResponse.eUnspecified;
await this._showCAResult(
windowAndResourceNameOrL10NId.resourceNameOrL10NId,
windowAndResourceNameOrL10NId.browsingContext,
windowAndResourceNameOrOperationType.resourceNameOrOperationType,
windowAndResourceNameOrOperationType.browsingContext,
request.requestToken,
responseResult
);
this._showAnotherPendingDialog(
windowAndResourceNameOrL10NId.browsingContext
windowAndResourceNameOrOperationType.browsingContext
);
break;
}
@ -327,7 +333,7 @@ export const ContentAnalysis = {
notification: this._showSlowCABlockingMessage(
otherBrowsingContext,
args.requestToken,
args.resourceNameOrL10NId
args.resourceNameOrOperationType
),
});
}
@ -400,39 +406,39 @@ export const ContentAnalysis = {
);
},
// This function also transforms the nameOrL10NId so we won't have to
// This function also transforms the nameOrOperationType so we won't have to
// look it up again.
_getResourceNameFromNameOrL10NId(nameOrL10NId) {
if (nameOrL10NId.name) {
return nameOrL10NId.name;
_getResourceNameFromNameOrOperationType(nameOrOperationType) {
if (!nameOrOperationType.name) {
let l10nId = undefined;
switch (nameOrOperationType.operationType) {
case Ci.nsIContentAnalysisRequest.eClipboard:
l10nId = "contentanalysis-operationtype-clipboard";
break;
case Ci.nsIContentAnalysisRequest.eDroppedText:
l10nId = "contentanalysis-operationtype-dropped-text";
break;
}
if (!l10nId) {
console.error(
"Unknown operationTypeForDisplay: " +
nameOrOperationType.operationType
);
return "";
}
nameOrOperationType.name = this.l10n.formatValueSync(l10nId);
}
nameOrL10NId.name = this.l10n.formatValueSync(nameOrL10NId.l10nId);
return nameOrL10NId.name;
return nameOrOperationType.name;
},
_getResourceNameOrL10NIdFromRequest(aRequest) {
_getResourceNameOrOperationTypeFromRequest(aRequest) {
if (
aRequest.operationTypeForDisplay ==
Ci.nsIContentAnalysisRequest.eCustomDisplayString
) {
return { name: aRequest.operationDisplayString };
}
let l10nId;
switch (aRequest.operationTypeForDisplay) {
case Ci.nsIContentAnalysisRequest.eClipboard:
l10nId = "contentanalysis-operationtype-clipboard";
break;
case Ci.nsIContentAnalysisRequest.eDroppedText:
l10nId = "contentanalysis-operationtype-dropped-text";
break;
}
if (!l10nId) {
console.error(
"Unknown operationTypeForDisplay: " + aRequest.operationTypeForDisplay
);
return { name: "" };
}
return { l10nId };
return { operationType: aRequest.operationTypeForDisplay };
},
/**
@ -442,14 +448,12 @@ export const ContentAnalysis = {
_showSlowCAMessage(
aOperation,
aRequest,
aResourceNameOrL10NId,
aResourceNameOrOperationType,
aBrowsingContext
) {
if (!this._shouldShowBlockingNotification(aOperation)) {
return this._showMessage(
this.l10n.formatValueSync("contentanalysis-slow-agent-notification", {
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
}),
this._getSlowDialogMessage(aResourceNameOrOperationType),
aBrowsingContext
);
}
@ -471,7 +475,7 @@ export const ContentAnalysis = {
return {
requestToken: aRequest.requestToken,
dialogBrowsingContextArgs: {
resourceNameOrL10NId: aResourceNameOrL10NId,
resourceNameOrOperationType: aResourceNameOrOperationType,
},
};
}
@ -479,22 +483,51 @@ export const ContentAnalysis = {
return this._showSlowCABlockingMessage(
aBrowsingContext,
aRequest.requestToken,
aResourceNameOrL10NId
aResourceNameOrOperationType
);
},
_getSlowDialogMessage(aResourceNameOrOperationType) {
if (aResourceNameOrOperationType.name) {
return this.l10n.formatValueSync(
"contentanalysis-slow-agent-dialog-body-file",
{
agent: lazy.agentName,
filename: aResourceNameOrOperationType.name,
}
);
}
let l10nId = undefined;
switch (aResourceNameOrOperationType.operationType) {
case Ci.nsIContentAnalysisRequest.eClipboard:
l10nId = "contentanalysis-slow-agent-dialog-body-clipboard";
break;
case Ci.nsIContentAnalysisRequest.eDroppedText:
l10nId = "contentanalysis-slow-agent-dialog-body-dropped-text";
break;
}
if (!l10nId) {
console.error(
"Unknown operationTypeForDisplay: " + aResourceNameOrOperationType
);
return "";
}
return this.l10n.formatValueSync(l10nId, {
agent: lazy.agentName,
});
},
_showSlowCABlockingMessage(
aBrowsingContext,
aRequestToken,
aResourceNameOrL10NId
aResourceNameOrOperationType
) {
let bodyMessage = this._getSlowDialogMessage(aResourceNameOrOperationType);
let promise = Services.prompt.asyncConfirmEx(
aBrowsingContext,
Ci.nsIPromptService.MODAL_TYPE_TAB,
this.l10n.formatValueSync("contentanalysis-slow-agent-dialog-title"),
this.l10n.formatValueSync("contentanalysis-slow-agent-dialog-body", {
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
}),
this.l10n.formatValueSync("contentanalysis-slow-agent-dialog-header"),
bodyMessage,
Ci.nsIPromptService.BUTTON_POS_0 *
Ci.nsIPromptService.BUTTON_TITLE_CANCEL +
Ci.nsIPromptService.BUTTON_POS_1_DEFAULT +
@ -537,7 +570,7 @@ export const ContentAnalysis = {
* @returns {object} a notification object (if shown)
*/
async _showCAResult(
aResourceNameOrL10NId,
aResourceNameOrOperationType,
aBrowsingContext,
aRequestToken,
aCAResult
@ -553,8 +586,8 @@ export const ContentAnalysis = {
message = await this.l10n.formatValue(
"contentanalysis-genericresponse-message",
{
content: this._getResourceNameFromNameOrL10NId(
aResourceNameOrL10NId
content: this._getResourceNameFromNameOrOperationType(
aResourceNameOrOperationType
),
response: "REPORT_ONLY",
}
@ -567,8 +600,8 @@ export const ContentAnalysis = {
Ci.nsIPromptService.MODAL_TYPE_TAB,
await this.l10n.formatValue("contentanalysis-warndialogtitle"),
await this.l10n.formatValue("contentanalysis-warndialogtext", {
content: this._getResourceNameFromNameOrL10NId(
aResourceNameOrL10NId
content: this._getResourceNameFromNameOrOperationType(
aResourceNameOrOperationType
),
}),
Ci.nsIPromptService.BUTTON_POS_0 *
@ -591,13 +624,17 @@ export const ContentAnalysis = {
return null;
case Ci.nsIContentAnalysisResponse.eBlock:
message = await this.l10n.formatValue("contentanalysis-block-message", {
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
content: this._getResourceNameFromNameOrOperationType(
aResourceNameOrOperationType
),
});
timeoutMs = this._RESULT_NOTIFICATION_TIMEOUT_MS;
break;
case Ci.nsIContentAnalysisResponse.eUnspecified:
message = await this.l10n.formatValue("contentanalysis-error-message", {
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
content: this._getResourceNameFromNameOrOperationType(
aResourceNameOrOperationType
),
});
timeoutMs = this._RESULT_NOTIFICATION_TIMEOUT_MS;
break;

View file

@ -1135,6 +1135,12 @@
#endif
mirror: always
# DLP agent name, for display in the browser
- name: browser.contentanalysis.agent_name
type: String
value: "A DLP agent"
mirror: never
# Content analysis by external applications, e.g. data-loss prevention apps
- name: browser.contentanalysis.enabled
type: bool

View file

@ -7,11 +7,19 @@ contentanalysis-alert-title = Content Analysis
# Variables:
# $content - Description of the content being warned about, such as "clipboard" or "aFile.txt"
contentanalysis-slow-agent-notification = The Content Analysis tool is taking a long time to respond for resource “{ $content }”
contentanalysis-slow-agent-dialog-title = Content analysis in progress
contentanalysis-slow-agent-dialog-header = Scan in progress
# Variables:
# $content - Description of the content being warned about, such as "clipboard" or "aFile.txt"
contentanalysis-slow-agent-dialog-body = Content Analysis is analyzing resource “{ $content }”
# $agent - The name of the DLP agent doing the analysis
# $filename - Name of the file being analyzed, such as "aFile.txt"
contentanalysis-slow-agent-dialog-body-file = { $agent } is reviewing “{ $filename }” against your organizations data policies. This may take a moment.
# Variables:
# $agent - The name of the DLP agent doing the analysis
contentanalysis-slow-agent-dialog-body-clipboard = { $agent } is reviewing what you pasted against your organizations data policies. This may take a moment.
# Note that this is shown when the user drag and drops text into the browser.
# Variables:
# $agent - The name of the DLP agent doing the analysis
contentanalysis-slow-agent-dialog-body-dropped-text = { $agent } is reviewing the text you dropped against your organizations data policies. This may take a moment.
contentanalysis-operationtype-clipboard = clipboard
contentanalysis-operationtype-dropped-text = dropped text