PerformanceObserverEntryList.cpp 3.0 KB

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