Bug 1882606 - Add about:support information for Content Analysis r=dlp-reviewers,fluent-reviewers,bolsson,handyman

Differential Revision: https://phabricator.services.mozilla.com/D205121
This commit is contained in:
Greg Stoll 2024-03-21 01:57:59 +00:00
parent dbb038279c
commit 5d3a39fdcd
8 changed files with 190 additions and 0 deletions

View File

@ -825,6 +825,8 @@ NS_IMPL_ISUPPORTS(ContentAnalysisAcknowledgement,
nsIContentAnalysisAcknowledgement);
NS_IMPL_ISUPPORTS(ContentAnalysisCallback, nsIContentAnalysisCallback);
NS_IMPL_ISUPPORTS(ContentAnalysisResult, nsIContentAnalysisResult);
NS_IMPL_ISUPPORTS(ContentAnalysisDiagnosticInfo,
nsIContentAnalysisDiagnosticInfo);
NS_IMPL_ISUPPORTS(ContentAnalysis, nsIContentAnalysis, ContentAnalysis);
ContentAnalysis::ContentAnalysis()
@ -1425,6 +1427,40 @@ nsresult ContentAnalysis::RunAcknowledgeTask(
return rv;
}
NS_IMETHODIMP
ContentAnalysis::GetDiagnosticInfo(JSContext* aCx,
mozilla::dom::Promise** aPromise) {
RefPtr<mozilla::dom::Promise> promise;
nsresult rv = MakePromise(aCx, &promise);
NS_ENSURE_SUCCESS(rv, rv);
mCaClientPromise->Then(
GetCurrentSerialEventTarget(), __func__,
[promise](std::shared_ptr<content_analysis::sdk::Client> client) mutable {
if (!client) {
auto info = MakeRefPtr<ContentAnalysisDiagnosticInfo>(
false, EmptyString(), false, 0);
promise->MaybeResolve(info);
return;
}
RefPtr<ContentAnalysis> self = GetContentAnalysisFromService();
std::string agentPath = client->GetAgentInfo().binary_path;
nsString agentWidePath = NS_ConvertUTF8toUTF16(agentPath);
auto info = MakeRefPtr<ContentAnalysisDiagnosticInfo>(
true, std::move(agentWidePath), false,
self ? self->mRequestCount : 0);
promise->MaybeResolve(info);
},
[promise](nsresult rv) {
RefPtr<ContentAnalysis> self = GetContentAnalysisFromService();
auto info = MakeRefPtr<ContentAnalysisDiagnosticInfo>(
false, EmptyString(), rv == NS_ERROR_INVALID_SIGNATURE,
self ? self->mRequestCount : 0);
promise->MaybeResolve(info);
});
promise.forget(aPromise);
return NS_OK;
}
NS_IMETHODIMP ContentAnalysisCallback::ContentResult(
nsIContentAnalysisResponse* aResponse) {
if (mPromise.isSome()) {
@ -1448,6 +1484,28 @@ ContentAnalysisCallback::ContentAnalysisCallback(RefPtr<dom::Promise> aPromise)
: mPromise(Some(new nsMainThreadPtrHolder<dom::Promise>(
"content analysis promise", aPromise))) {}
NS_IMETHODIMP ContentAnalysisDiagnosticInfo::GetConnectedToAgent(
bool* aConnectedToAgent) {
*aConnectedToAgent = mConnectedToAgent;
return NS_OK;
}
NS_IMETHODIMP ContentAnalysisDiagnosticInfo::GetAgentPath(
nsAString& aAgentPath) {
aAgentPath = mAgentPath;
return NS_OK;
}
NS_IMETHODIMP ContentAnalysisDiagnosticInfo::GetFailedSignatureVerification(
bool* aFailedSignatureVerification) {
*aFailedSignatureVerification = mFailedSignatureVerification;
return NS_OK;
}
NS_IMETHODIMP ContentAnalysisDiagnosticInfo::GetRequestCount(
int64_t* aRequestCount) {
*aRequestCount = mRequestCount;
return NS_OK;
}
#undef LOGD
#undef LOGE
} // namespace mozilla::contentanalysis

View File

@ -34,6 +34,27 @@ class ContentAnalysisResponse;
namespace mozilla::contentanalysis {
class ContentAnalysisDiagnosticInfo final
: public nsIContentAnalysisDiagnosticInfo {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSICONTENTANALYSISDIAGNOSTICINFO
ContentAnalysisDiagnosticInfo(bool aConnectedToAgent, nsString aAgentPath,
bool aFailedSignatureVerification,
int64_t aRequestCount)
: mConnectedToAgent(aConnectedToAgent),
mAgentPath(std::move(aAgentPath)),
mFailedSignatureVerification(aFailedSignatureVerification),
mRequestCount(aRequestCount) {}
private:
~ContentAnalysisDiagnosticInfo() = default;
bool mConnectedToAgent;
nsString mAgentPath;
bool mFailedSignatureVerification;
int64_t mRequestCount;
};
class ContentAnalysisRequest final : public nsIContentAnalysisRequest {
public:
NS_DECL_ISUPPORTS

View File

@ -166,6 +166,15 @@ interface nsIContentAnalysisCallback : nsISupports
void error(in nsresult aResult);
};
[scriptable, builtinclass, uuid(a430f6ef-a526-4055-8a82-7741ea757367)]
interface nsIContentAnalysisDiagnosticInfo : nsISupports
{
[infallible] readonly attribute boolean connectedToAgent;
readonly attribute AString agentPath;
[infallible] readonly attribute boolean failedSignatureVerification;
[infallible] readonly attribute long long requestCount;
};
[scriptable, builtinclass, uuid(61497587-2bba-4a88-acd3-3fbb2cedf163)]
interface nsIContentAnalysis : nsISupports
{
@ -254,4 +263,11 @@ interface nsIContentAnalysis : nsISupports
* given to Gecko on the command line.
*/
void testOnlySetCACmdLineArg(in boolean aVal);
/**
* Gets diagnostic information about content analysis. Returns a
* nsIContentAnalysisDiagnosticInfo via the returned promise.
*/
[implicit_jscontext]
Promise getDiagnosticInfo();
};

View File

@ -1369,6 +1369,17 @@ var snapshotFormatters = {
$("remote-debugging-url").textContent = data.url;
},
contentAnalysis(data) {
$("content-analysis-active").textContent = data.active;
if (data.active) {
$("content-analysis-connected-to-agent").textContent = data.connected;
$("content-analysis-agent-path").textContent = data.agentPath;
$("content-analysis-agent-failed-signature-verification").textContent =
data.failedSignatureVerification;
$("content-analysis-request-count").textContent = data.requestCount;
}
},
accessibility(data) {
$("a11y-activated").textContent = data.isActive;
$("a11y-force-disabled").textContent = data.forceDisabled || 0;

View File

@ -902,6 +902,38 @@
</table>
#endif
#ifndef ANDROID
<!-- - - - - - - - - - - - - - - - - - - - - -->
<h2 class="major-section" id="content-analysis" data-l10n-id="content-analysis-title"/>
<table>
<tbody>
<tr>
<th class="column" data-l10n-id="content-analysis-active"/>
<td id="content-analysis-active"/>
</tr>
<tr>
<th class="column" data-l10n-id="content-analysis-connected-to-agent"/>
<td id="content-analysis-connected-to-agent"/>
</tr>
<tr>
<th class="column" data-l10n-id="content-analysis-agent-path"/>
<td id="content-analysis-agent-path"/>
</tr>
<tr>
<th class="column" data-l10n-id="content-analysis-agent-failed-signature-verification"/>
<td id="content-analysis-agent-failed-signature-verification"/>
</tr>
<tr>
<th class="column" data-l10n-id="content-analysis-request-count"/>
<td id="content-analysis-request-count"/>
</tr>
</tbody>
</table>
#endif
</div>
</body>

View File

@ -452,3 +452,15 @@ pointing-device-mouse = Mouse
pointing-device-touchscreen = Touchscreen
pointing-device-pen-digitizer = Pen Digitizer
pointing-device-none = No pointing devices
## Content Analysis (DLP)
# DLP stands for Data Loss Prevention, an industry term for external software
# that enterprises can set up to prevent sensitive data from being transferred
# to external websites.
content-analysis-title = Content Analysis (DLP)
content-analysis-active = Active
content-analysis-connected-to-agent = Connected to Agent
content-analysis-agent-path = Agent Path
content-analysis-agent-failed-signature-verification = Agent Failed Signature Verification
content-analysis-request-count = Request Count

View File

@ -22,6 +22,7 @@ const PREFS_FOR_DISPLAY = [
"apz.",
"browser.cache.",
"browser.contentblocking.category",
"browser.contentanalysis.",
"browser.display.",
"browser.download.always_ask_before_handling_new_types",
"browser.download.enable_spam_prevention",
@ -999,6 +1000,24 @@ var dataProviders = {
});
},
contentAnalysis: async function contentAnalysis(done) {
const contentAnalysis = Cc["@mozilla.org/contentanalysis;1"].getService(
Ci.nsIContentAnalysis
);
if (!contentAnalysis.isActive) {
done({ active: false });
return;
}
let info = await contentAnalysis.getDiagnosticInfo();
done({
active: true,
connected: info.connectedToAgent,
agentPath: info.agentPath,
failedSignatureVerification: info.failedSignatureVerification,
requestCount: info.requestCount,
});
},
async normandy(done) {
if (!AppConstants.MOZ_NORMANDY) {
done();

View File

@ -1288,6 +1288,27 @@ const SNAPSHOT_SCHEMA = {
},
},
},
contentAnalysis: {
type: "object",
properties: {
active: {
required: true,
type: "boolean",
},
connected: {
type: "boolean",
},
agentPath: {
type: "string",
},
failedSignatureVerification: {
type: "boolean",
},
requestCount: {
type: "number",
},
},
},
},
};