gecko-dev/toolkit/actors/FinderChild.jsm
Felipe Gomes 93a0f8e0fd Bug 1490810 - Simulate Fission for browser actors by blocking them from receiving sub-frame events. r=kmag
If the pref browser.fission.simulate is true, the event dispatcher in ActorManagerChild will not dispatch events to actors that aren't associated with the same window as the event's target.

In addition, when that pref is on, the actors associated with sub-frames will have their content property bound to the correct content window, that might differ from the message manager's window (which is always related to the top level).

Then, in order to write Fission-compatible code, that specific actor will need to be declared with allFrames = true, meaning that it wants to be instantiated for every frame, and not just top-level ones

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

--HG--
extra : moz-landing-system : lando
2018-09-26 21:46:18 +00:00

138 lines
3.8 KiB
JavaScript

// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
// vim: set ts=2 sw=2 sts=2 et tw=80: */
// 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/.
var EXPORTED_SYMBOLS = ["FinderChild"];
ChromeUtils.import("resource://gre/modules/ActorChild.jsm");
ChromeUtils.defineModuleGetter(this, "Finder",
"resource://gre/modules/Finder.jsm");
const MESSAGES = [
"Finder:CaseSensitive",
"Finder:EntireWord",
"Finder:FastFind",
"Finder:FindAgain",
"Finder:SetSearchStringToSelection",
"Finder:GetInitialSelection",
"Finder:Highlight",
"Finder:HighlightAllChange",
"Finder:EnableSelection",
"Finder:RemoveSelection",
"Finder:FocusContent",
"Finder:FindbarClose",
"Finder:FindbarOpen",
"Finder:KeyPress",
"Finder:MatchesCount",
"Finder:ModalHighlightChange",
];
class FinderChild extends ActorChild {
constructor(dispatcher) {
super(dispatcher);
this._finder = new Finder(this.docShell);
this._finder.addResultListener(this);
for (let msg of MESSAGES) {
this.mm.addMessageListener(msg, this);
}
}
onFindResult(aData) {
this.mm.sendAsyncMessage("Finder:Result", aData);
}
// When the child receives messages with results of requestMatchesCount,
// it passes them forward to the parent.
onMatchesCountResult(aData) {
this.mm.sendAsyncMessage("Finder:MatchesResult", aData);
}
onHighlightFinished(aData) {
this.mm.sendAsyncMessage("Finder:HighlightFinished", aData);
}
receiveMessage(aMessage) {
let data = aMessage.data;
switch (aMessage.name) {
case "Finder:CaseSensitive":
this._finder.caseSensitive = data.caseSensitive;
break;
case "Finder:EntireWord":
this._finder.entireWord = data.entireWord;
break;
case "Finder:SetSearchStringToSelection": {
let selection = this._finder.setSearchStringToSelection();
this.mm.sendAsyncMessage("Finder:CurrentSelectionResult",
{ selection,
initial: false });
break;
}
case "Finder:GetInitialSelection": {
let selection = this._finder.getActiveSelectionText();
this.mm.sendAsyncMessage("Finder:CurrentSelectionResult",
{ selection,
initial: true });
break;
}
case "Finder:FastFind":
this._finder.fastFind(data.searchString, data.linksOnly, data.drawOutline);
break;
case "Finder:FindAgain":
this._finder.findAgain(data.findBackwards, data.linksOnly, data.drawOutline);
break;
case "Finder:Highlight":
this._finder.highlight(data.highlight, data.word, data.linksOnly);
break;
case "Finder:HighlightAllChange":
this._finder.onHighlightAllChange(data.highlightAll);
break;
case "Finder:EnableSelection":
this._finder.enableSelection();
break;
case "Finder:RemoveSelection":
this._finder.removeSelection();
break;
case "Finder:FocusContent":
this._finder.focusContent();
break;
case "Finder:FindbarClose":
this._finder.onFindbarClose();
break;
case "Finder:FindbarOpen":
this._finder.onFindbarOpen();
break;
case "Finder:KeyPress":
var KeyboardEvent = this._finder._getWindow().KeyboardEvent;
this._finder.keyPress(new KeyboardEvent("keypress", data));
break;
case "Finder:MatchesCount":
this._finder.requestMatchesCount(data.searchString, data.linksOnly);
break;
case "Finder:ModalHighlightChange":
this._finder.onModalHighlightChange(data.useModalHighlight);
break;
}
}
}