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 {ActorChild} = ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
12 const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
13 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
15 class KeyPressEventModelCheckerChild extends ActorChild {
16 // Currently, the event is dispatched only when the document becomes editable
17 // because of contenteditable. If you need to add new editor which is in
18 // designMode, you need to change MaybeDispatchCheckKeyPressEventModelEvent()
21 if (!AppConstants.DEBUG) {
22 // Stop propagation in opt build to save the propagation cost.
23 // However, the event is necessary for running test_bug1514940.html.
24 // Therefore, we need to keep propagating it at least on debug build.
25 aEvent.stopImmediatePropagation();
28 // Currently, even if we set HTMLDocument.KEYPRESS_EVENT_MODEL_CONFLATED
29 // here, conflated model isn't used forcibly. If you need it, you need
30 // to change WidgetKeyboardEvent, dom::KeyboardEvent and PresShell.
31 let model = HTMLDocument.KEYPRESS_EVENT_MODEL_DEFAULT;
32 if (this._isOldConfluence(aEvent.target.ownerGlobal)) {
33 model = HTMLDocument.KEYPRESS_EVENT_MODEL_SPLIT;
35 aEvent.target.setKeyPressEventModel(model);
38 _isOldConfluence(aWindow) {
42 // aWindow should be an editor window in <iframe>. However, we don't know
43 // whether it can be without <iframe>. Anyway, there should be tinyMCE
44 // object in the parent window or in the window.
46 // First, try to retrieve tinyMCE object from parent window.
48 tinyMCEObject = ChromeUtils.waiveXrays(aWindow.parent).tinyMCE;
50 // Ignore the exception for now.
52 // Next, if there is no tinyMCE object in the parent window, let's check
56 tinyMCEObject = ChromeUtils.waiveXrays(aWindow).tinyMCE;
58 // Fallthrough to return false below.
60 // If we couldn't find tinyMCE object, let's assume that it's not
61 // Confluence instance.
66 // If there is tinyMCE object, we can assume that we loaded Confluence
67 // instance. So, let's check the version whether it allows conflated
68 // keypress event model.
70 let {author, version} =
71 new tinyMCEObject.plugins.CursorTargetPlugin().getInfo();
72 // If it's not Confluence, don't include it into the telemetry because
73 // we just need to collect percentage of old version in all loaded
74 // Confluence instances.
75 if (author !== "Atlassian") {
78 let isOldVersion = version === "1.0";
79 Services.telemetry.keyedScalarAdd("dom.event.confluence_load_count",
80 isOldVersion ? "old" : "new", 1);