Bug 1300659 P2 Expose a ThrottledEventQueue on TabGroup and nsPIDOMWindow. r=smaug

This commit is contained in:
Ben Kelly 2016-11-07 12:30:17 -08:00
parent 2ee0844d95
commit 18e9d9bbcc
5 changed files with 66 additions and 10 deletions

View File

@ -1,17 +1,43 @@
/* -*- 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/. */
#include "mozilla/dom/TabGroup.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/Telemetry.h"
#include "nsIURI.h"
#include "nsIEffectiveTLDService.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Telemetry.h"
#include "mozilla/ThrottledEventQueue.h"
#include "nsIDocShell.h"
#include "nsIEffectiveTLDService.h"
#include "nsIURI.h"
namespace mozilla {
namespace dom {
TabGroup::TabGroup()
{}
static StaticRefPtr<TabGroup> sChromeTabGroup;
TabGroup::TabGroup(bool aIsChrome)
{
// Do not throttle runnables from chrome windows. In theory we should
// not have abuse issues from these windows and many browser chrome
// tests have races that fail if we do throttle chrome runnables.
if (aIsChrome) {
MOZ_ASSERT(!sChromeTabGroup);
return;
}
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
MOZ_DIAGNOSTIC_ASSERT(mainThread);
// This may return nullptr during xpcom shutdown. This is ok as we
// do not guarantee a ThrottledEventQueue will be present.
mThrottledEventQueue = ThrottledEventQueue::Create(mainThread);
}
TabGroup::~TabGroup()
{
@ -19,13 +45,11 @@ TabGroup::~TabGroup()
MOZ_ASSERT(mWindows.IsEmpty());
}
static StaticRefPtr<TabGroup> sChromeTabGroup;
TabGroup*
TabGroup::GetChromeTabGroup()
{
if (!sChromeTabGroup) {
sChromeTabGroup = new TabGroup();
sChromeTabGroup = new TabGroup(true /* chrome tab group */);
ClearOnShutdown(&sChromeTabGroup);
}
return sChromeTabGroup;
@ -130,6 +154,12 @@ TabGroup::GetTopLevelWindows()
return array;
}
ThrottledEventQueue*
TabGroup::GetThrottledEventQueue() const
{
return mThrottledEventQueue;
}
NS_IMPL_ISUPPORTS(TabGroup, nsISupports)
TabGroup::HashEntry::HashEntry(const nsACString* aKey)

View File

@ -16,6 +16,7 @@
#include "mozilla/RefPtr.h"
namespace mozilla {
class ThrottledEventQueue;
namespace dom {
// Two browsing contexts are considered "related" if they are reachable from one
@ -58,7 +59,7 @@ public:
static TabGroup*
GetChromeTabGroup();
TabGroup();
explicit TabGroup(bool aIsChrome = false);
// Get the docgroup for the corresponding doc group key.
// Returns null if the given key hasn't been seen yet.
@ -99,10 +100,16 @@ public:
nsTArray<nsPIDOMWindowOuter*> GetTopLevelWindows();
// Get the event queue that associated windows can use to issue runnables to
// the main thread. This may return nullptr during browser shutdown.
ThrottledEventQueue*
GetThrottledEventQueue() const;
private:
~TabGroup();
DocGroupMap mDocGroups;
nsTArray<nsPIDOMWindowOuter*> mWindows;
RefPtr<ThrottledEventQueue> mThrottledEventQueue;
};
} // namespace dom

View File

@ -80,6 +80,7 @@
#include "mozilla/EventStates.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/ProcessHangMonitor.h"
#include "mozilla/ThrottledEventQueue.h"
#include "AudioChannelService.h"
#include "nsAboutProtocolUtils.h"
#include "nsCharTraits.h" // NS_IS_HIGH/LOW_SURROGATE
@ -9516,6 +9517,18 @@ nsGlobalWindow::UpdateCommands(const nsAString& anAction, nsISelection* aSel, in
return NS_OK;
}
ThrottledEventQueue*
nsGlobalWindow::GetThrottledEventQueue()
{
// We must have an outer to access the TabGroup.
nsGlobalWindow* outer = GetOuterWindowInternal();
if (!outer) {
return nullptr;
}
return TabGroup()->GetThrottledEventQueue();
}
Selection*
nsGlobalWindow::GetSelectionOuter()
{

View File

@ -103,6 +103,7 @@ class nsWindowSizes;
namespace mozilla {
class DOMEventTargetHelper;
class ThrottledEventQueue;
namespace dom {
class BarProp;
struct ChannelPixelLayout;
@ -1157,6 +1158,8 @@ public:
nsPIDOMWindowOuter** _retval) override;
nsresult UpdateCommands(const nsAString& anAction, nsISelection* aSel, int16_t aReason) override;
mozilla::ThrottledEventQueue* GetThrottledEventQueue() override;
already_AddRefed<nsPIDOMWindowOuter>
GetContentInternal(mozilla::ErrorResult& aError, bool aUnprivilegedCaller);
void GetContentOuter(JSContext* aCx,

View File

@ -40,6 +40,7 @@ class nsXBLPrototypeHandler;
typedef uint32_t SuspendTypes;
namespace mozilla {
class ThrottledEventQueue;
namespace dom {
class AudioContext;
class DocGroup;
@ -581,6 +582,8 @@ public:
mozilla::dom::DocGroup* GetDocGroup();
virtual mozilla::ThrottledEventQueue* GetThrottledEventQueue() = 0;
protected:
// The nsPIDOMWindow constructor. The aOuterWindow argument should
// be null if and only if the created window itself is an outer