Bug 1538021 - Use owner of WindowEventDispatcher as window for messaging. r=yzen

Differential Revision: https://phabricator.services.mozilla.com/D24442

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Eitan Isaacson 2019-03-23 21:22:02 +00:00
parent 9a387fad8c
commit 0bcec64436
4 changed files with 54 additions and 42 deletions

View File

@ -115,9 +115,13 @@ var AccessFu = {
mm.loadFrameScript(FRAME_SCRIPT, true);
win.addEventListener("TabSelect", this);
if (win.WindowEventDispatcher) {
if (win.WindowEventDispatcher && !this._eventDispatcherListeners.has(win)) {
const listener = (event, data, callback) => {
this.onEvent(event, data, callback, win);
};
this._eventDispatcherListeners.set(win, listener);
// desktop mochitests don't have this.
win.WindowEventDispatcher.registerListener(this,
win.WindowEventDispatcher.registerListener(listener,
Object.values(GECKOVIEW_MESSAGE));
}
},
@ -131,14 +135,16 @@ var AccessFu = {
}
win.removeEventListener("TabSelect", this);
if (win.WindowEventDispatcher) {
if (win.WindowEventDispatcher && this._eventDispatcherListeners.has(win)) {
// desktop mochitests don't have this.
win.WindowEventDispatcher.unregisterListener(this,
win.WindowEventDispatcher.unregisterListener(
this._eventDispatcherListeners.get(win),
Object.values(GECKOVIEW_MESSAGE));
this._eventDispatcherListeners.delete(win);
}
},
onEvent(event, data, callback) {
onEvent(event, data, callback, win) {
switch (event) {
case GECKOVIEW_MESSAGE.SETTINGS:
if (data.enabled) {
@ -155,35 +161,35 @@ var AccessFu = {
data.rule.substr(1).toLowerCase();
}
let method = event.replace(/GeckoView:Accessibility(\w+)/, "move$1");
this.Input.moveCursor(method, rule, "gesture");
this.Input.moveCursor(method, rule, "gesture", win);
break;
}
case GECKOVIEW_MESSAGE.ACTIVATE:
this.Input.activateCurrent(data);
this.Input.activateCurrent(data, win);
break;
case GECKOVIEW_MESSAGE.LONG_PRESS:
// XXX: Advertize long press on supported objects and implement action
break;
case GECKOVIEW_MESSAGE.SCROLL_FORWARD:
this.Input.androidScroll("forward");
this.Input.androidScroll("forward", win);
break;
case GECKOVIEW_MESSAGE.SCROLL_BACKWARD:
this.Input.androidScroll("backward");
this.Input.androidScroll("backward", win);
break;
case GECKOVIEW_MESSAGE.CURSOR_TO_FOCUSED:
this.autoMove({ moveToFocused: true });
this.autoMove({ moveToFocused: true }, win);
break;
case GECKOVIEW_MESSAGE.BY_GRANULARITY:
this.Input.moveByGranularity(data);
this.Input.moveByGranularity(data, win);
break;
case GECKOVIEW_MESSAGE.EXPLORE_BY_TOUCH:
this.Input.moveToPoint("Simple", ...data.coordinates);
this.Input.moveToPoint("Simple", ...data.coordinates, win);
break;
case GECKOVIEW_MESSAGE.SET_SELECTION:
this.Input.setSelection(data);
this.Input.setSelection(data, win);
break;
case GECKOVIEW_MESSAGE.CLIPBOARD:
this.Input.clipboard(data);
this.Input.clipboard(data, win);
break;
}
},
@ -221,8 +227,8 @@ var AccessFu = {
}
},
autoMove: function autoMove(aOptions) {
const mm = Utils.getMessageManager();
autoMove: function autoMove(aOptions, aWindow) {
const mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:AutoMove", aOptions);
},
@ -232,6 +238,8 @@ var AccessFu = {
// Layerview is focused
_focused: false,
_eventDispatcherListeners: new WeakMap(),
/**
* Adjusts the given bounds that are defined in device display pixels
* to client-relative CSS pixels of the chrome window.
@ -251,43 +259,43 @@ var AccessFu = {
};
var Input = {
moveToPoint: function moveToPoint(aRule, aX, aY) {
const mm = Utils.getMessageManager();
moveToPoint: function moveToPoint(aRule, aX, aY, aWindow) {
Logger.debug("moveToPoint", aX, aY);
const mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:MoveToPoint",
{rule: aRule, x: aX, y: aY, origin: "top"});
},
moveCursor: function moveCursor(aAction, aRule, aInputType, aAdjustRange) {
const mm = Utils.getMessageManager();
moveCursor: function moveCursor(aAction, aRule, aInputType, aWindow) {
const mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:MoveCursor",
{ action: aAction, rule: aRule,
origin: "top", inputType: aInputType,
adjustRange: aAdjustRange });
origin: "top", inputType: aInputType });
},
androidScroll: function androidScroll(aDirection) {
const mm = Utils.getMessageManager();
androidScroll: function androidScroll(aDirection, aWindow) {
const mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:AndroidScroll",
{ direction: aDirection, origin: "top" });
},
moveByGranularity: function moveByGranularity(aDetails) {
const mm = Utils.getMessageManager();
moveByGranularity: function moveByGranularity(aDetails, aWindow) {
const mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:MoveByGranularity", aDetails);
},
setSelection: function setSelection(aDetails) {
const mm = Utils.getMessageManager();
setSelection: function setSelection(aDetails, aWindow) {
const mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:SetSelection", aDetails);
},
clipboard: function clipboard(aDetails) {
const mm = Utils.getMessageManager();
clipboard: function clipboard(aDetails, aWindow) {
const mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:Clipboard", aDetails);
},
activateCurrent: function activateCurrent(aData) {
let mm = Utils.getMessageManager();
activateCurrent: function activateCurrent(aData, aWindow) {
let mm = Utils.getCurrentMessageManager(aWindow);
mm.sendAsyncMessage("AccessFu:Activate", { offset: 0 });
},

View File

@ -131,7 +131,7 @@ this.ContentControl.prototype = {
if (moved) {
if (origin === "child") {
// We just stepped out of a child, clear child cursor.
Utils.getMessageManager(aMessage.target).sendAsyncMessage(
Utils.getMessageManagerForFrame(aMessage.target).sendAsyncMessage(
"AccessFu:ClearCursor", {});
} else {
// We potentially landed on a new child cursor. If so, we want to
@ -378,7 +378,7 @@ this.ContentControl.prototype = {
let domNode = acc.DOMNode;
let mm = this._childMessageSenders.get(domNode, null);
if (!mm) {
mm = Utils.getMessageManager(domNode);
mm = Utils.getMessageManagerForFrame(domNode);
mm.addWeakMessageListener("AccessFu:MoveCursor", this);
this._childMessageSenders.set(domNode, mm);
}

View File

@ -44,7 +44,7 @@ BaseTraversalRule.prototype = {
match: function BaseTraversalRule_match(aAccessible) {
let role = aAccessible.role;
if (role == Roles.INTERNAL_FRAME) {
return (Utils.getMessageManager(aAccessible.DOMNode)) ?
return (Utils.getMessageManagerForFrame(aAccessible.DOMNode)) ?
Filters.MATCH | Filters.IGNORE_SUBTREE : Filters.IGNORE;
}

View File

@ -76,10 +76,7 @@ var Utils = { // jshint ignore:line
},
getCurrentBrowser: function getCurrentBrowser(aWindow) {
let win = aWindow ||
Services.wm.getMostRecentWindow("navigator:browser") ||
Services.wm.getMostRecentWindow("navigator:geckoview");
return win.document.querySelector("browser[type=content][primary=true]");
return aWindow.document.querySelector("browser[type=content][primary=true]");
},
get isContentProcess() {
@ -133,10 +130,17 @@ var Utils = { // jshint ignore:line
return this.stringBundle;
},
getMessageManager: function getMessageManager(aBrowser) {
let browser = aBrowser || this.getCurrentBrowser();
getCurrentMessageManager: function getCurrentMessageManager(aWindow) {
try {
return browser.frameLoader.messageManager;
return this.getCurrentBrowser(aWindow).frameLoader.messageManager;
} catch (x) {
return null;
}
},
getMessageManagerForFrame: function getMessageManagerForFrame(aFrame) {
try {
return aFrame.frameLoader.messageManager;
} catch (x) {
return null;
}