Given a collection of frames (all residing in the same process, but possibly different WebContents), what's the best way to detect that the page within the frame has unloaded (frame removal, navigation, ...?)
Context:
I have a patch that puts lifetime management of an extension port in the browser process. A port can have multiple receivers (= a page in a frame), and it should be closed if all receivers are gone. For ports within a single tab, I can use a WebContentsObserver + RenderFrameDeleted + DidNavigateAnyFrame.
But when "an extension" is the "receiver", I have to track frames that may be in multiple tabs (
https://codereview.chromium.org/1413853005/). extensions::ProcessManager (PM) maintains a list of such frames and is kept up to date by multiple ExtensionWebContentObservers (EWCO). This PM has an observer interface that offers notifications for when the RenderFrame is created and removed.
This is almost complete for my use case, all I need is a notification for unloading. I'm thinking of adding a new notification to PM, which is triggered by an EWCO via DidNavigateAnyFrame.
Is this the best (correct) solution, or are there better ways of detecting when a page in a frame has unloaded?