Closed Bug 1617379 Opened 6 months ago Closed 4 months ago

WebExtension experiments don't have access to the addressBookCache

Categories

(Thunderbird :: Add-Ons: Extensions API, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Thunderbird 76.0

People

(Reporter: standard8, Assigned: darktrojan)

Details

Attachments

(1 file)

As far as I can tell, the extension context doesn't make the addressBookCache available. This makes it hard for authors to design experiment APIs where we pass in the contact id.

Summary: WebExtesion experiments don't have access to the addressBookCache → WebExtension experiments don't have access to the addressBookCache

I was looking in to fixing this when I discovered that you can access APIs from an experiment through context.apiObj, so listing the address books would be context.apiObj.addressBooks.list().

It calls the function directly rather than going through the WE mechanisms so you may get a result returned immediately where you'd get a Promise the normal way. In the case of the address book APIs especially I expect at least some of them will become asynchronous in the near future (due to the address book work) so it's probably best to just use await everywhere.

(In reply to Geoff Lankow (:darktrojan) from comment #1)

I was looking in to fixing this when I discovered that you can access APIs from an experiment through context.apiObj, so listing the address books would be context.apiObj.addressBooks.list().

I guess you realise this as you haven't closed the bug, but this isn't enough to make the API easy / performant. Generally I'd like to pass the id through, then via the cache to get the nsIAbCard to pass to other core functions. Whilst I can look it up again via name/email, that isn't guaranteed to get the same card as I had before.

That's a fair point. I was somewhat forgetting that the API's functions return a WE-friendly version of the object rather than the object itself.

I expect that the most useful parts would be findAddressBookById, findMailingListById, findContactById (and maybe convert if you'd ever want to return something from the API). Is there anything else you think would be worth having?

(Incidentally I'm kinda hoping the find…ById functions become redundant when the address book work finally gets some traction.)

Yeah, they would probably be the most useful.

This gives experiments access to the three "find" functions and convert. I've also tidied up the experiment test by converting the embedded file to a function so that it can be linted properly.

Assignee: nobody → geoff
Status: NEW → ASSIGNED
Attachment #9136657 - Flags: review?(mkmelin+mozilla)
Comment on attachment 9136657 [details] [diff] [review]
1617379-addrbookcache-experiments-1.diff

Review of attachment 9136657 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good, thx! r=mkmelin
Attachment #9136657 - Flags: review?(mkmelin+mozilla) → review+
Target Milestone: --- → Thunderbird 76.0

Pushed by mkmelin@iki.fi:
https://hg.mozilla.org/comm-central/rev/36da94e8ddb4
Give WebExtension experiments access to addressBookCache. r=mkmelin DONTBUILD

Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Pushed by geoff@darktrojan.net:
https://hg.mozilla.org/comm-central/rev/5117addf3359
follow-up - Delete address book at the end of a test. rs=bustage-fix
You need to log in before you can comment on or make changes to this bug.