This integrates Rust exposure suggestions with desktop. Exposure suggestions are a part of the replacement for the existing potential exposures feature (bug 1881875). When we want to test potential exposures in the future, we can add new exposure suggestions to remote settings and tell the Rust component to ingest them and return them in queries. When the Rust component returns an exposure suggestion, desktop will record it in exposure telemetry. (The other part of the replacement is keyword exposure telemetry in bug 1915507 D220501). More details about the design of exposure suggestions here: * Bug 1893086 * https://github.com/mozilla/application-services/pull/6343 The way desktop tells the Rust component about different types of exposure suggestions is through the new "provider constraints" feature. `ingest()` and `query()` can take a `SuggestionProviderConstraints` object that changes what's ingested and queried. Therefore, we need to re-ingest exposure suggestions when the provider constraints change. Right now, exposure suggestions are the only kind of suggestions that use provider constraints. Depends on D220359 Differential Revision: https://phabricator.services.mozilla.com/D220359
72 lines
2.3 KiB
JavaScript
72 lines
2.3 KiB
JavaScript
/* 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/. */
|
|
|
|
import { BaseFeature } from "resource:///modules/urlbar/private/BaseFeature.sys.mjs";
|
|
|
|
const lazy = {};
|
|
|
|
ChromeUtils.defineESModuleGetters(lazy, {
|
|
UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
|
|
UrlbarResult: "resource:///modules/UrlbarResult.sys.mjs",
|
|
UrlbarUtils: "resource:///modules/UrlbarUtils.sys.mjs",
|
|
});
|
|
|
|
/**
|
|
* A feature for exposure suggestions.
|
|
*/
|
|
export class ExposureSuggestions extends BaseFeature {
|
|
get shouldEnable() {
|
|
return !!this.exposureSuggestionTypes.size;
|
|
}
|
|
|
|
get enablingPreferences() {
|
|
return ["quicksuggest.exposureSuggestionTypes"];
|
|
}
|
|
|
|
get rustSuggestionTypes() {
|
|
return ["Exposure"];
|
|
}
|
|
|
|
getRustProviderConstraints() {
|
|
return {
|
|
exposureSuggestionTypes: [...this.exposureSuggestionTypes],
|
|
};
|
|
}
|
|
|
|
getSuggestionTelemetryType() {
|
|
return "exposure";
|
|
}
|
|
|
|
get exposureSuggestionTypes() {
|
|
// UrlbarPrefs converts this pref to a `Set` of type strings.
|
|
return lazy.UrlbarPrefs.get("quicksuggest.exposureSuggestionTypes");
|
|
}
|
|
|
|
async makeResult(queryContext, suggestion, _searchString) {
|
|
// It doesn't really matter what kind of result we return since it won't be
|
|
// shown. Use a dynamic result since that kind of makes sense and there are
|
|
// no requirements for its payload other than `dynamicType`.
|
|
return Object.assign(
|
|
new lazy.UrlbarResult(
|
|
lazy.UrlbarUtils.RESULT_TYPE.DYNAMIC,
|
|
lazy.UrlbarUtils.RESULT_SOURCE.SEARCH,
|
|
{
|
|
// Include `exposureSuggestionType` so tests can verify a suggestion
|
|
// of the expected type is returned. We don't use it otherwise.
|
|
exposureSuggestionType: suggestion.suggestionType,
|
|
dynamicType: "exposure",
|
|
}
|
|
),
|
|
{
|
|
// Exposure suggestions should always be hidden, and it's assumed that
|
|
// exposure telemetry should be recorded for them, so as a convenience
|
|
// set `exposureTelemetry` here. Otherwise experiments would need to set
|
|
// the corresponding Nimbus variables properly. (They can still do that,
|
|
// it's just not required.)
|
|
exposureTelemetry: lazy.UrlbarUtils.EXPOSURE_TELEMETRY.HIDDEN,
|
|
}
|
|
);
|
|
}
|
|
}
|