/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Extract flags from the given ID. static uint64_t GetBrowsingContextGroupIdFlags(uint64_t aId) { return aId & ((uint64_t(1) << kBrowsingContextGroupIdFlagBits) - 1);
}
uint64_t BrowsingContextGroup::CreateId(bool aPotentiallyCrossOriginIsolated) { // We encode the potentially cross-origin isolated bit within the ID so that // the information can be recovered whenever the group needs to be re-created // due to e.g. being garbage-collected. // // In the future if we end up needing more complex information stored within // the ID, we can consider converting it to a more complex type, like a // string.
uint64_t flags =
aPotentiallyCrossOriginIsolated ? kPotentiallyCrossOriginIsolatedFlag : 0;
uint64_t id = GenerateBrowsingContextGroupId(flags);
MOZ_ASSERT(GetBrowsingContextGroupIdFlags(id) == flags); return id;
}
void BrowsingContextGroup::EnsureHostProcess(ContentParent* aProcess) {
MOZ_DIAGNOSTIC_ASSERT(!mDestroyed);
MOZ_DIAGNOSTIC_ASSERT(this != sChromeGroup, "cannot have content host for chrome group");
MOZ_DIAGNOSTIC_ASSERT(aProcess->GetRemoteType() != PREALLOC_REMOTE_TYPE, "cannot use preallocated process as host");
MOZ_DIAGNOSTIC_ASSERT(!aProcess->GetRemoteType().IsEmpty(), "host process must have remote type");
// XXX: The diagnostic crashes in bug 1816025 seemed to come through caller // ContentParent::GetNewOrUsedLaunchingBrowserProcess where we already // did AssertAlive, so IsDead should be irrelevant here. Still it reads // wrong that we ever might do AddBrowsingContextGroup if aProcess->IsDead(). if (aProcess->IsDead() ||
mHosts.WithEntryHandle(aProcess->GetRemoteType(), [&](auto&& entry) { if (entry) { // We know from bug 1816025 that this happens quite often and we have // bug 1815480 on file that should harden the entire flow. But in the // meantime we can just live with NOT replacing the found host // process with a new one here if it is still alive.
MOZ_ASSERT(
entry.Data() == aProcess, "There's already another host process for this remote type"); if (!entry.Data()->IsShuttingDown()) { returnfalse;
}
}
// This process wasn't already marked as our host, so insert it (or // update if the old process is shutting down), and begin subscribing, // unless the process is still launching.
entry.InsertOrUpdate(do_AddRef(aProcess));
staticvoid CollectContextInitializers(
Span<RefPtr<BrowsingContext>> aContexts,
nsTArray<SyncedContextInitializer>& aInits) { // The order that we record these initializers is important, as it will keep // the order that children are attached to their parent in the newly connected // content process consistent. for (auto& context : aContexts) {
aInits.AppendElement(context->GetIPCInitializer()); for (constauto& window : context->GetWindowContexts()) {
aInits.AppendElement(window->GetIPCInitializer());
CollectContextInitializers(window->Children(), aInits);
}
}
}
// Check if we're already subscribed to this process. if (!mSubscribers.EnsureInserted(aProcess)) { return;
}
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED // If the process is already marked as dead, we won't be the host, but may // still need to subscribe to the process due to creating a popup while // shutting down. if (!aProcess->IsDead()) { auto hostEntry = mHosts.Lookup(aProcess->GetRemoteType());
MOZ_DIAGNOSTIC_ASSERT(hostEntry && hostEntry.Data() == aProcess, "Cannot subscribe a non-host process");
} #endif
// FIXME: This won't send non-discarded children of discarded BCs, but those // BCs will be in the process of being destroyed anyway. // FIXME: Prevent that situation from occuring.
nsTArray<SyncedContextInitializer> inits(mContexts.Count());
CollectContextInitializers(mToplevels, inits);
// Send all of our contexts to the target content process.
Unused << aProcess->SendRegisterBrowsingContextGroup(Id(), inits);
}
// Make sure to call `RemoveBrowsingContextGroup` for every entry in both // `mHosts` and `mSubscribers`. This will visit most entries twice, but // `RemoveBrowsingContextGroup` is safe to call multiple times. for (constauto& entry : mHosts.Values()) {
entry->RemoveBrowsingContextGroup(this);
} for (constauto& key : mSubscribers) {
key->RemoveBrowsingContextGroup(this);
}
mHosts.Clear();
mSubscribers.Clear();
if (sBrowsingContextGroups) {
sBrowsingContextGroups->Remove(Id());
}
}
auto BrowsingContextGroup::MakeKeepAlivePtr() -> KeepAlivePtr {
AddKeepAlive(); return KeepAlivePtr{do_AddRef(this).take()};
}
void BrowsingContextGroup::MaybeDestroy() { // Once there are no synced contexts referencing a `BrowsingContextGroup`, we // can clear subscribers and destroy this group. We only do this in the parent // process, as it will orchestrate destruction of BCGs in content processes. if (XRE_IsParentProcess() && mContexts.IsEmpty() && mKeepAliveCount == 0 && this != sChromeGroup) {
Destroy();
// We may have been deleted here, as `Destroy()` will clear references. Do // not access any members at this point.
}
}
// Ensure the queue is enabled if (mPostMessageEventQueue->IsPaused()) {
nsresult rv = mPostMessageEventQueue->SetIsPaused(false);
MOZ_ALWAYS_SUCCEEDS(rv);
}
void BrowsingContextGroup::NotifyFocusedOrActiveBrowsingContextToProcess(
ContentParent* aProcess) {
MOZ_DIAGNOSTIC_ASSERT(aProcess); // If the focused or active BrowsingContexts belong in this group, // tell the newly subscribed process. if (nsFocusManager* fm = nsFocusManager::GetFocusManager()) {
BrowsingContext* focused = fm->GetFocusedBrowsingContextInChrome(); if (focused && focused->Group() != this) {
focused = nullptr;
}
BrowsingContext* active = fm->GetActiveBrowsingContextInChrome(); if (active && active->Group() != this) {
active = nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.