tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PerformanceObserverEntryList.cpp (3415B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "PerformanceObserverEntryList.h"
      8 
      9 #include "PerformanceResourceTiming.h"
     10 #include "mozilla/dom/Performance.h"
     11 #include "mozilla/dom/PerformanceObserverEntryListBinding.h"
     12 #include "nsString.h"
     13 
     14 using namespace mozilla;
     15 using namespace mozilla::dom;
     16 
     17 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PerformanceObserverEntryList, mOwner,
     18                                      mEntries)
     19 
     20 NS_IMPL_CYCLE_COLLECTING_ADDREF(PerformanceObserverEntryList)
     21 NS_IMPL_CYCLE_COLLECTING_RELEASE(PerformanceObserverEntryList)
     22 
     23 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceObserverEntryList)
     24  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     25  NS_INTERFACE_MAP_ENTRY(nsISupports)
     26 NS_INTERFACE_MAP_END
     27 
     28 PerformanceObserverEntryList::~PerformanceObserverEntryList() = default;
     29 
     30 JSObject* PerformanceObserverEntryList::WrapObject(
     31    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     32  return PerformanceObserverEntryList_Binding::Wrap(aCx, this, aGivenProto);
     33 }
     34 
     35 void PerformanceObserverEntryList::GetEntries(
     36    const PerformanceEntryFilterOptions& aFilter,
     37    nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
     38  aRetval.Clear();
     39  RefPtr<nsAtom> name =
     40      aFilter.mName.WasPassed() ? NS_Atomize(aFilter.mName.Value()) : nullptr;
     41  RefPtr<nsAtom> entryType = aFilter.mEntryType.WasPassed()
     42                                 ? NS_Atomize(aFilter.mEntryType.Value())
     43                                 : nullptr;
     44  for (const RefPtr<PerformanceEntry>& entry : mEntries) {
     45    if (aFilter.mInitiatorType.WasPassed()) {
     46      const PerformanceResourceTiming* resourceEntry =
     47          entry->ToResourceTiming();
     48      if (!resourceEntry) {
     49        continue;
     50      }
     51      nsAutoString initiatorType;
     52      resourceEntry->GetInitiatorType(initiatorType);
     53      if (!initiatorType.Equals(aFilter.mInitiatorType.Value())) {
     54        continue;
     55      }
     56    }
     57    if (name && entry->GetName() != name) {
     58      continue;
     59    }
     60    if (entryType && entry->GetEntryType() != entryType) {
     61      continue;
     62    }
     63 
     64    aRetval.AppendElement(entry);
     65  }
     66  aRetval.Sort(PerformanceEntryComparator());
     67 }
     68 
     69 void PerformanceObserverEntryList::GetEntriesByType(
     70    const nsAString& aEntryType, nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
     71  aRetval.Clear();
     72  RefPtr<nsAtom> entryType = NS_Atomize(aEntryType);
     73  for (const RefPtr<PerformanceEntry>& entry : mEntries) {
     74    if (entry->GetEntryType() == entryType) {
     75      aRetval.AppendElement(entry);
     76    }
     77  }
     78  aRetval.Sort(PerformanceEntryComparator());
     79 }
     80 
     81 void PerformanceObserverEntryList::GetEntriesByName(
     82    const nsAString& aName, const Optional<nsAString>& aEntryType,
     83    nsTArray<RefPtr<PerformanceEntry>>& aRetval) {
     84  aRetval.Clear();
     85  RefPtr<nsAtom> name = NS_Atomize(aName);
     86  RefPtr<nsAtom> entryType =
     87      aEntryType.WasPassed() ? NS_Atomize(aEntryType.Value()) : nullptr;
     88  for (const RefPtr<PerformanceEntry>& entry : mEntries) {
     89    if (entry->GetName() != name) {
     90      continue;
     91    }
     92 
     93    if (entryType && entry->GetEntryType() != entryType) {
     94      continue;
     95    }
     96 
     97    aRetval.AppendElement(entry);
     98  }
     99  aRetval.Sort(PerformanceEntryComparator());
    100 }