Skip to content

Commit eacb248

Browse files
committed
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
1 parent 05e3016 commit eacb248

File tree

3 files changed

+109
-58
lines changed

3 files changed

+109
-58
lines changed

browser/components/contentanalysis/content/ContentAnalysis.sys.mjs

Lines changed: 92 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ XPCOMUtils.defineLazyPreferenceGetter(
3535
false
3636
);
3737

38+
XPCOMUtils.defineLazyPreferenceGetter(
39+
lazy,
40+
"agentName",
41+
"browser.contentanalysis.agent_name",
42+
"A DLP agent"
43+
);
44+
3845
/**
3946
* A class that groups browsing contexts by their top-level one.
4047
* This is necessary because if there may be a subframe that
@@ -251,19 +258,19 @@ export const ContentAnalysis = {
251258
"Got dlp-request-made message for a browsingContext that already has a busy view!"
252259
);
253260
}
254-
let resourceNameOrL10NId =
255-
this._getResourceNameOrL10NIdFromRequest(request);
261+
let resourceNameOrOperationType =
262+
this._getResourceNameOrOperationTypeFromRequest(request);
256263
this.requestTokenToRequestInfo.set(request.requestToken, {
257264
browsingContext,
258-
resourceNameOrL10NId,
265+
resourceNameOrOperationType,
259266
});
260267
this.dlpBusyViewsByTopBrowsingContext.setEntry(browsingContext, {
261268
timer: lazy.setTimeout(() => {
262269
this.dlpBusyViewsByTopBrowsingContext.setEntry(browsingContext, {
263270
notification: this._showSlowCAMessage(
264271
operation,
265272
request,
266-
resourceNameOrL10NId,
273+
resourceNameOrOperationType,
267274
browsingContext
268275
),
269276
});
@@ -279,10 +286,9 @@ export const ContentAnalysis = {
279286
throw new Error("Got dlp-response message but no request was passed");
280287
}
281288

282-
let windowAndResourceNameOrL10NId = this.requestTokenToRequestInfo.get(
283-
request.requestToken
284-
);
285-
if (!windowAndResourceNameOrL10NId) {
289+
let windowAndResourceNameOrOperationType =
290+
this.requestTokenToRequestInfo.get(request.requestToken);
291+
if (!windowAndResourceNameOrOperationType) {
286292
// Perhaps this was cancelled just before the response came in from the
287293
// DLP agent.
288294
console.warn(
@@ -292,24 +298,24 @@ export const ContentAnalysis = {
292298
}
293299
this.requestTokenToRequestInfo.delete(request.requestToken);
294300
let dlpBusyView = this.dlpBusyViewsByTopBrowsingContext.getEntry(
295-
windowAndResourceNameOrL10NId.browsingContext
301+
windowAndResourceNameOrOperationType.browsingContext
296302
);
297303
if (dlpBusyView) {
298304
this._disconnectFromView(dlpBusyView);
299305
this.dlpBusyViewsByTopBrowsingContext.deleteEntry(
300-
windowAndResourceNameOrL10NId.browsingContext
306+
windowAndResourceNameOrOperationType.browsingContext
301307
);
302308
}
303309
const responseResult =
304310
request?.action ?? Ci.nsIContentAnalysisResponse.eUnspecified;
305311
await this._showCAResult(
306-
windowAndResourceNameOrL10NId.resourceNameOrL10NId,
307-
windowAndResourceNameOrL10NId.browsingContext,
312+
windowAndResourceNameOrOperationType.resourceNameOrOperationType,
313+
windowAndResourceNameOrOperationType.browsingContext,
308314
request.requestToken,
309315
responseResult
310316
);
311317
this._showAnotherPendingDialog(
312-
windowAndResourceNameOrL10NId.browsingContext
318+
windowAndResourceNameOrOperationType.browsingContext
313319
);
314320
break;
315321
}
@@ -327,7 +333,7 @@ export const ContentAnalysis = {
327333
notification: this._showSlowCABlockingMessage(
328334
otherBrowsingContext,
329335
args.requestToken,
330-
args.resourceNameOrL10NId
336+
args.resourceNameOrOperationType
331337
),
332338
});
333339
}
@@ -400,39 +406,39 @@ export const ContentAnalysis = {
400406
);
401407
},
402408

403-
// This function also transforms the nameOrL10NId so we won't have to
409+
// This function also transforms the nameOrOperationType so we won't have to
404410
// look it up again.
405-
_getResourceNameFromNameOrL10NId(nameOrL10NId) {
406-
if (nameOrL10NId.name) {
407-
return nameOrL10NId.name;
411+
_getResourceNameFromNameOrOperationType(nameOrOperationType) {
412+
if (!nameOrOperationType.name) {
413+
let l10nId = undefined;
414+
switch (nameOrOperationType.operationType) {
415+
case Ci.nsIContentAnalysisRequest.eClipboard:
416+
l10nId = "contentanalysis-operationtype-clipboard";
417+
break;
418+
case Ci.nsIContentAnalysisRequest.eDroppedText:
419+
l10nId = "contentanalysis-operationtype-dropped-text";
420+
break;
421+
}
422+
if (!l10nId) {
423+
console.error(
424+
"Unknown operationTypeForDisplay: " +
425+
nameOrOperationType.operationType
426+
);
427+
return "";
428+
}
429+
nameOrOperationType.name = this.l10n.formatValueSync(l10nId);
408430
}
409-
nameOrL10NId.name = this.l10n.formatValueSync(nameOrL10NId.l10nId);
410-
return nameOrL10NId.name;
431+
return nameOrOperationType.name;
411432
},
412433

413-
_getResourceNameOrL10NIdFromRequest(aRequest) {
434+
_getResourceNameOrOperationTypeFromRequest(aRequest) {
414435
if (
415436
aRequest.operationTypeForDisplay ==
416437
Ci.nsIContentAnalysisRequest.eCustomDisplayString
417438
) {
418439
return { name: aRequest.operationDisplayString };
419440
}
420-
let l10nId;
421-
switch (aRequest.operationTypeForDisplay) {
422-
case Ci.nsIContentAnalysisRequest.eClipboard:
423-
l10nId = "contentanalysis-operationtype-clipboard";
424-
break;
425-
case Ci.nsIContentAnalysisRequest.eDroppedText:
426-
l10nId = "contentanalysis-operationtype-dropped-text";
427-
break;
428-
}
429-
if (!l10nId) {
430-
console.error(
431-
"Unknown operationTypeForDisplay: " + aRequest.operationTypeForDisplay
432-
);
433-
return { name: "" };
434-
}
435-
return { l10nId };
441+
return { operationType: aRequest.operationTypeForDisplay };
436442
},
437443

438444
/**
@@ -442,14 +448,12 @@ export const ContentAnalysis = {
442448
_showSlowCAMessage(
443449
aOperation,
444450
aRequest,
445-
aResourceNameOrL10NId,
451+
aResourceNameOrOperationType,
446452
aBrowsingContext
447453
) {
448454
if (!this._shouldShowBlockingNotification(aOperation)) {
449455
return this._showMessage(
450-
this.l10n.formatValueSync("contentanalysis-slow-agent-notification", {
451-
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
452-
}),
456+
this._getSlowDialogMessage(aResourceNameOrOperationType),
453457
aBrowsingContext
454458
);
455459
}
@@ -471,30 +475,59 @@ export const ContentAnalysis = {
471475
return {
472476
requestToken: aRequest.requestToken,
473477
dialogBrowsingContextArgs: {
474-
resourceNameOrL10NId: aResourceNameOrL10NId,
478+
resourceNameOrOperationType: aResourceNameOrOperationType,
475479
},
476480
};
477481
}
478482

479483
return this._showSlowCABlockingMessage(
480484
aBrowsingContext,
481485
aRequest.requestToken,
482-
aResourceNameOrL10NId
486+
aResourceNameOrOperationType
483487
);
484488
},
485489

490+
_getSlowDialogMessage(aResourceNameOrOperationType) {
491+
if (aResourceNameOrOperationType.name) {
492+
return this.l10n.formatValueSync(
493+
"contentanalysis-slow-agent-dialog-body-file",
494+
{
495+
agent: lazy.agentName,
496+
filename: aResourceNameOrOperationType.name,
497+
}
498+
);
499+
}
500+
let l10nId = undefined;
501+
switch (aResourceNameOrOperationType.operationType) {
502+
case Ci.nsIContentAnalysisRequest.eClipboard:
503+
l10nId = "contentanalysis-slow-agent-dialog-body-clipboard";
504+
break;
505+
case Ci.nsIContentAnalysisRequest.eDroppedText:
506+
l10nId = "contentanalysis-slow-agent-dialog-body-dropped-text";
507+
break;
508+
}
509+
if (!l10nId) {
510+
console.error(
511+
"Unknown operationTypeForDisplay: " + aResourceNameOrOperationType
512+
);
513+
return "";
514+
}
515+
return this.l10n.formatValueSync(l10nId, {
516+
agent: lazy.agentName,
517+
});
518+
},
519+
486520
_showSlowCABlockingMessage(
487521
aBrowsingContext,
488522
aRequestToken,
489-
aResourceNameOrL10NId
523+
aResourceNameOrOperationType
490524
) {
525+
let bodyMessage = this._getSlowDialogMessage(aResourceNameOrOperationType);
491526
let promise = Services.prompt.asyncConfirmEx(
492527
aBrowsingContext,
493528
Ci.nsIPromptService.MODAL_TYPE_TAB,
494-
this.l10n.formatValueSync("contentanalysis-slow-agent-dialog-title"),
495-
this.l10n.formatValueSync("contentanalysis-slow-agent-dialog-body", {
496-
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
497-
}),
529+
this.l10n.formatValueSync("contentanalysis-slow-agent-dialog-header"),
530+
bodyMessage,
498531
Ci.nsIPromptService.BUTTON_POS_0 *
499532
Ci.nsIPromptService.BUTTON_TITLE_CANCEL +
500533
Ci.nsIPromptService.BUTTON_POS_1_DEFAULT +
@@ -537,7 +570,7 @@ export const ContentAnalysis = {
537570
* @returns {object} a notification object (if shown)
538571
*/
539572
async _showCAResult(
540-
aResourceNameOrL10NId,
573+
aResourceNameOrOperationType,
541574
aBrowsingContext,
542575
aRequestToken,
543576
aCAResult
@@ -553,8 +586,8 @@ export const ContentAnalysis = {
553586
message = await this.l10n.formatValue(
554587
"contentanalysis-genericresponse-message",
555588
{
556-
content: this._getResourceNameFromNameOrL10NId(
557-
aResourceNameOrL10NId
589+
content: this._getResourceNameFromNameOrOperationType(
590+
aResourceNameOrOperationType
558591
),
559592
response: "REPORT_ONLY",
560593
}
@@ -567,8 +600,8 @@ export const ContentAnalysis = {
567600
Ci.nsIPromptService.MODAL_TYPE_TAB,
568601
await this.l10n.formatValue("contentanalysis-warndialogtitle"),
569602
await this.l10n.formatValue("contentanalysis-warndialogtext", {
570-
content: this._getResourceNameFromNameOrL10NId(
571-
aResourceNameOrL10NId
603+
content: this._getResourceNameFromNameOrOperationType(
604+
aResourceNameOrOperationType
572605
),
573606
}),
574607
Ci.nsIPromptService.BUTTON_POS_0 *
@@ -591,13 +624,17 @@ export const ContentAnalysis = {
591624
return null;
592625
case Ci.nsIContentAnalysisResponse.eBlock:
593626
message = await this.l10n.formatValue("contentanalysis-block-message", {
594-
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
627+
content: this._getResourceNameFromNameOrOperationType(
628+
aResourceNameOrOperationType
629+
),
595630
});
596631
timeoutMs = this._RESULT_NOTIFICATION_TIMEOUT_MS;
597632
break;
598633
case Ci.nsIContentAnalysisResponse.eUnspecified:
599634
message = await this.l10n.formatValue("contentanalysis-error-message", {
600-
content: this._getResourceNameFromNameOrL10NId(aResourceNameOrL10NId),
635+
content: this._getResourceNameFromNameOrOperationType(
636+
aResourceNameOrOperationType
637+
),
601638
});
602639
timeoutMs = this._RESULT_NOTIFICATION_TIMEOUT_MS;
603640
break;

modules/libpref/init/StaticPrefList.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,12 @@
11351135
#endif
11361136
mirror: always
11371137

1138+
# DLP agent name, for display in the browser
1139+
- name: browser.contentanalysis.agent_name
1140+
type: String
1141+
value: "A DLP agent"
1142+
mirror: never
1143+
11381144
# Content analysis by external applications, e.g. data-loss prevention apps
11391145
- name: browser.contentanalysis.enabled
11401146
type: bool

toolkit/locales/en-US/toolkit/contentanalysis/contentanalysis.ftl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ contentanalysis-alert-title = Content Analysis
77
# Variables:
88
# $content - Description of the content being warned about, such as "clipboard" or "aFile.txt"
99
contentanalysis-slow-agent-notification = The Content Analysis tool is taking a long time to respond for resource “{ $content }
10-
contentanalysis-slow-agent-dialog-title = Content analysis in progress
10+
contentanalysis-slow-agent-dialog-header = Scan in progress
1111
1212
# Variables:
13-
# $content - Description of the content being warned about, such as "clipboard" or "aFile.txt"
14-
contentanalysis-slow-agent-dialog-body = Content Analysis is analyzing resource “{ $content }
13+
# $agent - The name of the DLP agent doing the analysis
14+
# $filename - Name of the file being analyzed, such as "aFile.txt"
15+
contentanalysis-slow-agent-dialog-body-file = { $agent } is reviewing “{ $filename }” against your organization’s data policies. This may take a moment.
16+
# Variables:
17+
# $agent - The name of the DLP agent doing the analysis
18+
contentanalysis-slow-agent-dialog-body-clipboard = { $agent } is reviewing what you pasted against your organization’s data policies. This may take a moment.
19+
# Note that this is shown when the user drag and drops text into the browser.
20+
# Variables:
21+
# $agent - The name of the DLP agent doing the analysis
22+
contentanalysis-slow-agent-dialog-body-dropped-text = { $agent } is reviewing the text you dropped against your organization’s data policies. This may take a moment.
1523
contentanalysis-operationtype-clipboard = clipboard
1624
contentanalysis-operationtype-dropped-text = dropped text
1725

0 commit comments

Comments
 (0)