Not able to modify user preferences using XPCOM

Hi All,
I am trying to modify user preferences in mozilla firefox 1.5.0.12.
I am creating a dependent glue using Gecko 1.8.0.4(linking against
xpcomglue.lib) using XPCOM technology.I could successfully build my
application with Gecko 1.8.0.4 under GRE environment.
The preferences interface comes out to be valid and reading the
preference value is returning correctly. However,modifying the values
is not taking place successfully.
I am not sure whats happening here? I guess, I am not reading the
correct preferences file.
The following is the code that I am trying to execute.
  	XPCOMGlueStartup(nsnull);
	nsCOMPtr<nsILocalFile> binDir;
	nsCString s("C:\\Program Files\\Mozilla Firefox");
	rv = NS_NewNativeLocalFile(s, true, getter_AddRefs(binDir));

	nsCOMPtr<nsIServiceManager> servMan;
	rv = NS_InitXPCOM2(getter_AddRefs(servMan),binDir,nsnull);
	NS_ENSURE_SUCCESS (rv, false);

	nsCOMPtr<nsIComponentRegistrar> registrar =
do_QueryInterface(servMan);
	NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
	rv = registrar->AutoRegister(nsnull);
	NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to register.");

	nsCOMPtr<nsIPrefService> prefService
(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
	NS_ENSURE_SUCCESS (rv, false);

	nsCOMPtr<nsIPrefBranch> prefBranch;
	//Then we are reading javascript.enabled preferences.
	rv = prefService->GetBranch("",getter_AddRefs(prefBranch));
	NS_ENSURE_SUCCESS (rv, false);

	PRBool prefs;
	rv= prefBranch->GetBoolPref("javascript.enabled",&prefs);	//Always
getting true here...
	NS_ENSURE_SUCCESS(rv, false);
	rv = prefBranch->SetBoolPref("javascript.enabled",PR_FALSE);	//
Setting to false...
	NS_ENSURE_SUCCESS(rv, false);

	rv = prefBranch->GetBoolPref("javascript.enabled",&prefs);  //This
returns false but the //next time i execute i get true for
"javascript.enabled"
	NS_ENSURE_SUCCESS(rv, false);

I am new to this development... Please help..shall be highly thankful
Thanks in advance
0
ajay
7/1/2008 3:29:23 PM
mozilla.dev.tech.xpcom 1345 articles. 0 followers. Post Follow

1 Replies
1036 Views

Similar Articles

[PageSpeed] 24

Hi All,
Preferences are saving now. The issue was SavePrefFile(Prefs.js path
should be given here)..
For the time being I have hard coded the path but surely can't go
ahead with hard coded path.

I want to get the "Full Path of user Profile Folder of mozilla
firefox"...And for that matter tried the following API
	rv = NS_GetSpecialDirectory(NS_APP_PREFS_50_FILE,
getter_AddRefs(aFile1));
For my disappointment the above path in aFile1 is not coming out
correctly..I am not getting the significance of
NS_SHARED..

If somebody has any idea please share...

Thanks in advance

On Jul 1, 8:29 pm, "ajay....@gmail.com" <ajay....@gmail.com> wrote:
> Hi All,
> I am trying to modify user preferences in mozilla firefox 1.5.0.12.
> I am creating a dependent glue using Gecko 1.8.0.4(linking against
> xpcomglue.lib) using XPCOM technology.I could successfully build my
> application with Gecko 1.8.0.4 under GRE environment.
> The preferences interface comes out to be valid and reading the
> preference value is returning correctly. However,modifying the values
> is not taking place successfully.
> I am not sure whats happening here? I guess, I am not reading the
> correct preferences file.
> The following is the code that I am trying to execute.
>         XPCOMGlueStartup(nsnull);
>         nsCOMPtr<nsILocalFile> binDir;
>         nsCString s("C:\\Program Files\\Mozilla Firefox");
>         rv = NS_NewNativeLocalFile(s, true, getter_AddRefs(binDir));
>
>         nsCOMPtr<nsIServiceManager> servMan;
>         rv = NS_InitXPCOM2(getter_AddRefs(servMan),binDir,nsnull);
>         NS_ENSURE_SUCCESS (rv, false);
>
>         nsCOMPtr<nsIComponentRegistrar> registrar =
> do_QueryInterface(servMan);
>         NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
>         rv = registrar->AutoRegister(nsnull);
>         NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to register.");
>
>         nsCOMPtr<nsIPrefService> prefService
> (do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
>         NS_ENSURE_SUCCESS (rv, false);
>
>         nsCOMPtr<nsIPrefBranch> prefBranch;
>         //Then we are reading javascript.enabled preferences.
>         rv = prefService->GetBranch("",getter_AddRefs(prefBranch));
>         NS_ENSURE_SUCCESS (rv, false);
>
>         PRBool prefs;
>         rv= prefBranch->GetBoolPref("javascript.enabled",&prefs);      //Always
> getting true here...
>         NS_ENSURE_SUCCESS(rv, false);
>         rv = prefBranch->SetBoolPref("javascript.enabled",PR_FALSE);       //
> Setting to false...
>         NS_ENSURE_SUCCESS(rv, false);
>
>         rv = prefBranch->GetBoolPref("javascript.enabled",&prefs);  //This
> returns false but the //next time i execute i get true for
> "javascript.enabled"
>         NS_ENSURE_SUCCESS(rv, false);
>
> I am new to this development... Please help..shall be highly thankful
> Thanks in advance

0
ajay
7/3/2008 3:31:56 PM
Reply:

Similar Artilces:

XPCOM that use another XPCOM
Hi all, I have the following problem: I want to create a standalone application that uses an XPCOM module "A" written in C++ (a library). I want to create plugins for this application (.xpi package) that install another XPCOM module "B" that use the A XPCom library. I think I doesn't need to cross the interface and to write javascript code. How can I do this in a cross-platform manner? Does mozilla support the dynamic linking? Does it exist some pages of documentation about it? Thank you for your help, Lorenzo On 23 Mar, 14:48, Lorenzo <nos...@pl...

Purpose of dev-tech-xpcom
What's the purpose of this list? I used to think it was about XPCOM itself, basically for questions about the code in xpcom/**. However, that doesn't seem to be how everyone else uses it. In fact, it seems to be about all coding questions that are somewhat Firefox- or XULRunner-related. Basically what the platform or extension lists are supposed to be. Should we, therefore, delete this list/newsgroup? As it is used, it is redundant. -christian -- All the world's a stage, And all the men and women merely players: They have their exits and their entrances...

XPCOM, How to get access and modify text data entered by the user?
I'll explain in simple terms what I intend to do, so to be sure i don't miss any sollution. I want to be able to modify the text that the user enters in for example Google Docs or different blog websites and be able to alter that text before it is sent to the server. I need to display one text to the user on screen and send a different one to the server. What I need to know is how to get acces from XPCOM in the Mozilla framework to the objects (and what objects) that handle these operations. Any suggestions and ideeas are welcome. Thanks ...

XPCOM preferences
Is there a URL to a site that someone can point me that lists all the preferences that can be set on the preferences-service? I'd like to disable most of the things that are not required in headless operation as I'm running gecko through JavaXPCOM and a lot of stuff could be disabled/turned off. Thanks. Dzenno wrote: > Is there a URL to a site that someone can point me that lists all the > preferences that can be set on the preferences-service? There is no such list. The service is just a hashtable that maps string keys to values. Anyone can make up a name and...

XPCOM
Name: Jonny tango Email: jonnytangoattescodotnet Product: Firefox Summary: XPCOM Comments: have you fixed XPCOM problem with this update? Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-GB; rv:1.8.1.12) Gecko/20080201 Firefox/2.0.0.12 ...

xpcom
Hi, I posted this earlier and got no answers. Anyone care to drop a couple of lines on the subject? Hi, I have just started reading the documentation. I am just wondering about xpcom. Is it just a historical thing? i.e., if one is to write a new portable app, given how close java is performing compared to the native binary wouldn't it make sense to do it in java for simplicity and elegance? Surely modularization can be achieved in java or for that matter c#. Microsoft seems to be moving away from COM into managed code. Any thoughts? Thanks, Moheb moheb missaghi w...

XPCOM
Hi, I'm trying to build mozzilla in order to see a good example application of XPCOM. I read somewhere (http://www.ibm.com/ developerworks/webservices/library/co-xpcom3.html) that this was a good way to get a working version. However, that website seemed to be out of date. I would like to get some sort of "hello world" type of application of XPCOM on which I could conduct further experiements. Any suggestions about how I should get started? In trying to build an example app., I've been trying to build firefox following the directions at http://develope...

XPCOM
Hi, I'm trying to build mozzilla in order to see a good example application of XPCOM. I read somewhere (http://www.ibm.com/ developerworks/webservices/library/co-xpcom3.html) that this was a good way to get a working version. However, that website seemed to be out of date. I would like to get some sort of "hello world" type of application of XPCOM on which I could conduct further experiements. Any suggestions about how I should get started? In trying to build an example app., I've been trying to build firefox following the directions at http://developer....

XPCOM
I keep finding links for NS_StringToUTF16, NS_StringGetMutableData ? do such a functions exits ? Also found this http://developer.mozilla.org/en/docs/nsCStringEncoding but don't know where it should go Regards pete Pete Morgan wrote: > NS_StringToUTF16, NS_StringGetMutableData > > ? do such a functions exits ? NS_StringGetMutableData exists. NS_StringToUTF16 doesn't (the NS_String* functions all refer to strings that are in the UTF-16 encoding already), but NS_CStringToUTF16 does. > Also found this > http://developer.mozilla.org/en/doc...

xpcom
since xulplanet is no more, i miss the reference of the xpcom mail. didn't find it at mozdev neither. jef peeraer ...

XPCOM
Running Mozilla 1.1 and all is basically well, except for the occasional hang on shutdown. I get a message that XPCOM is not responding etc....I know it plays a part in Mozilla, but what does it do? I'd like to fix this, although its not a major issue. Thanks, XPCOM is a lightweight cross platform COM work-alike. It provides interfaces, factories, reference counting, QueryInterface based 'casting', auto pointers, and various other useful stuff. It is the foundation for modularity in mozilla You can get the source code here: http://lxr.mozilla.org/mozilla/source/xpco...

XPCOM how to integrate a XPCOM of thunderbird in firefox
Hello everybody! Well I have a question about the XPCOM. I want to developp a toolbar for firefox, which notify the arrival of new messages in my webmail account. This Webmail is a imap server. So to do that, i tried to download for mozilla source to get the composants wich allow to connect with imap protocol. When i downloaded it, i compiled all sources. Finally, i have many files : *.idl, *.h, *.xpt, so now i want to integrate them to firefox to use it. And i don't know how to do that? to be more precise i don't know what is the best solution to do this application .....

XPCOM Registeration for all users
Hi mlabs, I have created a Java Script XPCOM, "xyz.js" for protocol registration and I copy it in mozilla\components directory during installation of my application. But How do I locate %APPDATA% folder and delete compreg.dat for every user. Where should I run the following command: regxpcom -x "C:\Program Files\Mozilla Firefox\components" Q: I want this "xyz.js" file work for all users, is there any other way to force the registration to succeed without having to locate and delete compreg.dat for all users ??? Please let...

Use COM from XPCOM
Hi all, I' am new in the list and in XPCOM also. I' m trying to create an OPC Client XPCOM, to do that, I need to connect with an OPC Server in COM tecnology. Is that possible? Can I use a COM component from XPCOM? Somebody did that? CU Facundo ...