mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1102060 - Part1: Add two new functions to get TabParent in ContentProcessManager by given ContentParentId and TabId. r=kanru
This commit is contained in:
parent
aa0d5cfa9c
commit
20fe9672ed
@ -6,6 +6,7 @@
|
||||
|
||||
#include "ContentProcessManager.h"
|
||||
#include "ContentParent.h"
|
||||
#include "mozilla/dom/TabParent.h"
|
||||
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
@ -276,5 +277,62 @@ ContentProcessManager::GetRemoteFrameOpenerTabId(const ContentParentId& aChildCp
|
||||
return true;
|
||||
}
|
||||
|
||||
already_AddRefed<TabParent>
|
||||
ContentProcessManager::GetTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
|
||||
const TabId& aChildTabId)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
auto iter = mContentParentMap.find(aChildCpId);
|
||||
if (NS_WARN_IF(iter == mContentParentMap.end())) {
|
||||
ASSERT_UNLESS_FUZZING();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const InfallibleTArray<PBrowserParent*>& browsers =
|
||||
iter->second.mCp->ManagedPBrowserParent();
|
||||
for (uint32_t i = 0; i < browsers.Length(); i++) {
|
||||
nsRefPtr<TabParent> tab = static_cast<TabParent*>(browsers[i]);
|
||||
if (tab->GetTabId() == aChildTabId) {
|
||||
return tab.forget();
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<TabParent>
|
||||
ContentProcessManager::GetTopLevelTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
|
||||
const TabId& aChildTabId)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// Used to keep the current ContentParentId and the current TabId
|
||||
// in the iteration(do-while loop below)
|
||||
ContentParentId currentCpId;
|
||||
TabId currentTabId;
|
||||
|
||||
// To get the ContentParentId and the TabParentId on upper level
|
||||
ContentParentId parentCpId = aChildCpId;
|
||||
TabId openerTabId = aChildTabId;
|
||||
|
||||
// Stop this loop when the upper ContentParentId of
|
||||
// the current ContentParentId is chrome(ContentParentId = 0).
|
||||
do {
|
||||
// Update the current ContentParentId and TabId in iteration
|
||||
currentCpId = parentCpId;
|
||||
currentTabId = openerTabId;
|
||||
|
||||
// Get the ContentParentId and TabId on upper level
|
||||
if (!GetParentProcessId(currentCpId, &parentCpId) ||
|
||||
!GetRemoteFrameOpenerTabId(currentCpId, currentTabId, &openerTabId)) {
|
||||
return nullptr;
|
||||
}
|
||||
} while (parentCpId);
|
||||
|
||||
// Get the top level TabParent by the current ContentParentId and TabId
|
||||
return GetTabParentByProcessAndTabId(currentCpId, currentTabId);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -110,6 +110,31 @@ public:
|
||||
const TabId& aChildTabId,
|
||||
/*out*/ TabId* aOpenerTabId);
|
||||
|
||||
/**
|
||||
* Get the TabParent by the given content process and tab id.
|
||||
* Return nullptr when TabParent couldn't be found via aChildCpId
|
||||
* and aChildTabId.
|
||||
* (or probably because the TabParent is not in the chrome process)
|
||||
*/
|
||||
already_AddRefed<TabParent>
|
||||
GetTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
|
||||
const TabId& aChildTabId);
|
||||
|
||||
/**
|
||||
* Get the TabParent on top level by the given content process and tab id.
|
||||
*
|
||||
* This function return the TabParent belong to the chrome process,
|
||||
* called top-level TabParent here, by given aChildCpId and aChildTabId.
|
||||
* The given aChildCpId and aChildTabId are related to a content process
|
||||
* and a tab respectively. In nested-oop, the top-level TabParent isn't
|
||||
* always the opener tab of the given tab in content process. This function
|
||||
* will call GetTabParentByProcessAndTabId iteratively until the Tab returned
|
||||
* is belong to the chrome process.
|
||||
*/
|
||||
already_AddRefed<TabParent>
|
||||
GetTopLevelTabParentByProcessAndTabId(const ContentParentId& aChildCpId,
|
||||
const TabId& aChildTabId);
|
||||
|
||||
private:
|
||||
static StaticAutoPtr<ContentProcessManager> sSingleton;
|
||||
TabId mUniqueId;
|
||||
@ -120,4 +145,4 @@ private:
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user