tor-browser

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

PerformanceNavigationTiming.cpp (5486B)


      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 "mozilla/dom/PerformanceNavigationTiming.h"
      8 
      9 #include "mozilla/StaticPrefs_dom.h"
     10 #include "mozilla/StaticPrefs_privacy.h"
     11 #include "mozilla/dom/PerformanceNavigationTimingBinding.h"
     12 
     13 using namespace mozilla::dom;
     14 
     15 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceNavigationTiming)
     16 NS_INTERFACE_MAP_END_INHERITING(PerformanceResourceTiming)
     17 
     18 NS_IMPL_ADDREF_INHERITED(PerformanceNavigationTiming, PerformanceResourceTiming)
     19 NS_IMPL_RELEASE_INHERITED(PerformanceNavigationTiming,
     20                          PerformanceResourceTiming)
     21 
     22 JSObject* PerformanceNavigationTiming::WrapObject(
     23    JSContext* aCx, JS::Handle<JSObject*> aGivenProto) {
     24  return PerformanceNavigationTiming_Binding::Wrap(aCx, this, aGivenProto);
     25 }
     26 
     27 #define REDUCE_TIME_PRECISION                          \
     28  return nsRFPService::ReduceTimePrecisionAsMSecs(     \
     29      rawValue, mPerformance->GetRandomTimelineSeed(), \
     30      mPerformance->GetRTPCallerType())
     31 
     32 DOMHighResTimeStamp PerformanceNavigationTiming::UnloadEventStart() const {
     33  DOMHighResTimeStamp rawValue = 0;
     34  /*
     35   * Per Navigation Timing Level 2, the value is 0 if
     36   * a. there is no previous document or
     37   * b. the same-origin-check fails.
     38   *
     39   * The same-origin-check is defined as:
     40   * 1. If the previous document exists and its origin is not same
     41   *    origin as the current document's origin, return "fail".
     42   * 2. Let request be the current document's request.
     43   * 3. If request's redirect count is not zero, and all of request's
     44   *    HTTP redirects have the same origin as the current document,
     45   *    return "pass".
     46   * 4. Otherwise, return "fail".
     47   */
     48  if (mTimingData->AllRedirectsSameOrigin()) {  // same-origin-check:2/3
     49    /*
     50     * GetUnloadEventStartHighRes returns 0 if
     51     * 1. there is no previous document (a, above) or
     52     * 2. the current URI does not have the same origin as
     53     *    the previous document's URI. (same-origin-check:1)
     54     */
     55    rawValue = mPerformance->GetDOMTiming()->GetUnloadEventStartHighRes();
     56  }
     57 
     58  REDUCE_TIME_PRECISION;
     59 }
     60 
     61 DOMHighResTimeStamp PerformanceNavigationTiming::UnloadEventEnd() const {
     62  DOMHighResTimeStamp rawValue = 0;
     63 
     64  // See comments in PerformanceNavigationTiming::UnloadEventEnd().
     65  if (mTimingData->AllRedirectsSameOrigin()) {
     66    rawValue = mPerformance->GetDOMTiming()->GetUnloadEventEndHighRes();
     67  }
     68 
     69  REDUCE_TIME_PRECISION;
     70 }
     71 
     72 DOMHighResTimeStamp PerformanceNavigationTiming::DomInteractive() const {
     73  DOMHighResTimeStamp rawValue =
     74      mPerformance->GetDOMTiming()->GetDomInteractiveHighRes();
     75 
     76  REDUCE_TIME_PRECISION;
     77 }
     78 
     79 DOMHighResTimeStamp PerformanceNavigationTiming::DomContentLoadedEventStart()
     80    const {
     81  DOMHighResTimeStamp rawValue =
     82      mPerformance->GetDOMTiming()->GetDomContentLoadedEventStartHighRes();
     83 
     84  REDUCE_TIME_PRECISION;
     85 }
     86 
     87 DOMHighResTimeStamp PerformanceNavigationTiming::DomContentLoadedEventEnd()
     88    const {
     89  DOMHighResTimeStamp rawValue =
     90      mPerformance->GetDOMTiming()->GetDomContentLoadedEventEndHighRes();
     91 
     92  REDUCE_TIME_PRECISION;
     93 }
     94 
     95 DOMHighResTimeStamp PerformanceNavigationTiming::DomComplete() const {
     96  DOMHighResTimeStamp rawValue =
     97      mPerformance->GetDOMTiming()->GetDomCompleteHighRes();
     98 
     99  REDUCE_TIME_PRECISION;
    100 }
    101 
    102 DOMHighResTimeStamp PerformanceNavigationTiming::LoadEventStart() const {
    103  DOMHighResTimeStamp rawValue =
    104      mPerformance->GetDOMTiming()->GetLoadEventStartHighRes();
    105 
    106  REDUCE_TIME_PRECISION;
    107 }
    108 
    109 DOMHighResTimeStamp PerformanceNavigationTiming::LoadEventEnd() const {
    110  DOMHighResTimeStamp rawValue =
    111      mPerformance->GetDOMTiming()->GetLoadEventEndHighRes();
    112 
    113  REDUCE_TIME_PRECISION;
    114 }
    115 
    116 NavigationTimingType PerformanceNavigationTiming::Type() const {
    117  switch (mPerformance->GetDOMTiming()->GetType()) {
    118    case nsDOMNavigationTiming::TYPE_NAVIGATE:
    119      return NavigationTimingType::Navigate;
    120      break;
    121    case nsDOMNavigationTiming::TYPE_RELOAD:
    122      return NavigationTimingType::Reload;
    123      break;
    124    case nsDOMNavigationTiming::TYPE_BACK_FORWARD:
    125      return NavigationTimingType::Back_forward;
    126      break;
    127    default:
    128      // The type is TYPE_RESERVED or some other value that was later added.
    129      // We fallback to the default of Navigate.
    130      return NavigationTimingType::Navigate;
    131  }
    132 }
    133 
    134 uint16_t PerformanceNavigationTiming::RedirectCount() const {
    135  return mTimingData->GetRedirectCount();
    136 }
    137 
    138 DOMHighResTimeStamp PerformanceNavigationTiming::RedirectStart(
    139    nsIPrincipal& aSubjectPrincipal) const {
    140  return PerformanceResourceTiming::RedirectStart(
    141      aSubjectPrincipal, true /* aEnsureSameOriginAndIgnoreTAO */);
    142 }
    143 
    144 DOMHighResTimeStamp PerformanceNavigationTiming::RedirectEnd(
    145    nsIPrincipal& aSubjectPrincipal) const {
    146  return PerformanceResourceTiming::RedirectEnd(
    147      aSubjectPrincipal, true /* aEnsureSameOriginAndIgnoreTAO */);
    148 }
    149 
    150 void PerformanceNavigationTiming::UpdatePropertiesFromHttpChannel(
    151    nsIHttpChannel* aHttpChannel, nsITimedChannel* aChannel) {
    152  mTimingData->SetPropertiesFromHttpChannel(aHttpChannel, aChannel);
    153 }
    154 
    155 bool PerformanceNavigationTiming::Enabled(JSContext* aCx, JSObject* aGlobal) {
    156  return StaticPrefs::dom_enable_performance_navigation_timing();
    157 }