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/. */
9 var EXPORTED_SYMBOLS = ["KeyPressEventModelCheckerChild"];
11 const { AppConstants } = ChromeUtils.import(
12 "resource://gre/modules/AppConstants.jsm"
14 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
16 class KeyPressEventModelCheckerChild extends JSWindowActorChild {
17 // Currently, the event is dispatched only when the document becomes editable
18 // because of contenteditable. If you need to add new editor which is in
19 // designMode, you need to change MaybeDispatchCheckKeyPressEventModelEvent()
22 if (!AppConstants.DEBUG) {
23 // Stop propagation in opt build to save the propagation cost.
24 // However, the event is necessary for running test_bug1514940.html.
25 // Therefore, we need to keep propagating it at least on debug build.
26 aEvent.stopImmediatePropagation();
29 // Currently, even if we set Document.KEYPRESS_EVENT_MODEL_CONFLATED
30 // here, conflated model isn't used forcibly. If you need it, you need
31 // to change WidgetKeyboardEvent, dom::KeyboardEvent and PresShell.
32 let model = Document.KEYPRESS_EVENT_MODEL_DEFAULT;
34 this._isOldOfficeOnlineServer(aEvent.target) ||
35 this._isOldConfluence(aEvent.target.ownerGlobal)
37 model = Document.KEYPRESS_EVENT_MODEL_SPLIT;
39 aEvent.target.setKeyPressEventModel(model);
42 _isOldOfficeOnlineServer(aDocument) {
43 let editingElement = aDocument.getElementById(
44 "WACViewPanel_EditingElement"
46 // If it's not Office Online Server, don't include it into the telemetry
47 // because we just need to collect percentage of old version in all loaded
48 // Office Online Server instances.
49 if (!editingElement) {
52 let isOldVersion = !editingElement.classList.contains(
53 "WACViewPanel_DisableLegacyKeyCodeAndCharCode"
55 Services.telemetry.keyedScalarAdd(
56 "dom.event.office_online_load_count",
57 isOldVersion ? "old" : "new",
63 _isOldConfluence(aWindow) {
67 // aWindow should be an editor window in <iframe>. However, we don't know
68 // whether it can be without <iframe>. Anyway, there should be tinyMCE
69 // object in the parent window or in the window.
71 // First, try to retrieve tinyMCE object from parent window.
73 tinyMCEObject = ChromeUtils.waiveXrays(aWindow.parent).tinyMCE;
75 // Ignore the exception for now.
77 // Next, if there is no tinyMCE object in the parent window, let's check
81 tinyMCEObject = ChromeUtils.waiveXrays(aWindow).tinyMCE;
83 // Fallthrough to return false below.
85 // If we couldn't find tinyMCE object, let's assume that it's not
86 // Confluence instance.
91 // If there is tinyMCE object, we can assume that we loaded Confluence
92 // instance. So, let's check the version whether it allows conflated
93 // keypress event model.
98 } = new tinyMCEObject.plugins.CursorTargetPlugin().getInfo();
99 // If it's not Confluence, don't include it into the telemetry because
100 // we just need to collect percentage of old version in all loaded
101 // Confluence instances.
102 if (author !== "Atlassian") {
105 let isOldVersion = version === "1.0";
106 Services.telemetry.keyedScalarAdd(
107 "dom.event.confluence_load_count",
108 isOldVersion ? "old" : "new",