The extension code _tries_ to flush messages when the relevant delegate is attached.
The logic, however, is pretty flawed: we currently only flush runtime-messages
(i.e. not coming from a WebExtension Page) and we flush all messages when the
first delegate is attached, even though there could be messages for different
nativeApp values which don't have a delegate attached yet.
We also erroneusly return a rejected promise to javascript when a message is queued up.
This patch addresses the above by:
- Never rejecting a pending connection request, the connection request will be
resolved when the delegate for the right nativeApp is attached.
- Making the pending messages queue per-nativeApp and per-session.
- Flushing pending messages when a session delegate is attached.
Differential Revision: https://phabricator.services.mozilla.com/D96645