summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/GeckoViewPrintDelegateParent.sys.mjs
blob: 9e8f85a4a5e93daa5eb5bf0d2add9a93ff383cac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";

export class GeckoViewPrintDelegateParent extends GeckoViewActorParent {
  constructor() {
    super();
    this._browserStaticClone = null;
  }

  set browserStaticClone(staticClone) {
    this._browserStaticClone = staticClone;
  }

  get browserStaticClone() {
    return this._browserStaticClone;
  }

  clearStaticClone() {
    // Removes static browser element from DOM that was made for window.print
    this.browserStaticClone?.remove();
    this.browserStaticClone = null;
  }

  telemetryDotPrintRequested() {
    Glean.dotprint.requested.add(1);
  }

  telemetryDotPrintPdfCompleted(status) {
    if (status.isPdfSuccessful) {
      Glean.dotprint.androidDialogRequested.add(1);
    } else {
      var reason = "";
      switch (status.errorReason) {
        // ERROR_PRINT_SETTINGS_SERVICE_NOT_AVAILABLE
        case -1: {
          reason = "no_settings_service";
          break;
        }
        // ERROR_UNABLE_TO_CREATE_PRINT_SETTINGS
        case -2: {
          reason = "no_settings";
          break;
        }
        // ERROR_UNABLE_TO_RETRIEVE_CANONICAL_BROWSING_CONTEXT
        case -3: {
          reason = "no_canonical_context";
          break;
        }
        // ERROR_NO_ACTIVITY_CONTEXT_DELEGATE
        case -4: {
          reason = "no_activity_context_delegate";
          break;
        }
        // ERROR_NO_ACTIVITY_CONTEXT
        case -5: {
          reason = "no_activity_context";
          break;
        }
        default:
          reason = "unknown";
      }
      Glean.dotprint.failure[reason].add(1);
    }
  }

  printRequest() {
    if (this.browserStaticClone != null) {
      this.telemetryDotPrintRequested();
      this.eventDispatcher.sendRequest({
        type: "GeckoView:DotPrintRequest",
        canonicalBrowsingContextId: this.browserStaticClone.browsingContext.id,
      });
    }
  }
}