Bug 1580565 - Part 3: Simplify API for creating independent BCs, r=farre

There were previously a number of different APIs for creating BrowsingContext
instances. This simplifies them into two major cases: "CreateDetached", which
allows for creating BrowsingContexts which are related to other
BrowsingContexts, and "CreateIndependent" which creates new, fully unrelated,
browsing contexts.

Differential Revision: https://phabricator.services.mozilla.com/D71237
This commit is contained in:
Nika Layzell 2020-04-22 03:21:55 +00:00
Родитель daa9e7acad
Коммит 01ad33304d
5 изменённых файлов: 21 добавлений и 34 удалений

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

@ -261,19 +261,11 @@ already_AddRefed<BrowsingContext> BrowsingContext::CreateDetached(
return context.forget();
}
already_AddRefed<BrowsingContext> BrowsingContext::Create(
BrowsingContext* aParent, BrowsingContext* aOpener, const nsAString& aName,
already_AddRefed<BrowsingContext> BrowsingContext::CreateIndependent(
Type aType) {
RefPtr<BrowsingContext> bc(CreateDetached(aParent, aOpener, aName, aType));
bc->EnsureAttached();
return bc.forget();
}
already_AddRefed<BrowsingContext> BrowsingContext::CreateWindowless(
BrowsingContext* aParent, BrowsingContext* aOpener, const nsAString& aName,
Type aType) {
RefPtr<BrowsingContext> bc(CreateDetached(aParent, aOpener, aName, aType));
bc->mWindowless = true;
RefPtr<BrowsingContext> bc(
CreateDetached(nullptr, nullptr, EmptyString(), aType));
bc->mWindowless = bc->IsContent();
bc->EnsureAttached();
return bc.forget();
}

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

@ -166,28 +166,27 @@ class BrowsingContext : public nsILoadContext, public nsWrapperCache {
return GetFromWindow(aProxy);
}
// Create a brand-new BrowsingContext object.
static already_AddRefed<BrowsingContext> Create(BrowsingContext* aParent,
BrowsingContext* aOpener,
const nsAString& aName,
Type aType);
// Create a brand-new toplevel BrowsingContext with no relationships to other
// BrowsingContexts, and which is not embedded within any <browser> or frame
// element.
//
// This BrowsingContext is immediately attached, and cannot have LoadContext
// flags customized unless it is of `Type::Chrome`.
//
// The process which created this BrowsingContext is responsible for detaching
// it.
static already_AddRefed<BrowsingContext> CreateIndependent(Type aType);
// Same as the above, but does not immediately attach the browsing context.
// Create a brand-new BrowsingContext object, but does not immediately attach
// it. State such as OriginAttributes and PrivateBrowsingId may be customized
// to configure the BrowsingContext before it is attached.
//
// `EnsureAttached()` must be called before the BrowsingContext is used for a
// DocShell, BrowserParent, or BrowserBridgeChild.
static already_AddRefed<BrowsingContext> CreateDetached(
BrowsingContext* aParent, BrowsingContext* aOpener,
const nsAString& aName, Type aType);
// Same as Create, but for a BrowsingContext which does not belong to a
// visible window, and will always be detached by the process that created it.
// In contrast, any top-level BrowsingContext created in a content process
// using Create() is assumed to belong to a <browser> element in the parent
// process, which will be responsible for detaching it.
static already_AddRefed<BrowsingContext> CreateWindowless(
BrowsingContext* aParent, BrowsingContext* aOpener,
const nsAString& aName, Type aType);
void EnsureAttached();
bool EverAttached() const { return mEverAttached; }

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

@ -76,9 +76,7 @@ nsresult nsPrintObject::InitAsRootObject(nsIDocShell* aDocShell, Document* aDoc,
// is detached from any browser window or tab.
// Create a new BrowsingContext to create our DocShell in.
RefPtr<BrowsingContext> bc = BrowsingContext::CreateWindowless(
/* aParent */ nullptr,
/* aOpener */ nullptr, EmptyString(),
RefPtr<BrowsingContext> bc = BrowsingContext::CreateIndependent(
nsDocShell::Cast(aDocShell)->GetBrowsingContext()->GetType());
// Create a container docshell for printing.

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

@ -233,8 +233,7 @@ nsresult AppWindow::Initialize(nsIAppWindow* aParent, nsIAppWindow* aOpener,
// to pass in the opener window here. The opener is set later, if needed, by
// nsWindowWatcher.
RefPtr<BrowsingContext> browsingContext =
BrowsingContext::Create(/* aParent */ nullptr, /* aOpener */ nullptr,
EmptyString(), BrowsingContext::Type::Chrome);
BrowsingContext::CreateIndependent(BrowsingContext::Type::Chrome);
// Create web shell
mDocShell = nsDocShell::Create(browsingContext);

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

@ -449,8 +449,7 @@ nsAppShellService::CreateWindowlessBrowser(bool aIsChrome,
NS_ENSURE_SUCCESS(rv, rv);
// Create a BrowsingContext for our windowless browser.
RefPtr<BrowsingContext> browsingContext = BrowsingContext::CreateWindowless(
nullptr, nullptr, EmptyString(),
RefPtr<BrowsingContext> browsingContext = BrowsingContext::CreateIndependent(
aIsChrome ? BrowsingContext::Type::Chrome
: BrowsingContext::Type::Content);