2014-06-25 09:12:07 +04:00
|
|
|
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
2015-01-16 17:11:00 +03:00
|
|
|
// vim: set ts=2 sw=2 sts=2 et tw=80: */
|
2013-09-14 03:27:19 +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/.
|
|
|
|
|
2018-07-30 22:25:58 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["FinderParent"];
|
2013-09-14 03:27:19 +04:00
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
const kFissionEnabledPref = "fission.autostart";
|
|
|
|
const kModalHighlightPref = "findbar.modalHighlight";
|
|
|
|
|
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2019-09-18 12:33:52 +03:00
|
|
|
const { XPCOMUtils } = ChromeUtils.import(
|
|
|
|
"resource://gre/modules/XPCOMUtils.jsm"
|
|
|
|
);
|
2019-09-18 02:28:41 +03:00
|
|
|
|
2018-07-30 22:25:58 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"GetClipboardSearchString",
|
|
|
|
"resource://gre/modules/Finder.jsm"
|
|
|
|
);
|
2019-07-05 12:15:43 +03:00
|
|
|
|
2018-07-30 22:25:58 +03:00
|
|
|
ChromeUtils.defineModuleGetter(
|
|
|
|
this,
|
|
|
|
"Rect",
|
|
|
|
"resource://gre/modules/Geometry.jsm"
|
|
|
|
);
|
2015-01-16 17:11:00 +03:00
|
|
|
|
2019-09-18 12:33:52 +03:00
|
|
|
const kPrefLetterboxing = "privacy.resistFingerprinting.letterboxing";
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyPreferenceGetter(
|
|
|
|
this,
|
|
|
|
"isLetterboxingEnabled",
|
|
|
|
kPrefLetterboxing,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2018-07-30 22:25:58 +03:00
|
|
|
function FinderParent(browser) {
|
2015-01-16 17:11:00 +03:00
|
|
|
this._listeners = new Set();
|
2013-09-14 03:27:19 +04:00
|
|
|
this._searchString = null;
|
2019-09-18 02:28:41 +03:00
|
|
|
this._foundSearchString = null;
|
|
|
|
this._lastFoundBrowsingContext = null;
|
2013-09-14 03:27:19 +04:00
|
|
|
|
2015-02-19 03:47:43 +03:00
|
|
|
this.swapBrowser(browser);
|
2013-09-14 03:27:19 +04:00
|
|
|
}
|
|
|
|
|
2018-07-30 22:25:58 +03:00
|
|
|
FinderParent.prototype = {
|
2019-09-18 02:28:41 +03:00
|
|
|
// Called by findbar.js
|
2016-08-26 11:07:54 +03:00
|
|
|
destroy() {},
|
2016-06-09 14:30:49 +03:00
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
get browsingContext() {
|
|
|
|
return this._browser.browsingContext;
|
|
|
|
},
|
2015-02-19 03:47:43 +03:00
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
swapBrowser(aBrowser) {
|
2015-02-19 03:47:43 +03:00
|
|
|
this._browser = aBrowser;
|
|
|
|
// Ideally listeners would have removed themselves but that doesn't happen
|
|
|
|
// right now
|
|
|
|
this._listeners.clear();
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
addResultListener(aListener) {
|
2015-01-16 17:11:00 +03:00
|
|
|
this._listeners.add(aListener);
|
2013-09-14 03:27:19 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
removeResultListener(aListener) {
|
2015-01-16 17:11:00 +03:00
|
|
|
this._listeners.delete(aListener);
|
2013-09-14 03:27:19 +04:00
|
|
|
},
|
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
callListeners(aCallback, aArgs) {
|
2013-09-14 03:27:19 +04:00
|
|
|
for (let l of this._listeners) {
|
2015-02-19 03:47:43 +03:00
|
|
|
// Don't let one callback throwing stop us calling the rest
|
|
|
|
try {
|
2019-09-18 02:28:41 +03:00
|
|
|
l[aCallback].apply(l, aArgs);
|
2016-04-01 03:41:00 +03:00
|
|
|
} catch (e) {
|
2019-09-18 02:28:41 +03:00
|
|
|
if (!l[aCallback]) {
|
2016-04-01 03:41:00 +03:00
|
|
|
Cu.reportError(
|
2019-09-18 02:28:41 +03:00
|
|
|
`Missing ${aCallback} callback on RemoteFinderListener`
|
2016-04-01 03:41:00 +03:00
|
|
|
);
|
2018-04-27 19:41:24 +03:00
|
|
|
} else {
|
|
|
|
Cu.reportError(e);
|
2016-04-01 03:41:00 +03:00
|
|
|
}
|
2015-02-19 03:47:43 +03:00
|
|
|
}
|
2013-09-14 03:27:19 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
getLastFoundBrowsingContext(aList) {
|
|
|
|
// If a search was already performed, returned the last
|
|
|
|
// browsing context where the result was found. However,
|
|
|
|
// ensure that this browsing context is still valid, and
|
|
|
|
// if not, return null.
|
|
|
|
if (aList.includes(this._lastFoundBrowsingContext)) {
|
|
|
|
return this._lastFoundBrowsingContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._lastFoundBrowsingContext = null;
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
sendMessageToContext(aMessageName, aArgs = {}) {
|
|
|
|
// If there is a last found browsing context, use that. Otherwise,
|
|
|
|
// use the top-level browsing context.
|
|
|
|
let browsingContext = null;
|
|
|
|
if (this._lastFoundBrowsingContext) {
|
|
|
|
let list = this.gatherBrowsingContexts(this.browsingContext);
|
|
|
|
let lastBrowsingContext = this.getLastFoundBrowsingContext(list);
|
|
|
|
if (lastBrowsingContext) {
|
|
|
|
browsingContext = lastBrowsingContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!browsingContext) {
|
|
|
|
browsingContext = this.browsingContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
let windowGlobal = browsingContext.currentWindowGlobal;
|
|
|
|
if (windowGlobal) {
|
|
|
|
let actor = windowGlobal.getActor("Finder");
|
|
|
|
actor.sendAsyncMessage(aMessageName, aArgs);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
sendQueryToContext(aMessageName, aArgs, aBrowsingContext) {
|
|
|
|
let windowGlobal = aBrowsingContext.currentWindowGlobal;
|
|
|
|
if (windowGlobal) {
|
|
|
|
let actor = windowGlobal.getActor("Finder");
|
|
|
|
return actor
|
|
|
|
.sendQuery(aMessageName, aArgs)
|
|
|
|
.then(result => result, r => {});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.resolve({});
|
|
|
|
},
|
|
|
|
|
|
|
|
sendMessageToAllContexts(aMessageName, aArgs = {}) {
|
|
|
|
let list = this.gatherBrowsingContexts(this.browsingContext);
|
|
|
|
for (let browsingContext of list) {
|
|
|
|
let windowGlobal = browsingContext.currentWindowGlobal;
|
|
|
|
if (windowGlobal) {
|
|
|
|
let actor = windowGlobal.getActor("Finder");
|
|
|
|
actor.sendAsyncMessage(aMessageName, aArgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
gatherBrowsingContexts(aBrowsingContext) {
|
|
|
|
let list = [aBrowsingContext];
|
|
|
|
|
|
|
|
let children = aBrowsingContext.getChildren();
|
|
|
|
for (let child of children) {
|
|
|
|
list.push(...this.gatherBrowsingContexts(child));
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
},
|
|
|
|
|
|
|
|
// If the modal highlighter is on, and there are no out-of-process child
|
|
|
|
// frames, send a message only to the top-level frame and set the useSubFrames
|
|
|
|
// flag, so that the finder iterator iterates over subframes. If there is
|
|
|
|
// an out-of-process subframe, modal highlighting is disabled.
|
|
|
|
needSubFrameSearch(aList) {
|
|
|
|
let useSubFrames = false;
|
|
|
|
|
|
|
|
let useModalHighlighter = Services.prefs.getBoolPref(kModalHighlightPref);
|
|
|
|
let hasOutOfProcessChild = false;
|
|
|
|
if (useModalHighlighter) {
|
|
|
|
if (Services.prefs.getBoolPref(kFissionEnabledPref)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let browsingContext of aList) {
|
|
|
|
if (
|
|
|
|
browsingContext != this.browsingContext &&
|
|
|
|
browsingContext.currentWindowGlobal.isProcessRoot
|
|
|
|
) {
|
|
|
|
hasOutOfProcessChild = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasOutOfProcessChild) {
|
|
|
|
aList.splice(0);
|
|
|
|
aList.push(this.browsingContext);
|
|
|
|
useSubFrames = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return useSubFrames;
|
|
|
|
},
|
|
|
|
|
|
|
|
onResultFound(aResponse) {
|
|
|
|
this._foundSearchString = aResponse.searchString;
|
|
|
|
// The rect stops being a Geometry.jsm:Rect over IPC.
|
|
|
|
if (aResponse.rect) {
|
|
|
|
aResponse.rect = Rect.fromRect(aResponse.rect);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.callListeners("onFindResult", [aResponse]);
|
|
|
|
},
|
|
|
|
|
2013-09-14 03:27:19 +04:00
|
|
|
get searchString() {
|
2019-09-18 02:28:41 +03:00
|
|
|
return this._foundSearchString;
|
2013-09-14 03:27:19 +04:00
|
|
|
},
|
|
|
|
|
2015-01-16 17:11:00 +03:00
|
|
|
get clipboardSearchString() {
|
|
|
|
return GetClipboardSearchString(this._browser.loadContext);
|
|
|
|
},
|
|
|
|
|
2013-09-14 03:27:19 +04:00
|
|
|
set caseSensitive(aSensitive) {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToAllContexts("Finder:CaseSensitive", {
|
2013-09-14 03:27:19 +04:00
|
|
|
caseSensitive: aSensitive,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-06-28 16:13:53 +03:00
|
|
|
set entireWord(aEntireWord) {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToAllContexts("Finder:EntireWord", {
|
2016-06-28 16:13:53 +03:00
|
|
|
entireWord: aEntireWord,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
async setSearchStringToSelection() {
|
|
|
|
return this.setToSelection("Finder:SetSearchStringToSelection", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
async getInitialSelection() {
|
|
|
|
return this.setToSelection("Finder:GetInitialSelection", true);
|
|
|
|
},
|
|
|
|
|
|
|
|
async setToSelection(aMessage, aInitial) {
|
|
|
|
let browsingContext = this.browsingContext;
|
|
|
|
|
|
|
|
// Iterate over focused subframe descendants until one is found
|
|
|
|
// that has the selection.
|
|
|
|
let result;
|
|
|
|
do {
|
|
|
|
result = await this.sendQueryToContext(aMessage, {}, browsingContext);
|
|
|
|
if (!result || !result.focusedChildBrowserContextId) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
browsingContext = BrowsingContext.get(
|
|
|
|
result.focusedChildBrowserContextId
|
|
|
|
);
|
|
|
|
} while (browsingContext);
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
this.callListeners("onCurrentSelection", [result.selectedText, aInitial]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
|
|
|
async doFind(aFindNext, aArgs) {
|
|
|
|
let rootBC = this.browsingContext;
|
|
|
|
let highlightList = this.gatherBrowsingContexts(rootBC);
|
|
|
|
|
|
|
|
this._searchString = aArgs.searchString;
|
|
|
|
|
|
|
|
let initialBC = this.getLastFoundBrowsingContext(highlightList);
|
|
|
|
if (!initialBC) {
|
|
|
|
initialBC = rootBC;
|
|
|
|
aFindNext = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make a copy of the list starting from the
|
|
|
|
// browsing context that was last searched from. The original
|
|
|
|
// list will be used for the highlighter where the search
|
|
|
|
// order doesn't matter.
|
|
|
|
let searchList = [];
|
|
|
|
for (let c = 0; c < highlightList.length; c++) {
|
|
|
|
if (highlightList[c] == initialBC) {
|
|
|
|
searchList = highlightList.slice(c);
|
|
|
|
searchList.push(...highlightList.slice(0, c));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mode = Ci.nsITypeAheadFind.FIND_INITIAL;
|
|
|
|
if (aFindNext) {
|
|
|
|
mode = aArgs.findBackwards
|
|
|
|
? Ci.nsITypeAheadFind.FIND_PREVIOUS
|
|
|
|
: Ci.nsITypeAheadFind.FIND_NEXT;
|
|
|
|
}
|
|
|
|
aArgs.findAgain = aFindNext;
|
|
|
|
|
|
|
|
aArgs.useSubFrames = this.needSubFrameSearch(searchList);
|
|
|
|
if (aArgs.useSubFrames) {
|
|
|
|
// Use the single frame for the highlight list as well.
|
|
|
|
highlightList = searchList;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the initial browsing context twice to allow looping around.
|
|
|
|
searchList = [...searchList, initialBC];
|
|
|
|
|
|
|
|
if (aArgs.findBackwards) {
|
|
|
|
searchList.reverse();
|
|
|
|
}
|
|
|
|
|
|
|
|
let response = null;
|
|
|
|
let wrapped = false;
|
|
|
|
let foundBC = null;
|
|
|
|
|
|
|
|
for (let c = 0; c < searchList.length; c++) {
|
|
|
|
let currentBC = searchList[c];
|
|
|
|
aArgs.mode = mode;
|
|
|
|
|
|
|
|
// A search has started for a different string, so
|
|
|
|
// ignore further searches of the old string.
|
|
|
|
if (this._searchString != aArgs.searchString) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-18 12:31:43 +03:00
|
|
|
response = await this.sendQueryToContext("Finder:Find", aArgs, currentBC);
|
2019-09-18 02:28:41 +03:00
|
|
|
|
|
|
|
// This can happen if the tab is closed while the find is in progress.
|
|
|
|
if (!response) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the search term was found, stop iterating.
|
|
|
|
if (response.result != Ci.nsITypeAheadFind.FIND_NOTFOUND) {
|
|
|
|
if (
|
|
|
|
this._lastFoundBrowsingContext &&
|
|
|
|
this._lastFoundBrowsingContext != currentBC
|
|
|
|
) {
|
|
|
|
// If the new result is in a different frame than the previous result,
|
|
|
|
// clear the result from the old frame. If it is the same frame, the
|
|
|
|
// previous result will be cleared by the find component.
|
|
|
|
this.removeSelection(true);
|
|
|
|
}
|
|
|
|
this._lastFoundBrowsingContext = currentBC;
|
|
|
|
|
|
|
|
// Set the wrapped result flag if needed.
|
|
|
|
if (wrapped) {
|
|
|
|
response.result = Ci.nsITypeAheadFind.FIND_WRAPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
foundBC = currentBC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aArgs.findBackwards && currentBC == rootBC) {
|
|
|
|
wrapped = true;
|
|
|
|
} else if (
|
|
|
|
!aArgs.findBackwards &&
|
|
|
|
c + 1 < searchList.length &&
|
|
|
|
searchList[c + 1] == rootBC
|
|
|
|
) {
|
|
|
|
wrapped = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = aArgs.findBackwards
|
|
|
|
? Ci.nsITypeAheadFind.FIND_LAST
|
|
|
|
: Ci.nsITypeAheadFind.FIND_FIRST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response) {
|
|
|
|
response.useSubFrames = aArgs.useSubFrames;
|
|
|
|
// Update the highlight in all browsing contexts. This needs to happen separately
|
|
|
|
// once it is clear whether a match was found or not.
|
|
|
|
this.updateHighlightAndMatchCount({
|
|
|
|
list: highlightList,
|
|
|
|
message: "Finder:UpdateHighlightAndMatchCount",
|
|
|
|
args: response,
|
|
|
|
foundBrowsingContextId: foundBC ? foundBC.id : -1,
|
|
|
|
doHighlight: true,
|
|
|
|
doMatchCount: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Use the last result found.
|
|
|
|
this.onResultFound(response);
|
|
|
|
}
|
2015-01-16 17:11:00 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
fastFind(aSearchString, aLinksOnly, aDrawOutline) {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.doFind(false, {
|
2013-09-14 03:27:19 +04:00
|
|
|
searchString: aSearchString,
|
2019-09-18 02:28:41 +03:00
|
|
|
findBackwards: false,
|
2015-03-25 00:58:32 +03:00
|
|
|
linksOnly: aLinksOnly,
|
|
|
|
drawOutline: aDrawOutline,
|
|
|
|
});
|
2013-09-14 03:27:19 +04:00
|
|
|
},
|
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
findAgain(aSearchString, aFindBackwards, aLinksOnly, aDrawOutline) {
|
|
|
|
this.doFind(true, {
|
|
|
|
searchString: aSearchString,
|
2013-09-14 03:27:19 +04:00
|
|
|
findBackwards: aFindBackwards,
|
2015-03-25 00:58:32 +03:00
|
|
|
linksOnly: aLinksOnly,
|
|
|
|
drawOutline: aDrawOutline,
|
|
|
|
});
|
2013-09-14 03:27:19 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
highlight(aHighlight, aWord, aLinksOnly) {
|
2019-09-18 02:28:41 +03:00
|
|
|
let list = this.gatherBrowsingContexts(this.browsingContext);
|
|
|
|
let args = {
|
2013-09-14 03:27:19 +04:00
|
|
|
highlight: aHighlight,
|
2016-07-28 13:34:13 +03:00
|
|
|
linksOnly: aLinksOnly,
|
2019-09-18 02:28:41 +03:00
|
|
|
searchString: aWord,
|
|
|
|
};
|
|
|
|
|
|
|
|
args.useSubFrames = this.needSubFrameSearch(list);
|
|
|
|
|
|
|
|
let lastBrowsingContext = this.getLastFoundBrowsingContext(list);
|
|
|
|
this.updateHighlightAndMatchCount({
|
|
|
|
list,
|
|
|
|
message: "Finder:Highlight",
|
|
|
|
args,
|
|
|
|
foundBrowsingContextId: lastBrowsingContext ? lastBrowsingContext.id : -1,
|
|
|
|
doHighlight: true,
|
|
|
|
doMatchCount: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
requestMatchesCount(aSearchString, aLinksOnly) {
|
|
|
|
let list = this.gatherBrowsingContexts(this.browsingContext);
|
|
|
|
let args = { searchString: aSearchString, linksOnly: aLinksOnly };
|
|
|
|
|
|
|
|
args.useSubFrames = this.needSubFrameSearch(list);
|
|
|
|
|
|
|
|
let lastBrowsingContext = this.getLastFoundBrowsingContext(list);
|
|
|
|
this.updateHighlightAndMatchCount({
|
|
|
|
list,
|
|
|
|
message: "Finder:MatchesCount",
|
|
|
|
args,
|
|
|
|
foundBrowsingContextId: lastBrowsingContext ? lastBrowsingContext.id : -1,
|
|
|
|
doHighlight: false,
|
|
|
|
doMatchCount: true,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
updateHighlightAndMatchCount(options) {
|
|
|
|
let promises = [];
|
|
|
|
let found = options.args.result != Ci.nsITypeAheadFind.FIND_NOTFOUND;
|
|
|
|
for (let browsingContext of options.list) {
|
|
|
|
options.args.foundInThisFrame =
|
|
|
|
options.foundBrowsingContextId != -1 &&
|
|
|
|
found &&
|
|
|
|
browsingContext.id == options.foundBrowsingContextId;
|
|
|
|
|
|
|
|
// Don't wait for the result
|
|
|
|
let promise = this.sendQueryToContext(
|
|
|
|
options.message,
|
|
|
|
options.args,
|
|
|
|
browsingContext
|
|
|
|
);
|
|
|
|
promises.push(promise);
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise.all(promises).then(responses => {
|
|
|
|
if (options.doHighlight) {
|
|
|
|
let sendNotification = false;
|
|
|
|
let highlight = false;
|
|
|
|
let found = false;
|
|
|
|
for (let response of responses) {
|
|
|
|
if (!response) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendNotification = true;
|
|
|
|
if (response.found) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
highlight = response.highlight;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendNotification) {
|
|
|
|
this.callListeners("onHighlightFinished", [
|
|
|
|
{ searchString: options.args.searchString, highlight, found },
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.doMatchCount) {
|
|
|
|
let sendNotification = false;
|
|
|
|
let current = 0;
|
|
|
|
let total = 0;
|
|
|
|
let limit = 0;
|
|
|
|
for (let response of responses) {
|
|
|
|
// A null response can happen if another search was started
|
|
|
|
// and this one became invalid.
|
|
|
|
if (!response || !("total" in response)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sendNotification = true;
|
|
|
|
|
|
|
|
if (
|
|
|
|
options.args.useSubFrames ||
|
|
|
|
(options.foundBrowsingContextId >= 0 &&
|
|
|
|
response.browsingContextId == options.foundBrowsingContextId)
|
|
|
|
) {
|
|
|
|
current = total + response.current;
|
|
|
|
}
|
|
|
|
total += response.total;
|
|
|
|
limit = response.limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sendNotification) {
|
|
|
|
this.callListeners("onMatchesCountResult", [
|
|
|
|
{ searchString: options.args.searchString, current, total, limit },
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
2013-09-14 03:27:19 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
enableSelection() {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToContext("Finder:EnableSelection");
|
2013-10-16 04:02:23 +04:00
|
|
|
},
|
|
|
|
|
2019-09-18 02:28:41 +03:00
|
|
|
removeSelection(aKeepHighlight) {
|
|
|
|
this.sendMessageToContext("Finder:RemoveSelection", {
|
|
|
|
keepHighlight: aKeepHighlight,
|
|
|
|
});
|
2013-09-14 03:27:19 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
focusContent() {
|
2014-09-04 23:17:47 +04:00
|
|
|
// Allow Finder listeners to cancel focusing the content.
|
|
|
|
for (let l of this._listeners) {
|
|
|
|
try {
|
|
|
|
if ("shouldFocusContent" in l && !l.shouldFocusContent()) {
|
|
|
|
return;
|
2019-07-05 12:15:43 +03:00
|
|
|
}
|
2014-09-04 23:17:47 +04:00
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:58:32 +03:00
|
|
|
this._browser.focus();
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToContext("Finder:FocusContent");
|
2013-09-14 03:27:19 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onFindbarClose() {
|
2019-09-18 02:28:41 +03:00
|
|
|
this._lastFoundBrowsingContext = null;
|
|
|
|
this.sendMessageToAllContexts("Finder:FindbarClose");
|
2019-09-18 12:33:52 +03:00
|
|
|
|
|
|
|
if (isLetterboxingEnabled) {
|
|
|
|
let window = this._browser.ownerGlobal;
|
|
|
|
if (window.RFPHelper) {
|
|
|
|
window.RFPHelper.contentSizeUpdated(window);
|
|
|
|
}
|
|
|
|
}
|
2016-06-09 14:30:49 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onFindbarOpen() {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToAllContexts("Finder:FindbarOpen");
|
2019-09-18 12:33:52 +03:00
|
|
|
|
|
|
|
if (isLetterboxingEnabled) {
|
|
|
|
let window = this._browser.ownerGlobal;
|
|
|
|
if (window.RFPHelper) {
|
|
|
|
window.RFPHelper.contentSizeUpdated(window);
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 12:23:47 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onModalHighlightChange(aUseModalHighlight) {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToAllContexts("Finder:ModalHighlightChange", {
|
|
|
|
useModalHighlight: aUseModalHighlight,
|
|
|
|
});
|
2016-06-09 14:30:49 +03:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onHighlightAllChange(aHighlightAll) {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToAllContexts("Finder:HighlightAllChange", {
|
2018-08-31 08:59:17 +03:00
|
|
|
highlightAll: aHighlightAll,
|
2016-07-27 17:37:26 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
keyPress(aEvent) {
|
2019-09-18 02:28:41 +03:00
|
|
|
this.sendMessageToContext("Finder:KeyPress", {
|
2013-09-14 03:27:19 +04:00
|
|
|
keyCode: aEvent.keyCode,
|
2015-06-12 20:07:00 +03:00
|
|
|
ctrlKey: aEvent.ctrlKey,
|
|
|
|
metaKey: aEvent.metaKey,
|
|
|
|
altKey: aEvent.altKey,
|
2013-09-14 03:27:19 +04:00
|
|
|
shiftKey: aEvent.shiftKey,
|
|
|
|
});
|
2014-07-10 03:27:37 +04:00
|
|
|
},
|
2017-10-15 21:50:30 +03:00
|
|
|
};
|