LCOV - code coverage report
Current view: top level - dom/ipc - TelemetryScrollProbe.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 38 39 97.4 %
Date: 2017-07-14 16:53:18 Functions: 9 9 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 file,
       5             :  * You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "TelemetryScrollProbe.h"
       8             : 
       9             : #include "nsIDOMDocument.h"     // for nsIDOMDocument
      10             : #include "nsIDOMEvent.h"        // for nsIDOMEvent
      11             : #include "nsIURI.h"             // for nsIURI
      12             : #include "TabChild.h"           // for TabChildGlobal, TabChildBase
      13             : #include "mozilla/Telemetry.h"  // for mozilla::Telemetry
      14             : 
      15             : namespace mozilla {
      16             : namespace dom {
      17             : 
      18             : /* static */ void
      19           1 : TelemetryScrollProbe::Create(TabChildGlobal* aWebFrame)
      20             : {
      21           2 :   nsWeakPtr webNav = do_GetWeakReference(aWebFrame->mTabChild->WebNavigation());
      22           3 :   RefPtr<TelemetryScrollProbe> probe = new TelemetryScrollProbe(webNav);
      23             : 
      24           1 :   aWebFrame->AddEventListener(NS_LITERAL_STRING("pagehide"), probe, true, false, 0);
      25           1 : }
      26             : 
      27             : already_AddRefed<nsIWebNavigation>
      28           2 : TelemetryScrollProbe::GetWebNavigation() const
      29             : {
      30           4 :   nsCOMPtr<nsIWebNavigation> webNav = do_QueryReferent(mWebNav);
      31           4 :   return webNav.forget();
      32             : }
      33             : 
      34             : already_AddRefed<nsIDocument>
      35           2 : TelemetryScrollProbe::GetDocument() const
      36             : {
      37           4 :   nsCOMPtr<nsIDocument> result;
      38           4 :   if (nsCOMPtr<nsIWebNavigation> webNav = GetWebNavigation()) {
      39           4 :     nsCOMPtr<nsIDOMDocument> domDoc;
      40           2 :     webNav->GetDocument(getter_AddRefs(domDoc));
      41           2 :     result = do_QueryInterface(domDoc);
      42             :   }
      43           4 :   return result.forget();
      44             : }
      45             : 
      46             : already_AddRefed<nsIPresShell>
      47           1 : TelemetryScrollProbe::GetPresShell() const
      48             : {
      49           2 :   nsCOMPtr<nsIPresShell> result;
      50           2 :   if (nsCOMPtr<nsIDocument> doc = GetDocument()) {
      51           1 :     result = doc->GetShell();
      52             :   }
      53           2 :   return result.forget();
      54             : }
      55             : 
      56             : bool
      57           1 : TelemetryScrollProbe::ShouldIgnore(nsIDOMEvent* aEvent) const
      58             : {
      59           2 :   nsCOMPtr<nsIDOMEventTarget> target;
      60           1 :   aEvent->GetTarget(getter_AddRefs(target));
      61           2 :   nsCOMPtr<nsIDocument> targetDocument = do_QueryInterface(target);
      62           2 :   RefPtr<nsIDocument> document = GetDocument();
      63             : 
      64           2 :   return !document || targetDocument != document || nsContentUtils::IsSystemPrincipal(document->NodePrincipal());
      65             : }
      66             : 
      67           6 : NS_IMPL_ISUPPORTS(TelemetryScrollProbe, nsIDOMEventListener)
      68             : 
      69             : NS_IMETHODIMP
      70           1 : TelemetryScrollProbe::HandleEvent(nsIDOMEvent* aEvent)
      71             : {
      72           2 :   RefPtr<nsIPresShell> presShell = GetPresShell();
      73             : 
      74           1 :   if (!presShell || ShouldIgnore(aEvent)) {
      75           0 :     return NS_OK;
      76             :   }
      77             : 
      78           2 :   RefPtr<nsPresContext> presContext = presShell->GetPresContext();
      79             : 
      80           1 :   nscoord maxAppUnits = presContext->TelemetryScrollMaxY();
      81           1 :   nscoord totalAppUnits = presContext->TelemetryScrollTotalY();
      82             : 
      83           1 :   float maxCSSPixels = nsPresContext::AppUnitsToFloatCSSPixels(maxAppUnits);
      84           1 :   float totalCSSPixels = nsPresContext::AppUnitsToFloatCSSPixels(totalAppUnits);
      85             : 
      86           1 :   mozilla::Telemetry::Accumulate(mozilla::Telemetry::TOTAL_SCROLL_Y, totalCSSPixels);
      87           1 :   mozilla::Telemetry::Accumulate(mozilla::Telemetry::PAGE_MAX_SCROLL_Y, maxCSSPixels);
      88             : 
      89           1 :   return NS_OK;
      90             : }
      91             : 
      92             : } // namespace dom
      93             : } // namespace mozilla

Generated by: LCOV version 1.13