[Pkg-mozext-commits] [adblock-plus-element-hiding-helper] 233/483: Added own preference management module, also moved preferences to extensions.elemhidehelper. branch

David Prévot taffit at moszumanska.debian.org
Thu Jan 22 21:41:44 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository adblock-plus-element-hiding-helper.

commit 38f4628e77ba8a285d1acb78e5d57de35b35b579
Author: Wladimir Palant <trev at adblockplus.org>
Date:   Fri Oct 22 14:44:06 2010 +0200

    Added own preference management module, also moved preferences to extensions.elemhidehelper. branch
---
 defaults/preferences/elemhidehelper.js |   5 +-
 modules/ABPIntegration.jsm             |  24 +---
 modules/Aardvark.jsm                   |  12 +-
 modules/Prefs.jsm                      | 214 +++++++++++++++++++++++++++++++++
 4 files changed, 225 insertions(+), 30 deletions(-)

diff --git a/defaults/preferences/elemhidehelper.js b/defaults/preferences/elemhidehelper.js
index 404e05f..415aba7 100644
--- a/defaults/preferences/elemhidehelper.js
+++ b/defaults/preferences/elemhidehelper.js
@@ -1,4 +1,3 @@
-pref("extensions.adblockplus.ehh-selectelement_key", "Accel Shift K");
-pref("extensions.adblockplus.ehh.showhelp", true);
-pref("extensions.adblockplus.ehh.norequirementswarning", false);
+pref("extensions.elemhidehelper.selectelement_key", "Accel Shift K");
+pref("extensions.elemhidehelper.showhelp", true);
 
diff --git a/modules/ABPIntegration.jsm b/modules/ABPIntegration.jsm
index 502a3b0..5097486 100644
--- a/modules/ABPIntegration.jsm
+++ b/modules/ABPIntegration.jsm
@@ -22,13 +22,14 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
-var EXPORTED_SYMBOLS = ["EHH"];
+var EXPORTED_SYMBOLS = [];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
+let baseURI = Cc["@adblockplus.org/ehh/startup;1"].getService(Ci.nsIURI);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 /**
@@ -61,20 +62,6 @@ const myID = "elemhidehelper at adblockplus.org";
  */
 let timer = null;
 
-/**
- * Exported symbol of the module, will be triggered by Adblock Plus.
- * @class
- */
-var EHH =
-{
-  initialized: false,
-
-  startup: function()
-  {
-    EHH.initialized = true;
-  }
-};
-
 let extensionManager = null;
 
 /**
@@ -83,9 +70,7 @@ let extensionManager = null;
  */
 function init()
 {
-  let baseURI = Cc["@adblockplus.org/ehh/startup;1"].getService(Ci.nsIURI);
-  let moduleLocation = baseURI.spec + "ABPIntegration.jsm";
-
+  let moduleLocation = baseURI.spec + "Prefs.jsm";
   let categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
   categoryManager.addCategoryEntry("adblock-plus-module-location", moduleLocation, moduleLocation, false, true);
 
@@ -100,7 +85,8 @@ function init()
 function startABPCheck()
 {
   timer = null;
-  if (!EHH.initialized)
+  Cu.import(baseURI.spec + "Prefs.jsm");
+  if (!Prefs.initialized)
   {
     // Adblock Plus didn't initialize us - what's wrong?
     checkDependencies();
diff --git a/modules/Aardvark.jsm b/modules/Aardvark.jsm
index d5a1fc3..4180a72 100644
--- a/modules/Aardvark.jsm
+++ b/modules/Aardvark.jsm
@@ -30,6 +30,9 @@ const Ci = Components.interfaces;
 const Cr = Components.results;
 const Cu = Components.utils;
 
+let baseURI = Cc["@adblockplus.org/ehh/startup;1"].getService(Ci.nsIURI);
+Cu.import(baseURI.spec + "Prefs.jsm");
+
 // To be replaced when selection starts
 function E(id) {return null;}
 
@@ -72,14 +75,7 @@ Aardvark.start = function(wrapper) {
 
   this.initHelpBox();
 
-  var prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
-  var branch = prefService.getBranch("extensions.adblockplus.");
-  var showMenu = true;
-  try {
-    showMenu = branch.getBoolPref("ehh.showhelp");
-  } catch(e) {}
-
-  if (showMenu)
+  if (Prefs.showhelp)
     this.showMenu();
 }
 
diff --git a/modules/Prefs.jsm b/modules/Prefs.jsm
new file mode 100644
index 0000000..1bba497
--- /dev/null
+++ b/modules/Prefs.jsm
@@ -0,0 +1,214 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Adblock Plus Element Hiding Helper.
+ *
+ * The Initial Developer of the Original Code is
+ * Wladimir Palant.
+ * Portions created by the Initial Developer are Copyright (C) 2006-2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var EXPORTED_SYMBOLS = ["Prefs"];
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cr = Components.results;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+const prefRoot = "extensions.elemhidehelper.";
+
+let prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
+let branch = prefService.getBranch(prefRoot);
+
+var Prefs =
+{
+  initialized: false,
+  branch: null,
+
+  startup: function()
+  {
+    this.initialized = true;
+
+    let defaultBranch = prefService.getDefaultBranch(prefRoot);
+    for each (let name in defaultBranch.getChildList("", {}))
+    {
+      let type = defaultBranch.getPrefType(name);
+      switch (type)
+      {
+        case Ci.nsIPrefBranch.PREF_INT:
+          PrefsPrivate.defineIntegerProperty(name);
+          break;
+        case Ci.nsIPrefBranch.PREF_BOOL:
+          PrefsPrivate.defineBooleanProperty(name);
+          break;
+        case Ci.nsIPrefBranch.PREF_STRING:
+          PrefsPrivate.defineStringProperty(name);
+          break;
+      }
+      if ("_update_" + name in PrefsPrivate)
+        PrefsPrivate["_update_" + name]();
+    }
+
+    try
+    {
+      branch.QueryInterface(Ci.nsIPrefBranch2)
+            .addObserver("", PrefsPrivate, true);
+    }
+    catch (e)
+    {
+      Cu.reportError(e);
+    }
+
+    // Preferences used to be stored in Adblock Plus branch, import
+    let importBranch = prefService.getBranch("extensions.adblockplus.");
+    if (importBranch.prefHasUserValue("ehh-selectelement_key") && importBranch.getPrefType("ehh-selectelement_key") == Ci.nsIPrefBranch.PREF_STRING)
+    {
+      Prefs.selectelement_key = importBranch.getCharPref("ehh-selectelement_key");
+      importBranch.clearUserPref("ehh-selectelement_key");
+    }
+    if (importBranch.prefHasUserValue("ehh.showhelp") && importBranch.getPrefType("ehh.showhelp") == Ci.nsIPrefBranch.PREF_BOOL)
+    {
+      Prefs.showhelp = importBranch.getBoolPref("ehh.showhelp");
+      importBranch.clearUserPref("ehh.showhelp");
+    }
+  }
+};
+
+var PrefsPrivate =
+{
+  ignorePrefChanges: false,
+
+  defineIntegerProperty: function(name)
+  {
+    let value = 0;
+    PrefsPrivate["_update_" + name] = function()
+    {
+      try
+      {
+        value = branch.getIntPref(name);
+      }
+      catch(e)
+      {
+        Cu.reportError(e);
+      }
+    }
+    Prefs.__defineGetter__(name, function() value);
+    Prefs.__defineSetter__(name, function(newValue)
+    {
+      try
+      {
+        PrefsPrivate.ignorePrefChanges = true;
+        branch.setIntPref(name, newValue);
+        value = newValue;
+      }
+      catch(e)
+      {
+        Cu.reportError(e);
+      }
+      finally
+      {
+        PrefsPrivate.ignorePrefChanges = false;
+      }
+      return value;
+    });
+  },
+
+  defineBooleanProperty: function(name)
+  {
+    let value = false;
+    PrefsPrivate["_update_" + name] = function()
+    {
+      try
+      {
+        value = branch.getBoolPref(name);
+      }
+      catch(e)
+      {
+        Cu.reportError(e);
+      }
+    }
+    Prefs.__defineGetter__(name, function() value);
+    Prefs.__defineSetter__(name, function(newValue)
+    {
+      try
+      {
+        PrefsPrivate.ignorePrefChanges = true;
+        branch.setBoolPref(name, newValue);
+        value = newValue;
+      }
+      catch(e)
+      {
+        Cu.reportError(e);
+      }
+      finally
+      {
+        PrefsPrivate.ignorePrefChanges = false;
+      }
+      return value;
+    });
+  },
+
+  defineStringProperty: function(name)
+  {
+    let value = "";
+    PrefsPrivate["_update_" + name] = function()
+    {
+      try
+      {
+        value = branch.getComplexValue(name, Ci.nsISupportsString).data;
+      }
+      catch(e)
+      {
+        Cu.reportError(e);
+      }
+    }
+    Prefs.__defineGetter__(name, function() value);
+    Prefs.__defineSetter__(name, function(newValue)
+    {
+      try
+      {
+        PrefsPrivate.ignorePrefChanges = true;
+        let str = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
+        str.data = newValue;
+        branch.setComplexValue(name, Ci.nsISupportsString, str);
+        value = newValue;
+      }
+      catch(e)
+      {
+        Cu.reportError(e);
+      }
+      finally
+      {
+        PrefsPrivate.ignorePrefChanges = false;
+      }
+      return value;
+    });
+  },
+
+  observe: function(subject, topic, data)
+  {
+    if (PrefsPrivate.ignorePrefChanges || topic != "nsPref:changed")
+      return;
+
+    if ("_update_" + data in PrefsPrivate)
+      PrefsPrivate["_update_" + data]();
+  },
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference, Ci.nsIObserver])
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/adblock-plus-element-hiding-helper.git



More information about the Pkg-mozext-commits mailing list