2015-08-17 22:13:20 +00: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/. */
|
|
|
|
|
|
|
|
#include "PerformanceObserverEntryList.h"
|
|
|
|
|
2016-06-09 17:04:42 +00:00
|
|
|
#include "mozilla/dom/Performance.h"
|
2015-08-17 22:13:20 +00:00
|
|
|
#include "mozilla/dom/PerformanceObserverEntryListBinding.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "PerformanceResourceTiming.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PerformanceObserverEntryList, mOwner,
|
|
|
|
mEntries)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(PerformanceObserverEntryList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(PerformanceObserverEntryList)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceObserverEntryList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2020-03-04 09:10:03 +00:00
|
|
|
PerformanceObserverEntryList::~PerformanceObserverEntryList() = default;
|
2015-08-17 22:13:20 +00:00
|
|
|
|
|
|
|
JSObject* PerformanceObserverEntryList::WrapObject(
|
|
|
|
JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return PerformanceObserverEntryList_Binding::Wrap(aCx, this, aGivenProto);
|
2015-08-17 22:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerformanceObserverEntryList::GetEntries(
|
|
|
|
const PerformanceEntryFilterOptions& aFilter,
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
|
2015-08-17 22:13:20 +00:00
|
|
|
aRetval.Clear();
|
2021-01-24 12:16:55 +00:00
|
|
|
RefPtr<nsAtom> name =
|
|
|
|
aFilter.mName.WasPassed() ? NS_Atomize(aFilter.mName.Value()) : nullptr;
|
|
|
|
RefPtr<nsAtom> entryType = aFilter.mEntryType.WasPassed()
|
|
|
|
? NS_Atomize(aFilter.mEntryType.Value())
|
|
|
|
: nullptr;
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<PerformanceEntry>& entry : mEntries) {
|
2015-08-17 22:13:26 +00:00
|
|
|
if (aFilter.mInitiatorType.WasPassed()) {
|
|
|
|
const PerformanceResourceTiming* resourceEntry =
|
|
|
|
entry->ToResourceTiming();
|
|
|
|
if (!resourceEntry) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-08-17 22:13:20 +00:00
|
|
|
nsAutoString initiatorType;
|
|
|
|
resourceEntry->GetInitiatorType(initiatorType);
|
|
|
|
if (!initiatorType.Equals(aFilter.mInitiatorType.Value())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2021-01-24 12:16:55 +00:00
|
|
|
if (name && entry->GetName() != name) {
|
2015-08-17 22:13:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-01-24 12:16:55 +00:00
|
|
|
if (entryType && entry->GetEntryType() != entryType) {
|
2015-08-17 22:13:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRetval.AppendElement(entry);
|
|
|
|
}
|
2017-09-02 12:39:19 +00:00
|
|
|
aRetval.Sort(PerformanceEntryComparator());
|
2015-08-17 22:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerformanceObserverEntryList::GetEntriesByType(
|
2015-10-18 05:24:48 +00:00
|
|
|
const nsAString& aEntryType, nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
|
2015-08-17 22:13:20 +00:00
|
|
|
aRetval.Clear();
|
2021-01-24 12:16:55 +00:00
|
|
|
RefPtr<nsAtom> entryType = NS_Atomize(aEntryType);
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<PerformanceEntry>& entry : mEntries) {
|
2021-01-24 12:16:55 +00:00
|
|
|
if (entry->GetEntryType() == entryType) {
|
2015-08-17 22:13:20 +00:00
|
|
|
aRetval.AppendElement(entry);
|
|
|
|
}
|
|
|
|
}
|
2017-09-02 12:39:19 +00:00
|
|
|
aRetval.Sort(PerformanceEntryComparator());
|
2015-08-17 22:13:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PerformanceObserverEntryList::GetEntriesByName(
|
|
|
|
const nsAString& aName, const Optional<nsAString>& aEntryType,
|
2015-10-18 05:24:48 +00:00
|
|
|
nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
|
2015-08-17 22:13:20 +00:00
|
|
|
aRetval.Clear();
|
2021-01-24 12:16:55 +00:00
|
|
|
RefPtr<nsAtom> name = NS_Atomize(aName);
|
|
|
|
RefPtr<nsAtom> entryType =
|
|
|
|
aEntryType.WasPassed() ? NS_Atomize(aEntryType.Value()) : nullptr;
|
2015-10-18 05:24:48 +00:00
|
|
|
for (const RefPtr<PerformanceEntry>& entry : mEntries) {
|
2021-01-24 12:16:55 +00:00
|
|
|
if (entry->GetName() != name) {
|
2017-09-02 12:42:00 +00:00
|
|
|
continue;
|
2015-08-17 22:13:20 +00:00
|
|
|
}
|
2017-09-02 12:42:00 +00:00
|
|
|
|
2021-01-24 12:16:55 +00:00
|
|
|
if (entryType && entry->GetEntryType() != entryType) {
|
2017-09-02 12:42:00 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
aRetval.AppendElement(entry);
|
2015-08-17 22:13:20 +00:00
|
|
|
}
|
2017-09-02 12:39:19 +00:00
|
|
|
aRetval.Sort(PerformanceEntryComparator());
|
2015-08-17 22:13:20 +00:00
|
|
|
}
|