1 /* -*- mode: js; indent-tabs-mode: nil; js-indent-level: 2 -*- */
2 /* vim: set ts=2 sw=2 sts=2 et 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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
9 export class KeyPressEventModelCheckerChild extends JSWindowActorChild {
10 // Currently, the event is dispatched only when the document becomes editable
11 // because of contenteditable. If you need to add new editor which is in
12 // designMode, you need to change MaybeDispatchCheckKeyPressEventModelEvent()
15 if (!AppConstants.DEBUG) {
16 // Stop propagation in opt build to save the propagation cost.
17 // However, the event is necessary for running test_bug1514940.html.
18 // Therefore, we need to keep propagating it at least on debug build.
19 aEvent.stopImmediatePropagation();
22 // Currently, even if we set Document.KEYPRESS_EVENT_MODEL_CONFLATED
23 // here, conflated model isn't used forcibly. If you need it, you need
24 // to change WidgetKeyboardEvent, dom::KeyboardEvent and PresShell.
25 let model = Document.KEYPRESS_EVENT_MODEL_DEFAULT;
27 this._isOldOfficeOnlineServer(aEvent.target) ||
28 this._isOldConfluence(aEvent.target.ownerGlobal)
30 model = Document.KEYPRESS_EVENT_MODEL_SPLIT;
32 aEvent.target.setKeyPressEventModel(model);
35 _isOldOfficeOnlineServer(aDocument) {
36 let editingElement = aDocument.getElementById(
37 "WACViewPanel_EditingElement"
39 // If it's not Office Online Server, don't include it into the telemetry
40 // because we just need to collect percentage of old version in all loaded
41 // Office Online Server instances.
42 if (!editingElement) {
45 let isOldVersion = !editingElement.classList.contains(
46 "WACViewPanel_DisableLegacyKeyCodeAndCharCode"
48 Services.telemetry.keyedScalarAdd(
49 "dom.event.office_online_load_count",
50 isOldVersion ? "old" : "new",
56 _isOldConfluence(aWindow) {
60 // aWindow should be an editor window in <iframe>. However, we don't know
61 // whether it can be without <iframe>. Anyway, there should be tinyMCE
62 // object in the parent window or in the window.
64 // First, try to retrieve tinyMCE object from parent window.
66 tinyMCEObject = ChromeUtils.waiveXrays(aWindow.parent).tinyMCE;
68 // Ignore the exception for now.
70 // Next, if there is no tinyMCE object in the parent window, let's check
74 tinyMCEObject = ChromeUtils.waiveXrays(aWindow).tinyMCE;
76 // Fallthrough to return false below.
78 // If we couldn't find tinyMCE object, let's assume that it's not
79 // Confluence instance.
84 // If there is tinyMCE object, we can assume that we loaded Confluence
85 // instance. So, let's check the version whether it allows conflated
86 // keypress event model.
88 let { author, version } =
89 new tinyMCEObject.plugins.CursorTargetPlugin().getInfo();
90 // If it's not Confluence, don't include it into the telemetry because
91 // we just need to collect percentage of old version in all loaded
92 // Confluence instances.
93 if (author !== "Atlassian") {
96 let isOldVersion = version === "1.0";
97 Services.telemetry.keyedScalarAdd(
98 "dom.event.confluence_load_count",
99 isOldVersion ? "old" : "new",