2018-07-30 22:25:58 +03:00
|
|
|
// -*- 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.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"Finder",
|
|
|
|
"resource://gre/modules/Finder.jsm"
|
|
|
|
);
|
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
class FinderChild extends JSWindowActorChild {
|
|
|
|
get finder() {
|
|
|
|
if (!this._finder) {
|
|
|
|
this._finder = new Finder(this.docShell);
|
2018-07-30 22:25:58 +03:00
|
|
|
}
|
2019-09-18 02:28:41 +03:00
|
|
|
return this._finder;
|
2018-07-30 22:25:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
receiveMessage(aMessage) {
|
|
|
|
let data = aMessage.data;
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "Finder:CaseSensitive":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.caseSensitive = data.caseSensitive;
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
2019-12-09 22:26:40 +03:00
|
|
|
case "Finder:MatchDiacritics":
|
|
|
|
this.finder.matchDiacritics = data.matchDiacritics;
|
|
|
|
break;
|
|
|
|
|
2018-07-30 22:25:58 +03:00
|
|
|
case "Finder:EntireWord":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.entireWord = data.entireWord;
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:SetSearchStringToSelection": {
|
2019-09-18 02:28:41 +03:00
|
|
|
return new Promise(resolve => {
|
|
|
|
resolve(this.finder.setSearchStringToSelection());
|
2018-07-30 22:25:58 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
case "Finder:GetInitialSelection": {
|
2019-09-18 02:28:41 +03:00
|
|
|
return new Promise(resolve => {
|
|
|
|
resolve(this.finder.getActiveSelectionText());
|
2018-07-30 22:25:58 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-18 12:31:43 +03:00
|
|
|
case "Finder:Find":
|
|
|
|
return this.finder.find(data);
|
2018-07-30 22:25:58 +03:00
|
|
|
|
|
|
|
case "Finder:Highlight":
|
2019-09-18 02:28:41 +03:00
|
|
|
return this.finder
|
|
|
|
.highlight(
|
|
|
|
data.highlight,
|
|
|
|
data.searchString,
|
|
|
|
data.linksOnly,
|
|
|
|
data.useSubFrames
|
|
|
|
)
|
|
|
|
.then(result => {
|
|
|
|
if (result) {
|
|
|
|
result.browsingContextId = this.browsingContext.id;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
|
|
|
case "Finder:UpdateHighlightAndMatchCount":
|
|
|
|
return this.finder.updateHighlightAndMatchCount(data).then(result => {
|
|
|
|
if (result) {
|
|
|
|
result.browsingContextId = this.browsingContext.id;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
2018-07-30 22:25:58 +03:00
|
|
|
|
|
|
|
case "Finder:HighlightAllChange":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.onHighlightAllChange(data.highlightAll);
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:EnableSelection":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.enableSelection();
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:RemoveSelection":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.removeSelection(data.keepHighlight);
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:FocusContent":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.focusContent();
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:FindbarClose":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.onFindbarClose();
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:FindbarOpen":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.onFindbarOpen();
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:KeyPress":
|
2019-09-18 02:28:41 +03:00
|
|
|
var KeyboardEvent = this.finder._getWindow().KeyboardEvent;
|
|
|
|
this.finder.keyPress(new KeyboardEvent("keypress", data));
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "Finder:MatchesCount":
|
2019-09-18 02:28:41 +03:00
|
|
|
return this.finder
|
|
|
|
.requestMatchesCount(
|
|
|
|
data.searchString,
|
|
|
|
data.linksOnly,
|
|
|
|
data.useSubFrames
|
|
|
|
)
|
|
|
|
.then(result => {
|
|
|
|
if (result) {
|
|
|
|
result.browsingContextId = this.browsingContext.id;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
});
|
2018-07-30 22:25:58 +03:00
|
|
|
|
|
|
|
case "Finder:ModalHighlightChange":
|
2019-09-18 02:28:41 +03:00
|
|
|
this.finder.onModalHighlightChange(data.useModalHighlight);
|
2018-07-30 22:25:58 +03:00
|
|
|
break;
|
|
|
|
}
|
2019-09-18 02:28:41 +03:00
|
|
|
|
|
|
|
return null;
|
2018-07-30 22:25:58 +03:00
|
|
|
}
|
|
|
|
}
|