Files
firefox/docshell/base/BrowsingContext.h
T
arthur.iakab 69725c7dd7 Backed out 13 changesets (bug 1500948, bug 1509362, bug 1509591, bug 1448426, bug 1500949, bug 1487249, bug 1509930, bug 1500950, bug 1500944) for causing crashes and assertion failures on PBackgroundParent.cpp:696 CLOSED TREE
Backed out changeset c3fe435e473a (bug 1509362)
Backed out changeset 6494840edc17 (bug 1509591)
Backed out changeset 123b5d5a3637 (bug 1509591)
Backed out changeset bce195f98895 (bug 1509930)
Backed out changeset 66db13126408 (bug 1500950)
Backed out changeset 3b5fffae2d2b (bug 1500949)
Backed out changeset 71c3b3677db8 (bug 1500948)
Backed out changeset 784b3b56e2ab (bug 1500944)
Backed out changeset 0bad27401ddb (bug 1500944)
Backed out changeset e0f95dd96d54 (bug 1448426)
Backed out changeset c60fa11538db (bug 1487249)
Backed out changeset 0190d4ffa54f (bug 1487249)
Backed out changeset 3cd10aba9130 (bug 1487249)
2018-11-28 02:57:32 +02:00

162 lines
5.0 KiB
C++

/* -*- 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/. */
#ifndef BrowsingContext_h
#define BrowsingContext_h
#include "mozilla/LinkedList.h"
#include "mozilla/Maybe.h"
#include "mozilla/RefPtr.h"
#include "mozilla/WeakPtr.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsWrapperCache.h"
class nsIDocShell;
namespace mozilla {
class LogModule;
namespace dom {
class ContentParent;
// BrowsingContext, in this context, is the cross process replicated
// environment in which information about documents is stored. In
// particular the tree structure of nested browsing contexts is
// represented by the tree of BrowsingContexts.
//
// The tree of BrowsingContexts in created in step with its
// corresponding nsDocShell, and when nsDocShells are connected
// through a parent/child relationship, so are BrowsingContexts. The
// major difference is that BrowsingContexts are replicated (synced)
// to the parent process, making it possible to traverse the
// BrowsingContext tree for a tab, in both the parent and the child
// process.
//
// Trees of BrowsingContexts should only ever contain nodes of the
// same BrowsingContext::Type. This is enforced by asserts in the
// BrowsingContext::Create* methods.
class BrowsingContext
: public nsWrapperCache
, public SupportsWeakPtr<BrowsingContext>
, public LinkedListElement<RefPtr<BrowsingContext>>
{
public:
enum class Type
{
Chrome,
Content
};
static void Init();
static LogModule* GetLog();
static void CleanupContexts(uint64_t aProcessId);
// Look up a BrowsingContext in the current process by ID.
static already_AddRefed<BrowsingContext> Get(uint64_t aId);
// Create a brand-new BrowsingContext object.
static already_AddRefed<BrowsingContext> Create(BrowsingContext* aParent,
BrowsingContext* aOpener,
const nsAString& aName,
Type aType);
// Create a BrowsingContext object from over IPC.
static already_AddRefed<BrowsingContext> CreateFromIPC(
BrowsingContext* aParent,
BrowsingContext* aOpener,
const nsAString& aName,
uint64_t aId,
ContentParent* aOriginProcess);
// Get the DocShell for this BrowsingContext if it is in-process, or
// null if it's not.
nsIDocShell* GetDocShell() { return mDocShell; }
void SetDocShell(nsIDocShell* aDocShell);
// Attach the current BrowsingContext to its parent, in both the child and the
// parent process. BrowsingContext objects are created attached by default, so
// this method need only be called when restoring cached BrowsingContext
// objects.
void Attach();
// Detach the current BrowsingContext from its parent, in both the
// child and the parent process.
void Detach();
// Remove all children from the current BrowsingContext and cache
// them to allow them to be attached again.
void CacheChildren();
// Determine if the current BrowsingContext was 'cached' by the logic in
// CacheChildren.
bool IsCached();
// TODO(farre): We should sync changes from SetName to the parent
// process. [Bug 1490303]
void SetName(const nsAString& aName) { mName = aName; }
void GetName(nsAString& aName) { aName = mName; }
bool NameEquals(const nsAString& aName) { return mName.Equals(aName); }
bool IsContent() const { return mType == Type::Content; }
uint64_t Id() const { return mBrowsingContextId; }
BrowsingContext* GetParent() { return mParent; }
void GetChildren(nsTArray<RefPtr<BrowsingContext>>& aChildren);
BrowsingContext* GetOpener()
{
return mOpener;
}
void SetOpener(BrowsingContext* aOpener);
static void GetRootBrowsingContexts(
nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts);
nsISupports* GetParentObject() const;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext)
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BrowsingContext)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(BrowsingContext)
using Children = AutoCleanLinkedList<RefPtr<BrowsingContext>>;
protected:
virtual ~BrowsingContext();
BrowsingContext(BrowsingContext* aParent,
BrowsingContext* aOpener,
const nsAString& aName,
uint64_t aBrowsingContextId,
Type aType);
private:
// Type of BrowsingContent
const Type mType;
// Unique id identifying BrowsingContext
const uint64_t mBrowsingContextId;
WeakPtr<BrowsingContext> mParent;
Children mChildren;
WeakPtr<BrowsingContext> mOpener;
nsCOMPtr<nsIDocShell> mDocShell;
nsString mName;
};
} // namespace dom
} // namespace mozilla
#endif