Backed out 7 changesets (bug 1942424) for causing frequent crashes. a=backout
[gecko.git] / toolkit / components / antitracking / imageinputmetadatastripper / ImageInputTelemetry.h
blobe73e540bd4774e2e7e3535ab91b452f520aed537
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_imageinputtypetelemetry_h
8 #define mozilla_imageinputtypetelemetry_h
10 #include "nsStringFwd.h"
12 class nsIPrincipal;
14 namespace mozilla {
15 class InternalClipboardEvent;
16 class WidgetDragEvent;
17 namespace dom {
18 class Blob;
19 class DataTransfer;
20 } // namespace dom
22 // Class for collection of image input file type and input type telemetry.
23 class ImageInputTelemetry {
24 public:
25 enum ImageInputType {
26 Drop,
27 Paste,
28 FilePicker,
31 // Collect telemetry on drop of user image input to the browser. This is
32 // collected in DragEvent:GetDataTransfer(). Telemetry is not collected
33 // for about:* pages (e.g. newtab) and for system principals (e.g. drop on
34 // about:preferences).
35 static void MaybeRecordDropImageInputTelemetry(
36 WidgetDragEvent* aDragEvent, nsIPrincipal* aContentPrincipal);
37 // Collect telemetry on paste of user image input to the browser. This is
38 // collected in ClipboardEvent:GetClipboardData(). Telemetry is not collected
39 // for about:* pages (e.g. searchbar in about:preferences) and for system
40 // principals (e.g. paste to urlbar).
41 static void MaybeRecordPasteImageInputTelemetry(
42 InternalClipboardEvent* aClipboardEvent, nsIPrincipal* aContentPrincipal);
43 // Collect telemetry on user selection of image files through the FilePicker.
44 // The telemetry is collected in
45 // HTMLInputElement::nsFilePickerShownCallback::Done(), both for single and
46 // multiple collected files.
47 static void MaybeRecordFilePickerImageInputTelemetry(
48 dom::Blob* aFilePickerBlob);
50 private:
51 ImageInputTelemetry() = default;
52 ~ImageInputTelemetry() = default;
54 // This function returns true if kKnownImageMIMETypes contains aFileInputType.
55 static bool IsKnownImageMIMEType(const nsCString& aInputFileType);
56 // This function returns true if aContentPincipal is of any page possibly
57 // collectiing user data (including local e.g. html pages).
58 static bool IsContentPrincipal(nsIPrincipal* aContentPrincipal);
59 // Iterate through input files from aDataTransfer and record a Glean event if
60 // the file is an image of a type contained in kKnownImageMIMETypes.
61 static void MaybeRecordImageInputTelemetry(ImageInputType aInputType,
62 dom::DataTransfer* aDataTransfer);
63 // Wrapper for recording an image_input Glean event containing the image_type
64 // and the input_type (FilePicker, Paste, Drag).
65 static void RecordImageInputTelemetry(const nsCString& aImageType,
66 ImageInputType aInputType);
69 } // namespace mozilla
71 #endif // mozilla_imageinputtypetelemetry_h