2018-07-26 10:31:00 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
2018-10-20 01:00:59 +03:00
|
|
|
#ifndef mozilla_dom_BrowsingContext_h
|
|
|
|
#define mozilla_dom_BrowsingContext_h
|
2018-07-26 10:31:00 +03:00
|
|
|
|
|
|
|
#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"
|
2018-08-29 05:00:00 +03:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2018-07-26 10:31:00 +03:00
|
|
|
|
|
|
|
class nsIDocShell;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
class LogModule;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
class ContentParent;
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
// 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.
|
2018-11-05 15:43:10 +03:00
|
|
|
//
|
|
|
|
// Trees of BrowsingContexts should only ever contain nodes of the
|
|
|
|
// same BrowsingContext::Type. This is enforced by asserts in the
|
|
|
|
// BrowsingContext::Create* methods.
|
2018-08-29 05:00:00 +03:00
|
|
|
class BrowsingContext : public nsWrapperCache,
|
|
|
|
public SupportsWeakPtr<BrowsingContext>,
|
2018-07-26 10:31:00 +03:00
|
|
|
public LinkedListElement<RefPtr<BrowsingContext>> {
|
|
|
|
public:
|
2018-11-05 15:43:10 +03:00
|
|
|
enum class Type { Chrome, Content };
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
static void Init();
|
|
|
|
static LogModule* GetLog();
|
2018-06-29 02:41:00 +03:00
|
|
|
static void CleanupContexts(uint64_t aProcessId);
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
// Look up a BrowsingContext in the current process by ID.
|
2018-07-26 10:31:00 +03:00
|
|
|
static already_AddRefed<BrowsingContext> Get(uint64_t aId);
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
// Create a brand-new BrowsingContext object.
|
|
|
|
static already_AddRefed<BrowsingContext> Create(BrowsingContext* aParent,
|
2018-11-27 12:59:44 +03:00
|
|
|
BrowsingContext* aOpener,
|
2018-11-05 15:43:10 +03:00
|
|
|
const nsAString& aName,
|
|
|
|
Type aType);
|
|
|
|
|
|
|
|
// Create a BrowsingContext object from over IPC.
|
|
|
|
static already_AddRefed<BrowsingContext> CreateFromIPC(
|
2018-11-27 12:59:44 +03:00
|
|
|
BrowsingContext* aParent, BrowsingContext* aOpener,
|
2018-11-05 15:43:10 +03:00
|
|
|
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();
|
2018-07-26 10:31:00 +03:00
|
|
|
|
|
|
|
// Detach the current BrowsingContext from its parent, in both the
|
|
|
|
// child and the parent process.
|
|
|
|
void Detach();
|
|
|
|
|
2018-06-28 05:40:00 +03:00
|
|
|
// Remove all children from the current BrowsingContext and cache
|
|
|
|
// them to allow them to be attached again.
|
|
|
|
void CacheChildren();
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
// Determine if the current BrowsingContext was 'cached' by the logic in
|
|
|
|
// CacheChildren.
|
2018-06-28 05:40:00 +03:00
|
|
|
bool IsCached();
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
// TODO(farre): We should sync changes from SetName to the parent
|
|
|
|
// process. [Bug 1490303]
|
2018-07-26 10:31:00 +03:00
|
|
|
void SetName(const nsAString& aName) { mName = aName; }
|
|
|
|
void GetName(nsAString& aName) { aName = mName; }
|
|
|
|
bool NameEquals(const nsAString& aName) { return mName.Equals(aName); }
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
bool IsContent() const { return mType == Type::Content; }
|
|
|
|
|
2018-07-26 10:31:00 +03:00
|
|
|
uint64_t Id() const { return mBrowsingContextId; }
|
|
|
|
|
2018-11-05 15:43:10 +03:00
|
|
|
BrowsingContext* GetParent() { return mParent; }
|
2018-08-29 05:00:00 +03:00
|
|
|
|
|
|
|
void GetChildren(nsTArray<RefPtr<BrowsingContext>>& aChildren);
|
|
|
|
|
2018-11-09 11:53:53 +03:00
|
|
|
BrowsingContext* GetOpener() { return mOpener; }
|
|
|
|
|
|
|
|
void SetOpener(BrowsingContext* aOpener);
|
|
|
|
|
2018-08-29 05:00:00 +03:00
|
|
|
static void GetRootBrowsingContexts(
|
|
|
|
nsTArray<RefPtr<BrowsingContext>>& aBrowsingContexts);
|
|
|
|
|
|
|
|
nsISupports* GetParentObject() const;
|
2018-10-20 02:02:56 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2018-07-26 10:31:00 +03:00
|
|
|
|
|
|
|
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(BrowsingContext)
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(BrowsingContext)
|
2018-08-29 05:00:00 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(BrowsingContext)
|
2018-07-26 10:31:00 +03:00
|
|
|
|
|
|
|
using Children = AutoCleanLinkedList<RefPtr<BrowsingContext>>;
|
|
|
|
|
2018-09-14 17:57:18 +03:00
|
|
|
protected:
|
2018-08-29 05:00:00 +03:00
|
|
|
virtual ~BrowsingContext();
|
2018-11-05 15:43:10 +03:00
|
|
|
BrowsingContext(BrowsingContext* aParent, BrowsingContext* aOpener,
|
|
|
|
const nsAString& aName, uint64_t aBrowsingContextId,
|
|
|
|
Type aType);
|
2018-07-26 10:31:00 +03:00
|
|
|
|
2018-09-14 17:57:18 +03:00
|
|
|
private:
|
2018-11-05 15:43:10 +03:00
|
|
|
// Type of BrowsingContent
|
|
|
|
const Type mType;
|
|
|
|
|
|
|
|
// Unique id identifying BrowsingContext
|
2018-07-26 10:31:00 +03:00
|
|
|
const uint64_t mBrowsingContextId;
|
|
|
|
|
|
|
|
WeakPtr<BrowsingContext> mParent;
|
|
|
|
Children mChildren;
|
2018-11-09 11:53:53 +03:00
|
|
|
WeakPtr<BrowsingContext> mOpener;
|
2018-07-26 10:31:00 +03:00
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
|
|
|
nsString mName;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2018-10-20 01:00:59 +03:00
|
|
|
|
|
|
|
#endif // !defined(mozilla_dom_BrowsingContext_h)
|