Bug 1148797 - Part 2 - Replace our own privacy level check implementation with PrivacyLevel.jsm r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Tue, 31 Jan 2017 21:17:22 +0100
changeset 468584 ab9d05b2a4d5d6709ed775f57460259764799259
parent 468583 25e3df634c4414ed037f6862343cc2c52621d60b
child 543997 3f5c2463add7faa52d829c9183956f8e2cf7223e
push id43516
push usermozilla@buttercookie.de
push dateTue, 31 Jan 2017 20:33:31 +0000
reviewerssebastian
bugs1148797
milestone54.0a1
Bug 1148797 - Part 2 - Replace our own privacy level check implementation with PrivacyLevel.jsm r?sebastian MozReview-Commit-ID: 6vDZupfdFoj
mobile/android/components/SessionStore.js
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -10,16 +10,17 @@ const Cr = Components.results;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Messaging", "resource://gre/modules/Messaging.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PrivacyLevel", "resource://gre/modules/sessionstore/PrivacyLevel.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FormData", "resource://gre/modules/FormData.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "ScrollPosition", "resource://gre/modules/ScrollPosition.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "TelemetryStopwatch", "resource://gre/modules/TelemetryStopwatch.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Log", "resource://gre/modules/AndroidLog.jsm", "AndroidLog");
 XPCOMUtils.defineLazyModuleGetter(this, "SharedPreferences", "resource://gre/modules/SharedPreferences.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Utils", "resource://gre/modules/sessionstore/Utils.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "serializationHelper",
                                    "@mozilla.org/network/serialization-helper;1",
@@ -45,20 +46,16 @@ function log(a) {
 // Session Store
 // -----------------------------------------------------------------------
 
 const STATE_STOPPED = 0;
 const STATE_RUNNING = 1;
 const STATE_QUITTING = -1;
 const STATE_QUITTING_FLUSHED = -2;
 
-const PRIVACY_NONE = 0;
-const PRIVACY_ENCRYPTED = 1;
-const PRIVACY_FULL = 2;
-
 const PREFS_RESTORE_FROM_CRASH = "browser.sessionstore.resume_from_crash";
 const PREFS_MAX_CRASH_RESUMES = "browser.sessionstore.max_resumed_crashes";
 const PREFS_MAX_TABS_UNDO = "browser.sessionstore.max_tabs_undo";
 
 const MINIMUM_SAVE_DELAY = 2000;
 // We reduce the delay in background because we could be killed at any moment,
 // however we don't set it to 0 in order to allow for multiple events arriving
 // one after the other to be batched together in one write operation.
@@ -782,28 +779,28 @@ SessionStore.prototype = {
     }
 
     // Start with storing the main content
     let content = aBrowser.contentWindow;
 
     // If the main content document has an associated URL that we are not
     // allowed to store data for, bail out. We explicitly discard data for any
     // children as well even if storing data for those frames would be allowed.
-    if (!this.checkPrivacyLevel(content.document.documentURI)) {
+    if (!PrivacyLevel.check(content.document.documentURI)) {
       return;
     }
 
     // Store the main content
     let formdata = FormData.collect(content) || {};
 
     // Loop over direct child frames, and store the text data
     let children = [];
     for (let i = 0; i < content.frames.length; i++) {
       let frame = content.frames[i];
-      if (!this.checkPrivacyLevel(frame.document.documentURI)) {
+      if (!PrivacyLevel.check(frame.document.documentURI)) {
         continue;
       }
 
       let result = FormData.collect(frame);
       if (result && Object.keys(result).length) {
         children[i] = result;
       }
     }
@@ -1502,26 +1499,16 @@ SessionStore.prototype = {
       let tab = window.BrowserApp.addTab(tabData.entries[tabData.index - 1].url, params);
       tab.browser.__SS_data = tabData;
       tab.browser.__SS_extdata = tabData.extData;
       this._restoreTab(tabData, tab.browser);
     }
   },
 
   /**
-   * Don't save sensitive data if the user doesn't want to
-   * (distinguishes between encrypted and non-encrypted sites)
-   */
-  checkPrivacyLevel: function ss_checkPrivacyLevel(aURL) {
-    let isHTTPS = aURL.startsWith("https:");
-    let pref = "browser.sessionstore.privacy_level";
-    return Services.prefs.getIntPref(pref) < (isHTTPS ? PRIVACY_ENCRYPTED : PRIVACY_FULL);
-  },
-
-  /**
   * Starts the restoration process for a browser. History is restored at this
   * point, but text data must be delayed until the content loads.
   */
   _restoreTab: function ss_restoreTab(aTabData, aBrowser) {
     // aTabData shouldn't be empty here, but if it is,
     // _restoreHistory() will crash otherwise.
     if (!aTabData || aTabData.entries.length == 0) {
       Cu.reportError("SessionStore.js: Error trying to restore tab with empty tabdata");