nsIPrefBranch functions not able to read about:config preferences (current values), showing default values

53 views
Skip to first unread message

harshad wadkar

unread,
Jul 14, 2015, 4:26:34 PM7/14/15
to mozilla-la...@googlegroups.com
Hello,

I am trying to write a firefox addon that will read about:config preferences.

My main.js is as follows :

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

var data = require("sdk/self").data;
var window = require("sdk/windows").browserWindows;

var text_entry = require("sdk/panel").Panel({
  contentURL: data.url("myaddon.html"),
  contentScriptFile: data.url("myscript.js"),
  width:1000,
  height:700
});



// Create a button
var button = require("sdk/ui/button/action").ActionButton({
  id: "show-panel",
  label: "Read Preferences",
  icon: {
        //"16": "./icon-16.jpg",
    "16": "./abc.jpg",
    "32": "./def.png",
        "64": "./ghi.png"
  },
  onClick: handleClick
});

// Show the panel when the user clicks the button.
function handleClick(state) {
  text_entry.show({
    position:button
  });
 
}

const {Cc, Ci} = require("chrome");
var prefService = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
var prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService);
var firefox = Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);

var default_values = [  prefBranch.getBoolPref("browser.safebrowsing.enabled"),
                        prefBranch.getBoolPref("browser.safebrowsing.malware.enabled"),
                        prefBranch.getBoolPref("dom.event.clipboardevents.enabled"),
                        prefBranch.getBoolPref("dom.storage.enabled"),
                        prefBranch.getBoolPref("geo.enabled"),
                        prefBranch.getCharPref("geo.wifi.uri"), //string
                        prefBranch.getIntPref("network.cookie.cookieBehavior"), //integer
                        prefBranch.getIntPref("network.cookie.lifetimePolicy"), //integer
                        prefBranch.getBoolPref("network.dns.disablePrefetch"),
                        prefBranch.getIntPref("network.http.sendRefererHeader"), //integer
                        prefBranch.getBoolPref("network.http.sendSecureXSiteReferrer"),
                        prefBranch.getBoolPref("network.prefetch-next"),
                        prefBranch.getBoolPref("privacy.donottrackheader.enabled"),           
                        prefBranch.getBoolPref("toolkit.telemetry.enabled")];
text_entry.port.emit("default_values", default_values);


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Problem :
1. When I am trying to run the addon using $ cfx run, I am not able to find the current values of the preference - the values shown are the default values and
    not the current values of the preferences (I have observed this using about:config preference values).
2. When I tried the same code on Firefox 34, it is showing the current values but the code is not giving the expected output when running on Firefox 38.

Help needed to :
1. Check whether my above code is wrong?
2. If the code is wrong then need guidance to correct the code

Thanks & Regards

Harshad

Mikhail Khvoinitsky

unread,
Jul 14, 2015, 4:32:35 PM7/14/15
to mozilla-la...@googlegroups.com
Try to use preferences/service
https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/preferences_service

14.07.2015, 23:26, "harshad wadkar" <harshad...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mozilla-labs-jet...@googlegroups.com.
> To post to this group, send email to mozilla-la...@googlegroups.com.
> Visit this group at http://groups.google.com/group/mozilla-labs-jetpack.
> For more options, visit https://groups.google.com/d/optout.

harshad wadkar

unread,
Jul 15, 2015, 2:46:23 PM7/15/15
to mozilla-la...@googlegroups.com
Dear Mikhail Khvoinitsky,

I tried to use the low level api : get (referring https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/preferences_service) but I am still not able to read the current value of preferences - the values returned by the get function is a default value.

The code in main.js

var name = "network.cookie.cookieBehavior";
var name_val = require("sdk/preferences/service").get(name);

var name_val = require("sdk/preferences/service").get(name,0);
getting answer 0 (zero - default value) whereas I have set the value of network.cookie.cookieBehavior to 2. 
So getting output of name_val as zero (0) whereas I am expecting answer 2.
console.log(name_val) ;
Need guidance urgently.

Thanks & Regards

Harshad




You received this message because you are subscribed to a topic in the Google Groups "mozilla-labs-jetpack" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mozilla-labs-jetpack/VdaH-fAJZdY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mozilla-labs-jet...@googlegroups.com.

Mikhail Khvoinitsky

unread,
Jul 18, 2015, 4:48:13 AM7/18/15
to harshad wadkar, mozilla-la...@googlegroups.com
const preferences_service = require("sdk/preferences/service");
console.log(preferences_service.get('network.cookie.cookieBehavior'));

It works for me as well as your variant.
Please note that default value for network.cookie.cookieBehavior is 0.
And when you execute cfx run or jpm run, cfx or jpm will create new
empty profile for your browser (unless you provide -p /path/to/profile
option) with all preferences set to default values.
Reply all
Reply to author
Forward
0 new messages