Closed Bug 1959713 Opened 1 year ago Closed 1 year ago

Implement tabs.Tab.groupId

Categories

(WebExtensions :: General, enhancement, P1)

enhancement

Tracking

(firefox138 fixed, firefox139 fixed)

RESOLVED FIXED
139 Branch
Tracking Status
firefox138 --- fixed
firefox139 --- fixed

People

(Reporter: robwu, Assigned: robwu)

References

(Blocks 1 open bug)

Details

(Keywords: dev-doc-complete, Whiteboard: [addons-jira])

Attachments

(2 external files)

To enable extensions to identify tab groups, we need to expose the concept of a tab group to extensions. The bare minimum is tabs.Tab.groupId.

In the [extension API as already existing in Chrome, groupId is an integer. -1 is a non-existing tab Id, any non-negative integer could be a valid groupId. This ID is generated by the browser and may be used across the tabs and tabGroups extension APIs. The IDs are "unique within a browser session" (chrome's docs). In practice, the tab group IDs in Chrome are not stable across browser restarts.

Internally in Firefox, we currently use strings (generated here in tabbrowser.js, which are also saved in the session restore files). We could feasibly derive an integer from these (which eases a bidirectional mapping), or maintain a separate mapping of string<->integers.

Blocks: 1959714
Blocks: 1959715
Blocks: 1959716

dev-doc-needed: once the groupId concept is implemented/landed, we should also update the index part of the tabs.move documentation to clarify that if there are tab groups involved, that groupId may change upon changing the index of a tab. Similarly for tabs.create (see bug 1957723 for context).

For clarity, this is the full set of functionality that we intend to land together:

Keywords: dev-doc-needed
See Also: → 1957723

This patch exposes a groupId field on tabs.Tab objects in extensions.

On mobile (Android), the value is always -1.

On desktop, the value is the numeric representation composed from the
internal ID, which happens to fit in a safe integer. As long as the
browser is not running past year 2255, this works. As a fallback,
when an ID in a different format is encountered, the logic falls back
to returning a new unique ID based on a counter. This ID is then
stored in an internal in-memory map to maintain stable consistency.
Since it is unclear when exactly it is safe to discard this value, this
map is never cleared. This minor memory leak is acceptable because it
does not happen in practice, and even if it does, the number of tab
groups over the lifetime of a Firefox session is not going to reach
excessive values.

See Also: → 1960104
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/8e9a00f749f9 Expose tabs.Tab.groupId r=zombie,dao,tabbrowser-reviewers,frontend-codestyle-reviewers
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 139 Branch
See Also: → 1960156

This patch exposes a groupId field on tabs.Tab objects in extensions.

On mobile (Android), the value is always -1.

On desktop, the value is the numeric representation composed from the
internal ID, which happens to fit in a safe integer. As long as the
browser is not running past year 2255, this works. As a fallback,
when an ID in a different format is encountered, the logic falls back
to returning a new unique ID based on a counter. This ID is then
stored in an internal in-memory map to maintain stable consistency.
Since it is unclear when exactly it is safe to discard this value, this
map is never cleared. This minor memory leak is acceptable because it
does not happen in practice, and even if it does, the number of tab
groups over the lifetime of a Firefox session is not going to reach
excessive values.

Original Revision: https://phabricator.services.mozilla.com/D245159

Attachment #9478854 - Flags: approval-mozilla-beta?

beta Uplift Approval Request

  • User impact if declined: Extensions unable to distinguish tabs in tab groups, which may result in the loss of tab groups (e.g. by the MAC extension), see https://bugzilla.mozilla.org/show_bug.cgi?id=1956278#c22
  • Code covered by automated testing: yes
  • Fix verified in Nightly: no
  • Needs manual QE test: no
  • Steps to reproduce for manual QE testing: No QA needed for these APIs; Testing may be desired if the MAC extension is updated to use these API improvements (tracked at bug 1956278)
  • Risk associated with taking this patch: Low
  • Explanation of risk level: Low risk changes to extension APIs: new integer field (bug 1959713), new optional field (bug 1959715), new methods (bug 1959714). Slightly less trivial is a new event (bug 1959716), which becomes even more chattier than before, as it now fires whenever the tab group changes. This should be fine since the event itself was already firing frequently before.
  • String changes made/needed: None
  • Is Android affected?: no
Attachment #9478854 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

Developer documentation is being worked on:

Covering:

Documentation has been merged.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: