Bug 1841762 - Ensure onEngagement has queryContext defined. r=mak
Differential Revision: https://phabricator.services.mozilla.com/D197265
This commit is contained in:
@@ -669,6 +669,15 @@ export class UrlbarController {
|
||||
this.notify(NOTIFICATIONS.QUERY_RESULT_REMOVED, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the query context cache.
|
||||
*
|
||||
* @param {UrlbarQueryContext} queryContext the object to cache.
|
||||
*/
|
||||
setLastQueryContextCache(queryContext) {
|
||||
this._lastQueryContextWrapper = { queryContext };
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the previous query context cache.
|
||||
*/
|
||||
@@ -721,13 +730,14 @@ class TelemetryEvent {
|
||||
* invoking this on every input event as the user is typing, for example.
|
||||
*
|
||||
* @param {event} event A DOM event.
|
||||
* @param {UrlbarQueryContext} queryContext A queryContext.
|
||||
* @param {string} [searchString] Pass a search string related to the event if
|
||||
* you have one. The event by itself sometimes isn't enough to
|
||||
* determine the telemetry details we should record.
|
||||
* @throws This should never throw, or it may break the urlbar.
|
||||
* @see {@link https://firefox-source-docs.mozilla.org/browser/urlbar/telemetry.html}
|
||||
*/
|
||||
start(event, searchString = null) {
|
||||
start(event, queryContext, searchString = null) {
|
||||
if (this._startEventInfo) {
|
||||
if (this._startEventInfo.interactionType == "topsites") {
|
||||
// If the most recent event came from opening the results pane with an
|
||||
@@ -786,7 +796,6 @@ class TelemetryEvent {
|
||||
searchString,
|
||||
};
|
||||
|
||||
let { queryContext } = this._controller._lastQueryContextWrapper || {};
|
||||
this._controller.manager.notifyEngagementChange(
|
||||
"start",
|
||||
queryContext,
|
||||
|
||||
@@ -1598,11 +1598,11 @@ export class UrlbarInput {
|
||||
* will record engagement event telemetry for the query.
|
||||
*/
|
||||
startQuery({
|
||||
allowAutofill = true,
|
||||
allowAutofill,
|
||||
autofillIgnoresSelection = false,
|
||||
searchString = null,
|
||||
searchString,
|
||||
resetSearchState = true,
|
||||
event = null,
|
||||
event,
|
||||
} = {}) {
|
||||
if (!searchString) {
|
||||
searchString =
|
||||
@@ -1611,8 +1611,14 @@ export class UrlbarInput {
|
||||
throw new Error("The current value doesn't start with the search string");
|
||||
}
|
||||
|
||||
let queryContext = this.#makeQueryContext({
|
||||
allowAutofill,
|
||||
event,
|
||||
searchString,
|
||||
});
|
||||
|
||||
if (event) {
|
||||
this.controller.engagementEvent.start(event, searchString);
|
||||
this.controller.engagementEvent.start(event, queryContext, searchString);
|
||||
}
|
||||
|
||||
if (this._suppressStartQuery) {
|
||||
@@ -1624,39 +1630,17 @@ export class UrlbarInput {
|
||||
this._resetSearchState();
|
||||
}
|
||||
|
||||
this._lastSearchString = searchString;
|
||||
this._valueOnLastSearch = this.value;
|
||||
|
||||
let options = {
|
||||
allowAutofill,
|
||||
isPrivate: this.isPrivate,
|
||||
maxResults: lazy.UrlbarPrefs.get("maxRichResults"),
|
||||
searchString,
|
||||
userContextId:
|
||||
this.window.gBrowser.selectedBrowser.getAttribute("usercontextid"),
|
||||
currentPage: this.window.gBrowser.currentURI.spec,
|
||||
formHistoryName: this.formHistoryName,
|
||||
prohibitRemoteResults:
|
||||
event &&
|
||||
lazy.UrlbarUtils.isPasteEvent(event) &&
|
||||
lazy.UrlbarPrefs.get("maxCharsForSearchSuggestions") <
|
||||
event.data?.length,
|
||||
};
|
||||
|
||||
if (this.searchMode) {
|
||||
this.confirmSearchMode();
|
||||
options.searchMode = this.searchMode;
|
||||
if (this.searchMode.source) {
|
||||
options.sources = [this.searchMode.source];
|
||||
}
|
||||
}
|
||||
|
||||
this._lastSearchString = searchString;
|
||||
this._valueOnLastSearch = this.value;
|
||||
|
||||
// TODO (Bug 1522902): This promise is necessary for tests, because some
|
||||
// tests are not listening for completion when starting a query through
|
||||
// other methods than startQuery (input events for example).
|
||||
this.lastQueryContextPromise = this.controller.startQuery(
|
||||
new lazy.UrlbarQueryContext(options)
|
||||
);
|
||||
this.lastQueryContextPromise = this.controller.startQuery(queryContext);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3819,6 +3803,47 @@ export class UrlbarInput {
|
||||
return lazy.UrlbarUtils.stripUnsafeProtocolOnPaste(pasteData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a UrlbarQueryContext from the current context.
|
||||
*
|
||||
* @param {object} [options] Optional params
|
||||
* @param {boolean} options.allowAutofill Whether autofill is enabled.
|
||||
* @param {string} options.searchString The string being searched.
|
||||
* @param {object} options.event The event triggering the query.
|
||||
* @returns {UrlbarQueryContext}
|
||||
* The queryContext object.
|
||||
*/
|
||||
#makeQueryContext({
|
||||
allowAutofill = true,
|
||||
searchString = null,
|
||||
event = null,
|
||||
} = {}) {
|
||||
let options = {
|
||||
allowAutofill,
|
||||
isPrivate: this.isPrivate,
|
||||
maxResults: lazy.UrlbarPrefs.get("maxRichResults"),
|
||||
searchString,
|
||||
userContextId:
|
||||
this.window.gBrowser.selectedBrowser.getAttribute("usercontextid"),
|
||||
currentPage: this.window.gBrowser.currentURI.spec,
|
||||
formHistoryName: this.formHistoryName,
|
||||
prohibitRemoteResults:
|
||||
event &&
|
||||
lazy.UrlbarUtils.isPasteEvent(event) &&
|
||||
lazy.UrlbarPrefs.get("maxCharsForSearchSuggestions") <
|
||||
event.data?.length,
|
||||
};
|
||||
|
||||
if (this.searchMode) {
|
||||
options.searchMode = this.searchMode;
|
||||
if (this.searchMode.source) {
|
||||
options.sources = [this.searchMode.source];
|
||||
}
|
||||
}
|
||||
|
||||
return new lazy.UrlbarQueryContext(options);
|
||||
}
|
||||
|
||||
_on_scrollend(event) {
|
||||
this.updateTextOverflow();
|
||||
}
|
||||
@@ -4003,8 +4028,9 @@ export class UrlbarInput {
|
||||
this.focus();
|
||||
// To simplify tracking of events, register an initial event for event
|
||||
// telemetry, to replace the missing input event.
|
||||
this.controller.engagementEvent.start(event);
|
||||
this.controller.clearLastQueryContextCache();
|
||||
let queryContext = this.#makeQueryContext({ searchString: droppedURL });
|
||||
this.controller.setLastQueryContextCache(queryContext);
|
||||
this.controller.engagementEvent.start(event, queryContext);
|
||||
this.handleNavigation({ triggeringPrincipal: principal });
|
||||
// For safety reasons, in the drop case we don't want to immediately show
|
||||
// the the dropped value, instead we want to keep showing the current page
|
||||
|
||||
@@ -250,7 +250,7 @@ export class UrlbarProviderExtension extends UrlbarProvider {
|
||||
this.#pickResult(result, element);
|
||||
}
|
||||
|
||||
this._notifyListener("engagement", controller.input.isPrivate, state);
|
||||
this._notifyListener("engagement", queryContext.isPrivate, state);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -249,12 +249,7 @@ class ProviderQuickSuggest extends UrlbarProvider {
|
||||
result = this.#getVisibleResultFromLastQuery(controller.view);
|
||||
}
|
||||
|
||||
this.#recordEngagement(
|
||||
queryContext,
|
||||
controller.input.isPrivate,
|
||||
result,
|
||||
details
|
||||
);
|
||||
this.#recordEngagement(queryContext, result, details);
|
||||
}
|
||||
|
||||
if (details.result?.providerName == this.name) {
|
||||
@@ -477,8 +472,6 @@ class ProviderQuickSuggest extends UrlbarProvider {
|
||||
*
|
||||
* @param {UrlbarQueryContext} queryContext
|
||||
* The query context.
|
||||
* @param {boolean} isPrivate
|
||||
* Whether the engagement is in a private context.
|
||||
* @param {UrlbarResult} result
|
||||
* The quick suggest result that was present (and possibly picked) at the
|
||||
* end of the engagement or that was dismissed. Null if no quick suggest
|
||||
@@ -487,7 +480,7 @@ class ProviderQuickSuggest extends UrlbarProvider {
|
||||
* The `details` object that was passed to `onEngagement()`. It must look
|
||||
* like this: `{ selType, selIndex }`
|
||||
*/
|
||||
#recordEngagement(queryContext, isPrivate, result, details) {
|
||||
#recordEngagement(queryContext, result, details) {
|
||||
let resultSelType = "";
|
||||
let resultClicked = false;
|
||||
if (result && details.result == result) {
|
||||
@@ -507,7 +500,7 @@ class ProviderQuickSuggest extends UrlbarProvider {
|
||||
// Record engagement scalars, event, and pings.
|
||||
this.#recordEngagementScalars({ result, resultSelType, resultClicked });
|
||||
this.#recordEngagementEvent({ result, resultSelType, resultClicked });
|
||||
if (!isPrivate) {
|
||||
if (!queryContext.isPrivate) {
|
||||
this.#recordEngagementPings({ result, resultSelType, resultClicked });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,7 +307,7 @@ class ProviderTopSites extends UrlbarProvider {
|
||||
|
||||
onEngagement(state, queryContext, details, controller) {
|
||||
if (
|
||||
!controller.input.isPrivate &&
|
||||
!queryContext.isPrivate &&
|
||||
this.sponsoredSites &&
|
||||
["engagement", "abandonment"].includes(state)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user