Bug 1897245 - Convert the Weather provider onLegacyEngagement to use the new notifications. r=adw,urlbar-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D216687
This commit is contained in:
Karandeep
2024-07-19 19:41:51 +00:00
parent ea3243f101
commit b45f0d53f2
2 changed files with 31 additions and 60 deletions

View File

@@ -78,8 +78,6 @@ class ProviderWeather extends UrlbarProvider {
* @returns {boolean} Whether this provider should be invoked for the search.
*/
isActive(queryContext) {
this.#resultFromLastQuery = null;
// When Rust is enabled and keywords are not defined in Nimbus, weather
// results are created by the quick suggest provider, not this one.
if (
@@ -141,7 +139,6 @@ class ProviderWeather extends UrlbarProvider {
result.payload.source = weather.suggestion.source;
result.payload.provider = weather.suggestion.provider;
addCallback(this, result);
this.#resultFromLastQuery = result;
}
}
@@ -162,58 +159,26 @@ class ProviderWeather extends UrlbarProvider {
return lazy.QuickSuggest.weather.getViewUpdate(result);
}
onLegacyEngagement(state, queryContext, details, controller) {
// Ignore engagements on other results that didn't end the session.
if (details.result?.providerName != this.name && details.isSessionOngoing) {
return;
}
// Impression and clicked telemetry are both recorded on engagement. We
// define "impression" to mean a weather result was present in the view when
// any result was picked.
if (state == "engagement" && queryContext) {
// Get the result that's visible in the view. `details.result` is the
// engaged result, if any; if it's from this provider, then that's the
// visible result. Otherwise fall back to #getVisibleResultFromLastQuery.
let { result } = details;
if (result?.providerName != this.name) {
result = this.#getVisibleResultFromLastQuery(controller.view);
}
if (result) {
this.#recordEngagementTelemetry(
result,
controller.input.isPrivate,
details.result == result ? details.selType : ""
);
}
}
onEngagement(queryContext, controller, details) {
this.#recordEngagementTelemetry(
details.result,
controller.input.isPrivate,
details.selType
);
// Handle commands.
if (details.result?.providerName == this.name) {
this.#handlePossibleCommand(
controller.view,
details.result,
details.selType
);
}
this.#resultFromLastQuery = null;
this.#handlePossibleCommand(
controller.view,
details.result,
details.selType
);
}
#getVisibleResultFromLastQuery(view) {
let result = this.#resultFromLastQuery;
if (
result?.rowIndex >= 0 &&
view?.visibleResults?.[result.rowIndex] == result
) {
// The result was visible.
return result;
onImpression(state, queryContext, controller, providerVisibleResults) {
for (let i = 0; i < providerVisibleResults.length; i++) {
const { result } = providerVisibleResults[i];
this.#recordEngagementTelemetry(result, controller.input.isPrivate, "");
}
// Find a visible result.
return view?.visibleResults?.find(r => r.providerName == this.name);
}
/**
@@ -295,9 +260,6 @@ class ProviderWeather extends UrlbarProvider {
#handlePossibleCommand(view, result, selType) {
lazy.QuickSuggest.weather.handleCommand(view, result, selType);
}
// The result we added during the most recent query.
#resultFromLastQuery = null;
}
export var UrlbarProviderWeather = new ProviderWeather();

View File

@@ -723,16 +723,25 @@ add_tasks_with_rust(async function block() {
let result = context.results[0];
let provider = UrlbarProvidersManager.getProvider(result.providerName);
Assert.ok(provider, "Sanity check: Result provider found");
provider.onLegacyEngagement(
"engagement",
context,
{
if (result.providerName === "UrlbarProviderQuickSuggest") {
provider.onLegacyEngagement(
"engagement",
context,
{
result,
selType: "dismiss",
selIndex: context.results[0].rowIndex,
},
controller
);
} else {
provider.onEngagement(context, controller, {
result,
selType: "dismiss",
selIndex: context.results[0].rowIndex,
},
controller
);
});
}
Assert.ok(
!UrlbarPrefs.get("suggest.weather"),
"suggest.weather is false after blocking the result"