2012-10-02 00:33:26 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2017-04-27 13:53:38 +03:00
|
|
|
/* eslint-env mozilla/frame-script */
|
|
|
|
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "Logger",
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/Utils.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "Presentation",
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/Presentation.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "Utils",
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/Utils.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "EventManager",
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/EventManager.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "ContentControl",
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/ContentControl.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "Roles",
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/Constants.jsm");
|
2018-01-30 02:20:18 +03:00
|
|
|
ChromeUtils.defineModuleGetter(this, "States",
|
2017-08-01 19:13:27 +03:00
|
|
|
"resource://gre/modules/accessibility/Constants.jsm");
|
|
|
|
|
|
|
|
Logger.info("content-script.js", content.document.location);
|
2012-10-02 00:33:26 +04:00
|
|
|
|
2015-09-15 21:19:45 +03:00
|
|
|
var eventManager = null;
|
|
|
|
var contentControl = null;
|
2013-07-16 22:45:17 +04:00
|
|
|
|
|
|
|
function forwardToParent(aMessage) {
|
|
|
|
// XXX: This is a silly way to make a deep copy
|
|
|
|
let newJSON = JSON.parse(JSON.stringify(aMessage.json));
|
2017-08-01 19:13:27 +03:00
|
|
|
newJSON.origin = "child";
|
2013-07-16 22:45:17 +04:00
|
|
|
sendAsyncMessage(aMessage.name, newJSON);
|
|
|
|
}
|
|
|
|
|
|
|
|
function forwardToChild(aMessage, aListener, aVCPosition) {
|
|
|
|
let acc = aVCPosition || Utils.getVirtualCursor(content.document).position;
|
|
|
|
|
2013-11-19 22:17:43 +04:00
|
|
|
if (!Utils.isAliveAndVisible(acc) || acc.role != Roles.INTERNAL_FRAME) {
|
2013-07-16 22:45:17 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-27 19:42:45 +04:00
|
|
|
Logger.debug(() => {
|
2017-08-01 19:13:27 +03:00
|
|
|
return ["forwardToChild", Logger.accessibleToString(acc),
|
|
|
|
aMessage.name, JSON.stringify(aMessage.json, null, " ")];
|
2014-02-27 19:42:45 +04:00
|
|
|
});
|
2013-07-16 22:45:17 +04:00
|
|
|
|
|
|
|
let mm = Utils.getMessageManager(acc.DOMNode);
|
2014-02-11 22:41:02 +04:00
|
|
|
|
|
|
|
if (aListener) {
|
|
|
|
mm.addMessageListener(aMessage.name, aListener);
|
|
|
|
}
|
|
|
|
|
2013-07-16 22:45:17 +04:00
|
|
|
// XXX: This is a silly way to make a deep copy
|
|
|
|
let newJSON = JSON.parse(JSON.stringify(aMessage.json));
|
2017-08-01 19:13:27 +03:00
|
|
|
newJSON.origin = "parent";
|
2013-07-16 22:45:17 +04:00
|
|
|
if (Utils.isContentProcess) {
|
|
|
|
// XXX: OOP content's screen offset is 0,
|
|
|
|
// so we remove the real screen offset here.
|
|
|
|
newJSON.x -= content.mozInnerScreenX;
|
|
|
|
newJSON.y -= content.mozInnerScreenY;
|
|
|
|
}
|
|
|
|
mm.sendAsyncMessage(aMessage.name, newJSON);
|
|
|
|
return true;
|
2012-10-02 00:33:26 +04:00
|
|
|
}
|
|
|
|
|
2013-07-04 02:20:11 +04:00
|
|
|
function presentCaretChange(aText, aOldOffset, aNewOffset) {
|
|
|
|
if (aOldOffset !== aNewOffset) {
|
|
|
|
let msg = Presentation.textSelectionChanged(aText, aNewOffset, aNewOffset,
|
2013-07-11 23:55:40 +04:00
|
|
|
aOldOffset, aOldOffset, true);
|
2017-08-01 19:13:27 +03:00
|
|
|
sendAsyncMessage("AccessFu:Present", msg);
|
2013-06-20 00:11:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-02 00:33:26 +04:00
|
|
|
function scroll(aMessage) {
|
2014-08-19 23:26:02 +04:00
|
|
|
let position = Utils.getVirtualCursor(content.document).position;
|
|
|
|
if (!forwardToChild(aMessage, scroll, position)) {
|
2017-08-01 19:13:27 +03:00
|
|
|
sendAsyncMessage("AccessFu:DoScroll",
|
2018-04-19 12:31:00 +03:00
|
|
|
{ bounds: Utils.getBounds(position),
|
2013-07-26 19:18:12 +04:00
|
|
|
page: aMessage.json.page,
|
|
|
|
horizontal: aMessage.json.horizontal });
|
2012-10-02 00:33:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addMessageListener(
|
2017-08-01 19:13:27 +03:00
|
|
|
"AccessFu:Start",
|
2012-10-02 00:33:26 +04:00
|
|
|
function(m) {
|
2014-04-02 00:46:02 +04:00
|
|
|
if (m.json.logLevel) {
|
|
|
|
Logger.logLevel = Logger[m.json.logLevel];
|
|
|
|
}
|
|
|
|
|
2017-08-01 19:13:27 +03:00
|
|
|
Logger.debug("AccessFu:Start");
|
2012-10-02 00:33:26 +04:00
|
|
|
if (m.json.buildApp)
|
|
|
|
Utils.MozBuildApp = m.json.buildApp;
|
|
|
|
|
2017-08-01 19:13:27 +03:00
|
|
|
addMessageListener("AccessFu:Scroll", scroll);
|
2013-04-23 21:39:15 +04:00
|
|
|
|
2014-03-05 05:49:27 +04:00
|
|
|
if (!contentControl) {
|
|
|
|
contentControl = new ContentControl(this);
|
|
|
|
}
|
|
|
|
contentControl.start();
|
|
|
|
|
2014-06-13 21:56:38 +04:00
|
|
|
if (!eventManager) {
|
|
|
|
eventManager = new EventManager(this, contentControl);
|
|
|
|
}
|
2014-09-22 20:27:04 +04:00
|
|
|
eventManager.inTest = m.json.inTest;
|
2014-06-13 21:56:38 +04:00
|
|
|
eventManager.start();
|
|
|
|
|
2014-09-30 02:35:29 +04:00
|
|
|
function contentStarted() {
|
2016-08-08 18:47:48 +03:00
|
|
|
let accDoc = Utils.AccService.getAccessibleFor(content.document);
|
2014-09-30 02:35:29 +04:00
|
|
|
if (accDoc && !Utils.getState(accDoc).contains(States.BUSY)) {
|
2017-08-01 19:13:27 +03:00
|
|
|
sendAsyncMessage("AccessFu:ContentStarted");
|
2014-09-30 02:35:29 +04:00
|
|
|
} else {
|
|
|
|
content.setTimeout(contentStarted, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m.json.inTest) {
|
|
|
|
// During a test we want to wait for the document to finish loading for
|
|
|
|
// consistency.
|
|
|
|
contentStarted();
|
|
|
|
}
|
2012-10-02 00:33:26 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
addMessageListener(
|
2017-08-01 19:13:27 +03:00
|
|
|
"AccessFu:Stop",
|
2012-10-02 00:33:26 +04:00
|
|
|
function(m) {
|
2017-08-01 19:13:27 +03:00
|
|
|
Logger.debug("AccessFu:Stop");
|
2012-10-02 00:33:26 +04:00
|
|
|
|
2017-08-01 19:13:27 +03:00
|
|
|
removeMessageListener("AccessFu:Scroll", scroll);
|
2013-04-23 21:39:15 +04:00
|
|
|
|
2013-05-21 22:16:49 +04:00
|
|
|
eventManager.stop();
|
2014-03-05 05:49:27 +04:00
|
|
|
contentControl.stop();
|
2012-10-02 00:33:26 +04:00
|
|
|
});
|
|
|
|
|
2017-08-01 19:13:27 +03:00
|
|
|
sendAsyncMessage("AccessFu:Ready");
|