UrlbarInput Reference

class UrlbarInput(options)

Implements the text input part of the address bar UI.

  • options (object()) – The initial options for UrlbarInput.

  • options.textbox (object()) – The container element.


Called by the controller when the first result of a new search is received. If it’s an autofill result, then it may need to be autofilled, subject to a few restrictions.

  • result (UrlbarResult()) – The first result.

UrlbarInput._autofillValue(value, selectionStart, selectionEnd, type, adaptiveHistoryInput)

Autofills a value into the input. The value will be autofilled regardless of the input’s current value.

  • value (string()) – The value to autofill.

  • selectionStart (integer()) – The new selectionStart.

  • selectionEnd (integer()) – The new selectionEnd.

  • type (string()) – The autofill type, one of: “origin”, “url”, “adaptive”

  • adaptiveHistoryInput (string()) – If the autofill type is “adaptive”, this is the matching input value from adaptive history.

UrlbarInput._getSearchTermIfDefaultSerpUrl(uri, mustBeEqual)

Checks if the given uri is constructed by the default search engine. When passing URI’s to check against, it’s best to use the “original” URI that was requested, as the server may re-direct the URIs.

  • uri (nsIURI()) – The uri to check against

  • mustBeEqual (boolean()) – The uri to check against


string – The search terms use. Will return an empty string if it’s not a default SERP or if the default engine hasn’t been initialized.

UrlbarInput._loadURL(url, event, openUILinkWhere, params, resultDetails, result, browser)

Loads the url in the appropriate place.

  • url (string()) – The URL to open.

  • event (Event()) – The event that triggered to load the url.

  • openUILinkWhere (string()) – Where we expect the result to be opened.

  • params (object()) – The parameters related to how and where the result will be opened. Further supported paramters are listed in utilityOverlay.js#openUILinkIn.

  • params.triggeringPrincipal (object()) – The principal that the action was triggered from.

  • params.postData (nsIInputStream()) – The POST data associated with a search submission.

  • params.allowInheritPrincipal (boolean()) – Whether the principal can be inherited.

  • resultDetails (object()) – Details of the selected result, if any.

  • result.type (UrlbarUtils.RESULT_TYPE()) – Details of the result type, if any.

  • result.searchTerm (string()) – Search term of the result source, if any.

  • result.source (UrlbarUtils.RESULT_SOURCE()) – Details of the result source, if any.

  • browser (object()) – [optional] the browser to use for the load.


Autofills the autofill placeholder string if appropriate, and determines whether autofill should be allowed for the new search started by an input event.

  • value (string()) – The new search string.


boolean – Whether autofill should be allowed in the new search.

UrlbarInput._maybeCanonizeURL(event, value)

If appropriate, this prefixes a search string with ‘www.’ and suffixes it with browser.fixup.alternate.suffix prior to navigating.

  • event (Event()) – The event that triggered this query.

  • value (string()) – The search string that should be canonized.


string – Returns the canonized URL if available and null otherwise.

Determines if we should select all the text in the Urlbar based on the

Urlbar state, and whether the selection is empty.


This notifies observers that the user has entered or selected something in the URL bar which will cause navigation.

We use the observer service, so that we don’t need to load extra facilities if they aren’t being used, e.g. WebNavigation.

  • result (UrlbarResult()) – Details of the result that was selected, if any.

UrlbarInput._recordSearch(engine, event, searchActionDetails)

Get the url to load for the search query and records in telemetry that it is being loaded.

  • engine (nsISearchEngine()) – The engine to generate the query for.

  • event (Event()) – The event that triggered this query.

  • searchActionDetails (object()) – The details associated with this search query.

  • searchActionDetails.isSuggestion (boolean()) – True if this query was initiated from a suggestion from the search engine.

  • searchActionDetails.alias (boolean()) – True if this query was initiated via a search alias.

  • searchActionDetails.isFormHistory (boolean()) – True if this query was initiated from a form history result.

  • searchActionDetails.url (string()) – The url this query was triggered with.


Resets some state so that searches from the user’s previous interaction with the input don’t interfere with searches from a new interaction.

UrlbarInput._searchModeForResult(result, entry="null")

Returns a search mode object if a result should enter search mode when selected.

  • result (UrlbarResult()) –

  • entry (string()) – If provided, this will be recorded as the entry point into search mode. See setSearchMode() documentation for details.


object – A search mode object. Null if search mode should not be entered. See setSearchMode documentation for details.


Shortens the given value, usually by removing http:// and trailing slashes.

  • val (string()) – The string to be trimmed if it appears to be URI


string – The trimmed string


Updates the UI so that search mode is either entered or exited.

  • searchMode (object()) – See setSearchMode documentation. If null, then search mode is exited.


Invoked on overflow/underflow/scrollend events to update attributes related to the input text directionality. Overflow fade masks use these attributes to appear at the proper side of the urlbar.


Determines where a URL/page should be opened.

  • event (Event()) – the event triggering the opening.




When switching tabs quickly, TabSelect sometimes happens before _adjustFocusAfterTabSwitch and due to the focus still being on the old tab, we end up flickering the results pane briefly.


Confirms the current search mode.


Applies styling to the text in the urlbar input, depending on the text.

UrlbarInput.getSearchMode(browser, confirmedOnly=false)

Gets the search mode for a specific browser instance.

  • browser (Browser()) – The search mode for this browser will be returned.

  • confirmedOnly (boolean()) – Normally, if the browser has both preview and confirmed modes, preview mode will be returned since it takes precedence. If this argument is true, then only confirmed search mode will be returned, or null if search mode hasn’t been confirmed.


object – A search mode object. See setSearchMode documentation. If the browser is not in search mode, then null is returned.


Handles an event which might open text or a URL. If the event requires doing so, handleCommand forwards it to handleNavigation.

  • event (Event()) – The event triggering the open.


Passes DOM events to the _on_<event type> methods.

  • event (Event()) –

UrlbarInput.handleNavigation(event, oneOffParams, triggeringPrincipal)

Handles an event which would cause a URL or text to be opened.

  • event (Event()) – The event triggering the open.

  • oneOffParams (object()) – Optional. Pass if this navigation was triggered by a one-off. Practically speaking, UrlbarSearchOneOffs passes this when the user holds certain key modifiers while picking a one-off. In those cases, we do an immediate search using the one-off’s engine instead of entering search mode.

  • oneOffParams.openWhere (string()) – Where we expect the result to be opened.

  • oneOffParams.openParams (object()) – The parameters related to where the result will be opened.

  • oneOffParams.engine (Node()) – The selected one-off’s engine.

  • triggeringPrincipal (object()) – The principal that the action was triggered from.

UrlbarInput.handoff(searchString, searchEngine, newtabSessionId)

Called by inputs that resemble search boxes, but actually hand input off to the Urlbar. We use these fake inputs on the new tab page and about:privatebrowsing.

  • searchString (string()) –

  • searchEngine (nsISearchEngine()) – Optional. If included and the right prefs are set, we will enter search mode when handing searchString from the fake input to the Urlbar.

  • newtabSessionId (string()) – Optional. The id of the newtab session that handed off this search.


Converts an internal URI (e.g. a URI with a username or password) into one which we can expose to the user.

  • uri (nsIURI()) – The URI to be converted


nsIURI – The converted, exposable URI

UrlbarInput.maybeConfirmSearchModeFromResult(entry, result, checkValue, startQuery)

Confirms search mode and starts a new search if appropriate for the given result. See also _searchModeForResult.

  • entry (string()) – The search mode entry point. See setSearchMode documentation for details.

  • result (UrlbarResult()) – The result to confirm. Defaults to the currently selected result.

  • checkValue (boolean()) – If true, the trimmed input value must equal the result’s keyword in order to enter search mode.

  • startQuery (boolean()) – If true, start a query after entering search mode. Defaults to true.


boolean – True if we entered search mode and false if not.


Invoked by the controller when the first result is received.

  • firstResult (UrlbarResult()) – The first result received.


boolean – True if this method canceled the query and started a new one. False otherwise.

UrlbarInput.pickElement(element, event)

Called when an element of the view is picked.

  • element (Element()) – The element that was picked.

  • event (Event()) – The event that picked the element.

UrlbarInput.pickResult(result, event, element=null, browser)

Called when a result is picked.

  • result (UrlbarResult()) – The result that was picked.

  • event (Event()) – The event that picked the result.

  • element (DOMElement()) – the picked view element, if available.

  • browser (object()) – The browser to use for the load.


Restore focus styles. This is used by Activity Stream and about:privatebrowsing for search hand-off.

  • forceSuppressFocusBorder (Browser()) – Set true to suppress-focus-border attribute if this flag is true.


Restores the current browser search mode from a previously stored state.

UrlbarInput.search(value, options)

Sets the input’s value, starts a search, and opens the view.

  • value (string()) – The input’s value will be set to this value, and the search will use it as its query.

  • options.searchEngine (nsISearchEngine()) – Search engine to use when the search is using a known alias.

  • options.searchModeEntry (UrlbarUtils.SEARCH_MODE_ENTRY()) – If provided, we will record this parameter as the search mode entry point in Telemetry. Consumers should provide this if they expect their call to enter search mode.

  • options.focus (boolean()) – If true, the urlbar will be focused. If false, the focus will remain unchanged.


Enters search mode with the default engine.


Focus without the focus styles. This is used by Activity Stream and about:privatebrowsing for search hand-off.

UrlbarInput.setPageProxyState(state, updatePopupNotifications)

Updates the user interface to indicate whether the URI in the address bar is different than the loaded page, because it’s being edited or because a search result is currently selected and is displayed in the location bar.

  • state (string()) – The string “valid” indicates that the security indicators and other related user interface elments should be shown because the URI in the location bar matches the loaded page. The string “invalid” indicates that the URI in the location bar is different than the loaded page.

  • updatePopupNotifications (boolean()) – Indicates whether we should update the PopupNotifications visibility due to this change, otherwise avoid doing so as it is being handled somewhere else.


The input keeps track of the result associated with the current input value. This result can be set by calling either setValueFromResult or this method. Use this method when you need to set the result without also setting the input value. This can be the case when either the selection is cleared and no other result becomes selected, or when the result is the heuristic and we don’t want to modify the value the user is typing.

  • result (UrlbarResult()) – The result to associate with the current input value.

UrlbarInput.setSearchMode(searchMode, browser)

Sets search mode for a specific browser instance. If the given browser is selected, then this will also enter search mode.

  • searchMode (object()) – A search mode object.

  • searchMode.engineName (string()) – The name of the search engine to restrict to.

  • searchMode.source (UrlbarUtils.RESULT_SOURCE()) – A result source to restrict to.

  • searchMode.entry (string()) – How search mode was entered. This is recorded in event telemetry. One of the values in UrlbarUtils.SEARCH_MODE_ENTRY.

  • searchMode.isPreview (boolean()) – If true, we will preview search mode. Search mode preview does not record telemetry and has slighly different UI behavior. The preview is exited in favor of full search mode when a query is executed. False should be passed if the caller needs to enter search mode but expects it will not be interacted with right away. Defaults to true.

  • browser (Browser()) – The browser for which to set search mode.

UrlbarInput.setURI(uri=null, dueToTabSwitch=false, dueToSessionRestore=false, originalUri=null)

Sets the URI to display in the location bar.

  • uri (nsIURI()) – If this is unspecified, the current URI will be used.

  • dueToTabSwitch (boolean()) – True if this is being called due to switching tabs and false otherwise.

  • dueToSessionRestore (boolean()) – True if this is being called due to session restore and false otherwise.

  • originalUri (nsIURI()) – The uri may have been re-directed, so if originalUri exists, we can recover the uri used to make a request. This is also used as a means of knowing if the caller is a GET request.

UrlbarInput.setValueFromResult(result, event, urlOverride)

Called by the view when moving through results with the keyboard, and when picking a result. This sets the input value to the value of the result and invalidates the pageproxystate. It also sets the result that is associated with the current input value. If you need to set this result but don’t want to also set the input value, then use setResultForCurrentValue.

  • result (UrlbarResult()) – The result that was selected or picked, null if no result was selected.

  • event (Event()) – The event that picked the result.

  • urlOverride (string()) – Normally the URL is taken from result.payload.url, but if urlOverride is specified, it’s used instead.


boolean – Whether the value has been canonized


Starts a query based on the current input value.

  • options.allowAutofill (boolean()) – Whether or not to allow providers to include autofill results.

  • options.autofillIgnoresSelection (boolean()) – Normally we autofill only if the cursor is at the end of the string, if this is set we’ll autofill regardless of selection.

  • options.searchString (string()) – The search string. If not given, the current input value is used. Otherwise, the current input value must start with this value.

  • options.resetSearchState (boolean()) – If this is the first search of a user interaction with the input, set this to true (the default) so that search-related state from the previous interaction doesn’t interfere with the new interaction. Otherwise set it to false so that state is maintained during a single interaction. The intended use for this parameter is that it should be set to false when this method is called due to input events.

  • options.event (event()) – The user-generated event that triggered the query, if any. If given, we will record engagement event telemetry for the query.