Bug 1688040 - part10.2: Return existing ExtensionPort instance based on the Extension...
commit79596d7bee8c8764660de4df4e07161d8e9a9c97
authorLuca Greco <lgreco@mozilla.com>
Tue, 5 Oct 2021 17:05:44 +0000 (5 17:05 +0000)
committerLuca Greco <lgreco@mozilla.com>
Tue, 5 Oct 2021 17:05:44 +0000 (5 17:05 +0000)
tree7d397ffe823ed763df9d1df84e7116b523693eff
parent887f8691c8925f9c9210136eb4508fb4eb330ff0
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