Bug 1688040 - part10.2: Return existing ExtensionPort instance based on the Extension...
commitb69f48cd4ac032befcb054487f2ec52784ab9e9d
authorLuca Greco <lgreco@mozilla.com>
Wed, 6 Oct 2021 12:28:24 +0000 (6 12:28 +0000)
committerLuca Greco <lgreco@mozilla.com>
Wed, 6 Oct 2021 12:28:24 +0000 (6 12:28 +0000)
treed53049898ed9dab27a35f7a7c92e3c121a044c17
parent3bb81b1d2dccb1d45922c677c042a09bce776a73
Bug 1688040 - part10.2: Return existing ExtensionPort instance based on the ExtensionPortDescriptor portId. r=baku

The extensions expect that ExtensionPort instances they get in the calls to the
port event listeners to always be the same, and to be also strictly equal to the
object port got from browser.runtime.connect or browser.runtime.onConnect:

```
const port = browser.runtime.connect();
port.onDisconnect.addListener(disconnectedPort => {
  // port === disconnectedPort => true
});
```

This patch does add an extension port lookup map in the ExtensionBrowser
class and a new ExtensionBrowser::GetPort method which is responsible of
providing the expected behavior (returning an existing istance if one is
found in the lookup map).

Differential Revision: https://phabricator.services.mozilla.com/D107554
toolkit/components/extensions/test/xpcshell/webidl-api/test_ext_webidl_runtime_port.js
toolkit/components/extensions/webidl-api/ExtensionAPIBase.cpp
toolkit/components/extensions/webidl-api/ExtensionBrowser.cpp
toolkit/components/extensions/webidl-api/ExtensionBrowser.h
toolkit/components/extensions/webidl-api/ExtensionEventListener.cpp
toolkit/components/extensions/webidl-api/ExtensionPort.cpp
toolkit/components/extensions/webidl-api/ExtensionPort.h