Bug 1532402 - Part 2: Add a variant of nsContentUtils::ShouldResistFingerprinting() which accepts an nsIPrincipal* argument; r=baku
☠☠ backed out by b28187cd9146 ☠ ☠
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 05 Mar 2019 15:53:55 +0000
changeset 520292 ed1e303084c4026cdbba075464ef1050013df6b0
parent 520291 589d985b3cfeb911c79af2832552640f0af79771
child 520293 6df23def6c361ab16c5bffbc59bb666dae5e7490
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1532402
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532402 - Part 2: Add a variant of nsContentUtils::ShouldResistFingerprinting() which accepts an nsIPrincipal* argument; r=baku We can use this variant in cases where we don't know anything about the provenant source of the check except its principal. The principal may not be enough information in the future but at least porting call sites to this variant will allow us to have a small number of functions to extend in the future when we want to enable enabling fingerprinting resistance in certain frames (e.g. third-party tracking frames.) Depends on D21990 Differential Revision: https://phabricator.services.mozilla.com/D21991
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -2069,16 +2069,25 @@ bool nsContentUtils::ShouldResistFingerp
   if (!aDoc) {
     return false;
   }
   bool isChrome = nsContentUtils::IsChromeDoc(aDoc);
   return !isChrome && ShouldResistFingerprinting();
 }
 
 /* static */
+bool nsContentUtils::ShouldResistFingerprinting(nsIPrincipal* aPrincipal) {
+  if (!aPrincipal) {
+    return false;
+  }
+  bool isChrome = nsContentUtils::IsSystemPrincipal(aPrincipal);
+  return !isChrome && ShouldResistFingerprinting();
+}
+
+/* static */
 bool nsContentUtils::UseStandinsForNativeColors() {
   return ShouldResistFingerprinting() ||
          StaticPrefs::ui_use_standins_for_native_colors();
 }
 
 /* static */
 void nsContentUtils::CalcRoundedWindowSizeForResistingFingerprinting(
     int32_t aChromeWidth, int32_t aChromeHeight, int32_t aScreenWidth,
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -299,16 +299,17 @@ class nsContentUtils {
   static bool LookupBindingMember(
       JSContext* aCx, nsIContent* aContent, JS::Handle<jsid> aId,
       JS::MutableHandle<JS::PropertyDescriptor> aDesc);
 
   // Check whether we should avoid leaking distinguishing information to JS/CSS.
   // This function can be called both in the main thread and worker threads.
   static bool ShouldResistFingerprinting();
   static bool ShouldResistFingerprinting(nsIDocShell* aDocShell);
+  static bool ShouldResistFingerprinting(nsIPrincipal* aPrincipal);
   static bool ShouldResistFingerprinting(const Document* aDoc);
 
   // Prevent system colors from being exposed to CSS or canvas.
   static bool UseStandinsForNativeColors();
 
   // A helper function to calculate the rounded window size for fingerprinting
   // resistance. The rounded size is based on the chrome UI size and available
   // screen size. If the inputWidth/Height is greater than the available content