[tor-commits] [tor-browser/tor-browser-60.6.1esr-9.0-1] Bug 1407366 - Part 2: Rearrange RFPHelper for expansion r=johannh

gk at torproject.org gk at torproject.org
Fri May 17 07:43:38 UTC 2019


commit 7f3ce3ef4cf86690864a4abd7ca58a9e5dbb087f
Author: Tom Ritter <tom at mozilla.com>
Date:   Wed Apr 24 09:17:53 2019 -0500

    Bug 1407366 - Part 2: Rearrange RFPHelper for expansion r=johannh
    
    This patch rearranges RFPHelper.jsm to make it more clear what parts
    of the file are responsible for what feature.
---
 .../components/resistfingerprinting/RFPHelper.jsm  | 62 +++++++++++++---------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/toolkit/components/resistfingerprinting/RFPHelper.jsm b/toolkit/components/resistfingerprinting/RFPHelper.jsm
index 2e8e85072364..5aef203ad38b 100755
--- a/toolkit/components/resistfingerprinting/RFPHelper.jsm
+++ b/toolkit/components/resistfingerprinting/RFPHelper.jsm
@@ -14,6 +14,9 @@ const kPrefSpoofEnglish = "privacy.spoof_english";
 const kTopicHttpOnModifyRequest = "http-on-modify-request";
 
 class _RFPHelper {
+  // ============================================================================
+  // Setup
+  // ============================================================================
   constructor() {
     this._initialized = false;
   }
@@ -24,7 +27,9 @@ class _RFPHelper {
     }
     this._initialized = true;
 
+    // Add unconditional observers
     Services.prefs.addObserver(kPrefResistFingerprinting, this);
+    // Add RFP observers if the pref is enabled
     this._handleResistFingerprintingChanged();
   }
 
@@ -34,8 +39,10 @@ class _RFPHelper {
     }
     this._initialized = false;
 
+    // Remove unconditional observers
     Services.prefs.removeObserver(kPrefResistFingerprinting, this);
-    this._removeObservers();
+    // Remove the RFP observers, swallowing exceptions if they weren't present
+    this._removeRFPObservers();
   }
 
   observe(subject, topic, data) {
@@ -51,24 +58,6 @@ class _RFPHelper {
     }
   }
 
-  _removeObservers() {
-    try {
-      Services.pref.removeObserver(kPrefSpoofEnglish, this);
-    } catch (e) {
-      // do nothing
-    }
-    try {
-      Services.obs.removeObserver(this, kTopicHttpOnModifyRequest);
-    } catch (e) {
-      // do nothing
-    }
-  }
-
-  _shouldPromptForLanguagePref() {
-    return (Services.locale.getAppLocaleAsLangTag().substr(0, 2) !== "en")
-      && (Services.prefs.getIntPref(kPrefSpoofEnglish) === 0);
-  }
-
   _handlePrefChanged(data) {
     switch (data) {
       case kPrefResistFingerprinting:
@@ -82,14 +71,34 @@ class _RFPHelper {
     }
   }
 
+  // ============================================================================
+  // Language Prompt
+  // ============================================================================
+  _addRFPObservers() {
+    Services.prefs.addObserver(kPrefSpoofEnglish, this);
+    if (this._shouldPromptForLanguagePref()) {
+      Services.obs.addObserver(this, kTopicHttpOnModifyRequest);
+    }
+  }
+
+  _removeRFPObservers() {
+    try {
+      Services.pref.removeObserver(kPrefSpoofEnglish, this);
+    } catch (e) {
+      // do nothing
+    }
+    try {
+      Services.obs.removeObserver(this, kTopicHttpOnModifyRequest);
+    } catch (e) {
+      // do nothing
+    }
+  }
+
   _handleResistFingerprintingChanged() {
     if (Services.prefs.getBoolPref(kPrefResistFingerprinting)) {
-      Services.prefs.addObserver(kPrefSpoofEnglish, this);
-      if (this._shouldPromptForLanguagePref()) {
-        Services.obs.addObserver(this, kTopicHttpOnModifyRequest);
-      }
+      this._addRFPObservers();
     } else {
-      this._removeObservers();
+      this._removeRFPObservers();
       Services.prefs.setIntPref(kPrefSpoofEnglish, 0);
     }
   }
@@ -116,6 +125,11 @@ class _RFPHelper {
     }
   }
 
+  _shouldPromptForLanguagePref() {
+    return (Services.locale.getAppLocaleAsLangTag().substr(0, 2) !== "en")
+      && (Services.prefs.getIntPref(kPrefSpoofEnglish) === 0);
+  }
+
   _handleHttpOnModifyRequest(subject, data) {
     // If we are loading an HTTP page from content, show the
     // "request English language web pages?" prompt.





More information about the tor-commits mailing list