tor-browser

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

PerformanceServerTiming.cpp (1929B)


      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 "PerformanceServerTiming.h"
      8 
      9 #include "mozilla/dom/PerformanceServerTimingBinding.h"
     10 #include "nsITimedChannel.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PerformanceServerTiming, mParent)
     15 
     16 NS_IMPL_CYCLE_COLLECTING_ADDREF(PerformanceServerTiming)
     17 NS_IMPL_CYCLE_COLLECTING_RELEASE(PerformanceServerTiming)
     18 
     19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceServerTiming)
     20  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
     21  NS_INTERFACE_MAP_ENTRY(nsISupports)
     22 NS_INTERFACE_MAP_END
     23 
     24 JSObject* PerformanceServerTiming::WrapObject(
     25    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     26  return mozilla::dom::PerformanceServerTiming_Binding::Wrap(aCx, this,
     27                                                             aGivenProto);
     28 }
     29 
     30 void PerformanceServerTiming::GetName(nsAString& aName) const {
     31  aName.Truncate();
     32 
     33  if (!mServerTiming) {
     34    return;
     35  }
     36 
     37  nsAutoCString name;
     38  if (NS_WARN_IF(NS_FAILED(mServerTiming->GetName(name)))) {
     39    return;
     40  }
     41 
     42  aName.Assign(NS_ConvertUTF8toUTF16(name));
     43 }
     44 
     45 DOMHighResTimeStamp PerformanceServerTiming::Duration() const {
     46  if (!mServerTiming) {
     47    return 0;
     48  }
     49 
     50  double duration = 0;
     51  if (NS_WARN_IF(NS_FAILED(mServerTiming->GetDuration(&duration)))) {
     52    return 0;
     53  }
     54 
     55  return duration;
     56 }
     57 
     58 void PerformanceServerTiming::GetDescription(nsAString& aDescription) const {
     59  if (!mServerTiming) {
     60    return;
     61  }
     62 
     63  nsAutoCString description;
     64  if (NS_WARN_IF(NS_FAILED(mServerTiming->GetDescription(description)))) {
     65    return;
     66  }
     67 
     68  aDescription.Assign(NS_ConvertUTF8toUTF16(description));
     69 }
     70 
     71 }  // namespace mozilla::dom