From d0c653622fc1b6884f47d8ff092871acdc927a58 Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Wed, 31 May 2017 20:24:17 +0200 Subject: [PATCH] Bug 1357386: Gather telemetry for toplevel data: URI loads. r=dveditz,francois --- docshell/base/nsDocShell.cpp | 22 ++++++++++++++++++++ toolkit/components/telemetry/Histograms.json | 9 ++++++++ 2 files changed, 31 insertions(+) diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 20a9bf6cb780..9327f37dab40 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -11018,6 +11018,28 @@ nsDocShell::DoURILoad(nsIURI* aURI, new LoadInfo(loadingPrincipal, aTriggeringPrincipal, loadingNode, securityFlags, aContentPolicyType); + if (aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) { + enum TopLevelDataState { + DATA_NAVIGATED = 0, + DATA_TYPED = 1, + NO_DATA = 2, + }; + bool isDataURI = (NS_SUCCEEDED(aURI->SchemeIs("data", &isDataURI)) && isDataURI); + if (isDataURI) { + // In all cases where the toplevel document is navigated to a data: URI + // the triggeringPrincipal is a CodeBasePrincipal. In all other cases + // e.g. typing a data: URL into the URL-Bar or also clicking a bookmark + // uses a SystemPrincipal as the triggeringPrincipal. + if (aTriggeringPrincipal->GetIsCodebasePrincipal()) { + Telemetry::Accumulate(Telemetry::DOCUMENT_DATA_URI_LOADS, DATA_NAVIGATED); + } else { + Telemetry::Accumulate(Telemetry::DOCUMENT_DATA_URI_LOADS, DATA_TYPED); + } + } else { + Telemetry::Accumulate(Telemetry::DOCUMENT_DATA_URI_LOADS, NO_DATA); + } + } + if (aPrincipalToInherit) { loadInfo->SetPrincipalToInherit(aPrincipalToInherit); } diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index e450940449c7..b88366ffa39f 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -13173,6 +13173,15 @@ "bug_numbers": [1351021], "description": "Every time we run an unlabeled runnable, this histogram records the time (in ms) since the last unlabeled runnable ran." }, + "DOCUMENT_DATA_URI_LOADS": { + "record_in_processes": ["main", "content"], + "alert_emails": ["seceng-telemetry@mozilla.com"], + "bug_numbers": [1357386], + "expires_in_version": "60", + "kind": "enumerated", + "n_values": 3, + "description": "Whether a toplevel document uses data: URI? (0=data-navigated, 1=data-typed, 2=nodata)" + }, "VFC_INVALIDATE_LOCK_WAIT_MS": { "record_in_processes": ["main", "content"], "alert_emails": ["jwwang@mozilla.com"],