Commit afc359bd authored by Nika Layzell's avatar Nika Layzell
Browse files

Bug 1549783 - Ensure that cached contexts come after non-cached ones in EnsureSubscribed, r=farre

Differential Revision: https://phabricator.services.mozilla.com/D30230

--HG--
extra : moz-landing-system : lando
parent fe5995b8
Loading
Loading
Loading
Loading
+19 −16
Original line number Original line Diff line number Diff line
@@ -43,30 +43,33 @@ void BrowsingContextGroup::EnsureSubscribed(ContentParent* aProcess) {
    return;
    return;
  }
  }


  // Subscribe to the BrowsingContext, and send down initial state!
  Subscribe(aProcess);
  Subscribe(aProcess);


  // Iterate over each of our browsing contexts, locating those which are not in
  // their parent's children list. We can then use those as starting points to
  // get a pre-order walk of each tree.
  nsTArray<BrowsingContext::IPCInitializer> inits(mContexts.Count());
  nsTArray<BrowsingContext::IPCInitializer> inits(mContexts.Count());
  for (auto iter = mContexts.Iter(); !iter.Done(); iter.Next()) {
    auto* context = iter.Get()->GetKey();


    // If we have a parent, and are in our parent's `Children` list, skip
  // First, perform a pre-order walk of our BrowsingContext objects from our
    // ourselves as we'll be found in the pre-order traversal of our parent.
  // toplevels. This should visit every active BrowsingContext.
    if (context->GetParent() &&
  for (auto& context : mToplevels) {
        context->GetParent()->GetChildren().IndexOf(context) !=
    MOZ_DIAGNOSTIC_ASSERT(!IsContextCached(context),
            BrowsingContext::Children::NoIndex) {
                          "cached contexts must have a parent");
      continue;
    }


    // Add all elements to the list in pre-order.
    context->PreOrderWalk([&](BrowsingContext* aContext) {
    context->PreOrderWalk([&](BrowsingContext* aContext) {
      inits.AppendElement(aContext->GetIPCInitializer());
      inits.AppendElement(aContext->GetIPCInitializer());
    });
    });
  }
  }


  // Ensure that cached BrowsingContext objects are also visited, by visiting
  // them after mToplevels.
  for (auto iter = mCachedContexts.Iter(); !iter.Done(); iter.Next()) {
    iter.Get()->GetKey()->PreOrderWalk([&](BrowsingContext* aContext) {
      inits.AppendElement(aContext->GetIPCInitializer());
    });
  }

  // We should have visited every browsing context.
  MOZ_DIAGNOSTIC_ASSERT(inits.Length() == mContexts.Count(),
                        "Visited the wrong number of contexts!");

  // Send all of our contexts to the target content process.
  // Send all of our contexts to the target content process.
  Unused << aProcess->SendRegisterBrowsingContextGroup(inits);
  Unused << aProcess->SendRegisterBrowsingContextGroup(inits);
}
}