summaryrefslogtreecommitdiffstats
path: root/toolkit/components/contentanalysis/ContentAnalysis.h
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/contentanalysis/ContentAnalysis.h')
-rw-r--r--toolkit/components/contentanalysis/ContentAnalysis.h93
1 files changed, 90 insertions, 3 deletions
diff --git a/toolkit/components/contentanalysis/ContentAnalysis.h b/toolkit/components/contentanalysis/ContentAnalysis.h
index 17b6e3fc1b..f2545624fd 100644
--- a/toolkit/components/contentanalysis/ContentAnalysis.h
+++ b/toolkit/components/contentanalysis/ContentAnalysis.h
@@ -8,6 +8,8 @@
#include "mozilla/DataMutex.h"
#include "mozilla/MozPromise.h"
+#include "mozilla/dom/BrowsingContext.h"
+#include "mozilla/dom/MaybeDiscarded.h"
#include "mozilla/dom/Promise.h"
#include "nsIContentAnalysis.h"
#include "nsProxyRelease.h"
@@ -18,10 +20,16 @@
#include <regex>
#include <string>
+#ifdef XP_WIN
+# include <windows.h>
+#endif // XP_WIN
+
class nsIPrincipal;
+class nsIPrintSettings;
class ContentAnalysisTest;
namespace mozilla::dom {
+class CanonicalBrowsingContext;
class DataTransfer;
class WindowGlobalParent;
} // namespace mozilla::dom
@@ -34,6 +42,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
@@ -43,11 +72,15 @@ class ContentAnalysisRequest final : public nsIContentAnalysisRequest {
bool aStringIsFilePath, nsCString aSha256Digest,
nsCOMPtr<nsIURI> aUrl, OperationType aOperationType,
dom::WindowGlobalParent* aWindowGlobalParent);
+ ContentAnalysisRequest(const nsTArray<uint8_t> aPrintData,
+ nsCOMPtr<nsIURI> aUrl, nsString aPrinterName,
+ dom::WindowGlobalParent* aWindowGlobalParent);
static nsresult GetFileDigest(const nsAString& aFilePath,
nsCString& aDigestString);
private:
- ~ContentAnalysisRequest() = default;
+ ~ContentAnalysisRequest();
+
// Remove unneeded copy constructor/assignment
ContentAnalysisRequest(const ContentAnalysisRequest&) = delete;
ContentAnalysisRequest& operator=(ContentAnalysisRequest&) = delete;
@@ -84,7 +117,16 @@ class ContentAnalysisRequest final : public nsIContentAnalysisRequest {
// OPERATION_CUSTOMDISPLAYSTRING
nsString mOperationDisplayString;
+ // The name of the printer being printed to
+ nsString mPrinterName;
+
RefPtr<dom::WindowGlobalParent> mWindowGlobalParent;
+#ifdef XP_WIN
+ // The printed data to analyze, in PDF format
+ HANDLE mPrintDataHandle = 0;
+ // The size of the printed data in mPrintDataHandle
+ uint64_t mPrintDataSize = 0;
+#endif
friend class ::ContentAnalysisTest;
};
@@ -105,6 +147,40 @@ class ContentAnalysis final : public nsIContentAnalysis {
ContentAnalysis();
nsCString GetUserActionId();
+ void SetLastResult(nsresult aLastResult) { mLastResult = aLastResult; }
+
+ struct PrintAllowedResult final {
+ bool mAllowed;
+ dom::MaybeDiscarded<dom::BrowsingContext>
+ mCachedStaticDocumentBrowsingContext;
+ PrintAllowedResult(bool aAllowed, dom::MaybeDiscarded<dom::BrowsingContext>
+ aCachedStaticDocumentBrowsingContext)
+ : mAllowed(aAllowed),
+ mCachedStaticDocumentBrowsingContext(
+ aCachedStaticDocumentBrowsingContext) {}
+ explicit PrintAllowedResult(bool aAllowed)
+ : PrintAllowedResult(aAllowed, dom::MaybeDiscardedBrowsingContext()) {}
+ };
+ struct PrintAllowedError final {
+ nsresult mError;
+ dom::MaybeDiscarded<dom::BrowsingContext>
+ mCachedStaticDocumentBrowsingContext;
+ PrintAllowedError(nsresult aError, dom::MaybeDiscarded<dom::BrowsingContext>
+ aCachedStaticDocumentBrowsingContext)
+ : mError(aError),
+ mCachedStaticDocumentBrowsingContext(
+ aCachedStaticDocumentBrowsingContext) {}
+ explicit PrintAllowedError(nsresult aError)
+ : PrintAllowedError(aError, dom::MaybeDiscardedBrowsingContext()) {}
+ };
+ using PrintAllowedPromise =
+ MozPromise<PrintAllowedResult, PrintAllowedError, true>;
+#if defined(XP_WIN)
+ MOZ_CAN_RUN_SCRIPT static RefPtr<PrintAllowedPromise>
+ PrintToPDFToDetermineIfPrintAllowed(
+ dom::CanonicalBrowsingContext* aBrowsingContext,
+ nsIPrintSettings* aPrintSettings);
+#endif // defined(XP_WIN)
private:
~ContentAnalysis();
@@ -114,6 +190,10 @@ class ContentAnalysis final : public nsIContentAnalysis {
nsresult CreateContentAnalysisClient(nsCString&& aPipePathName,
nsString&& aClientSignatureSetting,
bool aIsPerUser);
+ nsresult AnalyzeContentRequestCallbackPrivate(
+ nsIContentAnalysisRequest* aRequest, bool aAutoAcknowledge,
+ nsIContentAnalysisCallback* aCallback);
+
nsresult RunAnalyzeRequestTask(
const RefPtr<nsIContentAnalysisRequest>& aRequest, bool aAutoAcknowledge,
int64_t aRequestCount,
@@ -129,6 +209,7 @@ class ContentAnalysis final : public nsIContentAnalysis {
content_analysis::sdk::ContentAnalysisRequest&& aRequest,
const std::shared_ptr<content_analysis::sdk::Client>& aClient);
void IssueResponse(RefPtr<ContentAnalysisResponse>& response);
+ bool LastRequestSucceeded();
// Did the URL filter completely handle the request or do we need to check
// with the agent.
@@ -147,6 +228,7 @@ class ContentAnalysis final : public nsIContentAnalysis {
bool mClientCreationAttempted;
bool mSetByEnterprise;
+ nsresult mLastResult = NS_OK;
class CallbackData final {
public:
@@ -180,7 +262,7 @@ class ContentAnalysis final : public nsIContentAnalysis {
std::vector<std::regex> mAllowUrlList;
std::vector<std::regex> mDenyUrlList;
- bool mParsedUrlLists;
+ bool mParsedUrlLists = false;
friend class ContentAnalysisResponse;
friend class ::ContentAnalysisTest;
@@ -198,6 +280,7 @@ class ContentAnalysisResponse final : public nsIContentAnalysisResponse {
void SetOwner(RefPtr<ContentAnalysis> aOwner);
void DoNotAcknowledge() { mDoNotAcknowledge = true; }
+ void SetCancelError(CancelError aCancelError);
private:
~ContentAnalysisResponse() = default;
@@ -218,7 +301,11 @@ class ContentAnalysisResponse final : public nsIContentAnalysisResponse {
// Identifier for the corresponding nsIContentAnalysisRequest
nsCString mRequestToken;
- // ContentAnalysis (or, more precisely, it's Client object) must outlive
+ // If mAction is eCanceled, this is the error explaining why the request was
+ // canceled, or eUserInitiated if the user canceled it.
+ CancelError mCancelError = CancelError::eUserInitiated;
+
+ // ContentAnalysis (or, more precisely, its Client object) must outlive
// the transaction.
RefPtr<ContentAnalysis> mOwner;