How do I set Mozilla preferences from Java when using the SWT browser widget?

I am using the SWT browser widget to embed the Mozilla browser in a Java process and I want at runtime I would like to change the browser: configuration settings programmatically from Java. Is it possible to do this? And if so, how?

+3


source to share


1 answer


You can use JavaXPCOM . Something like this should work:

import org.mozilla.xpcom.Mozilla;
import org.mozilla.interfaces.nsIServiceManager;
import org.mozilla.interfaces.nsIPrefBranch;

...

Mozilla mozilla = Mozilla.getInstance();
nsIServiceManager serviceManager = mozilla.getServiceManager();
nsIPrefBranch prefs = (nsIPrefBranch)serviceManager
    .getServiceByContractID("@mozilla.org/preferences-service;1",
        nsIPrefBranch.NS_IPREFBRANCH_IID);
prefs.setBoolPref("javascript.enabled", false);

      



If you cannot access JavaXPCOM, this is hardly doable.

+2


source







All Articles