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. * @returns {boolean} Whether this provider should be invoked for the search.
*/ */
isActive(queryContext) { isActive(queryContext) {
this.#resultFromLastQuery = null;
// When Rust is enabled and keywords are not defined in Nimbus, weather // When Rust is enabled and keywords are not defined in Nimbus, weather
// results are created by the quick suggest provider, not this one. // results are created by the quick suggest provider, not this one.
if ( if (
@@ -141,7 +139,6 @@ class ProviderWeather extends UrlbarProvider {
result.payload.source = weather.suggestion.source; result.payload.source = weather.suggestion.source;
result.payload.provider = weather.suggestion.provider; result.payload.provider = weather.suggestion.provider;
addCallback(this, result); addCallback(this, result);
this.#resultFromLastQuery = result;
} }
} }
@@ -162,35 +159,14 @@ class ProviderWeather extends UrlbarProvider {
return lazy.QuickSuggest.weather.getViewUpdate(result); return lazy.QuickSuggest.weather.getViewUpdate(result);
} }
onLegacyEngagement(state, queryContext, details, controller) { onEngagement(queryContext, controller, details) {
// 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( this.#recordEngagementTelemetry(
result, details.result,
controller.input.isPrivate, controller.input.isPrivate,
details.result == result ? details.selType : "" details.selType
); );
}
}
// Handle commands. // Handle commands.
if (details.result?.providerName == this.name) {
this.#handlePossibleCommand( this.#handlePossibleCommand(
controller.view, controller.view,
details.result, details.result,
@@ -198,22 +174,11 @@ class ProviderWeather extends UrlbarProvider {
); );
} }
this.#resultFromLastQuery = null; onImpression(state, queryContext, controller, providerVisibleResults) {
for (let i = 0; i < providerVisibleResults.length; i++) {
const { result } = providerVisibleResults[i];
this.#recordEngagementTelemetry(result, controller.input.isPrivate, "");
} }
#getVisibleResultFromLastQuery(view) {
let result = this.#resultFromLastQuery;
if (
result?.rowIndex >= 0 &&
view?.visibleResults?.[result.rowIndex] == result
) {
// The result was visible.
return result;
}
// 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) { #handlePossibleCommand(view, result, selType) {
lazy.QuickSuggest.weather.handleCommand(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(); export var UrlbarProviderWeather = new ProviderWeather();

View File

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