2016-10-28 21:25:43 +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/. */
|
|
|
|
|
|
|
|
#ifndef TabGroup_h
|
|
|
|
#define TabGroup_h
|
|
|
|
|
2017-07-20 02:07:39 +03:00
|
|
|
#include "nsHashKeys.h"
|
2016-10-28 21:25:43 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
2016-12-16 00:48:14 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2017-03-09 23:32:32 +03:00
|
|
|
#include "mozilla/SchedulerGroup.h"
|
2016-10-28 21:25:43 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
|
2017-02-02 00:38:14 +03:00
|
|
|
class mozIDOMWindowProxy;
|
|
|
|
class nsIDocShellTreeItem;
|
|
|
|
class nsIDocument;
|
|
|
|
class nsPIDOMWindowOuter;
|
|
|
|
|
2016-10-28 21:25:43 +03:00
|
|
|
namespace mozilla {
|
2016-12-01 13:33:05 +03:00
|
|
|
class AbstractThread;
|
2016-11-07 23:30:17 +03:00
|
|
|
class ThrottledEventQueue;
|
2016-10-28 21:25:43 +03:00
|
|
|
namespace dom {
|
2017-07-19 21:15:11 +03:00
|
|
|
class TabChild;
|
2016-10-28 21:25:43 +03:00
|
|
|
|
|
|
|
// Two browsing contexts are considered "related" if they are reachable from one
|
|
|
|
// another through window.opener, window.parent, or window.frames. This is the
|
|
|
|
// spec concept of a "unit of related browsing contexts"
|
|
|
|
//
|
|
|
|
// Two browsing contexts are considered "similar-origin" if they can be made to
|
|
|
|
// have the same origin by setting document.domain. This is the spec concept of
|
|
|
|
// a "unit of similar-origin related browsing contexts"
|
|
|
|
//
|
|
|
|
// A TabGroup is a set of browsing contexts which are all "related". Within a
|
|
|
|
// TabGroup, browsing contexts are broken into "similar-origin" DocGroups. In
|
|
|
|
// more detail, a DocGroup is actually a collection of documents, and a
|
|
|
|
// TabGroup is a collection of DocGroups. A TabGroup typically will contain
|
|
|
|
// (through its DocGroups) the documents from one or more tabs related by
|
|
|
|
// window.opener. A DocGroup is a member of exactly one TabGroup.
|
|
|
|
|
|
|
|
class DocGroup;
|
2017-07-20 02:07:39 +03:00
|
|
|
class TabChild;
|
2016-10-28 21:25:43 +03:00
|
|
|
|
2018-06-16 22:49:41 +03:00
|
|
|
class TabGroup final : public SchedulerGroup,
|
|
|
|
public LinkedListElement<TabGroup>
|
2016-10-28 21:25:43 +03:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
class HashEntry : public nsCStringHashKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// NOTE: Weak reference. The DocGroup destructor removes itself from its
|
|
|
|
// owning TabGroup.
|
|
|
|
DocGroup* mDocGroup;
|
|
|
|
explicit HashEntry(const nsACString* aKey);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef nsTHashtable<HashEntry> DocGroupMap;
|
2017-02-02 00:38:33 +03:00
|
|
|
|
2016-10-28 21:25:43 +03:00
|
|
|
public:
|
|
|
|
typedef DocGroupMap::Iterator Iterator;
|
|
|
|
|
|
|
|
friend class DocGroup;
|
|
|
|
|
2017-01-31 03:13:18 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TabGroup, override)
|
2016-10-28 21:25:43 +03:00
|
|
|
|
|
|
|
static TabGroup*
|
|
|
|
GetChromeTabGroup();
|
|
|
|
|
2017-04-07 02:46:18 +03:00
|
|
|
// Checks if the TabChild already has a TabGroup assigned to it in
|
|
|
|
// IPDL. Returns this TabGroup if it does. This could happen if the parent
|
|
|
|
// process created the PBrowser and we needed to assign a TabGroup immediately
|
|
|
|
// upon receiving the IPDL message. This method is main thread only.
|
|
|
|
static TabGroup* GetFromActor(TabChild* aTabChild);
|
|
|
|
|
|
|
|
static TabGroup* GetFromWindow(mozIDOMWindowProxy* aWindow);
|
2016-11-04 21:13:52 +03:00
|
|
|
|
2016-11-07 23:30:17 +03:00
|
|
|
explicit TabGroup(bool aIsChrome = false);
|
2016-10-28 21:25:43 +03:00
|
|
|
|
|
|
|
// Get the docgroup for the corresponding doc group key.
|
|
|
|
// Returns null if the given key hasn't been seen yet.
|
|
|
|
already_AddRefed<DocGroup>
|
|
|
|
GetDocGroup(const nsACString& aKey);
|
|
|
|
|
|
|
|
already_AddRefed<DocGroup>
|
|
|
|
AddDocument(const nsACString& aKey, nsIDocument* aDocument);
|
|
|
|
|
|
|
|
// Join the specified TabGroup, returning a reference to it. If aTabGroup is
|
|
|
|
// nullptr, create a new tabgroup to join.
|
|
|
|
static already_AddRefed<TabGroup>
|
|
|
|
Join(nsPIDOMWindowOuter* aWindow, TabGroup* aTabGroup);
|
|
|
|
|
|
|
|
void Leave(nsPIDOMWindowOuter* aWindow);
|
|
|
|
|
|
|
|
Iterator Iter()
|
|
|
|
{
|
|
|
|
return mDocGroups.Iter();
|
|
|
|
}
|
|
|
|
|
2018-05-30 05:48:00 +03:00
|
|
|
// Returns the size of the set of "similar-origin" DocGroups. To
|
|
|
|
// only consider DocGroups with at least one active document, call
|
|
|
|
// Count with 'aActiveOnly' = true
|
|
|
|
uint32_t Count(bool aActiveOnly = false) const;
|
2016-10-28 21:25:43 +03:00
|
|
|
|
|
|
|
// Returns the nsIDocShellTreeItem with the given name, searching each of the
|
|
|
|
// docShell trees which are within this TabGroup. It will pass itself as
|
|
|
|
// aRequestor to each docShellTreeItem which it asks to search for the name,
|
|
|
|
// and will not search the docShellTreeItem which is passed as aRequestor.
|
|
|
|
//
|
|
|
|
// This method is used in order to correctly namespace named windows based on
|
|
|
|
// their unit of related browsing contexts.
|
|
|
|
//
|
|
|
|
// It is illegal to pass in the special case-insensitive names "_blank",
|
|
|
|
// "_self", "_parent" or "_top", as those should be handled elsewhere.
|
|
|
|
nsresult
|
|
|
|
FindItemWithName(const nsAString& aName,
|
|
|
|
nsIDocShellTreeItem* aRequestor,
|
|
|
|
nsIDocShellTreeItem* aOriginalRequestor,
|
|
|
|
nsIDocShellTreeItem** aFoundItem);
|
|
|
|
|
2017-05-02 15:10:00 +03:00
|
|
|
nsTArray<nsPIDOMWindowOuter*> GetTopLevelWindows() const;
|
2017-02-22 02:01:27 +03:00
|
|
|
const nsTArray<nsPIDOMWindowOuter*>& GetWindows() { return mWindows; }
|
2016-10-21 23:56:51 +03:00
|
|
|
|
2016-12-16 00:48:14 +03:00
|
|
|
// This method is always safe to call off the main thread. The nsIEventTarget
|
|
|
|
// can always be used off the main thread.
|
2017-06-13 23:40:00 +03:00
|
|
|
nsISerialEventTarget* EventTargetFor(TaskCategory aCategory) const override;
|
2016-11-04 21:13:52 +03:00
|
|
|
|
2017-05-24 18:36:27 +03:00
|
|
|
void WindowChangedBackgroundStatus(bool aIsNowBackground);
|
|
|
|
|
2017-05-02 15:10:00 +03:00
|
|
|
// Returns true if all of the TabGroup's top-level windows are in
|
|
|
|
// the background.
|
|
|
|
bool IsBackground() const override;
|
|
|
|
|
2017-04-18 13:21:34 +03:00
|
|
|
// Increase/Decrease the number of IndexedDB transactions/databases for the
|
|
|
|
// decision making of the preemption in the scheduler.
|
|
|
|
Atomic<uint32_t>& IndexedDBTransactionCounter()
|
|
|
|
{
|
|
|
|
return mNumOfIndexedDBTransactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
Atomic<uint32_t>& IndexedDBDatabaseCounter()
|
|
|
|
{
|
|
|
|
return mNumOfIndexedDBDatabases;
|
|
|
|
}
|
|
|
|
|
2018-06-16 22:49:41 +03:00
|
|
|
static LinkedList<TabGroup>* GetTabGroupList()
|
|
|
|
{
|
|
|
|
return sTabGroups;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns true if all the window objects in all the TabGroups are
|
|
|
|
// either inactive (for example in bfcache) or are in background tabs which
|
|
|
|
// can be throttled.
|
|
|
|
static bool HasOnlyThrottableTabs();
|
|
|
|
|
2017-01-31 03:13:18 +03:00
|
|
|
private:
|
2016-12-01 13:33:05 +03:00
|
|
|
virtual AbstractThread*
|
2017-01-31 03:13:18 +03:00
|
|
|
AbstractMainThreadForImpl(TaskCategory aCategory) override;
|
2016-12-01 13:33:05 +03:00
|
|
|
|
2017-02-02 00:38:14 +03:00
|
|
|
TabGroup* AsTabGroup() override { return this; }
|
|
|
|
|
2016-11-04 21:13:52 +03:00
|
|
|
void EnsureThrottledEventQueues();
|
|
|
|
|
2016-10-28 21:25:43 +03:00
|
|
|
~TabGroup();
|
2017-01-31 19:08:35 +03:00
|
|
|
|
|
|
|
// Thread-safe members
|
2016-12-16 00:48:14 +03:00
|
|
|
Atomic<bool> mLastWindowLeft;
|
2016-11-27 22:24:34 +03:00
|
|
|
Atomic<bool> mThrottledQueuesInitialized;
|
2017-04-18 13:21:34 +03:00
|
|
|
Atomic<uint32_t> mNumOfIndexedDBTransactions;
|
|
|
|
Atomic<uint32_t> mNumOfIndexedDBDatabases;
|
2017-01-31 19:08:35 +03:00
|
|
|
const bool mIsChrome;
|
|
|
|
|
|
|
|
// Main thread only
|
|
|
|
DocGroupMap mDocGroups;
|
|
|
|
nsTArray<nsPIDOMWindowOuter*> mWindows;
|
2017-05-24 18:36:27 +03:00
|
|
|
uint32_t mForegroundCount;
|
2018-06-16 22:49:41 +03:00
|
|
|
|
|
|
|
static LinkedList<TabGroup>* sTabGroups;
|
2016-10-28 21:25:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // defined(TabGroup_h)
|