Backed out changeset 585e0230b2d5 (bug 1580766) as requested. CLOSED TREE

This commit is contained in:
Razvan Maries 2020-06-16 21:01:26 +03:00
Родитель f53bbea39a
Коммит 73dfe9d277
16 изменённых файлов: 22 добавлений и 268 удалений

Просмотреть файл

@ -1,35 +1,7 @@
// Swaps the content of tab a into tab b and then closes tab a.
function swapTabsAndCloseOther(a, b) {
gBrowser.swapBrowsersAndCloseOther(gBrowser.tabs[b], gBrowser.tabs[a]);
}
// Mirrors the effect of the above function on an array.
function swapArrayContentsAndRemoveOther(arr, a, b) {
arr[b] = arr[a];
arr.splice(a, 1);
}
function checkBrowserIds(expected) {
is(
gBrowser.tabs.length,
expected.length,
"Should have the right number of tabs."
);
for (let [i, tab] of gBrowser.tabs.entries()) {
is(
tab.linkedBrowser.browserId,
expected[i],
`Tab ${i} should have the right browser ID.`
);
is(
tab.linkedBrowser.browserId,
tab.linkedBrowser.browsingContext.browserId,
`Browser for tab ${i} has the same browserId as its BrowsingContext`
);
}
}
var getClicks = function(tab) {
return SpecialPowers.spawn(tab.linkedBrowser, [], function() {
return content.wrappedJSObject.clicks;
@ -140,40 +112,23 @@ add_task(async function() {
);
await BrowserTestUtils.switchTab(gBrowser, tabs[3]);
let browserIds = tabs.map(t => t.linkedBrowser.browserId);
checkBrowserIds(browserIds);
is(gBrowser.tabs[1], tabs[1], "tab1");
is(gBrowser.tabs[2], tabs[2], "tab2");
is(gBrowser.tabs[3], tabs[3], "tab3");
is(gBrowser.tabs[4], tabs[4], "tab4");
swapTabsAndCloseOther(2, 3); // now: 0 1 2 4
// Tab 2 is gone (what was tab 3 is displaying its content).
tabs.splice(2, 1);
swapArrayContentsAndRemoveOther(browserIds, 2, 3);
is(gBrowser.tabs[1], tabs[1], "tab1");
is(gBrowser.tabs[2], tabs[2], "tab2");
is(gBrowser.tabs[3], tabs[3], "tab4");
checkBrowserIds(browserIds);
is(gBrowser.tabs[2], tabs[3], "tab3");
is(gBrowser.tabs[3], tabs[4], "tab4");
delete tabs[2];
info("about to cacheObjectValue");
await cacheObjectValue(tabs[3].linkedBrowser);
await cacheObjectValue(tabs[4].linkedBrowser);
info("just finished cacheObjectValue");
swapTabsAndCloseOther(3, 2); // now: 0 1 4
tabs.splice(3, 1);
swapArrayContentsAndRemoveOther(browserIds, 3, 2);
is(
Array.prototype.indexOf.call(gBrowser.tabs, gBrowser.selectedTab),
2,
"The third tab should be selected"
);
checkBrowserIds(browserIds);
delete tabs[4];
ok(
await checkObjectValue(gBrowser.tabs[2].linkedBrowser),
@ -181,19 +136,15 @@ add_task(async function() {
);
is(gBrowser.tabs[1], tabs[1], "tab1");
is(gBrowser.tabs[2], tabs[2], "tab4");
is(gBrowser.tabs[2], tabs[3], "tab4");
let clicks = await getClicks(gBrowser.tabs[2]);
is(clicks, 0, "no click on BODY so far");
await clickTest(gBrowser.tabs[2]);
swapTabsAndCloseOther(2, 1); // now: 0 4
tabs.splice(2, 1);
swapArrayContentsAndRemoveOther(browserIds, 2, 1);
is(gBrowser.tabs[1], tabs[1], "tab4");
checkBrowserIds(browserIds);
is(gBrowser.tabs[1], tabs[1], "tab1");
delete tabs[3];
ok(
await checkObjectValue(gBrowser.tabs[1].linkedBrowser),
@ -224,14 +175,9 @@ add_task(async function() {
await loadURI(tabs[1], "about:blank");
let key = tabs[1].linkedBrowser.permanentKey;
checkBrowserIds(browserIds);
let win = gBrowser.replaceTabWithWindow(tabs[1]);
await new Promise(resolve => whenDelayedStartupFinished(win, resolve));
let newWinBrowserId = browserIds[1];
browserIds.splice(1, 1);
checkBrowserIds(browserIds);
delete tabs[1];
// Verify that the original window now only has the initial tab left in it.
is(gBrowser.tabs[0], tabs[0], "tab0");
@ -239,12 +185,6 @@ add_task(async function() {
let tab = win.gBrowser.tabs[0];
is(tab.linkedBrowser.permanentKey, key, "Should have kept the key");
is(tab.linkedBrowser.browserId, newWinBrowserId, "Should have kept the ID");
is(
tab.linkedBrowser.browserId,
tab.linkedBrowser.browsingContext.browserId,
"Should have kept the ID"
);
let awaitPageShow = BrowserTestUtils.waitForContentEvent(
tab.linkedBrowser,

Просмотреть файл

@ -30,7 +30,6 @@
#include "mozilla/dom/WindowGlobalParent.h"
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/dom/SyncedContextInlines.h"
#include "mozilla/dom/XULFrameElement.h"
#include "mozilla/net/DocumentLoadListener.h"
#include "mozilla/net/RequestContextService.h"
#include "mozilla/Assertions.h"
@ -51,7 +50,6 @@
#include "nsGlobalWindowOuter.h"
#include "nsIObserverService.h"
#include "nsContentUtils.h"
#include "nsQueryObject.h"
#include "nsSandboxFlags.h"
#include "nsScriptError.h"
#include "nsThreadUtils.h"
@ -189,14 +187,10 @@ bool BrowsingContext::SameOriginWithTop() {
/* static */
already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
nsGlobalWindowInner* aParent, BrowsingContext* aOpener,
const nsAString& aName, Type aType, uint64_t aBrowserId) {
if (aParent) {
MOZ_DIAGNOSTIC_ASSERT(aParent->GetWindowContext());
MOZ_DIAGNOSTIC_ASSERT(aParent->GetBrowsingContext()->mType == aType);
MOZ_DIAGNOSTIC_ASSERT(aParent->GetBrowsingContext()->GetBrowserId() == 0 ||
aParent->GetBrowsingContext()->GetBrowserId() ==
aBrowserId);
}
const nsAString& aName, Type aType) {
MOZ_DIAGNOSTIC_ASSERT(!aParent ||
aParent->GetBrowsingContext()->mType == aType);
MOZ_DIAGNOSTIC_ASSERT(!aParent || aParent->GetWindowContext());
MOZ_DIAGNOSTIC_ASSERT(aType != Type::Chrome || XRE_IsParentProcess());
@ -238,7 +232,6 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
context->mFields.SetWithoutSyncing<IDX_OpenerId>(aOpener->Id());
context->mFields.SetWithoutSyncing<IDX_HadOriginalOpener>(true);
}
if (aParent) {
MOZ_DIAGNOSTIC_ASSERT(parentBC->Group() == context->Group());
MOZ_DIAGNOSTIC_ASSERT(parentBC->mType == context->mType);
@ -251,8 +244,6 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
context->mFields.SetWithoutSyncing<IDX_OpenerPolicy>(
nsILoadInfo::OPENER_POLICY_UNSAFE_NONE);
context->mFields.SetWithoutSyncing<IDX_BrowserId>(aBrowserId);
if (aOpener && aOpener->SameOriginWithTop()) {
// We inherit the opener policy if there is a creator and if the creator's
// origin is same origin with the creator's top-level origin.
@ -336,10 +327,8 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
already_AddRefed<BrowsingContext> BrowsingContext::CreateIndependent(
Type aType) {
uint64_t browserId =
aType == Type::Content ? nsContentUtils::GenerateBrowserId() : 0;
RefPtr<BrowsingContext> bc(
CreateDetached(nullptr, nullptr, EmptyString(), aType, browserId));
CreateDetached(nullptr, nullptr, EmptyString(), aType));
bc->mWindowless = bc->IsContent();
bc->EnsureAttached();
return bc.forget();
@ -511,29 +500,6 @@ static bool OwnerAllowsFullscreen(const Element& aEmbedder) {
void BrowsingContext::SetEmbedderElement(Element* aEmbedder) {
mEmbeddedByThisProcess = true;
// Update the browser ID on the embedder if necessary. We currently don't care
// about browser IDs for chrome-type BrowsingContexts.
if (RefPtr<nsFrameLoaderOwner> owner = do_QueryObject(aEmbedder);
owner && !IsChrome()) {
uint64_t browserId = GetBrowserId();
uint64_t frameBrowserId = owner->GetBrowserId();
MOZ_DIAGNOSTIC_ASSERT(browserId != 0);
if (frameBrowserId == 0) {
// We'll arrive here if we're a top-level BrowsingContext for a window
// or tab that was opened in a content process. There should be no
// children to update at this point. This ID was generated in
// ContentChild::ProvideWindowCommon.
MOZ_DIAGNOSTIC_ASSERT(IsTopContent());
MOZ_DIAGNOSTIC_ASSERT(Children().IsEmpty());
owner->SetBrowserId(browserId);
} else {
// We would've inherited or generated an ID in CreateBrowsingContext.
MOZ_DIAGNOSTIC_ASSERT(browserId == frameBrowserId);
}
}
// Update embedder-element-specific fields in a shared transaction.
// Don't do this when clearing our embedder, as we're being destroyed either
// way.
@ -2436,13 +2402,6 @@ void BrowsingContext::DidSet(FieldIndex<IDX_HasSessionHistory>,
CreateChildSHistory();
}
bool BrowsingContext::CanSet(FieldIndex<IDX_BrowserId>, const uint32_t& aValue,
ContentParent* aSource) {
// We should only be able to set this for toplevel contexts which don't have
// an ID yet.
return GetBrowserId() == 0 && IsTop() && Children().IsEmpty();
}
} // namespace dom
namespace ipc {

Просмотреть файл

@ -107,13 +107,6 @@ class WindowProxyHolder;
FIELD(FeaturePolicy, RefPtr<mozilla::dom::FeaturePolicy>) \
/* See nsSandboxFlags.h for the possible flags. */ \
FIELD(SandboxFlags, uint32_t) \
/* A unique identifier for the browser element that is hosting this \
* BrowsingContext tree. Every BrowsingContext in the element's tree will \
* return the same ID in all processes and it will remain stable \
* regardless of process changes. When a browser element's frameloader is \
* switched to another browser element this ID will remain the same but \
* hosted under the under the new browser element. */ \
FIELD(BrowserId, uint64_t) \
FIELD(HistoryID, nsID) \
FIELD(InRDMPane, bool) \
FIELD(Loading, bool) \
@ -205,7 +198,7 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
// DocShell, BrowserParent, or BrowserBridgeChild.
static already_AddRefed<BrowsingContext> CreateDetached(
nsGlobalWindowInner* aParent, BrowsingContext* aOpener,
const nsAString& aName, Type aType, uint64_t aBrowserId);
const nsAString& aName, Type aType);
void EnsureAttached();
@ -403,8 +396,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
bool UseGlobalHistory() const { return GetUseGlobalHistory(); }
uint64_t BrowserId() const { return GetBrowserId(); }
bool IsLoading();
// ScreenOrientation related APIs
@ -772,9 +763,6 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
void DidSet(FieldIndex<IDX_HasSessionHistory>, bool aOldValue);
bool CanSet(FieldIndex<IDX_BrowserId>, const uint32_t& aValue,
ContentParent* aSource);
template <size_t I, typename T>
bool CanSet(FieldIndex<I>, const T&, ContentParent*) {
return true;

Просмотреть файл

@ -28,7 +28,7 @@ add_task(async function() {
true,
true
);
let browserIds = await SpecialPowers.spawn(
await SpecialPowers.spawn(
browser,
[{ base1: BASE1, base2: BASE2 }],
async function({ base1, base2 }) {
@ -172,58 +172,10 @@ add_task(async function() {
}
await unreachable(start, seventh);
}
let topBrowserId = topBC.browserId;
ok(topBrowserId > 0, "Should have a browser ID.");
for (let [name, bc] of Object.entries({
first,
second,
third,
fourth,
fifth,
})) {
is(
bc.browserId,
topBrowserId,
`${name} frame should have the same browserId as top.`
);
}
ok(sixth.browserId > 0, "sixth should have a browserId.");
isnot(
sixth.browserId,
topBrowserId,
"sixth frame should have a different browserId to top."
);
return [topBrowserId, sixth.browserId];
}
);
[sixth, seventh] = await Promise.all([sixth, seventh]);
is(
browser.browserId,
browserIds[0],
"browser should have the right browserId."
);
is(
browser.browsingContext.browserId,
browserIds[0],
"browser's BrowsingContext should have the right browserId."
);
is(
sixth.linkedBrowser.browserId,
browserIds[1],
"sixth should have the right browserId."
);
is(
sixth.linkedBrowser.browsingContext.browserId,
browserIds[1],
"sixth's BrowsingContext should have the right browserId."
);
for (let tab of [sixth, seventh]) {
for (let tab of await Promise.all([sixth, seventh])) {
BrowserTestUtils.removeTab(tab);
}
}

Просмотреть файл

@ -9716,14 +9716,6 @@ uint64_t nsContentUtils::GenerateTabId() {
return GenerateProcessSpecificId(++gNextTabId);
}
// Next process-local Browser ID.
static uint64_t gNextBrowserId = 0;
/* static */
uint64_t nsContentUtils::GenerateBrowserId() {
return GenerateProcessSpecificId(++gNextBrowserId);
}
// Next process-local Browsing Context ID.
static uint64_t gNextBrowsingContextId = 0;

Просмотреть файл

@ -3142,11 +3142,6 @@ class nsContentUtils {
*/
static uint64_t GenerateTabId();
/**
* Compose a browser id with process id and a serial number.
*/
static uint64_t GenerateBrowserId();
/**
* Generate an id for a BrowsingContext using a range of serial
* numbers reserved for the current process.

Просмотреть файл

@ -83,7 +83,6 @@
#include "mozilla/dom/MozFrameLoaderOwnerBinding.h"
#include "mozilla/dom/SessionStoreListener.h"
#include "mozilla/dom/WindowGlobalParent.h"
#include "mozilla/dom/XULFrameElement.h"
#include "mozilla/gfx/CrossProcessPaint.h"
#include "nsGenericHTMLFrameElement.h"
#include "GeckoProfiler.h"
@ -296,10 +295,6 @@ static already_AddRefed<BrowsingContext> CreateBrowsingContext(
nsAutoString frameName;
GetFrameName(aOwner, frameName);
// By default we just use the same browser ID as the parent.
uint64_t browserId = parentBC->GetBrowserId();
RefPtr<nsFrameLoaderOwner> owner = do_QueryObject(aOwner);
// Create our BrowsingContext without immediately attaching it. It's possible
// that no DocShell or remote browser will ever be created for this
// FrameLoader, particularly if the document that we were created for is not
@ -307,38 +302,16 @@ static already_AddRefed<BrowsingContext> CreateBrowsingContext(
// it will wind up attached as a child of the currently active inner window
// for the BrowsingContext, and cause no end of trouble.
if (IsTopContent(parentBC, aOwner)) {
if (owner && owner->GetBrowserId() != 0) {
// This frame has already been assigned an ID. This can happen for example
// if a frame is re-inserted into the DOM (i.e. on a remoteness change).
browserId = owner->GetBrowserId();
// This implies that we do not support changing a frame's "type"
// attribute. Doing so would mean needing to change the browser ID for the
// frame and the intent is to never change this.
MOZ_DIAGNOSTIC_ASSERT(browserId != parentBC->GetBrowserId());
} else {
browserId = nsContentUtils::GenerateBrowserId();
if (owner) {
owner->SetBrowserId(browserId);
}
}
// Create toplevel content without a parent & as Type::Content.
return BrowsingContext::CreateDetached(
nullptr, opener, frameName, BrowsingContext::Type::Content, browserId);
return BrowsingContext::CreateDetached(nullptr, opener, frameName,
BrowsingContext::Type::Content);
}
MOZ_ASSERT(!aOpenWindowInfo,
"Can't have openWindowInfo for non-toplevel context");
if (owner) {
MOZ_DIAGNOSTIC_ASSERT(owner->GetBrowserId() == 0 ||
owner->GetBrowserId() == browserId);
owner->SetBrowserId(browserId);
}
return BrowsingContext::CreateDetached(parentInner, nullptr, frameName,
parentBC->GetType(), browserId);
parentBC->GetType());
}
static bool InitialLoadIsRemote(Element* aOwner) {
@ -1321,13 +1294,6 @@ nsresult nsFrameLoader::SwapWithOtherRemoteLoader(
MaybeUpdatePrimaryBrowserParent(eBrowserParentRemoved);
aOther->MaybeUpdatePrimaryBrowserParent(eBrowserParentRemoved);
// When embedding the frame in SetOwnerContent, we check that the
// BrowsingContext's browser ID matches that of the embedder element, so swap
// the IDs here.
uint64_t ourBrowserId = aThisOwner->GetBrowserId();
aThisOwner->SetBrowserId(aOtherOwner->GetBrowserId());
aOtherOwner->SetBrowserId(ourBrowserId);
SetOwnerContent(otherContent);
aOther->SetOwnerContent(ourContent);
@ -1742,13 +1708,6 @@ nsresult nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
otherDocshell, ourOwner,
ourBc->IsContent() ? ourChromeEventHandler.get() : nullptr);
// When embedding the frame in SetOwnerContent, we check that the
// BrowsingContext's browser ID matches that of the embedder element, so swap
// the IDs here.
uint64_t ourBrowserId = aThisOwner->GetBrowserId();
aThisOwner->SetBrowserId(aOtherOwner->GetBrowserId());
aOtherOwner->SetBrowserId(ourBrowserId);
// Switch the owner content before we start calling AddTreeItemToTreeOwner.
// Note that we rely on this to deal with setting mObservingOwnerContent to
// false and calling RemoveMutationObserver as needed.

Просмотреть файл

@ -286,9 +286,3 @@ void nsFrameLoaderOwner::SubframeCrashed() {
/* inProgress */ false,
/* isRemote */ false, frameLoaderInit, IgnoreErrors());
}
void nsFrameLoaderOwner::UnbindFromTree() {
// If we're being adopted into a different document, we'll want to inherit a
// browser ID from our new BrowsingContext, so clear our current ID here.
mBrowserId = 0;
}

Просмотреть файл

@ -74,12 +74,6 @@ class nsFrameLoaderOwner : public nsISupports {
void SubframeCrashed();
// Prepare for a frame to be removed from its current DOM tree.
void UnbindFromTree();
uint64_t GetBrowserId() { return mBrowserId; }
void SetBrowserId(uint64_t aBrowserId) { mBrowserId = aBrowserId; }
private:
bool UseRemoteSubframes();
@ -105,8 +99,6 @@ class nsFrameLoaderOwner : public nsISupports {
std::function<void()>& aFrameLoaderInit,
mozilla::ErrorResult& aRv);
uint64_t mBrowserId = 0;
protected:
virtual ~nsFrameLoaderOwner() = default;
RefPtr<nsFrameLoader> mFrameLoader;

Просмотреть файл

@ -568,7 +568,6 @@ nsresult nsObjectLoadingContent::BindToTree(BindContext& aContext,
}
void nsObjectLoadingContent::UnbindFromTree(bool aNullParent) {
nsFrameLoaderOwner::UnbindFromTree();
nsImageLoadingContent::UnbindFromTree(aNullParent);
nsCOMPtr<Element> thisElement =

Просмотреть файл

@ -105,16 +105,6 @@ interface BrowsingContext {
// The watchedByDevTools flag indicates whether or not DevTools are currently
// debugging this browsing context.
[SetterThrows] attribute boolean watchedByDevTools;
/**
* A unique identifier for the browser element that is hosting this
* BrowsingContext tree. Every BrowsingContext in the element's tree will
* return the same ID in all processes and it will remain stable regardless of
* process changes. When a browser element's frameloader is switched to
* another browser element this ID will remain the same but hosted under the
* under the new browser element.
*/
attribute unsigned long long browserId;
};
BrowsingContext includes LoadContextMixin;

Просмотреть файл

@ -16,9 +16,7 @@ interface XULFrameElement : XULElement
readonly attribute nsIWebNavigation? webNavigation;
readonly attribute WindowProxy? contentWindow;
readonly attribute Document? contentDocument;
readonly attribute unsigned long long browserId;
readonly attribute Document? contentDocument;
};
XULFrameElement includes MozFrameLoaderOwner;

Просмотреть файл

@ -208,7 +208,6 @@ void nsGenericHTMLFrameElement::UnbindFromTree(bool aNullParent) {
mFrameLoader = nullptr;
}
nsFrameLoaderOwner::UnbindFromTree();
nsGenericHTMLElement::UnbindFromTree(aNullParent);
}

Просмотреть файл

@ -949,9 +949,8 @@ nsresult ContentChild::ProvideWindowCommon(
openerBC = parent;
}
uint64_t browserId(nsContentUtils::GenerateBrowserId());
RefPtr<BrowsingContext> browsingContext = BrowsingContext::CreateDetached(
nullptr, openerBC, aName, BrowsingContext::Type::Content, browserId);
nullptr, openerBC, aName, BrowsingContext::Type::Content);
MOZ_ALWAYS_SUCCEEDS(browsingContext->SetRemoteTabs(true));
MOZ_ALWAYS_SUCCEEDS(browsingContext->SetRemoteSubframes(useRemoteSubframes));
MOZ_ALWAYS_SUCCEEDS(browsingContext->SetOriginAttributes(

Просмотреть файл

@ -154,7 +154,6 @@ void XULFrameElement::UnbindFromTree(bool aNullParent) {
}
mFrameLoader = nullptr;
nsFrameLoaderOwner::UnbindFromTree();
nsXULElement::UnbindFromTree(aNullParent);
}

Просмотреть файл

@ -39,7 +39,6 @@ class XULFrameElement final : public nsXULElement, public nsFrameLoaderOwner {
already_AddRefed<nsIWebNavigation> GetWebNavigation();
Nullable<WindowProxyHolder> GetContentWindow();
Document* GetContentDocument();
uint64_t BrowserId() { return GetBrowserId(); }
void SwapFrameLoaders(mozilla::dom::HTMLIFrameElement& aOtherLoaderOwner,
mozilla::ErrorResult& rv);